Skip to content

Instantly share code, notes, and snippets.

@legege
Created March 22, 2018 19:06
Show Gist options
  • Save legege/575e3f2be80d39f7090a608aac8a8814 to your computer and use it in GitHub Desktop.
Save legege/575e3f2be80d39f7090a608aac8a8814 to your computer and use it in GitHub Desktop.
Nexus 3 assets scan
import org.apache.commons.io.FileUtils
import org.sonatype.nexus.repository.storage.Asset
import org.sonatype.nexus.repository.storage.Component;
import org.sonatype.nexus.repository.storage.Query
import org.sonatype.nexus.repository.storage.Query.Builder;
import org.sonatype.nexus.repository.storage.StorageFacet
def repo = repository.repositoryManager.get('releases')
StorageFacet storageFacet = repo.facet(StorageFacet)
def tx = storageFacet.txSupplier().get()
try {
tx.begin()
Builder qb = Query.builder()
qb.where('group = ').param('com.google.truth')
qb.and('name = ').param('truth')
qb.and('version matches ').param('0.([0-9])*' )
Iterable<Component> comps = tx.
findComponents(qb.build(), [repo])
comps.each { Component comp ->
log.info("Component:" + comp.toStringExternal());
log.info("Component... " + comp.attributes().toString());
log.info("Component... " + comp.getEntityMetadata().toString());
log.info("Component... " + comp.getEntityMetadata().getId().getValue());
tx.browseAssets(comp).each { Asset asset ->
log.info("Asset: " + asset)
log.info("Asset... " + asset.attributes().toString())
log.info("Asset... " + asset.contentType())
}
}
}
finally {
tx.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment