Skip to content

Commit

Permalink
Merge pull request #558 from jonesbusy/feature/ensure-relative-path-t…
Browse files Browse the repository at this point in the history
…op-level

Made `EnsureRelativePath` a top level recipe
  • Loading branch information
jonesbusy authored Jan 2, 2025
2 parents 9a91821 + 345340b commit 9cbffde
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import io.jenkins.tools.pluginmodernizer.core.model.Plugin
@import io.jenkins.tools.pluginmodernizer.core.model.Recipe
@param Plugin plugin
@param Recipe recipe
Disable local resolution of parent pom
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ recipeList:
artifactId: commons-text
---
type: specs.openrewrite.org/v1beta/recipe
name: io.jenkins.tools.pluginmodernizer.EnsureRelativePath
displayName: Disable local resolution of parent POM
description: Disable local resolution of parent POM.
tags: ['chore']
recipeList:
- io.jenkins.tools.pluginmodernizer.core.recipes.EnsureRelativePath
---
type: specs.openrewrite.org/v1beta/recipe
name: io.jenkins.tools.pluginmodernizer.UpgradeToRecommendCoreVersion
displayName: Upgrade to latest recommended core version and ensure the bom is matching the core version
description: Upgrade to latest recommended core version and ensure the bom is matching the core version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,72 @@ void migrateToJenkinsBaseLinePropertyTest() {
"""));
}

@Test
void ensureEnsureRelativePath() {
rewriteRun(
spec -> spec.recipeFromResource(
"/META-INF/rewrite/recipes.yml", "io.jenkins.tools.pluginmodernizer.EnsureRelativePath"),
// language=xml
pomXml(
"""
<?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>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.88</version>
</parent>
<groupId>io.jenkins.plugins</groupId>
<artifactId>empty</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Empty Plugin</name>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
""",
"""
<?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>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.88</version>
<relativePath />
</parent>
<groupId>io.jenkins.plugins</groupId>
<artifactId>empty</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Empty Plugin</name>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
"""));
}

@Test
void shouldRemoveReleaseDrafterIfContinuousDeliveryEnabled() {
rewriteRun(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,24 @@ public void testFriendlyPrTitleRemoveReleaseDrafter() {
// Assert
assertEquals("Remove release drafter due to enabled cd", result);
}

@Test
public void testFriendlyPrTitleEnsureRelativePath() {

// Mocks
Plugin plugin = mock(Plugin.class);
PluginMetadata metadata = mock(PluginMetadata.class);
Recipe recipe = mock(Recipe.class);

doReturn(metadata).when(plugin).getMetadata();
doReturn("io.jenkins.tools.pluginmodernizer.EnsureRelativePath")
.when(recipe)
.getName();

// Test
String result = TemplateUtils.renderPullRequestTitle(plugin, recipe);

// Assert
assertEquals("Disable local resolution of parent pom", result);
}
}

0 comments on commit 9cbffde

Please sign in to comment.