Skip to content

Commit

Permalink
Merge pull request #453 from jenkinsci/fallback
Browse files Browse the repository at this point in the history
Remove support for plugins without an SCM tag
  • Loading branch information
jtnord authored Feb 23, 2023
2 parents 2412ac8 + c8a405d commit d9d5930
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 104 deletions.
16 changes: 2 additions & 14 deletions src/main/java/org/jenkins/tools/test/PluginCompatTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private void testPluginAgainst(
cloneFromScm(
pomData.getConnectionUrl(),
config.getFallbackGitHubOrganization(),
getScmTag(pomData, plugin.name, plugin.version),
pomData.getScmTag(),
pluginCheckoutDir);
}
} else {
Expand Down Expand Up @@ -341,7 +341,7 @@ private void testPluginAgainst(
cloneFromScm(
pomData.getConnectionUrl(),
config.getFallbackGitHubOrganization(),
getScmTag(pomData, plugin.name, plugin.version),
pomData.getScmTag(),
pluginCheckoutDir);
}
} else {
Expand Down Expand Up @@ -593,18 +593,6 @@ private static void cloneImpl(String gitUrl, String scmTag, File checkoutDirecto
}
}

public static String getScmTag(PomData pomData, String name, String version) {
String scmTag;
if (pomData.getScmTag() != null) {
scmTag = pomData.getScmTag();
LOGGER.log(Level.INFO, "Using SCM tag {0} from POM", scmTag);
} else {
scmTag = name + "-" + version;
LOGGER.log(Level.INFO, "POM did not provide an SCM tag; inferring tag {0}", scmTag);
}
return scmTag;
}

public static List<String> getFallbackConnectionURL(
List<String> connectionURLs,
String connectionURLPomData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Map<String, Object> action(Map<String, Object> moreInfo)
boolean shouldExecuteHook = localCheckoutDir == null || !localCheckoutDir.exists();

if (shouldExecuteHook) {
LOGGER.log(Level.INFO, "Executing hook for {0}", getParentProjectName());
LOGGER.log(Level.INFO, "Executing hook for {0}", currentPlugin.getDisplayName());
// Determine if we need to run the download; only run for first identified plugin in the
// series
if (firstRun) {
Expand All @@ -48,10 +48,9 @@ public Map<String, Object> action(Map<String, Object> moreInfo)
pomData = (PomData) moreInfo.get("pomData");
// Like the call in PluginCompatTester#runHooks but with subdirectories trimmed:
PluginCompatTester.cloneFromScm(
getUrl(),
pomData.getConnectionUrl(),
config.getFallbackGitHubOrganization(),
PluginCompatTester.getScmTag(
pomData, getParentProjectName(), currentPlugin.version),
pomData.getScmTag(),
parentPath);
}

Expand Down Expand Up @@ -82,10 +81,6 @@ pomData, getParentProjectName(), currentPlugin.version),
return moreInfo;
}

public String getUrl() {
return pomData.getConnectionUrl().replaceFirst("^(.+github[.]com/[^/]+/[^/]+)/.+", "$1");
}

