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

Handle jenkins.baseline on AddPluginsPom #77

Merged
merged 3 commits into from
Nov 11, 2024
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
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