scanner8

jdk 1.8下的扫描工具

License

License

GroupId

GroupId

com.whosly
ArtifactId

ArtifactId

scanner8
Last Version

Last Version

1.3.0-RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

scanner8
jdk 1.8下的扫描工具
Project URL

Project URL

https://github.com/yueny/scanner
Source Code Management

Source Code Management

https://github.com/yueny/scanner

Download scanner8

How to add to project

<!-- https://jarcasting.com/artifacts/com.whosly/scanner8/ -->
<dependency>
    <groupId>com.whosly</groupId>
    <artifactId>scanner8</artifactId>
    <version>1.3.0-RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/com.whosly/scanner8/
implementation 'com.whosly:scanner8:1.3.0-RELEASE'
// https://jarcasting.com/artifacts/com.whosly/scanner8/
implementation ("com.whosly:scanner8:1.3.0-RELEASE")
'com.whosly:scanner8:jar:1.3.0-RELEASE'
<dependency org="com.whosly" name="scanner8" rev="1.3.0-RELEASE">
  <artifact name="scanner8" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.whosly', module='scanner8', version='1.3.0-RELEASE')
)
libraryDependencies += "com.whosly" % "scanner8" % "1.3.0-RELEASE"
[com.whosly/scanner8 "1.3.0-RELEASE"]

Dependencies

compile (4)

Group / Artifact Type Version
org.apache.commons : commons-lang3 jar 3.9
org.apache.commons : commons-collections4 jar 4.0
com.google.guava : guava jar 27.0.1-jre
org.slf4j : slf4j-api jar 1.7.25

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.8

test (4)

Group / Artifact Type Version
org.slf4j : jcl-over-slf4j jar 1.7.25
org.slf4j : log4j-over-slf4j jar 1.7.25
ch.qos.logback : logback-classic jar 1.2.3
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

scanner

介绍

scanner 为一个脱离 spring 环境的包路径(package)下的类扫描工具。 用于获取指定包下的Class类,同时可根据指定Annotation或父类接口进行过滤。

使用说明

项目已上传Maven中央仓库。

https://search.maven.org/search?q=whosly

https://mvnrepository.com/search?q=whosly

1.注意事项

  • 项目JDK 版本 1.8+
  • 基线 yueny-parent 1.3.0。 请提前部署。

https://github.com/yueny/base/blob/master/yueny/pom.xml

  • 组件依赖明细
        <dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-collections4</artifactId>
		</dependency>
		<dependency>
	        <groupId>org.projectlombok</groupId> 
	        <artifactId>lombok</artifactId>
	    </dependency>
		<dependency>
			<groupId>com.google.guava</groupId>
			<artifactId>guava</artifactId>
		</dependency>

2.依赖

  • 添加依赖 在项目添加以下依赖包:
<dependency>
    <groupId>com.whosly</groupId>
    <artifactId>scanner8</artifactId>
    <version>version</version>
</dependency>

3. 使用手册

  • 示例代码
package com.whosly.scanner.util;

import com.google.common.collect.Sets;
import com.whosly.scanner.Scanner;
import com.whosly.scanner.api.IScanner;
import com.whosly.scanner.config.ScanConfig;
import com.whosly.scanner.util.st.ISt;
import com.whosly.scanner.util.st.anno.St;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

/**
 * @Author yueny09 <deep_blue_yang@126.com>
 * @Date 2019-09-04 21:18
 */
@Slf4j
public class ScannerTest {
    private final List<String> scanPkgs = Arrays.asList(
            "org", "lombok", "com.sun", "javax",
            "com.whosly");
    private IScanner scanner = new Scanner();

    /**
     * 测试用例:扫描多个包
     */
    @Test
    public void testScan() {
        List<Class<?>> classList = scanner.scan(scanPkgs);
        Assert.assertTrue(classList.size() > 0);
        log.info("共扫描到{}个类", classList.size());
    }

    /**
     *
     */
    @Test
    public void testScanByAnnotation() {
        List<Class<?>> classList = scanner.scan(scanPkgs, Deprecated.class);
        Assert.assertTrue(classList.size() > 0);
        log.info("共扫描到{}个类", classList.size());

        classList = scanner.scan(scanPkgs, St.class);
        Assert.assertTrue(classList.size() == 3);
        log.info("共扫描到{}个类", classList.size());

        ScanConfig scanConfig = ScanConfig.builder()
                .basePackages(scanPkgs)
                .annotation(St.class)
                .build();
        log.info("扫描配置: {}.", scanConfig);
    }


    /**
     */
    @Test
    public void testScanByClass() {
        List<Class<?>> classList = scanner.scan(Sets.newHashSet(Arrays.asList(
                "com.aaa",  "com.whosly")), ISt.class);
        Assert.assertTrue(classList.size() == 7);
        log.info("共扫描到{}个类:{}.", classList.size(), classList);

        classList = scanner.scan(Sets.newHashSet(Arrays.asList(
                "com.aaa",  "com.whosly")), ISt.class, Arrays.asList(ScanConfig.ClazzType.INTERFACE, ScanConfig.ClazzType.CLASS, ScanConfig.ClazzType.ABSTRACT));
        Assert.assertTrue(classList.size() == 8);
        log.info("共扫描到{}个类:{}.", classList.size(), classList);

        classList = scanner.scan(Sets.newHashSet(Arrays.asList(
                "com.aaa",  "com.whosly")), ISt.class, Arrays.asList(ScanConfig.ClazzType.INTERFACE, ScanConfig.ClazzType.CLASS));
        Assert.assertTrue(classList.size() == 7);
        log.info("共扫描到{}个类:{}.", classList.size(), classList);

        classList = scanner.scan(Sets.newHashSet(Arrays.asList(
                "com.aaa",  "com.whosly")), ISt.class, Arrays.asList(ScanConfig.ClazzType.INTERFACE));
        Assert.assertTrue(classList.size() == 2);
        log.info("共扫描到{}个类:{}.", classList.size(), classList);

        classList = scanner.scan(Sets.newHashSet(Arrays.asList(
                "com.aaa",  "com.whosly")), ISt.class, Arrays.asList(ScanConfig.ClazzType.CLASS));
        Assert.assertTrue(classList.size() == 5);
        log.info("共扫描到{}个类:{}.", classList.size(), classList);

        classList = scanner.scan(Sets.newHashSet(Arrays.asList(
                "com.aaa",  "com.whosly")), ISt.class, Arrays.asList(ScanConfig.ClazzType.ABSTRACT));
        Assert.assertTrue(classList.size() == 1);
        log.info("共扫描到{}个类:{}.", classList.size(), classList);

    }

}

联系方式

Versions

Version
1.3.0-RELEASE
1.2.0-RELEASE