Skip to content

Commit

Permalink
[JENKINS-28913] correctly regenerate the ID.
Browse files Browse the repository at this point in the history
If the id was not generated correctly then delete the file before
regenerating the ID, otherwise the new ID will never be created.
  • Loading branch information
jtnord committed Jun 15, 2015
1 parent f79e4cd commit aa7d348
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Expand Up @@ -64,7 +64,8 @@ public String get(PersistenceRoot object) {
try {
String str = FileUtils.readFileToString(f, StandardCharsets.UTF_8);
if (str.length() == 0) {
// regenerate it.
// regenerate it JENKINS-28913
f.delete();
make(object);
str = FileUtils.readFileToString(f, StandardCharsets.UTF_8);
}
Expand Down
20 changes: 19 additions & 1 deletion src/test/java/org/jenkinsci/plugins/uniqueid/IdTest.java
Expand Up @@ -4,18 +4,21 @@
import hudson.model.AbstractProject;
import hudson.model.Project;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

import org.hamcrest.core.Is;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import com.cloudbees.hudson.plugins.folder.Folder;

import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
Expand Down Expand Up @@ -81,4 +84,19 @@ public void uniqueness() throws Exception {
}
assertThat(ids, hasSize(200));
}

@Test
@Issue("JENKINS-28913")
public void correctJenkins28913() throws Exception {
Project<?, ?> p = jenkinsRule.createFreeStyleProject();
File f = new File(p.getRootDir(), "unique-id.txt");
assertThat(f.exists(), is(false));

assertThat("no Id yet made", IdStore.getId(p), nullValue());

assertThat(f.createNewFile(), is(true));

String id = IdStore.getId(p);
assertThat("id file was empty should have been re-gernerated", id.length(), greaterThan(20));
}
}

0 comments on commit aa7d348

Please sign in to comment.