protected void configureLocalCheckOut(
UpdateSite.Plugin currentPlugin, File localCheckoutDir, Map<String, Object> moreInfo) {
// Do nothing to keep compatibility with pre-existing Hooks
Expand All @@ -101,14 +96,6 @@ protected void configureLocalCheckOut(
*/
protected abstract String getParentFolder();

/**
* Return the prefix to the SCM tag (usually the artifact ID of the base module). This will be
* used to form the checkout tag with the format {@code parentProjectName-version} in the
* (highly unlikely, and impossible for incrementalified plugins) event that the SCM tag is
* missing from the plugin's POM.
*/
protected abstract String getParentProjectName();

/**
* Returns the plugin folder name. By default it will be the plugin name, but it can be
* overridden to support plugins (like {@code workflow-cps}) that are not located in a folder
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/jenkins/tools/test/hook/AwsJavaSdkHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ protected String getParentFolder() {
return "aws-java-sdk-plugin";
}

@Override
protected String getParentProjectName() {
return "aws-java-sdk-parent";
}

@Override
public boolean check(Map<String, Object> info) {
PomData data = (PomData) info.get("pomData");
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/jenkins/tools/test/hook/BlueOceanHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ protected String getParentFolder() {
return "blueocean-plugin";
}

@Override
protected String getParentProjectName() {
return "blueocean-parent";
}

@Override
public boolean check(Map<String, Object> info) {
PomData data = (PomData) info.get("pomData");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ protected String getParentFolder() {
return "configuration-as-code-plugin";
}

@Override
protected String getParentProjectName() {
return "configuration-as-code";
}

@Override
public boolean check(Map<String, Object> info) {
PomData data = (PomData) info.get("pomData");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ protected String getParentFolder() {
return "pipeline-model-definition-plugin";
}

@Override
protected String getParentProjectName() {
return "pipeline-model-definition";
}

@Override
public boolean check(Map<String, Object> info) {
PomData data = (PomData) info.get("pomData");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ protected String getParentFolder() {
return "declarative-pipeline-migration-assistant-plugin";
}

@Override
protected String getParentProjectName() {
return "declarative-pipeline-migration-assistant";
}

@Override
public boolean check(Map<String, Object> info) {
PomData data = (PomData) info.get("pomData");
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/jenkins/tools/test/hook/MinaSshdApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ protected String getParentFolder() {
return "mina-sshd-api-plugin";
}

@Override
protected String getParentProjectName() {
return "mina-sshd-api-parent";
}

@Override
public boolean check(Map<String, Object> info) {
PomData data = (PomData) info.get("pomData");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ protected String getParentFolder() {
return "pipeline-stage-view-plugin";
}

@Override
protected String getParentProjectName() {
return "pipeline-stage-view";
}

@Override
protected String getPluginFolderName(UpdateSite.Plugin currentPlugin) {
return currentPlugin.name.equals("pipeline-rest-api") ? "rest-api" : "ui";
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/jenkins/tools/test/hook/SwarmHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ protected String getParentFolder() {
return "swarm-plugin";
}

@Override
protected String getParentProjectName() {
return "swarm-plugin";
}

@Override
protected String getPluginFolderName(UpdateSite.Plugin currentPlugin) {
return "plugin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ protected String getParentFolder() {
return "warnings-ng-plugin";
}

@Override
protected String getParentProjectName() {
return "warnings-ng";
}

@Override
public boolean check(Map<String, Object> info) {
return isWarningsNG(info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ protected String getParentFolder() {
return "workflow-cps-plugin";
}

@Override
protected String getParentProjectName() {
return "workflow-cps";
}

@Override
protected String getPluginFolderName(UpdateSite.Plugin currentPlugin) {
return "plugin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ public PomData retrievePomData() throws PluginSourcesUnavailableException {
model.getArtifactId(),
model.getPackaging(),
// scm may contain properties so it needs to be resolved.
interpolateString(
model.getScm() != null ? model.getScm().getConnection() : null,
model.getArtifactId()),
model.getScm() != null ? model.getScm().getTag() : null,
interpolateString(model.getScm().getConnection(), model.getArtifactId()),
model.getScm().getTag(),
parent,
model.getGroupId());
}
Expand All @@ -144,9 +142,6 @@ public PomData retrievePomData() throws PluginSourcesUnavailableException {
* @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);
}
}
27 changes: 14 additions & 13 deletions src/main/java/org/jenkins/tools/test/model/PomData.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,44 @@
* @author Frederic Camblor
*/
public class PomData {
public final String artifactId;
public final String groupId;
@NonNull public final String artifactId;

@CheckForNull public final String groupId;

@NonNull private final String packaging;

@CheckForNull public final MavenCoordinates parent;
private String connectionUrl;
private String scmTag;

@NonNull private String connectionUrl;

@NonNull private String scmTag;

public PomData(
String artifactId,
@NonNull String artifactId,
@CheckForNull String packaging,
String connectionUrl,
String scmTag,
@NonNull String connectionUrl,
@NonNull String scmTag,
@CheckForNull MavenCoordinates parent,
String groupId) {
@CheckForNull String groupId) {
this.artifactId = artifactId;
this.groupId = groupId;
this.packaging = packaging != null ? packaging : "jar";
this.setConnectionUrl(connectionUrl);
this.connectionUrl = connectionUrl;
this.scmTag = scmTag;
this.parent = parent;
}

@NonNull
public String getConnectionUrl() {
return connectionUrl;
}

public void setConnectionUrl(String connectionUrl) {
this.connectionUrl = connectionUrl;
}

@NonNull
public String getPackaging() {
return packaging;
}

@NonNull
public String getScmTag() {
return scmTag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ void testStringInterpolation() {
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"));
Expand All @@ -46,7 +45,7 @@ void smokes() throws Exception {
}

@Test
void noScm() throws Exception {
void parent() throws Exception {
File pomFile = new File(getClass().getResource("scm/pom.xml").toURI());
PluginRemoting pluginRemoting = new PluginRemoting(pomFile);
PomData pomData = pluginRemoting.retrievePomData();
Expand All @@ -56,7 +55,9 @@ void noScm() throws Exception {
assertThat(pomData.groupId, nullValue());
assertThat(pomData.artifactId, is("example"));
assertThat(pomData.getPackaging(), is("hpi"));
assertThat(pomData.getConnectionUrl(), nullValue());
assertThat(pomData.getScmTag(), nullValue());
assertThat(
pomData.getConnectionUrl(),
is("scm:git:https://jenkins.example.com/example-plugin.git"));
assertThat(pomData.getScmTag(), is("example-4.1"));
}
}
6 changes: 6 additions & 0 deletions src/test/resources/org/jenkins/tools/test/model/scm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
<packaging>hpi</packaging>
<name>Example</name>
<url>https://jenkins.example.com/example-plugin</url>
<scm>
<connection>scm:git:https://jenkins.example.com/example-plugin.git</connection>
<developerConnection>scm:git:[email protected]/example-plugin.git</developerConnection>
<tag>example-4.1</tag>
<url>https://jenkins.example.com/example-plugin</url>
</scm>
</project>

0 comments on commit d9d5930

Please sign in to comment.