From e3521a1f1dd199bb87496c38ea0e91ca0829a572 Mon Sep 17 00:00:00 2001 From: Sam Snyder Date: Mon, 23 Oct 2023 11:39:01 -0700 Subject: [PATCH] Sort out classloader issues on saas relating to static state on this recipe --- .../maven/IncrementProjectVersion.java | 82 ++++++++++--------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/IncrementProjectVersion.java b/rewrite-maven/src/main/java/org/openrewrite/maven/IncrementProjectVersion.java index 259f82aca95..8f924eb8182 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/IncrementProjectVersion.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/IncrementProjectVersion.java @@ -69,10 +69,6 @@ public enum SemverDigit { PATCH } - private static final Pattern SEMVER_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)\\.?(\\d+)?(-.+)?$"); - private static final XPathMatcher PROJECT_MATCHER = new XPathMatcher("/project"); - private static final XPathMatcher PARENT_MATCHER = new XPathMatcher("/project/parent"); - @Override public Map getInitialValue(ExecutionContext ctx) { return new HashMap<>(); @@ -80,6 +76,9 @@ public Map getInitialValue(ExecutionContext ctx) { @Override public TreeVisitor getScanner(Map acc) { + final XPathMatcher PROJECT_MATCHER = new XPathMatcher("/project"); + final Pattern SEMVER_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)\\.?(\\d+)?(-.+)?$"); + return new MavenIsoVisitor() { @Override public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { @@ -111,12 +110,51 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { newVersion); return t; } + + private String incrementSemverDigit(String oldVersion) { + Matcher m = SEMVER_PATTERN.matcher(oldVersion); + if(!m.matches()) { + return oldVersion; + } + String major = m.group(1); + String minor = m.group(2); + String patch = m.group(3); + // Semver does not have a concept of a fourth number, but it is common enough to support + String fourth = m.group(4); + String extra = m.group(5); + switch (digit) { + case MAJOR: + major = String.valueOf(Integer.parseInt(major) + 1); + minor = "0"; + patch = "0"; + break; + case MINOR: + minor = String.valueOf(Integer.parseInt(minor) + 1); + patch = "0"; + break; + case PATCH: + patch = String.valueOf(Integer.parseInt(patch) + 1); + break; + } + if(fourth == null) { + fourth = ""; + } else { + fourth = ".0"; + } + if(extra == null) { + extra = ""; + } + return major + "." + minor + "." + patch + fourth + extra; + } }; + } @Override public TreeVisitor getVisitor(Map acc) { return new MavenIsoVisitor() { + final XPathMatcher PARENT_MATCHER = new XPathMatcher("/project/parent"); + final XPathMatcher PROJECT_MATCHER = new XPathMatcher("/project"); @Override public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { @@ -137,40 +175,4 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { } }; } - - private String incrementSemverDigit(String oldVersion) { - Matcher m = SEMVER_PATTERN.matcher(oldVersion); - if(!m.matches()) { - return oldVersion; - } - String major = m.group(1); - String minor = m.group(2); - String patch = m.group(3); - // Semver does not have a concept of a fourth number, but it is common enough to support - String fourth = m.group(4); - String extra = m.group(5); - switch (digit) { - case MAJOR: - major = String.valueOf(Integer.parseInt(major) + 1); - minor = "0"; - patch = "0"; - break; - case MINOR: - minor = String.valueOf(Integer.parseInt(minor) + 1); - patch = "0"; - break; - case PATCH: - patch = String.valueOf(Integer.parseInt(patch) + 1); - break; - } - if(fourth == null) { - fourth = ""; - } else { - fourth = ".0"; - } - if(extra == null) { - extra = ""; - } - return major + "." + minor + "." + patch + fourth + extra; - } }