Skip to content

Commit

Permalink
fixes #1333 Expand ${settings.localRepository} in <argLine>
Browse files Browse the repository at this point in the history
  • Loading branch information
martinoconnor committed Dec 29, 2024
1 parent 7bcb168 commit 93c3add
Show file tree
Hide file tree
Showing 4 changed files with 29 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 @@ -401,6 +402,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 @@ -668,6 +672,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 @@ -568,6 +568,8 @@ private String replacePropertyExpressions(String argLine) {
argLine = replaceFieldForSymbol('$', key, argLine);
}

argLine = replaceSettingsField(argLine);

return argLine;
}

Expand All @@ -579,4 +581,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 @@ -31,6 +31,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 @@ -49,6 +50,9 @@ public abstract class BasePitMojoTest extends AbstractMojoTestCase {
@Mock
protected MavenSession session;

@Mock
protected Settings settings;

@Mock
protected RunPitStrategy executionStrategy;

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

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

if (pitMojo.getAdditionalClasspathElements() == null) {
ArrayList<String> elements = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,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 testAddsModulesToMutationPathWhenCrossModule() {
MavenProject dependedOn = project("com.example", "foo");
MavenProject notDependedOn = project("com.example", "bar");
Expand Down

0 comments on commit 93c3add

Please sign in to comment.