Skip to content
Permalink
Browse files

[JENKINS-41124] When using a ChildNameGenerator, record the name for …

…new items too
  • Loading branch information...
stephenc committed Jan 18, 2017
1 parent 1d90bf7 commit 9f4be16479e6b6e97e219531d3e7103a0ff096e1
@@ -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}
*/
@@ -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;
}

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

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

@Override
@@ -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();
@@ -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();

0 comments on commit 9f4be16

Please sign in to comment.
You can’t perform that action at this time.