Repository: orika-mapper/orika
Pull request #274 (2018-07-11 23:22:12)

Make sure java8 tests run on any jdk >= 8
- Make sure java8 tests run on any jdk >= 8
- Remove duplicated javassist.version property defined in orika-tests-jdk8 pom file
- Use fast-classpath-scanner library for finding subclasses - this library understands Java 9 modules


Patch:
diff --git a/pom.xml b/pom.xml
index e4c8dcfd..b1782ac0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -352,7 +352,7 @@
         <profile>
             <id>include-jdk8-test</id>
             <activation>
-                <jdk>1.8</jdk>
+                <jdk>[1.8</jdk>
             </activation>
             <modules>
                 <module>tests-jdk8</module>


Test patch:
diff --git a/tests-jdk8/pom.xml b/tests-jdk8/pom.xml
index 2aa49c3b..34f7e5ba 100644
--- a/tests-jdk8/pom.xml
+++ b/tests-jdk8/pom.xml
@@ -10,7 +10,6 @@
 	<name>Orika - tests for JDK8</name>
 
 	<properties>
-		<javassist.version>3.22.0-GA</javassist.version>
 		<maven.compiler.source>1.8</maven.compiler.source>
 		<maven.compiler.target>1.8</maven.compiler.target>
 	</properties>
@@ -66,6 +65,12 @@
 			<scope>compile</scope>
 		</dependency>
 
+		<dependency>
+			<groupId>io.github.lukehutch</groupId>
+			<artifactId>fast-classpath-scanner</artifactId>
+			<version>3.1.9</version>
+		</dependency>
+
 	</dependencies>
 
 	<build>
diff --git a/tests-jdk8/src/test/java/ma/glasnost/orika/test/jdk8/JavaDateApiTest.java b/tests-jdk8/src/test/java/ma/glasnost/orika/test/jdk8/JavaDateApiTest.java
index 561c3bb1..6bab74ec 100644
--- a/tests-jdk8/src/test/java/ma/glasnost/orika/test/jdk8/JavaDateApiTest.java
+++ b/tests-jdk8/src/test/java/ma/glasnost/orika/test/jdk8/JavaDateApiTest.java
@@ -4,10 +4,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.notNullValue;
 
-import java.io.File;
 import java.lang.reflect.Modifier;
-import java.net.URL;
-import java.net.URLDecoder;
 import java.time.DayOfWeek;
 import java.time.Duration;
 import java.time.Instant;
@@ -26,13 +23,11 @@ import java.time.ZonedDateTime;
 import java.time.temporal.TemporalAccessor;
 import java.time.temporal.TemporalAmount;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
+import java.util.Comparator;
 import java.util.List;
 import java.util.stream.Collectors;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
 
+import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -171,52 +166,14 @@ public class JavaDateApiTest {
     
     
     @SuppressWarnings("unchecked")
-    private <T> List<Class<T>> getJdkClasses(String rootPackage, final Class<T> type) throws Exception {
-        
-        String rootPackagePath = rootPackage.replace('.', '/');
-        String path = type.getName().replace('.', '/') + ".class";
-        URL resource = ClassLoader.getSystemClassLoader().getResource(path);
-        if (resource == null) {
-            throw new RuntimeException("Unexpected problem: No resource for " + path);
-        }
-        String filePath = resource.getFile();
-        File jarFile = getJarFile(filePath);
-        
-        List<Class<T>> subTypes = new ArrayList<>();
-        
-        try (ZipFile zipFile = new ZipFile(jarFile)) {
-            Enumeration<? extends ZipEntry> entries = zipFile.entries();
-            while (entries.hasMoreElements()) {
-                ZipEntry zipEntry = entries.nextElement();
-                if (zipEntry.getName().startsWith(rootPackagePath)) {
-                    String className = zipEntry.getName();
-                    if (className.endsWith(".class")) {
-                        className = className.substring(0, className.length() - ".class".length());
-                        className = className.replace('/', '.');
-                        Class<?> clazz = Class.forName(className);
-                        if (type.isAssignableFrom(clazz)) {
-                            subTypes.add((Class<T>) clazz);
-                        }
-                    }
-                }
-            }
-        }
-        Collections.sort(subTypes, (type1, type2) -> type1.getName().compareTo(type2.getName()));
-        
+    private <T> List<Class<? extends T>> getJdkClasses(String rootPackage, final Class<T> type) {
+        List<Class<? extends T>> subTypes = new ArrayList<>();
+        new FastClasspathScanner("!!",rootPackage)
+                .matchClassesImplementing(type, subTypes::add)
+                .scan();
+        subTypes.sort(Comparator.comparing(Class::getName));
         return subTypes;
     }
-
-    private File getJarFile(String filePath) throws Exception {
-        String jarFilePath = filePath;
-        jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
-        if (jarFilePath.startsWith("file:")) {
-            jarFilePath = jarFilePath.substring(jarFilePath.lastIndexOf("file:") + "file:".length(), jarFilePath.length());
-        }
-        if (jarFilePath.contains(".jar!")) {
-        	jarFilePath = jarFilePath.substring(0, jarFilePath.lastIndexOf(".jar!"))+ ".jar";
-        }
-        return new File(jarFilePath);
-    }
     
     public static class A {