Created
July 17, 2018 20:31
-
-
Save DarthHater/9933910ade642384c3a6f89b67e8b4bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.sonatype.nexus.repository.Repository | |
import org.sonatype.nexus.repository.storage.Query | |
import org.sonatype.nexus.repository.storage.StorageFacet | |
import groovy.json.JsonOutput | |
def result = [:] | |
def totalComponents = 0 | |
def totalAssets = 0 | |
repository.repositoryManager.browse().each { Repository repo -> | |
def tx = repo.facet(StorageFacet).txSupplier().get() | |
def components = 0 | |
def assets = 0 | |
try { | |
tx.begin() | |
components = tx.countComponents(Query.builder().where('1').eq(1).build(), [repo]) | |
assets = tx.countAssets(Query.builder().where('1').eq(1).build(), [repo]) | |
tx.commit() | |
} catch (Exception e) { | |
log.warn("Transaction failed {}", e.toString()) | |
tx.rollback() | |
} finally { | |
tx.close() | |
} | |
totalComponents += components | |
totalAssets += assets | |
result[repo.name] = [components: components, assets: assets] | |
} | |
result["_totals"] = [components : totalComponents, assets : totalAssets] | |
def json = JsonOutput.toJson(result) | |
log.info json | |
return json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment