Skip to content

Commit

Permalink
fix JENKINS-69410: Links to Deployed Artifacts broken with maven-depl…
Browse files Browse the repository at this point in the history
…oy-plugin 3.0.0 (#519)
  • Loading branch information
bguerin authored Sep 18, 2022
1 parent 9dbfbaa commit ceea7b9
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ private static void loadMavenArtifact(Element artifactElt, MavenArtifact mavenAr
if (mavenArtifact.getBaseVersion() == null || mavenArtifact.getBaseVersion().isEmpty()) {
mavenArtifact.setBaseVersion(mavenArtifact.getVersion());
}
mavenArtifact.setSnapshot(Boolean.parseBoolean(artifactElt.getAttribute("snapshot")));
String snapshot = artifactElt.getAttribute("snapshot");
mavenArtifact.setSnapshot(snapshot != null && !snapshot.trim().isEmpty()
? Boolean.parseBoolean(artifactElt.getAttribute("snapshot"))
: mavenArtifact.getBaseVersion().contains("SNAPSHOT"));
mavenArtifact.setType(artifactElt.getAttribute("type"));
if (mavenArtifact.getType() == null || mavenArtifact.getType().isEmpty()) {
// workaround: sometimes we use "XmlUtils.newMavenArtifact()" on "project" elements, in this case, "packaging" is defined but "type" is not defined
Expand Down Expand Up @@ -450,11 +453,17 @@ public static List<MavenArtifact> listGeneratedArtifacts(Element mavenSpyLogs, b
pomArtifact.setGroupId(projectArtifact.getGroupId());
pomArtifact.setArtifactId(projectArtifact.getArtifactId());
pomArtifact.setBaseVersion(projectArtifact.getBaseVersion());
pomArtifact.setVersion(projectArtifact.getVersion());
pomArtifact.setSnapshot(projectArtifact.isSnapshot());
pomArtifact.setType("pom");
pomArtifact.setExtension("pom");
pomArtifact.setFile(projectElt.getAttribute("file"));
Element artifactDeployedEvent = XmlUtils.getArtifactDeployedEvent(artifactDeployedEvents, pomArtifact.getFile());
if (artifactDeployedEvent == null) {
// artifact has not been deployed ("mvn deploy")
pomArtifact.setVersion(projectArtifact.getVersion());
} else {
pomArtifact.setVersion(XmlUtils.getUniqueChildElement(artifactDeployedEvent, "artifact").getAttribute("version"));
}

result.add(pomArtifact);

Expand All @@ -473,10 +482,11 @@ public static List<MavenArtifact> listGeneratedArtifacts(Element mavenSpyLogs, b
} else {
mavenArtifact.setFile(StringUtils.trim(fileElt.getTextContent()));

Element artifactDeployedEvent = XmlUtils.getArtifactDeployedEvent(artifactDeployedEvents, mavenArtifact.getFile());
if(artifactDeployedEvent == null) {
artifactDeployedEvent = XmlUtils.getArtifactDeployedEvent(artifactDeployedEvents, mavenArtifact.getFile());
if (artifactDeployedEvent == null) {
// artifact has not been deployed ("mvn deploy")
} else {
mavenArtifact.setVersion(XmlUtils.getUniqueChildElement(artifactDeployedEvent, "artifact").getAttribute("version"));
mavenArtifact.setRepositoryUrl(XmlUtils.getUniqueChildElement(artifactDeployedEvent, "repository").getAttribute("url"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,65 @@ public void test_listGeneratedArtifacts() throws Exception {
}
}
}

@Test
public void test_listGeneratedArtifacts_deploy_2_8() throws Exception {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-deploy-2.8.xml");
in.getClass(); // check non null
Element mavenSpyLogs = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in).getDocumentElement();

List<MavenArtifact> generatedArtifacts = XmlUtils.listGeneratedArtifacts(mavenSpyLogs, false);

assertThat(generatedArtifacts.size(), is(2));

assertThat(generatedArtifacts.get(0).getGroupId(), is("com.acme.maven.plugins"));
assertThat(generatedArtifacts.get(0).getArtifactId(), is("postgresql-compare-maven-plugin"));
assertThat(generatedArtifacts.get(0).getExtension(), is("pom"));
assertThat(generatedArtifacts.get(0).getClassifier(), is(emptyOrNullString()));
assertThat(generatedArtifacts.get(0).getBaseVersion(), is("1.0.2-SNAPSHOT"));
assertThat(generatedArtifacts.get(0).getType(), is("pom"));
assertThat(generatedArtifacts.get(0).getVersion(), is("1.0.2-20220904.210621-1"));
assertThat(generatedArtifacts.get(0).isSnapshot(), is(true));

assertThat(generatedArtifacts.get(1).getGroupId(), is("com.acme.maven.plugins"));
assertThat(generatedArtifacts.get(1).getArtifactId(), is("postgresql-compare-maven-plugin"));
assertThat(generatedArtifacts.get(1).getExtension(), is("jar"));
assertThat(generatedArtifacts.get(1).getClassifier(), is(emptyOrNullString()));
assertThat(generatedArtifacts.get(1).getBaseVersion(), is("1.0.2-SNAPSHOT"));
assertThat(generatedArtifacts.get(1).getType(), is("maven-plugin"));
assertThat(generatedArtifacts.get(1).getVersion(), is("1.0.2-20220904.210621-1"));
assertThat(generatedArtifacts.get(1).isSnapshot(), is(true));
}

@Test
public void test_listGeneratedArtifacts_deploy_3_0() throws Exception {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-deploy-3.0.xml");
in.getClass(); // check non null
Element mavenSpyLogs = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in).getDocumentElement();

List<MavenArtifact> generatedArtifacts = XmlUtils.listGeneratedArtifacts(mavenSpyLogs, false);

assertThat(generatedArtifacts.size(), is(2));

assertThat(generatedArtifacts.get(0).getGroupId(), is("com.acme.maven.plugins"));
assertThat(generatedArtifacts.get(0).getArtifactId(), is("postgresql-compare-maven-plugin"));
assertThat(generatedArtifacts.get(0).getExtension(), is("pom"));
assertThat(generatedArtifacts.get(0).getClassifier(), is(emptyOrNullString()));
assertThat(generatedArtifacts.get(0).getBaseVersion(), is("1.0.2-SNAPSHOT"));
assertThat(generatedArtifacts.get(0).getType(), is("pom"));
assertThat(generatedArtifacts.get(0).getVersion(), is("1.0.2-20220904.210621-1"));
assertThat(generatedArtifacts.get(0).isSnapshot(), is(true));

assertThat(generatedArtifacts.get(1).getGroupId(), is("com.acme.maven.plugins"));
assertThat(generatedArtifacts.get(1).getArtifactId(), is("postgresql-compare-maven-plugin"));
assertThat(generatedArtifacts.get(1).getExtension(), is("jar"));
assertThat(generatedArtifacts.get(1).getClassifier(), is(emptyOrNullString()));
assertThat(generatedArtifacts.get(1).getBaseVersion(), is("1.0.2-SNAPSHOT"));
assertThat(generatedArtifacts.get(1).getType(), is("maven-plugin"));
assertThat(generatedArtifacts.get(1).getVersion(), is("1.0.2-20220904.210621-1"));
assertThat(generatedArtifacts.get(1).isSnapshot(), is(true));
}

@Test
public void test_listGeneratedArtifacts_including_generated_artifacts() throws Exception {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-deploy-jar.xml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<mavenExecution _time="2022-09-04 21:06:21.351">
<ExecutionEvent type="MojoStarted" class="org.apache.maven.lifecycle.internal.DefaultExecutionEvent" _time="2022-09-04 21:07:43.592">
<project baseDir="/home/jenkins/workspace/gresql-compare-maven-plugin_main" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/pom.xml" groupId="com.acme.maven.plugins" name="PostGreSQL comparison Maven plugin" artifactId="postgresql-compare-maven-plugin" packaging="maven-plugin" version="1.0.2-SNAPSHOT">
<build sourceDirectory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/src/main/java" directory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/target"/>
</project>
<plugin executionId="default-deploy" goal="deploy" lifecyclePhase="deploy" groupId="org.apache.maven.plugins" artifactId="maven-deploy-plugin" version="2.8.2">
<altDeploymentRepository>${altDeploymentRepository}</altDeploymentRepository>
<altReleaseDeploymentRepository>${altReleaseDeploymentRepository}</altReleaseDeploymentRepository>
<altSnapshotDeploymentRepository>${altSnapshotDeploymentRepository}</altSnapshotDeploymentRepository>
<deployAtEnd>${deployAtEnd}</deployAtEnd>
<offline>${settings.offline}</offline>
<project>${project}</project>
<reactorProjects>${reactorProjects}</reactorProjects>
<retryFailedDeploymentCount>${retryFailedDeploymentCount}</retryFailedDeploymentCount>
<session>${session}</session>
<skip>${maven.deploy.skip}</skip>
</plugin>
</ExecutionEvent>
<RepositoryEvent type="ARTIFACT_DEPLOYED" class="org.eclipse.aether.RepositoryEvent" _time="2022-09-04 21:07:44.043">
<artifact extension="jar" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/target/postgresql-compare-maven-plugin-1.0.2-SNAPSHOT.jar" baseVersion="1.0.2-SNAPSHOT" groupId="com.acme.maven.plugins" classifier="" artifactId="postgresql-compare-maven-plugin" id="com.acme.maven.plugins:postgresql-compare-maven-plugin:jar:1.0.2-20220904.210621-1" version="1.0.2-20220904.210621-1" snapshot="true"/>
<repository layout="default" id="acme" url="https://server/maven-snapshots/"/>
</RepositoryEvent>
<RepositoryEvent type="ARTIFACT_DEPLOYED" class="org.eclipse.aether.RepositoryEvent" _time="2022-09-04 21:07:44.08">
<artifact extension="pom" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/pom.xml" baseVersion="1.0.2-SNAPSHOT" groupId="com.acme.maven.plugins" classifier="" artifactId="postgresql-compare-maven-plugin" id="com.acme.maven.plugins:postgresql-compare-maven-plugin:pom:1.0.2-20220904.210621-1" version="1.0.2-20220904.210621-1" snapshot="true"/>
<repository layout="default" id="acme" url="https://server/maven-snapshots/"/>
</RepositoryEvent>
<ExecutionEvent type="MojoSucceeded" class="org.apache.maven.lifecycle.internal.DefaultExecutionEvent" _time="2022-09-04 21:07:44.178">
<project baseDir="/home/jenkins/workspace/gresql-compare-maven-plugin_main" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/pom.xml" groupId="com.acme.maven.plugins" name="PostGreSQL comparison Maven plugin" artifactId="postgresql-compare-maven-plugin" packaging="maven-plugin" version="1.0.2-SNAPSHOT">
<build sourceDirectory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/src/main/java" directory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/target"/>
</project>
<plugin executionId="default-deploy" goal="deploy" lifecyclePhase="deploy" groupId="org.apache.maven.plugins" artifactId="maven-deploy-plugin" version="2.8.2">
<altDeploymentRepository>${altDeploymentRepository}</altDeploymentRepository>
<altReleaseDeploymentRepository>${altReleaseDeploymentRepository}</altReleaseDeploymentRepository>
<altSnapshotDeploymentRepository>${altSnapshotDeploymentRepository}</altSnapshotDeploymentRepository>
<deployAtEnd>${deployAtEnd}</deployAtEnd>
<offline>${settings.offline}</offline>
<project>${project}</project>
<reactorProjects>${reactorProjects}</reactorProjects>
<retryFailedDeploymentCount>${retryFailedDeploymentCount}</retryFailedDeploymentCount>
<session>${session}</session>
<skip>${maven.deploy.skip}</skip>
</plugin>
<artifactRepository>
<id>acme</id>
<url>https://server/maven-snapshots/</url>
</artifactRepository>
</ExecutionEvent>
<ExecutionEvent type="ProjectSucceeded" class="org.apache.maven.lifecycle.internal.DefaultExecutionEvent" _time="2022-09-04 21:07:44.178">
<project baseDir="/home/jenkins/workspace/gresql-compare-maven-plugin_main" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/pom.xml" groupId="com.acme.maven.plugins" name="PostGreSQL comparison Maven plugin" artifactId="postgresql-compare-maven-plugin" packaging="maven-plugin" version="1.0.2-SNAPSHOT">
<build sourceDirectory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/src/main/java" directory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/target"/>
</project>
<no-execution-found/>
<artifact extension="jar" baseVersion="1.0.2-SNAPSHOT" groupId="com.acme.maven.plugins" artifactId="postgresql-compare-maven-plugin" id="com.acme.maven.plugins:postgresql-compare-maven-plugin:maven-plugin:1.0.2-SNAPSHOT" type="maven-plugin" version="1.0.2-20220904.210621-1" snapshot="true">
<file>/home/jenkins/workspace/gresql-compare-maven-plugin_main/target/postgresql-compare-maven-plugin-1.0.2-SNAPSHOT.jar</file>
</artifact>
<attachedArtifacts/>
</ExecutionEvent>
<MavenExecutionResult class="org.apache.maven.execution.DefaultMavenExecutionResult" _time="2022-09-04 21:07:44.18">
<buildSummary baseDir="/home/jenkins/workspace/gresql-compare-maven-plugin_main" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/pom.xml" groupId="com.acme.maven.plugins" name="PostGreSQL comparison Maven plugin" artifactId="postgresql-compare-maven-plugin" packaging="maven-plugin" time="82481" version="1.0.2-SNAPSHOT" class="org.apache.maven.execution.BuildSuccess">
<build sourceDirectory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/src/main/java" directory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/target"/>
</buildSummary>
</MavenExecutionResult>

</mavenExecution>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<mavenExecution _time="2022-09-04 21:06:21.351">
<ExecutionEvent type="MojoStarted" class="org.apache.maven.lifecycle.internal.DefaultExecutionEvent" _time="2022-09-04 21:07:43.592">
<project baseDir="/home/jenkins/workspace/gresql-compare-maven-plugin_main" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/pom.xml" groupId="com.acme.maven.plugins" name="PostGreSQL comparison Maven plugin" artifactId="postgresql-compare-maven-plugin" packaging="maven-plugin" version="1.0.2-SNAPSHOT">
<build sourceDirectory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/src/main/java" directory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/target"/>
</project>
<plugin executionId="default-deploy" goal="deploy" lifecyclePhase="deploy" groupId="org.apache.maven.plugins" artifactId="maven-deploy-plugin" version="3.0.0">
<altDeploymentRepository>${altDeploymentRepository}</altDeploymentRepository>
<altReleaseDeploymentRepository>${altReleaseDeploymentRepository}</altReleaseDeploymentRepository>
<altSnapshotDeploymentRepository>${altSnapshotDeploymentRepository}</altSnapshotDeploymentRepository>
<deployAtEnd>${deployAtEnd}</deployAtEnd>
<offline>${settings.offline}</offline>
<project>${project}</project>
<reactorProjects>${reactorProjects}</reactorProjects>
<retryFailedDeploymentCount>${retryFailedDeploymentCount}</retryFailedDeploymentCount>
<session>${session}</session>
<skip>${maven.deploy.skip}</skip>
</plugin>
</ExecutionEvent>
<RepositoryEvent type="ARTIFACT_DEPLOYED" class="org.eclipse.aether.RepositoryEvent" _time="2022-09-04 21:07:44.043">
<artifact extension="jar" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/target/postgresql-compare-maven-plugin-1.0.2-SNAPSHOT.jar" baseVersion="1.0.2-SNAPSHOT" groupId="com.acme.maven.plugins" classifier="" artifactId="postgresql-compare-maven-plugin" id="com.acme.maven.plugins:postgresql-compare-maven-plugin:jar:1.0.2-20220904.210621-1" version="1.0.2-20220904.210621-1" snapshot="true"/>
<repository layout="default" id="acme" url="https://server/maven-snapshots/"/>
</RepositoryEvent>
<RepositoryEvent type="ARTIFACT_DEPLOYED" class="org.eclipse.aether.RepositoryEvent" _time="2022-09-04 21:07:44.08">
<artifact extension="pom" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/pom.xml" baseVersion="1.0.2-SNAPSHOT" groupId="com.acme.maven.plugins" classifier="" artifactId="postgresql-compare-maven-plugin" id="com.acme.maven.plugins:postgresql-compare-maven-plugin:pom:1.0.2-20220904.210621-1" version="1.0.2-20220904.210621-1" snapshot="true"/>
<repository layout="default" id="acme" url="https://server/maven-snapshots/"/>
</RepositoryEvent>
<ExecutionEvent type="MojoSucceeded" class="org.apache.maven.lifecycle.internal.DefaultExecutionEvent" _time="2022-09-04 21:07:44.178">
<project baseDir="/home/jenkins/workspace/gresql-compare-maven-plugin_main" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/pom.xml" groupId="com.acme.maven.plugins" name="PostGreSQL comparison Maven plugin" artifactId="postgresql-compare-maven-plugin" packaging="maven-plugin" version="1.0.2-SNAPSHOT">
<build sourceDirectory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/src/main/java" directory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/target"/>
</project>
<plugin executionId="default-deploy" goal="deploy" lifecyclePhase="deploy" groupId="org.apache.maven.plugins" artifactId="maven-deploy-plugin" version="3.0.0">
<altDeploymentRepository>${altDeploymentRepository}</altDeploymentRepository>
<altReleaseDeploymentRepository>${altReleaseDeploymentRepository}</altReleaseDeploymentRepository>
<altSnapshotDeploymentRepository>${altSnapshotDeploymentRepository}</altSnapshotDeploymentRepository>
<deployAtEnd>${deployAtEnd}</deployAtEnd>
<offline>${settings.offline}</offline>
<project>${project}</project>
<reactorProjects>${reactorProjects}</reactorProjects>
<retryFailedDeploymentCount>${retryFailedDeploymentCount}</retryFailedDeploymentCount>
<session>${session}</session>
<skip>${maven.deploy.skip}</skip>
</plugin>
<artifactRepository>
<id>acme</id>
<url>https://server/maven-snapshots/</url>
</artifactRepository>
</ExecutionEvent>
<ExecutionEvent type="ProjectSucceeded" class="org.apache.maven.lifecycle.internal.DefaultExecutionEvent" _time="2022-09-04 21:07:44.178">
<project baseDir="/home/jenkins/workspace/gresql-compare-maven-plugin_main" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/pom.xml" groupId="com.acme.maven.plugins" name="PostGreSQL comparison Maven plugin" artifactId="postgresql-compare-maven-plugin" packaging="maven-plugin" version="1.0.2-SNAPSHOT">
<build sourceDirectory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/src/main/java" directory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/target"/>
</project>
<no-execution-found/>
<artifact extension="jar" baseVersion="1.0.2-SNAPSHOT" groupId="com.acme.maven.plugins" artifactId="postgresql-compare-maven-plugin" id="com.acme.maven.plugins:postgresql-compare-maven-plugin:maven-plugin:1.0.2-SNAPSHOT" type="maven-plugin" version="1.0.2-SNAPSHOT" snapshot="true">
<file>/home/jenkins/workspace/gresql-compare-maven-plugin_main/target/postgresql-compare-maven-plugin-1.0.2-SNAPSHOT.jar</file>
</artifact>
<attachedArtifacts/>
</ExecutionEvent>
<MavenExecutionResult class="org.apache.maven.execution.DefaultMavenExecutionResult" _time="2022-09-04 21:07:44.18">
<buildSummary baseDir="/home/jenkins/workspace/gresql-compare-maven-plugin_main" file="/home/jenkins/workspace/gresql-compare-maven-plugin_main/pom.xml" groupId="com.acme.maven.plugins" name="PostGreSQL comparison Maven plugin" artifactId="postgresql-compare-maven-plugin" packaging="maven-plugin" time="82481" version="1.0.2-SNAPSHOT" class="org.apache.maven.execution.BuildSuccess">
<build sourceDirectory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/src/main/java" directory="/home/jenkins/workspace/gresql-compare-maven-plugin_main/target"/>
</buildSummary>
</MavenExecutionResult>

</mavenExecution>

0 comments on commit ceea7b9

Please sign in to comment.