Skip to content

Commit

Permalink
fix: Correctly handle multiple classpaths.
Browse files Browse the repository at this point in the history
  • Loading branch information
sindrets committed Sep 19, 2020
1 parent 509dc3f commit 67d5716
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

def mainClass = "no.stide.fling.Main"
version = "1.1.1"
version = "1.1.2"

repositories {
flatDir {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/no/stide/fling/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void main(String[] args) {

String[] includes = flags.containsKey("include") ? flags.get("include").split(":|;") : new String[0];
String[] excludes = flags.containsKey("exclude") ? flags.get("exclude").split(":|;") : new String[0];
TestRunner testRunner = new TestRunner(params.toArray(new String[params.size()]));
TestRunner testRunner = new TestRunner(params.get(0).split(":|;"));
testRunner.setIncludes(includes);
testRunner.setExcludes(excludes);
try {
Expand All @@ -95,4 +95,4 @@ public static void main(String[] args) {
System.exit(1);
}
}
}
}
14 changes: 12 additions & 2 deletions src/main/java/no/stide/fling/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.FileSystems;
Expand All @@ -25,13 +26,23 @@ public class TestRunner {

static final Chalk chalk = new Chalk();
private String[] classpaths;
private URL[] classpathUrls;
private ArrayList<String> exclude = new ArrayList<>();
private ArrayList<String> include = new ArrayList<>();
private UnitTest unitTest = new UnitTest();
private TestStatus testStatus = TestStatus.NOT_STARTED;

public TestRunner(String[] classpaths) {
this.classpaths = classpaths;
this.classpathUrls = new URL[classpaths.length];
for (int i = 0; i < classpaths.length; i++) {
try {
this.classpathUrls[i] = new File(classpaths[i]).toURI().toURL();
} catch (MalformedURLException e) {
System.err.println("Malformed classpath! '" + this.classpaths[i] + "'");
System.exit(1);
}
}
}

public void run() throws TestFailedException {
Expand Down Expand Up @@ -103,8 +114,7 @@ private void processClass(String classpath, Path filePath) throws ClassNotFoundE
packagePath = packagePath.replaceAll("\\" + File.separator, ".").replaceAll("\\.class$", "");
// System.out.println("FOUND CLASS: " + packagePath);

URL classPathUrl = new File(classpath).toURI().toURL();
URLClassLoader cl = new URLClassLoader(new URL[] { classPathUrl });
URLClassLoader cl = new URLClassLoader(this.classpathUrls);

Class<?> clazz = cl.loadClass(packagePath);
Method[] methods = clazz.getDeclaredMethods();
Expand Down

0 comments on commit 67d5716

Please sign in to comment.