Skip to content

Commit

Permalink
Parse pom.xml without SCM section in `PluginRemoting#retrievePomDat…
Browse files Browse the repository at this point in the history
…a` (#451)
  • Loading branch information
basil committed Feb 8, 2023
1 parent 142eefa commit 2b33259
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ public PomData retrievePomData() throws PluginSourcesUnavailableException {
model.getArtifactId(),
model.getPackaging(),
// scm may contain properties so it needs to be resolved.
interpolateString(model.getScm().getConnection(), model.getArtifactId()),
model.getScm().getTag(),
interpolateString(
model.getScm() != null ? model.getScm().getConnection() : null,
model.getArtifactId()),
model.getScm() != null ? model.getScm().getTag() : null,
parent,
model.getGroupId());
}
Expand Down
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
Expand Up @@ -4,6 +4,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

import java.io.File;
import org.junit.Test;

public class PluginRemotingTest {
Expand All @@ -28,4 +29,34 @@ public void testStringInterpolation() {
PluginRemoting.interpolateString("${projectXartifactId}suffix", "something"),
is("${projectXartifactId}suffix"));
}

@Test
public void smokes() throws Exception {
File pomFile = new File(getClass().getResource("smokes/pom.xml").toURI());
PluginRemoting pluginRemoting = new PluginRemoting(pomFile);
PomData pomData = pluginRemoting.retrievePomData();
assertThat(pomData.parent, nullValue());
assertThat(pomData.groupId, is("com.example.jenkins"));
assertThat(pomData.artifactId, is("example"));
assertThat(pomData.getPackaging(), is("hpi"));
assertThat(
pomData.getConnectionUrl(),
is("scm:git:https://jenkins.example.com/example-plugin.git"));
assertThat(pomData.getScmTag(), is("example-4.1"));
}

@Test
public void noScm() throws Exception {
File pomFile = new File(getClass().getResource("scm/pom.xml").toURI());
PluginRemoting pluginRemoting = new PluginRemoting(pomFile);
PomData pomData = pluginRemoting.retrievePomData();
assertThat(
pomData.parent,
is(new MavenCoordinates("com.example.jenkins", "example-parent", "4.1")));
assertThat(pomData.groupId, nullValue());
assertThat(pomData.artifactId, is("example"));
assertThat(pomData.getPackaging(), is("hpi"));
assertThat(pomData.getConnectionUrl(), nullValue());
assertThat(pomData.getScmTag(), nullValue());
}
}
13 changes: 13 additions & 0 deletions src/test/resources/org/jenkins/tools/test/model/scm/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example.jenkins</groupId>
<artifactId>example-parent</artifactId>
<version>4.1</version>
</parent>
<artifactId>example</artifactId>
<packaging>hpi</packaging>
<name>Example</name>
<url>https://jenkins.example.com/example-plugin</url>
</project>
39 changes: 39 additions & 0 deletions src/test/resources/org/jenkins/tools/test/model/smokes/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.jenkins</groupId>
<artifactId>example</artifactId>
<version>4.1</version>
<packaging>hpi</packaging>
<name>Example</name>
<url>https://jenkins.example.com/example-plugin</url>
<licenses>
<license>
<name>The MIT License (MIT)</name>
<url>https://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<connection>scm:git:https://jenkins.example.com/example-plugin.git</connection>
<developerConnection>scm:git:git@jenkins.example.com/example-plugin.git</developerConnection>
<tag>example-4.1</tag>
<url>https://jenkins.example.com/example-plugin</url>
</scm>
<distributionManagement>
<repository>
<id>maven.example.com</id>
<url>https://repo.example.com/releases/</url>
</repository>
<snapshotRepository>
<id>maven.example.com</id>
<url>https://repo.example.com/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>repo.example.com</id>
<url>https://repo.example.com/public/</url>
</repository>
</repositories>
</project>

0 comments on commit 2b33259

Please sign in to comment.