Skip to content

Instantly share code, notes, and snippets.

@DarthHater
Created July 17, 2018 20:31
Show Gist options
  • Save DarthHater/9933910ade642384c3a6f89b67e8b4bb to your computer and use it in GitHub Desktop.
Save DarthHater/9933910ade642384c3a6f89b67e8b4bb to your computer and use it in GitHub Desktop.
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