Skip to content

Commit

Permalink
Merge pull request #77 from jonesbusy/feature/handle-bom-baseline
Browse files Browse the repository at this point in the history
Handle jenkins.baseline on AddPluginsPom
  • Loading branch information
jonesbusy authored Nov 11, 2024
2 parents 1cb0139 + ad0f851 commit c08e927
Show file tree
Hide file tree
Showing 4 changed files with 492 additions and 366 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/openrewrite/jenkins/AddPluginsBom.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
if (isManagedDependencyTag()) {
String groupId = tag.getChildValue("groupId").orElse("");
String artifactId = tag.getChildValue("artifactId").orElse("");
if (artifactId.equals("bom-${jenkins.baseline}.x")) {
artifactId = "bom-" + getResolutionResult().getPom().getProperties().get("jenkins.baseline") + ".x";
}
if (PLUGINS_BOM_GROUP_ID.equals(groupId) && !artifactId.isEmpty()) {
List<Xml.Tag> pluginBoms = getCursor().getNearestMessage(PLUGIN_BOMS_KEY, new LinkedList<>());
pluginBoms.add(t);
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/org/openrewrite/jenkins/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* Utility class
*/
class Jenkins {
private static final Predicate<String> LTS_PATTERN = Pattern.compile("^\\d\\.\\d+\\.\\d$").asPredicate();
private static final Predicate<String> LTS_PATTERN = Pattern.compile("^\\d\\.(\\d+)\\.\\d$").asPredicate();
private static final Predicate<String> LTS_BASELINE_PATTERN = Pattern.compile("^\\$\\{jenkins.baseline\\}.\\d$").asPredicate();

/**
* Determines if this is a Jenkins Plugin Pom by checking for a managed version
Expand All @@ -46,10 +47,15 @@ class Jenkins {

@NonNull
public static String bomNameForJenkinsVersion(@NonNull String version) {
if (LTS_PATTERN.test(version)) {
int lastIndex = version.lastIndexOf(".");
String prefix = version.substring(0, lastIndex);
return "bom-" + prefix + ".x";
if (LTS_PATTERN.test(version) || LTS_BASELINE_PATTERN.test(version)) {
if (version.startsWith("${jenkins.baseline}")) {
return "bom-${jenkins.baseline}.x";
}
else {
int lastIndex = version.lastIndexOf(".");
String prefix = version.substring(0, lastIndex);
return "bom-" + prefix + ".x";
}
}
return "bom-weekly";
}
Expand Down
Loading

0 comments on commit c08e927

Please sign in to comment.