Skip to content

Commit

Permalink
Merge pull request #904 from hcoles/822_regression
Browse files Browse the repository at this point in the history
Fix regression of #822, #798 and #797
  • Loading branch information
hcoles authored Jun 1, 2021
2 parents d51eb95 + 6a16dd3 commit b7fc56e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ private CombinedStatistics runAnalysis(Runtime runtime, long t0, EngineArguments

LOG.info("Completed in " + timeSpan(t0));

printStats(stats);
CombinedStatistics combined = new CombinedStatistics(stats.getStatistics(),
coverageData.createSummary());

return new CombinedStatistics(stats.getStatistics(),
coverageData.createSummary());
printStats(combined);

return combined;
}

private Predicate<MutationInterceptor> allInterceptors() {
Expand Down Expand Up @@ -274,13 +276,14 @@ private void verifyBuildSuitableForMutationTesting() {
this.strategies.buildVerifier().verify(this.code);
}

private void printStats(final MutationStatisticsListener stats) {
private void printStats(CombinedStatistics combinedStatistics) {
MutationStatistics stats = combinedStatistics.getMutationStatistics();
final PrintStream ps = System.out;

ps.println(StringUtil.separatorLine('='));
ps.println("- Mutators");
ps.println(StringUtil.separatorLine('='));
for (final Score each : stats.getStatistics().getScores()) {
for (final Score each : stats.getScores()) {
each.report(ps);
ps.println(StringUtil.separatorLine());
}
Expand All @@ -293,7 +296,14 @@ private void printStats(final MutationStatisticsListener stats) {
ps.println(StringUtil.separatorLine('='));
ps.println("- Statistics");
ps.println(StringUtil.separatorLine('='));
stats.getStatistics().report(ps);

final CoverageSummary coverage = combinedStatistics.getCoverageSummary();
if (coverage != null) {
ps.println(String.format(">> Line Coverage: %d/%d (%d%%)", coverage.getNumberOfCoveredLines(),
coverage.getNumberOfLines(), coverage.getCoverage()));
}

stats.report(ps);
}

private List<MutationAnalysisUnit> buildMutationTests(CoverageDatabase coverageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public class AbstractPitMojo extends AbstractMojo {
/**
* Arguments to pass to child processes
*/
@Parameter
@Parameter(property = "jvmArgs")
private ArrayList<String> jvmArgs;

/**
Expand Down
10 changes: 6 additions & 4 deletions pitest/src/main/java/org/pitest/classpath/ClassPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.util.logging.Logger;
import java.util.zip.ZipException;

import static org.pitest.util.ManifestUtils.CLASSPATH_JAR_FILE_PREFIX;

public class ClassPath {

private static final Logger LOG = Log.getLogger();
Expand Down Expand Up @@ -128,14 +130,14 @@ public static Collection<File> getClassPathElementsAsFiles() {
/**
* Because classpaths can become longer than the OS supports pitest creates temporary jar files and places the classpath
* in the manifest where there is no size limit.
*
*
* We must therefore parse them out again here.
*
*
* @param elements existing elements
*/
private static void addEntriesFromClasspathManifest(final Set<File> elements) {
Optional<File> maybeJar = elements.stream().filter( f -> f.getName().startsWith("classpath") && f.getName().endsWith(".jar"))
.findFirst();
Optional<File> maybeJar = elements.stream().filter(f -> f.getName().startsWith(CLASSPATH_JAR_FILE_PREFIX) && f.getName().endsWith(".jar"))
.findFirst();
maybeJar.ifPresent(file -> elements.addAll(ManifestUtils.readClasspathManifest(file)));
}

Expand Down
32 changes: 17 additions & 15 deletions pitest/src/main/java/org/pitest/util/ManifestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,52 +34,54 @@
*/
public class ManifestUtils {

public static final String CLASSPATH_JAR_FILE_PREFIX = "pitest-classpath-jar-file-";

// Method based on
// https://github.com/JetBrains/intellij-community/blob/master/java/java-runtime/src/com/intellij/rt/execution/testFrameworks/ForkedByModuleSplitter.java
// JetBrains copyright notice and licence retained above.
public static File createClasspathJarFile(String classpath)
throws IOException {
throws IOException {
final Manifest manifest = new Manifest();
final Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");

String classpathForManifest = "";
StringBuilder classpathForManifest = new StringBuilder();
int idx = 0;
int endIdx = 0;
while (endIdx >= 0) {
endIdx = classpath.indexOf(File.pathSeparator, idx);
String path = endIdx < 0 ? classpath.substring(idx)
: classpath.substring(idx, endIdx);
: classpath.substring(idx, endIdx);
if (classpathForManifest.length() > 0) {
classpathForManifest += " ";
classpathForManifest.append(" ");
}

classpathForManifest += new File(path).toURI().toURL().toString();
classpathForManifest.append(new File(path).toURI().toURL());
idx = endIdx + File.pathSeparator.length();
}
attributes.put(Attributes.Name.CLASS_PATH, classpathForManifest);
attributes.put(Attributes.Name.CLASS_PATH, classpathForManifest.toString());

File jarFile = File.createTempFile("classpath", ".jar");
File jarFile = File.createTempFile(CLASSPATH_JAR_FILE_PREFIX, ".jar");
try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(jarFile));
ZipOutputStream jarPlugin = new JarOutputStream(out, manifest)
) {
jarFile.deleteOnExit();
ZipOutputStream jarPlugin = new JarOutputStream(out, manifest)
) {
jarFile.deleteOnExit();
}

return jarFile;
}

public static Collection<File> readClasspathManifest(File file) {
try (FileInputStream fis = new FileInputStream(file);
JarInputStream jarStream = new JarInputStream(fis)) {
JarInputStream jarStream = new JarInputStream(fis)) {
Manifest mf = jarStream.getManifest();
Attributes att = mf.getMainAttributes();
String cp = att.getValue(Attributes.Name.CLASS_PATH);
String[] parts = cp.split("file:");
return Arrays.stream(parts)
.filter(part -> !part.isEmpty())
.map(part -> new File(part.trim()))
.collect(Collectors.toList());
.filter(part -> !part.isEmpty())
.map(part -> new File(part.trim()))
.collect(Collectors.toList());
} catch (IOException ex) {
throw new RuntimeException("Could not read classpath jar manifest", ex);
}
Expand Down

0 comments on commit b7fc56e

Please sign in to comment.