From af4e221fa85c8a171581e9136528d2255c351445 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Sun, 31 Mar 2019 08:15:02 +0800 Subject: [PATCH 1/3] BAEL-2779 Guide to classgraph library --- libraries/pom.xml | 7 ++ .../classgraph/ClassGraphUnitTest.java | 78 +++++++++++++++++++ .../classgraph/ClassWithAnnotation.java | 5 ++ .../classgraph/FieldWithAnnotation.java | 7 ++ .../classgraph/MethodWithAnnotation.java | 8 ++ .../MethodWithAnnotationParameterDao.java | 8 ++ .../MethodWithAnnotationParameterWeb.java | 8 ++ .../baeldung/classgraph/TestAnnotation.java | 14 ++++ .../src/test/resources/classgraph/my.config | 1 + 9 files changed, 136 insertions(+) create mode 100644 libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java create mode 100644 libraries/src/test/resources/classgraph/my.config diff --git a/libraries/pom.xml b/libraries/pom.xml index 7823732224..a6179a843d 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -699,6 +699,12 @@ ${reflections.version} + + io.github.classgraph + classgraph + ${classgraph.version} + + @@ -916,6 +922,7 @@ 2.7.1 3.6 0.9.11 + 4.8.22 diff --git a/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java b/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java new file mode 100644 index 0000000000..5767396948 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java @@ -0,0 +1,78 @@ +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 checker) { + try (ScanResult result = new ClassGraph().enableAllInfo() + .whitelistPackages(getClass().getPackage().getName()) + .scan()) + { + checker.accept(result); + } + } +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java new file mode 100644 index 0000000000..0f3eeef293 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java @@ -0,0 +1,5 @@ +package com.baeldung.classgraph; + +@TestAnnotation +public class ClassWithAnnotation { +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java new file mode 100644 index 0000000000..c5d1cc6062 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java @@ -0,0 +1,7 @@ +package com.baeldung.classgraph; + +public class FieldWithAnnotation { + + @TestAnnotation + private String s; +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java new file mode 100644 index 0000000000..12d0c9927c --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotation { + + @TestAnnotation + public void service() { + } +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java new file mode 100644 index 0000000000..9e38f42013 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotationParameterDao { + + @TestAnnotation("dao") + public void service() { + } +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java new file mode 100644 index 0000000000..1ef3d46b6f --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotationParameterWeb { + + @TestAnnotation("web") + public void service() { + } +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java new file mode 100644 index 0000000000..f47ec180a9 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java @@ -0,0 +1,14 @@ +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 ""; +} diff --git a/libraries/src/test/resources/classgraph/my.config b/libraries/src/test/resources/classgraph/my.config new file mode 100644 index 0000000000..b99df573f6 --- /dev/null +++ b/libraries/src/test/resources/classgraph/my.config @@ -0,0 +1 @@ +my data \ No newline at end of file From 732a7413f419a40123e263ab2854c3d2a306d451 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Mon, 22 Apr 2019 08:13:32 +0800 Subject: [PATCH 2/3] Revert "BAEL-2779 Guide to classgraph library" This reverts commit af4e221f as it was asked to move it to libraries-2 --- libraries/pom.xml | 7 -- .../classgraph/ClassGraphUnitTest.java | 78 ------------------- .../classgraph/ClassWithAnnotation.java | 5 -- .../classgraph/FieldWithAnnotation.java | 7 -- .../classgraph/MethodWithAnnotation.java | 8 -- .../MethodWithAnnotationParameterDao.java | 8 -- .../MethodWithAnnotationParameterWeb.java | 8 -- .../baeldung/classgraph/TestAnnotation.java | 14 ---- .../src/test/resources/classgraph/my.config | 1 - 9 files changed, 136 deletions(-) delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java delete mode 100644 libraries/src/test/resources/classgraph/my.config diff --git a/libraries/pom.xml b/libraries/pom.xml index a6179a843d..7823732224 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -699,12 +699,6 @@ ${reflections.version} - - io.github.classgraph - classgraph - ${classgraph.version} - - @@ -922,7 +916,6 @@ 2.7.1 3.6 0.9.11 - 4.8.22 diff --git a/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java b/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java deleted file mode 100644 index 5767396948..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java +++ /dev/null @@ -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 checker) { - try (ScanResult result = new ClassGraph().enableAllInfo() - .whitelistPackages(getClass().getPackage().getName()) - .scan()) - { - checker.accept(result); - } - } -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java deleted file mode 100644 index 0f3eeef293..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.classgraph; - -@TestAnnotation -public class ClassWithAnnotation { -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java deleted file mode 100644 index c5d1cc6062..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.classgraph; - -public class FieldWithAnnotation { - - @TestAnnotation - private String s; -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java deleted file mode 100644 index 12d0c9927c..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.classgraph; - -public class MethodWithAnnotation { - - @TestAnnotation - public void service() { - } -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java deleted file mode 100644 index 9e38f42013..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.classgraph; - -public class MethodWithAnnotationParameterDao { - - @TestAnnotation("dao") - public void service() { - } -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java deleted file mode 100644 index 1ef3d46b6f..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.classgraph; - -public class MethodWithAnnotationParameterWeb { - - @TestAnnotation("web") - public void service() { - } -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java deleted file mode 100644 index f47ec180a9..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java +++ /dev/null @@ -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 ""; -} diff --git a/libraries/src/test/resources/classgraph/my.config b/libraries/src/test/resources/classgraph/my.config deleted file mode 100644 index b99df573f6..0000000000 --- a/libraries/src/test/resources/classgraph/my.config +++ /dev/null @@ -1 +0,0 @@ -my data \ No newline at end of file From 541e0cc9d55e28c095c757f95e6330fe94b8d92e Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Mon, 22 Apr 2019 08:17:20 +0800 Subject: [PATCH 3/3] BAEL-2779 Guide to classgraph library --- libraries-2/pom.xml | 12 +++ .../classgraph/ClassGraphUnitTest.java | 74 +++++++++++++++++++ .../classgraph/ClassWithAnnotation.java | 5 ++ .../classgraph/FieldWithAnnotation.java | 7 ++ .../classgraph/MethodWithAnnotation.java | 8 ++ .../MethodWithAnnotationParameterDao.java | 8 ++ .../MethodWithAnnotationParameterWeb.java | 8 ++ .../baeldung/classgraph/TestAnnotation.java | 14 ++++ .../src/test/resources/classgraph/my.config | 1 + 9 files changed, 137 insertions(+) create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java create mode 100644 libraries-2/src/test/resources/classgraph/my.config diff --git a/libraries-2/pom.xml b/libraries-2/pom.xml index a839f56b56..965cb195bf 100644 --- a/libraries-2/pom.xml +++ b/libraries-2/pom.xml @@ -30,6 +30,16 @@ + + org.assertj + assertj-core + ${assertj.version} + + + io.github.classgraph + classgraph + ${classgraph.version} + org.jbpm jbpm-test @@ -38,6 +48,8 @@ + 3.6.2 + 4.8.22 6.0.0.Final diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java b/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java new file mode 100644 index 0000000000..3dc99e6a32 --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.classgraph; + +import io.github.classgraph.*; +import org.junit.Test; + +import java.io.IOException; +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 checker) { + try (ScanResult result = new ClassGraph().enableAllInfo() + .whitelistPackages(getClass().getPackage().getName()) + .scan()) + { + checker.accept(result); + } + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java new file mode 100644 index 0000000000..fe476769a6 --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java @@ -0,0 +1,5 @@ +package com.baeldung.classgraph; + +@TestAnnotation +public class ClassWithAnnotation { +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java new file mode 100644 index 0000000000..f72a7621f9 --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java @@ -0,0 +1,7 @@ +package com.baeldung.classgraph; + +public class FieldWithAnnotation { + + @TestAnnotation + private String s; +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java new file mode 100644 index 0000000000..29a59c09ea --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotation { + + @TestAnnotation + public void service() { + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java new file mode 100644 index 0000000000..f01c2743eb --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotationParameterDao { + + @TestAnnotation("dao") + public void service() { + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java new file mode 100644 index 0000000000..bf01f7d23c --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotationParameterWeb { + + @TestAnnotation("web") + public void service() { + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java new file mode 100644 index 0000000000..e3f5df92ed --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java @@ -0,0 +1,14 @@ +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 ""; +} \ No newline at end of file diff --git a/libraries-2/src/test/resources/classgraph/my.config b/libraries-2/src/test/resources/classgraph/my.config new file mode 100644 index 0000000000..b99df573f6 --- /dev/null +++ b/libraries-2/src/test/resources/classgraph/my.config @@ -0,0 +1 @@ +my data \ No newline at end of file