-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/test/java/io/github/classgraph/issues/issue766/ClassgraphIssue766.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.github.classgraph.issues.issue766; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.URL; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.github.classgraph.ClassGraph; | ||
import io.github.classgraph.ScanResult; | ||
|
||
public class ClassgraphIssue766 { | ||
|
||
@Test | ||
public void testURLs() { | ||
final URL url = ClassgraphIssue766.class.getResource("/issue766/ProjectWithAnnotations.iar"); | ||
|
||
final String fileUrl = "file:" + url.getPath(); | ||
final String jarFileUrl = "jar:file:" + url.getPath(); | ||
final String jarUrl = "jar:///" + url.getPath(); | ||
|
||
assertThat(scan("javax.annotation.ManagedBean", fileUrl)).containsOnly("ch.ivyteam.test.MyManagedBean"); | ||
assertThat(scan("javax.annotation.ManagedBean", jarFileUrl)).containsOnly("ch.ivyteam.test.MyManagedBean"); | ||
assertThat(scan("javax.annotation.ManagedBean", jarUrl)).containsOnly("ch.ivyteam.test.MyManagedBean"); | ||
} | ||
|
||
public static Set<String> scan(final String annotation, final String url) { | ||
final ClassGraph classGraph = new ClassGraph() | ||
.overrideClasspath(Set.of(url)).disableNestedJarScanning().enableAnnotationInfo(); | ||
try (ScanResult result = classGraph.scan()) { | ||
return result.getClassesWithAnnotation(annotation).getStandardClasses().getNames().stream() | ||
.collect(Collectors.toSet()); | ||
} | ||
} | ||
} |
Binary file not shown.