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

fix JENKINS-69410: Links to Attached Artifacts broken #854

Merged
merged 2 commits into from
Nov 25, 2024
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 @@ -137,8 +137,9 @@ public String getShortDescription() {
@Nullable
public String getUrl() {
if (getRepositoryUrl() == null) return null;
return getRepositoryUrl() + "/" + getGroupId().replace('.', '/') + "/" + getArtifactId() + "/"
+ getBaseVersion() + "/" + getFileNameWithVersion();
return getRepositoryUrl() + (getRepositoryUrl().endsWith("/") ? "" : "/")
+ getGroupId().replace('.', '/') + "/" + getArtifactId() + "/" + getBaseVersion() + "/"
+ getFileNameWithVersion();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ public static List<MavenArtifact> listGeneratedArtifacts(Element mavenSpyLogs, b
if (attachedArtifactDeployedEvent == null) {
// artifact has not been deployed ("mvn deploy")
} else {
attachedMavenArtifact.setVersion(
XmlUtils.getUniqueChildElement(attachedArtifactDeployedEvent, "artifact")
.getAttribute("version"));
attachedMavenArtifact.setRepositoryUrl(
XmlUtils.getUniqueChildElement(attachedArtifactDeployedEvent, "repository")
.getAttribute("url"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void test_getExecutedLifecyclePhases() throws Exception {
InputStream in = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-package-jar.xml");
in.getClass(); // check non null
assertThat(in).isNotNull();
Element mavenSpyLogs = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(in)
Expand All @@ -258,7 +258,7 @@ public void test_getArtifactDeployedEvent() throws Exception {
InputStream in = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-deploy-jar.xml");
in.getClass(); // check non null
assertThat(in).isNotNull();
Element mavenSpyLogs = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(in)
Expand All @@ -278,7 +278,7 @@ public void test_getExecutionEventsByPlugin() throws Exception {
InputStream in = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-deploy-jar.xml");
in.getClass(); // check non null
assertThat(in).isNotNull();
Element mavenSpyLogs = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(in)
Expand All @@ -302,13 +302,12 @@ public void test_listGeneratedArtifacts() throws Exception {
InputStream in = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-deploy-jar.xml");
in.getClass(); // check non null
assertThat(in).isNotNull();
Element mavenSpyLogs = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(in)
.getDocumentElement();
List<MavenArtifact> generatedArtifacts = XmlUtils.listGeneratedArtifacts(mavenSpyLogs, false);
System.out.println(generatedArtifacts);
assertThat(generatedArtifacts.size()).isEqualTo(2); // a jar file and a pom file are generated

for (MavenArtifact mavenArtifact : generatedArtifacts) {
Expand All @@ -331,7 +330,7 @@ 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
assertThat(in).isNotNull();
Element mavenSpyLogs = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(in)
Expand Down Expand Up @@ -365,7 +364,7 @@ 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
assertThat(in).isNotNull();
Element mavenSpyLogs = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(in)
Expand Down Expand Up @@ -399,18 +398,20 @@ public void test_listGeneratedArtifacts_including_generated_artifacts() throws E
InputStream in = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-deploy-jar.xml");
in.getClass(); // check non null
assertThat(in).isNotNull();
Element mavenSpyLogs = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(in)
.getDocumentElement();
List<MavenArtifact> generatedArtifacts = XmlUtils.listGeneratedArtifacts(mavenSpyLogs, true);
System.out.println(generatedArtifacts);
assertThat(generatedArtifacts.size()).isEqualTo(3); // a jar file and a pom file are generated

for (MavenArtifact mavenArtifact : generatedArtifacts) {
assertThat(mavenArtifact.getGroupId()).isEqualTo("com.example");
assertThat(mavenArtifact.getArtifactId()).isEqualTo("my-jar");
assertThat(mavenArtifact.getBaseVersion()).isEqualTo("0.5-SNAPSHOT");
assertThat(mavenArtifact.getVersion()).isEqualTo("0.5-20180304.184830-1");
assertThat(mavenArtifact.isSnapshot()).isTrue();
if ("pom".equals(mavenArtifact.getType())) {
assertThat(mavenArtifact.getExtension()).isEqualTo("pom");
assertThat(mavenArtifact.getClassifier()).isNullOrEmpty();
Expand All @@ -430,19 +431,21 @@ public void test_listGeneratedArtifacts_including_generated_artifacts() throws E
public void test_listGeneratedArtifacts_includeAttachedArtifacts() throws Exception {
InputStream in = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-include-attached-artifacts.log");
in.getClass(); // check non null
.getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/maven-spy-include-attached-artifacts.xml");
assertThat(in).isNotNull();
Element mavenSpyLogs = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(in)
.getDocumentElement();
List<MavenArtifact> generatedArtifacts = XmlUtils.listGeneratedArtifacts(mavenSpyLogs, true);
System.out.println(generatedArtifacts);
assertThat(generatedArtifacts.size()).isEqualTo(2); // pom artifact plus 1 attachment

for (MavenArtifact mavenArtifact : generatedArtifacts) {
assertThat(mavenArtifact.getGroupId()).isEqualTo("com.example");
assertThat(mavenArtifact.getArtifactId()).isEqualTo("my-jar");
assertThat(mavenArtifact.getBaseVersion()).isEqualTo("0.5-SNAPSHOT");
assertThat(mavenArtifact.getVersion()).isEqualTo("0.5-20180410.070244-14");
assertThat(mavenArtifact.isSnapshot()).isTrue();
if ("pom".equals(mavenArtifact.getType())) {
assertThat(mavenArtifact.getExtension()).isEqualTo("pom");
assertThat(mavenArtifact.getClassifier()).isNullOrEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,11 +961,11 @@
<build sourceDirectory="/path/to/my-jar/src/main/java" directory="/path/to/my-jar/target"/>
</project>
<no-execution-found/>
<artifact extension="jar" baseVersion="0.5-SNAPSHOT" groupId="com.example" artifactId="my-jar" id="com.example:my-jar:jar:0.5-SNAPSHOT" type="jar" version="0.5-20180304.184830-1" snapshot="true">
<artifact extension="jar" baseVersion="0.5-SNAPSHOT" groupId="com.example" artifactId="my-jar" id="com.example:my-jar:jar:0.5-SNAPSHOT" type="jar" version="0.5-20180304.184830-2" snapshot="true">
<file>/path/to/my-jar/target/my-jar-0.5-SNAPSHOT.jar</file>
</artifact>
<attachedArtifacts>
<artifact extension="jar" baseVersion="0.5-SNAPSHOT" groupId="com.example" classifier="sources" artifactId="my-jar" id="com.example:my-jar:java-source:sources:0.5-SNAPSHOT" type="java-source" version="0.5-20180304.184830-1" snapshot="true">
<artifact extension="jar" baseVersion="0.5-SNAPSHOT" groupId="com.example" classifier="sources" artifactId="my-jar" id="com.example:my-jar:java-source:sources:0.5-SNAPSHOT" type="java-source" version="0.5-20180304.184830-2" snapshot="true">
<file>/path/to/my-jar/target/my-jar-0.5-SNAPSHOT-sources.jar</file>
</artifact>
</attachedArtifacts>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@
<build sourceDirectory="/Users/Shared/Jenkins/Home/workspace/my-jar/src/main/java" directory="/Users/Shared/Jenkins/Home/workspace/my-jar/target"/>
</project>
<no-execution-found/>
<artifact extension="pom" baseVersion="0.5-SNAPSHOT" groupId="com.example" artifactId="my-jar" id="com.example:my-jar:pom:0.5-SNAPSHOT" type="pom" version="0.5-20180410.070244-14" snapshot="true">
<artifact extension="pom" baseVersion="0.5-SNAPSHOT" groupId="com.example" artifactId="my-jar" id="com.example:my-jar:pom:0.5-SNAPSHOT" type="pom" version="0.5-20180410.070244-15" snapshot="true">
<file/>
</artifact>
<attachedArtifacts>
<artifact extension="ova" baseVersion="0.5-SNAPSHOT" groupId="com.example" artifactId="my-jar" id="com.example:my-jar:ova:0.5-SNAPSHOT" type="ova" version="0.5-20180410.070244-14" snapshot="true">
<artifact extension="ova" baseVersion="0.5-SNAPSHOT" groupId="com.example" artifactId="my-jar" id="com.example:my-jar:ova:0.5-SNAPSHOT" type="ova" version="0.5-20180410.070244-15" snapshot="true">
<file>/Users/Shared/Jenkins/Home/workspace/my-jar/my-jar-0.5-SNAPSHOT.ova</file>
</artifact>
</attachedArtifacts>
Expand Down