Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-41124] Additional tracking of legacy name
  • Loading branch information
stephenc committed Jan 20, 2017
1 parent 93e075a commit b2e6e88
Showing 1 changed file with 20 additions and 9 deletions.
Expand Up @@ -534,12 +534,12 @@ public boolean accept(File child) {
}
// Try to retain the identity of an existing child object if we can.
V item = byDirName.get(childName);
boolean itemNeedsSave = false;
if (item == null) {
XmlFile xmlFile = Items.getConfigFile(subdir);
if (xmlFile.exists()) {
item = (V) xmlFile.read();
String name;
boolean itemNeedsSave = false;
if (childNameGenerator == null) {
name = subdir.getName();
} else {
Expand Down Expand Up @@ -595,14 +595,6 @@ public boolean accept(File child) {
}
}
item.onLoad(parent, name);
if (itemNeedsSave) {
try {
item.save();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Could not update {0} after applying folder naming rules",
item.getFullName());
}
}
} else {
Logger.getLogger(AbstractFolder.class.getName())
.log(Level.WARNING, "could not find file " + xmlFile.getFile());
Expand All @@ -618,6 +610,17 @@ public boolean accept(File child) {
if (name == null) {
name = childNameGenerator.itemNameFromLegacy(parent, childName);
FileUtils.writeStringToFile(nameFile, name, "UTF-8");
BulkChange bc = new BulkChange(item); // suppress any attempt to save as parent not set
try {
childNameGenerator.recordLegacyName(parent, item, childName);
itemNeedsSave = true;
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Ignoring {0} as could not record legacy name",
subdir);
continue;
} finally {
bc.abort();
}
} else if (!childName.equals(name) || legacy) {
FileUtils.writeStringToFile(nameFile, name, "UTF-8");
}
Expand All @@ -633,6 +636,14 @@ public boolean accept(File child) {
}
item.onLoad(parent, name);
}
if (itemNeedsSave) {
try {
item.save();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Could not update {0} after applying folder naming rules",
item.getFullName());
}
}
configurations.put(key.call(item), item);
} catch (Exception e) {
Logger.getLogger(ItemGroupMixIn.class.getName()).log(Level.WARNING, "could not load " + subdir, e);
Expand Down

0 comments on commit b2e6e88

Please sign in to comment.