Nexus 3 Rest api to check if component exist

≡放荡痞女 提交于 2019-12-11 05:05:42

问题


Maybe I miss something but i can't find a way to upload a component(jar or dll) to the nexus 3 repository from the UI. So I am trying to build a tool for this job, to optimize the upload process I need a way to check if component exist in the nexus repository programmatically, all my tries to find suitable rest api failed.

Anyone have suggestions?


回答1:


At this time, the REST API has been released as beta. You can get more information and give us feedback by going to this link: http://blog.sonatype.com/nexus-repository-new-beta-rest-api-for-content

You can use some of the new endpoints to check if a component/asset exists, and then use curl or something akin depending on the format to upload it via the existing format endpoints.




回答2:


Maybe you can upload a groovy script and use that script to check whether the component exists or not.

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;


来源:https://stackoverflow.com/questions/42873731/nexus-3-rest-api-to-check-if-component-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!