Skip to content

Commit

Permalink
Merge pull request #466 from maxgabut/ignore-empty-directory
Browse files Browse the repository at this point in the history
Ignore absent code directories when aggregating report
  • Loading branch information
hcoles authored May 23, 2018
2 parents e1bd952 + d785fcb commit dd13d70
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.logging.Logger;

import org.pitest.classpath.CodeSource;
import org.pitest.coverage.BlockCoverage;
Expand All @@ -27,6 +28,7 @@
import org.pitest.mutationtest.SourceLocator;
import org.pitest.mutationtest.report.html.MutationHtmlReportListener;
import org.pitest.mutationtest.tooling.SmartSourceLocator;
import org.pitest.util.Log;
import org.pitest.util.ResultOutputStrategy;

public final class ReportAggregator {
Expand Down Expand Up @@ -109,6 +111,9 @@ public static Builder builder() {
}

public static class Builder {

private static final Logger LOG = Log.getLogger();

private ResultOutputStrategy resultOutputStrategy;
private final Set<File> lineCoverageFiles = new HashSet<>();
private final Set<File> mutationResultsFiles = new HashSet<>();
Expand Down Expand Up @@ -158,7 +163,11 @@ public Builder sourceCodeDirectories(final List<File> sourceCodeDirectories) {

public Builder addSourceCodeDirectory(final File sourceCodeDirectory) {
validateDirectory(sourceCodeDirectory);
this.sourceCodeDirectories.add(sourceCodeDirectory);
if (sourceCodeDirectory.exists()) {
this.sourceCodeDirectories.add(sourceCodeDirectory);
} else {
LOG.info("ignoring absent source code directory " + sourceCodeDirectory.getAbsolutePath());
}
return this;
}

Expand All @@ -172,7 +181,11 @@ public Builder compiledCodeDirectories(final List<File> compiledCodeDirectories)

public Builder addCompiledCodeDirectory(final File compiledCodeDirectory) {
validateDirectory(compiledCodeDirectory);
this.compiledCodeDirectories.add(compiledCodeDirectory);
if (compiledCodeDirectory.exists()) {
this.compiledCodeDirectories.add(compiledCodeDirectory);
} else {
LOG.info("ignoring absent compiled code directory " + compiledCodeDirectory.getAbsolutePath());
}
return this;
}

Expand Down Expand Up @@ -231,8 +244,10 @@ private void validateDirectory(final File directory) {
if (directory == null) {
throw new IllegalArgumentException("directory is null");
}
if (!directory.exists() || !directory.isDirectory()) {
throw new IllegalArgumentException(directory.getAbsolutePath() + " does not exist or is not a directory");
// For this method, a non existing directory is valid.
// It probably needs some special treatment later, but it shouldn't prevent the aggregator to be built.
if (directory.exists() && !directory.isDirectory()) {
throw new IllegalArgumentException(directory.getAbsolutePath() + " is not a directory");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.pitest.aggregate;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.pitest.aggregate.TestInvocationHelper.getCompiledDirectory;
import static org.pitest.aggregate.TestInvocationHelper.getCoverageFile;
import static org.pitest.aggregate.TestInvocationHelper.getMutationFile;
Expand All @@ -20,7 +21,7 @@
public class ReportAggregatorBuilderTest {

private static final String NOT_A_FILE = "does not exist or is not a file";
private static final String NOT_A_DIR = "does not exist or is not a directory";
private static final String NOT_A_DIR = "is not a directory";
private static final String IS_NULL = "is null";
@Rule
public ExpectedException expected = ExpectedException.none();
Expand Down Expand Up @@ -83,10 +84,10 @@ public void testSourceCodeDirectories_withNull() {

@Test
public void testSourceCodeDirectories_withFake() {
this.expected.expect(IllegalArgumentException.class);
this.expected.expectMessage(Matchers.containsString(NOT_A_DIR));
ReportAggregator.Builder builder = ReportAggregator.builder()
.sourceCodeDirectories(Arrays.asList(new File("fakedirectory")));

ReportAggregator.builder().sourceCodeDirectories(Arrays.asList(new File("fakedirectory")));
assertTrue(builder.getSourceCodeDirectories().isEmpty());
}

@Test
Expand All @@ -107,10 +108,10 @@ public void testCompiledCodeDirectories_withNull() {

@Test
public void testCompiledCodeDirectories_withFake() {
this.expected.expect(IllegalArgumentException.class);
this.expected.expectMessage(Matchers.containsString(NOT_A_DIR));
ReportAggregator.Builder builder = ReportAggregator.builder()
.compiledCodeDirectories(Arrays.asList(new File("fakedirectory")));

ReportAggregator.builder().compiledCodeDirectories(Arrays.asList(new File("fakedirectory")));
assertTrue(builder.getCompiledCodeDirectories().isEmpty());
}

@Test
Expand Down

0 comments on commit dd13d70

Please sign in to comment.