【问题标题】:Nexus 3 Rest api to check if component existNexus 3 Rest api 检查组件是否存在
【发布时间】:2017-08-09 23:13:56
【问题描述】:

也许我错过了一些东西,但我找不到从 UI 将组件(jar 或 dll)上传到 nexus 3 存储库的方法。所以我正在尝试为这项工作构建一个工具,以优化上传过程,我需要一种方法来以编程方式检查组件是否存在于 nexus 存储库中,我所有寻找合适的 rest api 的尝试都失败了。

有人有建议吗?

【问题讨论】:

    标签: java rest nexus sonatype nexus3


    【解决方案1】:

    也许你可以上传一个 groovy 脚本并使用该脚本来检查组件是否存在。

    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;
    

    【讨论】:

      【解决方案2】:

      此时,REST API 已作为测试版发布。您可以通过以下链接获取更多信息并向我们提供反馈:http://blog.sonatype.com/nexus-repository-new-beta-rest-api-for-content

      您可以使用一些新的端点来检查组件/资产是否存在,然后根据格式使用 curl 或类似的东西通过现有的格式端点上传它。

      【讨论】:

        猜你喜欢
        • 2022-01-20
        • 2014-09-17
        • 1970-01-01
        • 2023-03-05
        • 1970-01-01
        • 1970-01-01
        • 2017-01-22
        • 2021-02-04
        • 2018-05-25
        相关资源
        最近更新 更多