-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComputeComponentSize.groovy
More file actions
42 lines (33 loc) · 1.32 KB
/
ComputeComponentSize.groovy
File metadata and controls
42 lines (33 loc) · 1.32 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
import org.sonatype.nexus.repository.storage.StorageFacet
import org.sonatype.nexus.repository.Repository
import org.sonatype.nexus.repository.storage.Component
import groovy.json.JsonOutput
def completResult = []
repository.repositoryManager.browse().each { Repository repo ->
StorageFacet storageFacet = repo.facet(StorageFacet)
def tx = storageFacet.txSupplier().get()
def results = [:].withDefault { 0 }
try {
tx.begin()
tx.browseComponents(tx.findBucket(repo)).each { component ->
def size = 0
if (component.group() != null) {
tx.browseAssets(component).each { asset ->
size = size + asset.size()
}
results.put(component.group(),(results.get(component.group()) + size))
}
}
} finally {
tx.close();
}
//Convert Map in List of Object
def resultsValue = results.collect {key, value -> [repo.getName(), key, value]}
completResult = completResult + resultsValue
}
def sorted = completResult.sort { a, b -> b.value[2] <=> a.value[2] }
def formated = []
sorted.each { item ->
formated.push("${item[0]} -- ${item[1]} -- ${(item[2]/1024/1024).setScale(2, BigDecimal.ROUND_HALF_UP)}Mo")
}
log.info(JsonOutput.prettyPrint(JsonOutput.toJson(formated)))