diff --git a/pitest-maven/src/main/java/org/pitest/maven/MojoToReportOptionsConverter.java b/pitest-maven/src/main/java/org/pitest/maven/MojoToReportOptionsConverter.java index 2c1176747..ae9d9894f 100644 --- a/pitest-maven/src/main/java/org/pitest/maven/MojoToReportOptionsConverter.java +++ b/pitest-maven/src/main/java/org/pitest/maven/MojoToReportOptionsConverter.java @@ -285,12 +285,23 @@ private void checkForObsoleteOptions(AbstractPitMojo mojo) { } private void determineHistory(final ReportOptions data) { + + // set explicit history files if configured + data.setHistoryInputLocation(this.mojo.getHistoryInputFile()); + data.setHistoryOutputLocation(this.mojo.getHistoryOutputFile()); + + // If withHistory option set, overwrite config with files in temp dir. + // This allows a user to configure files for use on ci, but still easily use temp files + // for local running if (this.mojo.useHistory()) { useHistoryFileInTempDir(data); - } else { - data.setHistoryInputLocation(this.mojo.getHistoryInputFile()); + } + + if (data.getHistoryInputLocation() != null) { log.info("Will read history at " + data.getHistoryInputLocation()); - data.setHistoryOutputLocation(this.mojo.getHistoryOutputFile()); + } + + if (data.getHistoryOutputLocation() != null) { log.info("Will write history at " + data.getHistoryOutputLocation()); } } @@ -302,15 +313,16 @@ private void useHistoryFileInTempDir(final ReportOptions data) { + project.getArtifactId() + "." + project.getVersion() + "_pitest_history.bin"; File historyFile = new File(tempDir, name); - log.info("Will read and write history at " + historyFile); - if (this.mojo.getHistoryInputFile() == null) { - data.setHistoryInputLocation(historyFile); - } - if (this.mojo.getHistoryOutputFile() == null) { - data.setHistoryOutputLocation(historyFile); + + if (mojo.getHistoryInputFile() != null || mojo.getHistoryOutputFile() != null) { + log.info("Using withHistory option. This overrides the explicitly set history file paths."); } + data.setHistoryInputLocation(historyFile); + data.setHistoryOutputLocation(historyFile); + } - + + private ReportOptions updateFromSurefire(ReportOptions option) { Collection plugins = lookupPlugin("org.apache.maven.plugins:maven-surefire-plugin"); if (!this.mojo.isParseSurefireConfig()) { diff --git a/pitest-maven/src/test/java/org/pitest/maven/MojoToReportOptionsConverterTest.java b/pitest-maven/src/test/java/org/pitest/maven/MojoToReportOptionsConverterTest.java index 410a81982..3f4d518d1 100644 --- a/pitest-maven/src/test/java/org/pitest/maven/MojoToReportOptionsConverterTest.java +++ b/pitest-maven/src/test/java/org/pitest/maven/MojoToReportOptionsConverterTest.java @@ -335,6 +335,17 @@ public void testParsesLocalHistoryFlag() { when(this.project.getVersion()).thenReturn("0.1-SNAPSHOT"); final ReportOptions actual = parseConfig("true"); String expected = "com.example.foo.0.1-SNAPSHOT_pitest_history.bin"; + assertThat(actual.getHistoryInputLocation()).isNotNull(); + assertThat(actual.getHistoryInputLocation().getAbsolutePath()).endsWith(expected); + } + + public void testOverridesExplicitPathsWhenWithHistoryFlagSet() { + when(this.project.getGroupId()).thenReturn("com.example"); + when(this.project.getArtifactId()).thenReturn("foo"); + when(this.project.getVersion()).thenReturn("0.1-SNAPSHOT"); + final ReportOptions actual = parseConfig("foo.bintrue"); + String expected = "com.example.foo.0.1-SNAPSHOT_pitest_history.bin"; + assertThat(actual.getHistoryInputLocation()).isNotNull(); assertThat(actual.getHistoryInputLocation().getAbsolutePath()).endsWith(expected); }