Skip to content

Commit

Permalink
[JENKINS-72613] Introduced ItemGroup.getItemName (#8902)
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored Feb 1, 2024
1 parent d7be82a commit 57419f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/AbstractItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ public void load() throws IOException {
Items.whileUpdatingByXml(new NotReallyRoleSensitiveCallable<Void, IOException>() {
@Override
public Void call() throws IOException {
onLoad(getParent(), getRootDir().getName());
onLoad(getParent(), getParent().getItemName(getRootDir(), AbstractItem.this));
return null;
}
});
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/hudson/model/ItemGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,17 @@ default Iterable<Item> 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<Item> and provide a Predicate<Item> 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();
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 57419f4

Please sign in to comment.