1

I search a way to request components or assets from groupId and artefactId.

Documentation provides any help about how to create this request.

This doc has been a great help.

Unfortunately, it's not enough to resolve my need and I try to create query to request components from groupId and artefactId like that:

Query.builder().where('group = ').param('###').and('name = ').param('###').and('version = ').param('###).build()

Last time I played my script it throwed java.lang.StackOverflowError. After increasing memory, I had the same result. It seems there is too much components to return, but in my nexus repository there's only one component with such group, name and version.

What's wrong with this query?

Is there someone pass this difficulty (it was so easy with nexus2 and rest api!) and retrieve components information with a groovy script?

VincenzoC
  • 30,117
  • 12
  • 90
  • 112
olivier
  • 11
  • 2

2 Answers2

1

Here is the script I successfully uploaded and use. You may easily add version to your requests - the parameter will be, for example, "snapshots-lib,com.m121.somebundle,someBundle,7.2.1-SNAPSHOT,all". As you may see, I decided to filter the sequence locally, because did not find the way to specify in query version parameter.

{
  "name": "listgroup",
  "type": "groovy",
  "content": "import org.sonatype.nexus.repository.storage.Query;
    import org.sonatype.nexus.repository.storage.StorageFacet;
    import groovy.json.JsonOutput;

    def repositoryId = args.split(',')[0];
    def groupId = args.split(',')[1];
    def artifactId = args.split(',')[2];
    def baseVersion = args.split(',')[3];
    def latestOnly = args.split(',')[4];

    def repo = repository.repositoryManager.get(repositoryId);
    StorageFacet storageFacet = repo.facet(StorageFacet);
    def tx = storageFacet.txSupplier().get();

   tx.begin();
   def components = tx.findComponents(Query.builder().where('group = ').param(groupId).and('name = ').param(artifactId).build(), [repo]);
   def found = components.findAll{it.attributes().child('maven2').get('baseVersion')==baseVersion}.collect{def version = it.attributes().child('maven2').get('version');\"${version}\"};

   // found = found.unique().sort();
   def latest = found.isEmpty() ? found : found.last();
   
   tx.commit();
   def result = latestOnly == 'latest' ? JsonOutput.toJson(latest) : JsonOutput.toJson(found);

   return result;"
}
0

okee,

in fact my needs are : i want to retrieve last release version and its date of a component by group and artefact. I definitely leave the groovy API option.

A way i found consists in use of extdirect api. This "rest" api is used by nexus frontend to communicate with backend. No documentation exists.

I do a call to extdirect api to retrieve all versions from a component by group and artefact. I parse the results to get the last version on a release (snapshot and releases). It's not really good because this call retrieves all the versions on all repositories and could be huge.

Another call to extdirect api to find the release date from the component id of the last release version.

I hope someday nexus publishs official documentation of an useful rest api.

olivier
  • 11
  • 2