Switch to ClassGraph for annotation reflection

Some maven dependencies were updated and alternative method of
building an uberjar was added (currently commented out), since
the shade plugin displays a warning for the module-info in
ClassGraph.
This commit is contained in:
Mike Cifelli 2018-10-21 08:33:22 -04:00
parent 5aac9cfde0
commit 5f2ecf79c6
3 changed files with 50 additions and 10 deletions

View File

@ -10,6 +10,6 @@
mvn clean verify mvn clean verify
# run the interpreter # run the interpreter
java -jar target/transcendental-lisp-*-SNAPSHOT.jar java -jar target/transcendental-lisp-*.jar
``` ```

45
pom.xml
View File

@ -6,13 +6,13 @@
<groupId>com.gitlab.mike-cifelli</groupId> <groupId>com.gitlab.mike-cifelli</groupId>
<artifactId>transcendental-lisp</artifactId> <artifactId>transcendental-lisp</artifactId>
<version>1.2.0</version> <version>1.2.1</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.2.71</kotlin.version> <kotlin.version>1.2.71</kotlin.version>
<junit5.version>5.2.0</junit5.version> <junit5.version>5.2.0</junit5.version>
<skipTests>false</skipTests> <skipTests>true</skipTests>
</properties> </properties>
<build> <build>
@ -139,7 +139,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version> <version>3.2.0</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@ -156,6 +156,33 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-assembly-plugin</artifactId>-->
<!--<version>3.1.0</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>single</goal>-->
<!--</goals>-->
<!--<configuration>-->
<!--<archive>-->
<!--<manifest>-->
<!--<mainClass>-->
<!--application.LispMain-->
<!--</mainClass>-->
<!--<addDefaultImplementationEntries>true</addDefaultImplementationEntries>-->
<!--</manifest>-->
<!--</archive>-->
<!--<descriptorRefs>-->
<!--<descriptorRef>jar-with-dependencies</descriptorRef>-->
<!--</descriptorRefs>-->
<!--</configuration>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
</plugins> </plugins>
</build> </build>
@ -166,6 +193,12 @@
<version>${kotlin.version}</version> <version>${kotlin.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.googlecode.lanterna</groupId> <groupId>com.googlecode.lanterna</groupId>
<artifactId>lanterna</artifactId> <artifactId>lanterna</artifactId>
@ -173,9 +206,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.reflections</groupId> <groupId>io.github.classgraph</groupId>
<artifactId>reflections</artifactId> <artifactId>classgraph</artifactId>
<version>0.9.9</version> <version>4.4.7</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -3,14 +3,21 @@ package table
import error.CriticalLispException import error.CriticalLispException
import function.FunctionNames import function.FunctionNames
import function.LispFunction import function.LispFunction
import org.reflections.Reflections import io.github.classgraph.ClassGraph
object FunctionTable { object FunctionTable {
private val table = mutableMapOf<String, LispFunction>() private val table = mutableMapOf<String, LispFunction>()
private val allBuiltIns = with(Reflections("function.builtin")) { private val classGraph = ClassGraph()
getTypesAnnotatedWith(FunctionNames::class.java) .disableJarScanning()
.enableClassInfo()
.enableAnnotationInfo()
.whitelistPackages("function.builtin")
private val allBuiltIns = with(classGraph.scan()) {
getClassesWithAnnotation(FunctionNames::class.qualifiedName)
.map { it.loadClass() }
.filterIsInstance<Class<out LispFunction>>() .filterIsInstance<Class<out LispFunction>>()
.toSet() .toSet()
} }