Skip to content

Commit

Permalink
fixes hcoles#1333 Expand ${settings.localRepository} in <argLine>
Browse files Browse the repository at this point in the history
  • Loading branch information
martinoconnor committed Jun 25, 2024
1 parent dd84e8b commit e82268b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.eclipse.aether.RepositorySystem;
import org.pitest.coverage.CoverageSummary;
import org.pitest.mutationtest.config.PluginServices;
Expand Down Expand Up @@ -385,6 +386,9 @@ public class AbstractPitMojo extends AbstractMojo {
@Parameter(property = "project", readonly = true, required = true)
private MavenProject project;

@Parameter(property = "settings", readonly = true, required = true)
private Settings settings;

/**
* <i>Internal</i>: Map of plugin artifacts.
*/
Expand Down Expand Up @@ -630,6 +634,10 @@ public MavenProject getProject() {
return this.project;
}

public Settings getSettings() {
return this.settings;
}

public Map<String, Artifact> getPluginArtifactMap() {
return this.pluginArtifactMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ private String replacePropertyExpressions(String argLine) {
argLine = replaceFieldForSymbol('$', key, argLine);
}

argLine = replaceSettingsField(argLine);

return argLine;
}

Expand All @@ -511,4 +513,12 @@ private String replaceFieldForSymbol(char symbol, String key, String argLine) {
return argLine;
}

private String replaceSettingsField(String argLine) {
String field = "${settings.localRepository}";
if (argLine.contains(field)) {
return argLine.replace(field, mojo.getSettings().getLocalRepository());
}
return argLine;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.maven.model.Build;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
Expand All @@ -45,6 +46,9 @@ public abstract class BasePitMojoTest extends AbstractMojoTestCase {
@Mock
protected MavenProject project;

@Mock
protected Settings settings;

@Mock
protected RunPitStrategy executionStrategy;

Expand Down Expand Up @@ -119,6 +123,8 @@ protected void configurePitMojo(final AbstractPitMojo pitMojo, final String conf

setVariableValueToObject(pitMojo, "project", this.project);

setVariableValueToObject(pitMojo, "settings", this.settings);

if (pitMojo.getAdditionalClasspathElements() == null) {
ArrayList<String> elements = new ArrayList<>();
setVariableValueToObject(pitMojo, "additionalClasspathElements", elements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ public void testEvaluatesNormalPropertiesInArgLines() {
assertThat(actual.getArgLine()).isEqualTo("fooValue barValue");
}

public void testEvaluatesLocalRepositoryPropertyInArgLines() {
when(this.settings.getLocalRepository()).thenReturn("localRepoValue");
ReportOptions actual = parseConfig("<argLine>${settings.localRepository}/jar</argLine>");
assertThat(actual.getArgLine()).isEqualTo("localRepoValue/jar");
}

public void testAutoAddsKotlinSourceDirsWhenPresent() throws IOException {
// we're stuck in junit 3 land but can
// use junit 4's temporary folder rule programatically
Expand Down

0 comments on commit e82268b

Please sign in to comment.