Skip to content

Commit

Permalink
[JENKINS-41124] When using a ChildNameGenerator, record the name for …
Browse files Browse the repository at this point in the history
…new items too
  • Loading branch information
stephenc committed Jan 18, 2017
1 parent 1d90bf7 commit 9f4be16
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Expand Up @@ -621,6 +621,31 @@ public boolean accept(File child) {
}


protected final I itemsPut(String name, I item) {
ChildNameGenerator<AbstractFolder<I>, I> childNameGenerator = childNameGenerator();
if (childNameGenerator != null) {
File nameFile = new File(getRootDirFor(item), ChildNameGenerator.CHILD_NAME_FILE);
String oldName;
if (nameFile.isFile()) {
try {
oldName = StringUtils.trimToNull(FileUtils.readFileToString(nameFile, "UTF-8"));
} catch (IOException e) {
oldName = null;
}
} else {
oldName = null;
}
if (!name.equals(oldName)) {
try {
FileUtils.writeStringToFile(nameFile, name, "UTF-8");
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Could not create " + nameFile);
}
}
}
return items.put(name, item);
}

/**
* {@inheritDoc}
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/cloudbees/hudson/plugins/folder/Folder.java
Expand Up @@ -331,7 +331,7 @@ public DescriptorImpl getDescriptor() {
if (items.containsKey(name)) {
throw new IllegalArgumentException("already an item '" + name + "'");
}
items.put(item.getName(), item);
itemsPut(item.getName(), item);
return item;
}

Expand Down Expand Up @@ -378,7 +378,7 @@ private MixInImpl(Folder parent) {

@Override
protected void add(TopLevelItem item) {
items.put(item.getName(), item);
itemsPut(item.getName(), item);
}

@Override
Expand Down
Expand Up @@ -672,7 +672,7 @@ public void created(I child) {
} catch (IOException x) {
LOGGER.log(Level.WARNING, "Failed to save " + child, x);
}
items.put(name, child);
itemsPut(name, child);
Jenkins j = Jenkins.getInstance();
if (j != null) {
j.rebuildDependencyGraphAsync();
Expand Down Expand Up @@ -747,7 +747,7 @@ public void created(I child) {
} catch (IOException x) {
LOGGER.log(Level.WARNING, "Failed to save " + child, x);
}
items.put(name, child);
itemsPut(name, child);
Jenkins j = Jenkins.getInstance();
if (j != null) {
j.rebuildDependencyGraphAsync();
Expand Down

0 comments on commit 9f4be16

Please sign in to comment.