-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.groovy
49 lines (34 loc) · 1.38 KB
/
Utils.groovy
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
39
40
41
42
43
44
45
46
47
48
49
package org.egov.jenkins
import org.egov.jenkins.models.JobConfig
class Utils {
static List<String> foldersToBeCreatedOrUpdated(List<JobConfig> configs, def env) {
Set<String> folders = new HashSet<>();
configs.each { config ->
String configName = config.getName();
while(configName.lastIndexOf("/")!=-1) {
configName= configName.substring(0, configName.lastIndexOf("/"));
folders.add(configName);
}
}
List<String> uniqueFolders = folders.toList();
for (int j = 0; j < uniqueFolders.size()-1; j++) {
if (numberOfOccurrences(uniqueFolders.get(j),"/") > numberOfOccurrences(uniqueFolders.get(j + 1),"/")) {
String temp = uniqueFolders.get(j);
uniqueFolders.set(j,uniqueFolders.get(j + 1));
uniqueFolders.set(j+1,temp);
j = -1;
}
}
return uniqueFolders;
}
private static int numberOfOccurrences(String source, String match){
return source.length() - source.replace(match, "").length();
}
static String getDirName(String url) {
String dirName = "";
int startIndex = url.lastIndexOf("/");
int endIndex = url.lastIndexOf(".");
dirName = url.substring(startIndex+1,endIndex);
return dirName;
}
}