Skip to content
Permalink
Browse files
Avoid trying to update build number for tags that don't have one
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Mar 22, 2021
1 parent 1843566 commit 3fb77c90a2f2a11c5f6b0effd8f35ec2c67a63b7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
@@ -182,7 +182,7 @@ private List<Throwable> handleTags(Repository localRepo, UpdateHistory history,
.map(OpenJDKTag::create)
.filter(Optional::isPresent)
.map(Optional::get)
.sorted(Comparator.comparingInt(OpenJDKTag::buildNum))
.sorted(Comparator.comparingInt(tag -> tag.buildNum().orElse(-1)))
.collect(Collectors.toList());
for (var tag : newJdkTags) {
var commits = new ArrayList<Commit>();
@@ -281,6 +281,9 @@ public void onNewOpenJDKTagCommits(HostedRepository repository, Repository local
if (buildName == null) {
return;
}
if (tag.buildNum().isEmpty()) {
return;
}

for (var commit : commits) {
var commitMessage = CommitMessageParsers.v1.parse(commit);
@@ -344,7 +347,7 @@ public void onNewOpenJDKTagCommits(HostedRepository repository, Repository local

// Check if the build name should be updated
var oldBuild = issue.properties().getOrDefault("customfield_10006", JSON.of());
var newBuild = "b" + String.format("%02d", tag.buildNum());
var newBuild = "b" + String.format("%02d", tag.buildNum().get());
if (BuildCompare.shouldReplace(newBuild, oldBuild.asString())) {
issue.setProperty("customfield_10006", JSON.of(newBuild));
} else {
@@ -95,7 +95,10 @@ public void onNewCommits(HostedRepository repository, Repository localRepository

@Override
public void onNewOpenJDKTagCommits(HostedRepository repository, Repository localRepository, List<Commit> commits, OpenJDKTag tag, Tag.Annotated annotation) throws NonRetriableException {
var build = String.format("b%02d", tag.buildNum());
if (tag.buildNum().isEmpty()) {
return;
}
var build = String.format("b%02d", tag.buildNum().get());
try (var writer = new JsonWriter(path, repository.name())) {
var issues = new ArrayList<Issue>();
for (var commit : commits) {
@@ -108,25 +108,25 @@ public String version() {
*
* @return
*/
public int buildNum() {
public Optional<Integer> buildNum() {
if (buildNum == null) {
return 0;
return Optional.empty();
}
return Integer.parseInt(buildNum);
return Optional.of(Integer.parseInt(buildNum));
}

/**
* Tag of the previous build (if any).
* Tag of the previous build (if any). Build 0 (and no build number at all) have no previous build.
*
* @return
*/
public Optional<OpenJDKTag> previous() {
if (buildNum() == 0) {
if (buildNum().orElse(0) == 0) {
return Optional.empty();
}

// Make sure build numbers < 10 for JDK 9 tags are not prefixed with '0'
var previousBuildNum = buildNum() - 1;
var previousBuildNum = buildNum().get() - 1;
var formattedBuildNum = String.format(buildPrefix.equals("+") ? "%d" : "%02d", previousBuildNum);
var tagName = prefix + buildPrefix + formattedBuildNum;
var tag = new Tag(tagName);
@@ -33,64 +33,64 @@ class OpenJDKTagTests {
void parseTags() {
var tag = new Tag("jdk-10+20");
var jdkTag = OpenJDKTag.create(tag).orElseThrow();
assertEquals(20, jdkTag.buildNum());
assertEquals(20, jdkTag.buildNum().orElseThrow());
var previousTag = jdkTag.previous().orElseThrow();
assertEquals(19, previousTag.buildNum());
assertEquals(19, previousTag.buildNum().orElseThrow());
}

@Test
void parseSingleDigitTags() {
var tag = new Tag("jdk-10+10");
var jdkTag = OpenJDKTag.create(tag).orElseThrow();
assertEquals(10, jdkTag.buildNum());
assertEquals(10, jdkTag.buildNum().orElseThrow());
var previousTag = jdkTag.previous().orElseThrow();
assertEquals("jdk-10+9", previousTag.tag().name());
assertEquals(9, previousTag.buildNum());
assertEquals(9, previousTag.buildNum().orElseThrow());
}

@Test
void parseLegacyTags() {
var tag = new Tag("jdk7-b147");
var jdkTag = OpenJDKTag.create(tag).orElseThrow();
assertEquals(147, jdkTag.buildNum());
assertEquals(147, jdkTag.buildNum().orElseThrow());
var previousTag = jdkTag.previous().orElseThrow();
assertEquals(146, previousTag.buildNum());
assertEquals(146, previousTag.buildNum().orElseThrow());
}

@Test
void parseSingleDigitLegacyTags() {
var tag = new Tag("jdk7-b10");
var jdkTag = OpenJDKTag.create(tag).orElseThrow();
assertEquals(10, jdkTag.buildNum());
assertEquals(10, jdkTag.buildNum().orElseThrow());
var previousTag = jdkTag.previous().orElseThrow();
assertEquals("jdk7-b09", previousTag.tag().name());
assertEquals(9, previousTag.buildNum());
assertEquals(9, previousTag.buildNum().orElseThrow());
}

@Test
void parseHotspotTags() {
var tag = new Tag("hs23.6-b19");
var jdkTag = OpenJDKTag.create(tag).orElseThrow();
assertEquals(19, jdkTag.buildNum());
assertEquals(19, jdkTag.buildNum().orElseThrow());
var previousTag = jdkTag.previous().orElseThrow();
assertEquals(18, previousTag.buildNum());
assertEquals(18, previousTag.buildNum().orElseThrow());
}

@Test
void parseSingleDigitHotspotTags() {
var tag = new Tag("hs23.6-b10");
var jdkTag = OpenJDKTag.create(tag).orElseThrow();
assertEquals(10, jdkTag.buildNum());
assertEquals(10, jdkTag.buildNum().orElseThrow());
var previousTag = jdkTag.previous().orElseThrow();
assertEquals("hs23.6-b09", previousTag.tag().name());
assertEquals(9, previousTag.buildNum());
assertEquals(9, previousTag.buildNum().orElseThrow());
}

@Test
void noPrevious() {
var tag = new Tag("jdk-10+0");
var jdkTag = OpenJDKTag.create(tag).orElseThrow();
assertEquals(0, jdkTag.buildNum());
assertEquals(0, jdkTag.buildNum().orElseThrow());
assertFalse(jdkTag.previous().isPresent());
}

@@ -99,16 +99,16 @@ void parseJfxTags() {
var tag = new Tag("12.1.3+14");
var jdkTag = OpenJDKTag.create(tag).orElseThrow();
assertEquals("12.1.3", jdkTag.version());
assertEquals(14, jdkTag.buildNum());
assertEquals(14, jdkTag.buildNum().orElseThrow());
var previousTag = jdkTag.previous().orElseThrow();
assertEquals(13, previousTag.buildNum());
assertEquals(13, previousTag.buildNum().orElseThrow());
}

@Test
void parseJfxTagsGa() {
var tag = new Tag("12.1-ga");
var jdkTag = OpenJDKTag.create(tag).orElseThrow();
assertEquals("12.1", jdkTag.version());
assertEquals(0, jdkTag.buildNum());
assertTrue(jdkTag.buildNum().isEmpty());
}
}

1 comment on commit 3fb77c9

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 3fb77c9 Mar 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.