Skip to content

Commit

Permalink
Fix travis build error
Browse files Browse the repository at this point in the history
  • Loading branch information
NooBxGockeL committed Nov 25, 2016
1 parent 64e25c8 commit 32addf6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
22 changes: 17 additions & 5 deletions urm-core/src/main/java/de/markusmo3/urm/DomainClassFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.FilterBuilder;

import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
import java.util.logging.Logger;
Expand All @@ -18,8 +19,7 @@ public class DomainClassFinder {
private static final Logger logger = Logger.getLogger(DomainClassFinder.class.getName());

private static final String URM_PACKAGE = "de.markusmo3.urm";
private static final boolean ALLOW_FINDING_INTERNAL_CLASSES = Boolean.parseBoolean(
System.getProperty("de.markusmo3.urm.DomainClassFinder.allowFindingInternalClasses", "false"));
public static boolean ALLOW_FINDING_INTERNAL_CLASSES;

public static ClassLoader[] classLoaders;

Expand All @@ -43,10 +43,12 @@ private static boolean isNotAnonymousClass(Class<?> clazz) {
}

private static Set<Class<?>> getClasses(URLClassLoader classLoader, String packageName) {
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
List<ClassLoader> classLoadersList = new LinkedList<>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
classLoadersList.add(classLoader);
if (classLoader != null) {
classLoadersList.add(classLoader);
}

classLoaders = classLoadersList.toArray(new ClassLoader[0]);

Expand All @@ -56,16 +58,26 @@ private static Set<Class<?>> getClasses(URLClassLoader classLoader, String packa
filter.exclude(FilterBuilder.prefix(URM_PACKAGE));
}

Collection<URL> urls = ClasspathHelper.forClassLoader(classLoaders);
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(classLoaders))
.setUrls(urls)
.filterInputsBy(filter)
.addClassLoaders(classLoadersList)
);
logger.severe("#mo3-debug# ClassLoaders: " + classLoadersList.toString()
+ "\n urls: " + urls
+ "\n ALLOW_FINDING_INTERNAL_CLASSES: " + ALLOW_FINDING_INTERNAL_CLASSES
);
return Sets.union(reflections.getSubTypesOf(Object.class),
reflections.getSubTypesOf(Enum.class));
}

public static boolean isAllowFindingInternalClasses() {
return ALLOW_FINDING_INTERNAL_CLASSES |= Boolean.parseBoolean(
System.getProperty("de.markusmo3.urm.DomainClassFinder.allowFindingInternalClasses", "false"));
}

private DomainClassFinder() {
// private constructor for utility class
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DomainClassFinderTest {

@Before
public void setup() {
System.setProperty("de.markusmo3.urm.DomainClassFinder.allowFindingInternalClasses", "true");
DomainClassFinder.ALLOW_FINDING_INTERNAL_CLASSES = true;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DomainMapperCliTest extends DomainMapperCli { // extends to silence
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
System.setProperty("de.markusmo3.urm.DomainClassFinder.allowFindingInternalClasses", "true");
DomainClassFinder.ALLOW_FINDING_INTERNAL_CLASSES = true;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DomainMapperGraphvizTest {

@Before
public void setup() {
System.setProperty("de.markusmo3.urm.DomainClassFinder.allowFindingInternalClasses", "true");
DomainClassFinder.ALLOW_FINDING_INTERNAL_CLASSES = true;
}

@Test
Expand Down

0 comments on commit 32addf6

Please sign in to comment.