Skip to content

Commit

Permalink
Merge pull request #708 from jonesbusy/feature/group-bom-update
Browse files Browse the repository at this point in the history
Fix some tests and group bom update
  • Loading branch information
jonesbusy authored Jan 25, 2025
2 parents 3b9e810 + 67a8e4f commit da7ccd5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 25 deletions.
2 changes: 1 addition & 1 deletion plugin-modernizer-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.479.x</artifactId>
<version>3944.v1a_e4f8b_452db_</version>
<version>4023.va_eeb_b_4e45f07</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLParser;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException;
import io.jenkins.tools.pluginmodernizer.core.model.Plugin;
import io.jenkins.tools.pluginmodernizer.core.model.Recipe;
Expand All @@ -17,6 +16,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
Expand Down Expand Up @@ -60,6 +61,9 @@ public class Settings {

public static final Double PLUGIN_LOW_SCORE_THRESHOLD = 80.0;

public static final Predicate<String> JENKINS_VERSION_LTS_PATTERN =
Pattern.compile("^\\d\\.(\\d+)\\.\\d$").asPredicate();

public static final String ADOPTIUM_GITHUB_API_URL = "https://api.github.com/repos/adoptium";

public static final ComparableVersion MAVEN_MINIMAL_VERSION = new ComparableVersion("3.9.7");
Expand Down Expand Up @@ -177,27 +181,57 @@ private static Path getDefaultMavenLocalRepo() {
return Path.of(mavenLocalRepo);
}

private static @Nullable String getRewritePluginVersion() {
private static String getRewritePluginVersion() {
return readProperty("openrewrite.maven.plugin.version", "versions.properties");
}

public static @Nullable String getJenkinsParentVersion() {
public static String getJenkinsParentVersion() {
return readProperty("jenkins.parent.version", "versions.properties");
}

public static @Nullable String getBomVersion() {
public static String getBomVersion() {
return readProperty("bom.version", "versions.properties");
}

private static @Nullable URL getUpdateCenterUrl() throws MalformedURLException {
public static String getJenkinsMinimumVersion() {
return readProperty("jenkins.core.minimum.version", "versions.properties");
}

public static String getJenkinsMinimumBaseline() {
String jenkinsVersion = getJenkinsMinimumVersion();
if (JENKINS_VERSION_LTS_PATTERN.test(jenkinsVersion)) {
int lastIndex = jenkinsVersion.lastIndexOf(".");
return jenkinsVersion.substring(0, lastIndex);
}
return jenkinsVersion;
}

public static String getJenkinsMinimumPatchVersion() {
String jenkinsVersion = getJenkinsMinimumVersion();
// Get last digit
int lastIndex = jenkinsVersion.lastIndexOf(".");
return jenkinsVersion.substring(lastIndex + 1);
}

public static String getBomArtifactId() {
String jenkinsVersion = getJenkinsMinimumVersion();
if (JENKINS_VERSION_LTS_PATTERN.test(jenkinsVersion) || JENKINS_VERSION_LTS_PATTERN.test(jenkinsVersion)) {
int lastIndex = jenkinsVersion.lastIndexOf(".");
String prefix = jenkinsVersion.substring(0, lastIndex);
return "bom-" + prefix + ".x";
}
return "bom-weekly";
}

private static URL getUpdateCenterUrl() throws MalformedURLException {
String url = System.getenv("JENKINS_UC");
if (url != null) {
return new URL(url);
}
return new URL(readProperty("update.center.url", "urls.properties"));
}

private static @Nullable URL getPluginVersions() throws MalformedURLException {
private static URL getPluginVersions() throws MalformedURLException {
String url = System.getenv("JENKINS_PLUGIN_INFO");
if (url != null) {
return new URL(url);
Expand All @@ -220,15 +254,15 @@ private static URL getGithubApiUrl() throws MalformedURLException {
return readProperty("remediation.jenkins.plugin.parent.version", "versions.properties");
}

private static @Nullable URL getHealthScoreUrl() throws MalformedURLException {
private static URL getHealthScoreUrl() throws MalformedURLException {
String url = System.getenv("JENKINS_PHS");
if (url != null) {
return new URL(url);
}
return new URL(readProperty("plugin.health.score.url", "urls.properties"));
}

private static @Nullable URL getPluginsStatsInstallationsUrl() throws MalformedURLException {
private static URL getPluginsStatsInstallationsUrl() throws MalformedURLException {
String url = System.getenv("JENKINS_PLUGINS_STATS_INSTALLATIONS_URL");
if (url != null) {
return new URL(url);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
openrewrite.maven.plugin.version = ${openrewrite.maven.plugin.version}
jenkins.parent.version = 5.5
bom.version = 3944.v1a_e4f8b_452db_
bom.version = 4023.va_eeb_b_4e45f07
remediation.jenkins.plugin.parent.version = 2.37
jenkins.core.minimum.version = 2.462.3
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class UpgradeJenkinsVersionTest implements RewriteTest {
@Test
void testPerformUpgradeWithoutBom() {
rewriteRun(
spec -> spec.recipe(new UpgradeJenkinsVersion("2.452.4")),
spec -> spec.recipe(new UpgradeJenkinsVersion(Settings.getJenkinsMinimumVersion())),
// language=xml
pomXml(
"""
Expand Down Expand Up @@ -75,7 +75,7 @@ void testPerformUpgradeWithoutBom() {
<packaging>hpi</packaging>
<name>Empty Plugin</name>
<properties>
<jenkins.version>2.452.4</jenkins.version>
<jenkins.version>%s</jenkins.version>
</properties>
<repositories>
<repository>
Expand All @@ -90,13 +90,14 @@ void testPerformUpgradeWithoutBom() {
</pluginRepository>
</pluginRepositories>
</project>
"""));
"""
.formatted(Settings.getJenkinsMinimumVersion())));
}

@Test
void testPerformUpgradeWithBaselineWithoutBom() {
rewriteRun(
spec -> spec.recipe(new UpgradeJenkinsVersion("2.452.4")),
spec -> spec.recipe(new UpgradeJenkinsVersion(Settings.getJenkinsMinimumVersion())),
// language=xml
pomXml(
"""
Expand Down Expand Up @@ -148,8 +149,8 @@ void testPerformUpgradeWithBaselineWithoutBom() {
<packaging>hpi</packaging>
<name>Empty Plugin</name>
<properties>
<jenkins.baseline>2.452</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.4</jenkins.version>
<jenkins.baseline>%s</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.%s</jenkins.version>
</properties>
<repositories>
<repository>
Expand All @@ -164,13 +165,16 @@ void testPerformUpgradeWithBaselineWithoutBom() {
</pluginRepository>
</pluginRepositories>
</project>
"""));
"""
.formatted(
Settings.getJenkinsMinimumBaseline(),
Settings.getJenkinsMinimumPatchVersion())));
}

@Test
void testPerformUpgradeWithoutBaselineWithBomAndUpgradeBomIfDoesntExistsForNewJenkinsVersion() {
rewriteRun(
spec -> spec.recipe(new UpgradeJenkinsVersion("2.452.4")),
spec -> spec.recipe(new UpgradeJenkinsVersion(Settings.getJenkinsMinimumVersion())),
// language=xml
pomXml(
"""
Expand Down Expand Up @@ -232,13 +236,13 @@ void testPerformUpgradeWithoutBaselineWithBomAndUpgradeBomIfDoesntExistsForNewJe
<packaging>hpi</packaging>
<name>Empty Plugin</name>
<properties>
<jenkins.version>2.452.4</jenkins.version>
<jenkins.version>%s</jenkins.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.452.x</artifactId>
<artifactId>%s</artifactId>
<version>%s</version>
<type>pom</type>
<scope>import</scope>
Expand All @@ -259,13 +263,16 @@ void testPerformUpgradeWithoutBaselineWithBomAndUpgradeBomIfDoesntExistsForNewJe
</pluginRepositories>
</project>
"""
.formatted(Settings.getBomVersion())));
.formatted(
Settings.getJenkinsMinimumVersion(),
Settings.getBomArtifactId(),
Settings.getBomVersion())));
}

@Test
void testPerformUpgradeWithBaselineWithBomAndUpgradeBomIfDoesntExistsForNewJenkinsVersion() {
rewriteRun(
spec -> spec.recipe(new UpgradeJenkinsVersion("2.452.4")),
spec -> spec.recipe(new UpgradeJenkinsVersion(Settings.getJenkinsMinimumVersion())),
// language=xml
pomXml(
"""
Expand Down Expand Up @@ -328,8 +335,8 @@ void testPerformUpgradeWithBaselineWithBomAndUpgradeBomIfDoesntExistsForNewJenki
<packaging>hpi</packaging>
<name>Empty Plugin</name>
<properties>
<jenkins.baseline>2.452</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.4</jenkins.version>
<jenkins.baseline>%s</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.%s</jenkins.version>
</properties>
<dependencyManagement>
<dependencies>
Expand All @@ -356,6 +363,9 @@ void testPerformUpgradeWithBaselineWithBomAndUpgradeBomIfDoesntExistsForNewJenki
</pluginRepositories>
</project>
"""
.formatted(Settings.getBomVersion())));
.formatted(
Settings.getJenkinsMinimumBaseline(),
Settings.getJenkinsMinimumPatchVersion(),
Settings.getBomVersion())));
}
}

0 comments on commit da7ccd5

Please sign in to comment.