2016-12-15 50 views
2

我試圖通過關係3 API自動化部件缺失的Nexus 3

我遵循了以下問題 Using the Nexus3 API how do I get a list of artifacts in a repository

的指示,進行如下修改了它給刪除存儲庫中的一些組件刪除神器

import groovy.json.JsonOutput 
import org.sonatype.nexus.repository.storage.Component 
import org.sonatype.nexus.repository.storage.Query 
import org.sonatype.nexus.repository.storage.StorageFacet 

def repoName = "eddie-test" 
def startDate = "2016/01/01" 
def artifactName = "you-artifact-name" 
def artifactVersion = "1.0.6" 

log.info(" Attempting to delete for repository: ${repoName} as of startDate: ${startDate}") 

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

tx.begin() 

// build a query to return a list of components scoped by name and version 
Iterable<Component> foundComponents = tx.findComponents(Query.builder().where('name = ').param(artifactName).and('version = ').param(artifactVersion).build(), [repo]) 

// extra logic for validation goes here 
if (foundComponents.size() == 1) { 
    tx.deleteComponent(foundComponents[0]) 
} 

tx.commit() 
log.info("done") 

但是當我詢問Maven的metadata.xml中的 http://localhost:32769/repository/eddie-test/com/company/you-artifact-name/maven-metadata.xml 的版本仍然是上市。 即

<metadata> 
    <groupId>com.company</groupId> 
    <artifactId>you-artifact-name</artifactId> 
    <versioning> 
     <release>1.0.7</release> 
     <versions> 
      <version>1.0.6</version> 
      <version>1.0.7</version> 
     </versions> 
     <lastUpdated>20161213115754</lastUpdated> 
    </versioning> 

刪除經由用戶界面中的刪除的組件按鈕組件,更新預期行家-metadata.xml中)

那麼,有一個確保通過API刪除文件時更新的方法?

回答

2

運行此操作後,您可以運行重建Maven存儲庫元數據計劃任務,這將實現您的目標。

目前沒有用於調用該任務的公共API。如果你想,彈出到https://issues.sonatype.org/browse/NEXUS,並作出一個問題:)

+1

問題已記錄任何有興趣的人https://issues.sonatype.org/projects/NEXUS/issues/NEXUS-11964?filter=allopenissues –