Skip to content

Commit

Permalink
Allow interpolation of SCM URLs (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtnord committed Feb 8, 2023
1 parent e00a890 commit 142eefa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/java/org/jenkins/tools/test/model/PluginRemoting.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,25 @@ public PomData retrievePomData() throws PluginSourcesUnavailableException {
return new PomData(
model.getArtifactId(),
model.getPackaging(),
model.getScm().getConnection(),
// scm may contain properties so it needs to be resolved.
interpolateString(model.getScm().getConnection(), model.getArtifactId()),
model.getScm().getTag(),
parent,
model.getGroupId());
}

/**
* Replaces any occurence of {@code "${project.artifactId}"} or {@code "${artifactId}"} with the
* supplied value of the artifactId/
*
* @param original the original string
* @param artifactId the interpolated String
* @return the original string with any interpolation for the artifactId resolved.
*/
static String interpolateString(String original, String artifactId) {
if (original == null) {
return null;
}
return original.replace("${project.artifactId}", artifactId);
}
}
31 changes: 31 additions & 0 deletions src/test/java/org/jenkins/tools/test/model/PluginRemotingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.jenkins.tools.test.model;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

import org.junit.Test;

public class PluginRemotingTest {

@Test
public void testStringInterpolation() {
assertThat(
PluginRemoting.interpolateString("${project.artifactId}", "wibble"), is("wibble"));
assertThat(
PluginRemoting.interpolateString("prefix-${project.artifactId}", "blah"),
is("prefix-blah"));
assertThat(
PluginRemoting.interpolateString("${project.artifactId}suffix", "something"),
is("somethingsuffix"));

// no interpolation - contains neither ${artifactId} not ${project.artifactId}
assertThat(PluginRemoting.interpolateString(null, "wibble"), nullValue());
assertThat(
PluginRemoting.interpolateString("${aartifactId}suffix", "something"),
is("${aartifactId}suffix"));
assertThat(
PluginRemoting.interpolateString("${projectXartifactId}suffix", "something"),
is("${projectXartifactId}suffix"));
}
}

0 comments on commit 142eefa

Please sign in to comment.