Skip to content

Commit

Permalink
Merge pull request #262 from Ladicek/common-libraries-test
Browse files Browse the repository at this point in the history
Add test for indexing some common libraries
  • Loading branch information
Ladicek committed Sep 16, 2022
2 parents c770f78 + d86ad02 commit d15b246
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.junit.jupiter.api.Test;

public class RecursiveTypeParametersTest {
static class MyComparable<T extends Comparable<T>> {
static class MyComparable<T extends MyComparable<T>> {
}

static class DeepTypeParameterReference<T extends Collection<List<Queue<Map<? super T[][], Iterable<? extends T>>>>>> {
Expand Down Expand Up @@ -83,14 +83,14 @@ private void myComparable(Index index) {
assertEquals(1, typeParam.bounds().size());
Type bound = typeParam.bounds().get(0);
assertEquals(Type.Kind.PARAMETERIZED_TYPE, bound.kind());
assertEquals(DotName.createSimple(Comparable.class.getName()), bound.asParameterizedType().name());
assertEquals(DotName.createSimple(MyComparable.class.getName()), bound.asParameterizedType().name());
assertEquals(1, bound.asParameterizedType().arguments().size());
Type boundTypeArg = bound.asParameterizedType().arguments().get(0);
assertEquals(Type.Kind.TYPE_VARIABLE_REFERENCE, boundTypeArg.kind());
assertEquals("T", boundTypeArg.asTypeVariableReference().identifier());
assertNotNull(boundTypeArg.asTypeVariableReference().follow());
assertSame(typeParam, boundTypeArg.asTypeVariableReference().follow());
assertEquals("T extends java.lang.Comparable<T>", typeParam.toString());
assertEquals("T extends org.jboss.jandex.test.RecursiveTypeParametersTest$MyComparable<T>", typeParam.toString());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.junit.jupiter.api.Test;

public class RecursiveTypeParametersWithAnnotationsTest {
static class MyComparable<@MyAnnotation("1") T extends @MyAnnotation("2") Comparable<@MyAnnotation("3") T>> {
static class MyComparable<@MyAnnotation("1") T extends @MyAnnotation("2") MyComparable<@MyAnnotation("3") T>> {
}

static class MyBuilder<@MyAnnotation("1") T, @MyAnnotation("2") THIS extends @MyAnnotation("3") MyBuilder<@MyAnnotation("4") T, @MyAnnotation("5") THIS>> {
Expand Down Expand Up @@ -52,7 +52,7 @@ private void myComparable(Index index) {
assertEquals(1, typeParam.bounds().size());
Type bound = typeParam.bounds().get(0);
assertEquals(Type.Kind.PARAMETERIZED_TYPE, bound.kind());
assertEquals(DotName.createSimple(Comparable.class.getName()), bound.asParameterizedType().name());
assertEquals(DotName.createSimple(MyComparable.class.getName()), bound.asParameterizedType().name());
assertEquals(1, bound.asParameterizedType().arguments().size());
assertTypeAnnotation(bound, "2");

Expand All @@ -64,7 +64,7 @@ private void myComparable(Index index) {
assertSame(typeParam, boundTypeArg.asTypeVariableReference().follow());

assertEquals(
"@MyAnnotation(\"1\") T extends java.lang.@MyAnnotation(\"2\") Comparable<@MyAnnotation(\"3\") T>",
"@MyAnnotation(\"1\") T extends org.jboss.jandex.test.@MyAnnotation(\"2\") RecursiveTypeParametersWithAnnotationsTest$MyComparable<@MyAnnotation(\"3\") T>",
typeParam.toString());
}

Expand Down
121 changes: 121 additions & 0 deletions maven-plugin/src/it/someLibraries/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-build-parent</artifactId>
<version>31</version>
</parent>

<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin-someLibraries</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.5.0</version>
</dependency>
<dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
<version>3.6.4</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.9.1-1</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>1.7.10</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>@version.maven-compiler-plugin@</version>
</plugin>

<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
<configuration>
<processDefaultFileSet>false</processDefaultFileSet>
<indexDir>${project.build.directory}/index</indexDir>
<fileSets>
<fileSet>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</fileSet>
<fileSet>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
</fileSet>
<fileSet>
<dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
</dependency>
</fileSet>
<fileSet>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
</dependency>
</fileSet>
<fileSet>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-common</artifactId>
</dependency>
</fileSet>
<fileSet>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>
</fileSet>
<fileSet>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk7</artifactId>
</dependency>
</fileSet>
<fileSet>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</dependency>
</fileSet>
</fileSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
9 changes: 9 additions & 0 deletions maven-plugin/src/it/someLibraries/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import org.jboss.jandex.IndexReader

// index dir explicitly configured
def jandexFile = new File(basedir, 'target/index/jandex.idx')
assert jandexFile.exists() : "File ${jandexFile} does not exist"
assert jandexFile.length() > 0 : "File ${jandexFile} is empty"

index = new IndexReader(jandexFile.newInputStream()).read()
assert index.getKnownClasses().size() > 0 : "Index ${jandexFile} contains no class"

0 comments on commit d15b246

Please sign in to comment.