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

Parse pom.xml without SCM section in PluginRemoting#retrievePomData #451

Merged
merged 2 commits into from
Feb 8, 2023
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 @@ -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
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>