diff --git a/core/src/main/java/hudson/model/AbstractItem.java b/core/src/main/java/hudson/model/AbstractItem.java index 35c491bf67d4..0649bdb33b10 100644 --- a/core/src/main/java/hudson/model/AbstractItem.java +++ b/core/src/main/java/hudson/model/AbstractItem.java @@ -966,7 +966,7 @@ public void load() throws IOException { Items.whileUpdatingByXml(new NotReallyRoleSensitiveCallable() { @Override public Void call() throws IOException { - onLoad(getParent(), getRootDir().getName()); + onLoad(getParent(), getParent().getItemName(getRootDir(), AbstractItem.this)); return null; } }); diff --git a/core/src/main/java/hudson/model/ItemGroup.java b/core/src/main/java/hudson/model/ItemGroup.java index 6404e82626e1..4ff13df71bfe 100644 --- a/core/src/main/java/hudson/model/ItemGroup.java +++ b/core/src/main/java/hudson/model/ItemGroup.java @@ -176,4 +176,17 @@ default Iterable allItems() { // TODO could delegate to allItems overload taking Authentication, but perhaps more useful to introduce a variant to perform preauth filtering using Predicate and check Item.READ afterwards // or return a Stream and provide a Predicate public static Items.readable(), and see https://stackoverflow.com/q/22694884/12916 if you are looking for just one result + /** + * Determines the item name based on a logic that can be overridden (e.g. by AbstractFolder). + * + * Defaults to the item root directory name. + * + * @param dir The root directory the item was loaded from. + * @param item the partially loaded item (take care what methods you call, the item will not have a reference to its parent). + * + * @since TODO + */ + default String getItemName(File dir, T item) { + return dir.getName(); + } } diff --git a/core/src/main/java/hudson/model/Items.java b/core/src/main/java/hudson/model/Items.java index ee460686b949..a1386565cfd0 100644 --- a/core/src/main/java/hudson/model/Items.java +++ b/core/src/main/java/hudson/model/Items.java @@ -373,7 +373,7 @@ static String getRelativeNameFrom(String itemFullName, String groupFullName) { */ public static Item load(ItemGroup parent, File dir) throws IOException { Item item = (Item) getConfigFile(dir).read(); - item.onLoad(parent, dir.getName()); + item.onLoad(parent, parent.getItemName(dir, item)); return item; }