3

I am attempting to delete some components in a repository via the nexus 3 api

I have followed the instructions in the following question Using the Nexus3 API how do I get a list of artifacts in a repository

and have modified it as follows to delete an artifact

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")

however when I interrogate the maven-metadata.xml in http://localhost:32769/repository/eddie-test/com/company/you-artifact-name/maven-metadata.xml the version is still listed. i.e.

<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>

(deleting the component via the delete component button in the ui, updates the maven-metadata.xml as expected)

So is there a way to make sure that the file is updated when deleting via the API?

Community
  • 1
  • 1

1 Answers1

2

After running this, you can run the Rebuild Maven repository metadata Scheduled Task and that will accomplish what you aim to achieve.

There is currently no Public API for calling that task. If you want, pop on over to https://issues.sonatype.org/browse/NEXUS and make an issue for that :)

DarthHater
  • 3,222
  • 25
  • 26
  • 1
    issue has been logged for anyone interested https://issues.sonatype.org/projects/NEXUS/issues/NEXUS-11964?filter=allopenissues – Eddie Dvorak Dec 21 '16 at 09:44