-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathGitMaintenanceSCM.java
More file actions
93 lines (77 loc) · 2.4 KB
/
GitMaintenanceSCM.java
File metadata and controls
93 lines (77 loc) · 2.4 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package jenkins.plugins.git.maintenance;
import jenkins.model.Jenkins;
import jenkins.plugins.git.AbstractGitSCMSource;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* GitMaintenanceSCM is responsible for fetching all caches along with locks on Jenkins controller. It extends {@link AbstractGitSCMSource}.
*
* @author Hrushikesh Rao
*/
public class GitMaintenanceSCM extends AbstractGitSCMSource {
String remote;
private static Logger LOGGER = Logger.getLogger(GitMaintenanceSCM.class.getName());
protected GitMaintenanceSCM(String remote){
this.remote = remote;
}
/**
* Stores the File object and lock for cache.
*/
static class Cache {
File cache;
Lock lock;
Cache(File cache, Lock lock){
this.cache = cache;
this.lock = lock;
}
/**
* Return the File object of a cache.
* @return File object of a cache.
*/
public File getCacheFile(){
return cache;
}
/**
* Returns the lock for a cache.
*
* @return lock for a cache.
*/
public Lock getLock(){
return lock;
}
}
@Override
public String getCredentialsId() {
return null;
}
@Override
public String getRemote() {
return remote;
}
/**
* Returns a list of {@link Cache}.
* @return A list of {@link Cache}.
*/
public static List<Cache> getCaches(){
Jenkins jenkins = Jenkins.getInstanceOrNull();
List<Cache> caches = new ArrayList<>();
if (jenkins == null){
LOGGER.log(Level.WARNING,"Internal error. Couldn't get Jenkins instance.");
return caches;
}
for (String cacheEntry : getCacheEntries()) {
File cacheDir = getCacheDir(cacheEntry,false);
Lock cacheLock = getCacheLock(cacheEntry);
// skip caches size less than 10 mb
if(FileUtils.sizeOfDirectory(cacheDir) < 10000000)continue;
LOGGER.log(Level.FINE,"Cache Entry " + cacheEntry);
caches.add(new Cache(cacheDir,cacheLock));
}
return caches;
}
}