-
-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathDefaultChildLoader.java
More file actions
38 lines (32 loc) · 1.21 KB
/
DefaultChildLoader.java
File metadata and controls
38 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.cloudbees.hudson.plugins.folder;
import hudson.Extension;
import hudson.model.TopLevelItem;
import hudson.util.CopyOnWriteMap;
import java.io.File;
import java.util.Map;
import java.util.function.Function;
@Extension
public final class DefaultChildLoader extends ChildLoader {
@Override
public <K, V extends TopLevelItem> Map<K, V> loadChildren(
AbstractFolder<V> parent, File modulesDir, Function<? super V, ? extends K> key) {
CopyOnWriteMap.Tree<K, V> configurations = new CopyOnWriteMap.Tree<>();
if (!ensureDirExists(modulesDir, parent)) {
return configurations;
}
File[] subdirs = modulesDir.listFiles(File::isDirectory);
if (subdirs == null) {
return configurations;
}
Map<String, V> byDirName = getItemsByDirName(parent);
for (File subdir : subdirs) {
// Try to retain the identity of an existing child object if we can.
V existingItem = byDirName.get(subdir.getName());
V item = loadItem(parent, subdir, existingItem);
if (item != null) {
configurations.put(key.apply(item), item);
}
}
return configurations;
}
}