Skip to content

Commit

Permalink
Sort out classloader issues on saas relating to static state on this …
Browse files Browse the repository at this point in the history
…recipe
  • Loading branch information
sambsnyd committed Oct 23, 2023
1 parent bb04cd1 commit e3521a1
Showing 1 changed file with 42 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ 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<GroupArtifact, String> getInitialValue(ExecutionContext ctx) {
return new HashMap<>();
}

@Override
public TreeVisitor<?, ExecutionContext> getScanner(Map<GroupArtifact, String> acc) {
final XPathMatcher PROJECT_MATCHER = new XPathMatcher("/project");
final Pattern SEMVER_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)\\.?(\\d+)?(-.+)?$");

return new MavenIsoVisitor<ExecutionContext>() {
@Override
public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
Expand Down Expand Up @@ -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<?, ExecutionContext> getVisitor(Map<GroupArtifact, String> acc) {
return new MavenIsoVisitor<ExecutionContext>() {
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) {
Expand All @@ -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;
}
}

0 comments on commit e3521a1

Please sign in to comment.