Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes hcoles/pitest#1333 Expand ${settings.localRepository} in <argLine> #1334

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading