Revert "BAEL-2779 Guide to classgraph library"
This reverts commit af4e221f as it was asked to move it to libraries-2
This commit is contained in:
parent
7acfa36d59
commit
732a7413f4
@ -699,12 +699,6 @@
|
|||||||
<version>${reflections.version}</version>
|
<version>${reflections.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.classgraph</groupId>
|
|
||||||
<artifactId>classgraph</artifactId>
|
|
||||||
<version>${classgraph.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
@ -922,7 +916,6 @@
|
|||||||
<mockftpserver.version>2.7.1</mockftpserver.version>
|
<mockftpserver.version>2.7.1</mockftpserver.version>
|
||||||
<commons-net.version>3.6</commons-net.version>
|
<commons-net.version>3.6</commons-net.version>
|
||||||
<reflections.version>0.9.11</reflections.version>
|
<reflections.version>0.9.11</reflections.version>
|
||||||
<classgraph.version>4.8.22</classgraph.version>
|
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
package com.baeldung.classgraph;
|
|
||||||
|
|
||||||
import io.github.classgraph.*;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
public class ClassGraphUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenClassAnnotationFilterIsDefined_thenTargetClassesCanBeFound() {
|
|
||||||
doTest(result -> {
|
|
||||||
ClassInfoList classInfos = result.getClassesWithAnnotation(TestAnnotation.class.getName());
|
|
||||||
assertThat(classInfos).extracting(ClassInfo::getName).contains(ClassWithAnnotation.class.getName());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenMethodAnnotationFilterIsDefined_thenTargetClassesCanBeFound() {
|
|
||||||
doTest(result -> {
|
|
||||||
ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName());
|
|
||||||
assertThat(classInfos).extracting(ClassInfo::getName).contains(MethodWithAnnotation.class.getName());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenMethodAnnotationValueFilterIsDefined_thenTargetClassesCanBeFound() {
|
|
||||||
doTest(result -> {
|
|
||||||
ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName());
|
|
||||||
ClassInfoList filteredClassInfos = classInfos.filter(classInfo -> {
|
|
||||||
return classInfo.getMethodInfo().stream().anyMatch(methodInfo -> {
|
|
||||||
AnnotationInfo annotationInfo = methodInfo.getAnnotationInfo(TestAnnotation.class.getName());
|
|
||||||
if (annotationInfo == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "web".equals(annotationInfo.getParameterValues().getValue("value"));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
assertThat(filteredClassInfos)
|
|
||||||
.extracting(ClassInfo::getName)
|
|
||||||
.contains(MethodWithAnnotationParameterWeb.class.getName());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenFieldAnnotationFilterIsDefined_thenTargetClassesCanBeFound() {
|
|
||||||
doTest(result -> {
|
|
||||||
ClassInfoList classInfos = result.getClassesWithFieldAnnotation(TestAnnotation.class.getName());
|
|
||||||
assertThat(classInfos).extracting(ClassInfo::getName).contains(FieldWithAnnotation.class.getName());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenResourceIsUsed_thenItCanBeFoundAndLoaded() throws IOException {
|
|
||||||
try (ScanResult result = new ClassGraph().whitelistPaths("classgraph").scan()) {
|
|
||||||
ResourceList resources = result.getResourcesWithExtension("config");
|
|
||||||
assertThat(resources).extracting(Resource::getPath).containsOnly("classgraph/my.config");
|
|
||||||
assertThat(resources.get(0).getContentAsString()).isEqualTo("my data");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doTest(Consumer<ScanResult> checker) {
|
|
||||||
try (ScanResult result = new ClassGraph().enableAllInfo()
|
|
||||||
.whitelistPackages(getClass().getPackage().getName())
|
|
||||||
.scan())
|
|
||||||
{
|
|
||||||
checker.accept(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package com.baeldung.classgraph;
|
|
||||||
|
|
||||||
@TestAnnotation
|
|
||||||
public class ClassWithAnnotation {
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package com.baeldung.classgraph;
|
|
||||||
|
|
||||||
public class FieldWithAnnotation {
|
|
||||||
|
|
||||||
@TestAnnotation
|
|
||||||
private String s;
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package com.baeldung.classgraph;
|
|
||||||
|
|
||||||
public class MethodWithAnnotation {
|
|
||||||
|
|
||||||
@TestAnnotation
|
|
||||||
public void service() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package com.baeldung.classgraph;
|
|
||||||
|
|
||||||
public class MethodWithAnnotationParameterDao {
|
|
||||||
|
|
||||||
@TestAnnotation("dao")
|
|
||||||
public void service() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package com.baeldung.classgraph;
|
|
||||||
|
|
||||||
public class MethodWithAnnotationParameterWeb {
|
|
||||||
|
|
||||||
@TestAnnotation("web")
|
|
||||||
public void service() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package com.baeldung.classgraph;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.*;
|
|
||||||
|
|
||||||
@Target({TYPE, METHOD, FIELD})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface TestAnnotation {
|
|
||||||
|
|
||||||
String value() default "";
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
my data
|
|
Loading…
x
Reference in New Issue
Block a user