Skip to content

Commit

Permalink
Fix classloader initialization
Browse files Browse the repository at this point in the history
Signed-off-by: André Silva <andre15andre@hotmail.com>
  • Loading branch information
andre15silva committed Jun 30, 2021
1 parent 7881def commit 0af35b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import eu.stamp_project.testrunner.listener.CoverageTransformer;
import eu.stamp_project.testrunner.listener.CoveredTestResult;
import eu.stamp_project.testrunner.listener.TestResult;
import eu.stamp_project.testrunner.listener.impl.CoverageCollectorDetailed;
import eu.stamp_project.testrunner.listener.impl.CoverageCollectorMethodDetailed;
import eu.stamp_project.testrunner.listener.impl.CoverageCollectorSummarization;
import eu.stamp_project.testrunner.runner.Failure;
import eu.stamp_project.testrunner.utils.ConstantsHelper;
import org.apache.commons.io.FileUtils;
Expand All @@ -24,12 +21,9 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.ResourceBundle.clearCache;

Expand Down Expand Up @@ -64,16 +58,17 @@ public JacocoRunner(String classesDirectory, String testClassesDirectory, Covera
* @param blackList the names of the test methods to NOT be run.
*/
public JacocoRunner(String classesDirectory, String testClassesDirectory, List<String> blackList, CoverageTransformer coverageTransformer) {
try {
this.instrumentedClassLoader = new MemoryClassLoader(
new URL[]{
new File(classesDirectory).toURI().toURL(),
new File(testClassesDirectory).toURI().toURL()
}
);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
URL[] dirs = Stream.concat(Arrays.stream(classesDirectory.split(File.pathSeparator)), Stream.of(testClassesDirectory))
.map(x -> {
try {
return new File(x).toURI().toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
})
.toArray(URL[]::new);
Arrays.stream(dirs).peek(System.out::println);
this.instrumentedClassLoader = new MemoryClassLoader(dirs);
this.blackList = blackList;
this.runtime = new LoggerRuntime();
this.instrumenter = new Instrumenter(this.runtime);
Expand Down Expand Up @@ -298,7 +293,7 @@ public void instrumentAll(String classesDirectory) {
instrumentedClassLoader.addDefinition(fullQualifiedName,
instrumenter.instrument(instrumentedClassLoader.getResourceAsStream(fileName), fullQualifiedName));
} catch (IOException e) {
throw new RuntimeException(fileName + "," + new File(fileName).getAbsolutePath() +
throw new RuntimeException(fileName + "," + next.getAbsolutePath() +
"," + fullQualifiedName, e);
}
}
Expand Down
Binary file not shown.

0 comments on commit 0af35b5

Please sign in to comment.