Search in sources :

Example 1 with InstallResult

use of org.sonatype.aether.installation.InstallResult in project sonatype-aether by sonatype.

the class DefaultInstallerTest method testSuccessfulInstall.

@Test
public void testSuccessfulInstall() throws InstallationException, UnsupportedEncodingException, IOException {
    File artifactFile = new File(session.getLocalRepositoryManager().getRepository().getBasedir(), localArtifactPath);
    File metadataFile = new File(session.getLocalRepositoryManager().getRepository().getBasedir(), localMetadataPath);
    artifactFile.delete();
    metadataFile.delete();
    request.addArtifact(artifact);
    request.addMetadata(metadata);
    InstallResult result = installer.install(session, request);
    assertTrue(artifactFile.exists());
    TestFileUtils.assertContent("artifact".getBytes("UTF-8"), artifactFile);
    assertTrue(metadataFile.exists());
    TestFileUtils.assertContent("metadata".getBytes("UTF-8"), metadataFile);
    assertEquals(result.getRequest(), request);
    assertEquals(result.getArtifacts().size(), 1);
    assertTrue(result.getArtifacts().contains(artifact));
    assertEquals(result.getMetadata().size(), 1);
    assertTrue(result.getMetadata().contains(metadata));
    assertEquals(1, lrm.getMetadataRegistration().size());
    assertTrue(lrm.getMetadataRegistration().contains(metadata));
    assertEquals(1, lrm.getArtifactRegistration().size());
    assertTrue(lrm.getArtifactRegistration().contains(artifact));
}
Also used : File(java.io.File) InstallResult(org.sonatype.aether.installation.InstallResult) Test(org.junit.Test)

Example 2 with InstallResult

use of org.sonatype.aether.installation.InstallResult in project sonatype-aether by sonatype.

the class DefaultInstaller method install.

private InstallResult install(SyncContext syncContext, RepositorySystemSession session, InstallRequest request) throws InstallationException {
    InstallResult result = new InstallResult(request);
    RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
    List<MetadataGenerator> generators = getMetadataGenerators(session, request);
    List<Artifact> artifacts = new ArrayList<Artifact>(request.getArtifacts());
    IdentityHashMap<Metadata, Object> processedMetadata = new IdentityHashMap<Metadata, Object>();
    List<Metadata> metadatas = Utils.prepareMetadata(generators, artifacts);
    syncContext.acquire(artifacts, Utils.combine(request.getMetadata(), metadatas));
    for (Metadata metadata : metadatas) {
        install(session, trace, metadata);
        processedMetadata.put(metadata, null);
        result.addMetadata(metadata);
    }
    for (int i = 0; i < artifacts.size(); i++) {
        Artifact artifact = artifacts.get(i);
        for (MetadataGenerator generator : generators) {
            artifact = generator.transformArtifact(artifact);
        }
        artifacts.set(i, artifact);
        install(session, trace, artifact);
        result.addArtifact(artifact);
    }
    metadatas = Utils.finishMetadata(generators, artifacts);
    syncContext.acquire(null, metadatas);
    for (Metadata metadata : metadatas) {
        install(session, trace, metadata);
        processedMetadata.put(metadata, null);
        result.addMetadata(metadata);
    }
    for (Metadata metadata : request.getMetadata()) {
        if (!processedMetadata.containsKey(metadata)) {
            install(session, trace, metadata);
            result.addMetadata(metadata);
        }
    }
    return result;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) MergeableMetadata(org.sonatype.aether.metadata.MergeableMetadata) Metadata(org.sonatype.aether.metadata.Metadata) RequestTrace(org.sonatype.aether.RequestTrace) DefaultRequestTrace(org.sonatype.aether.util.DefaultRequestTrace) InstallResult(org.sonatype.aether.installation.InstallResult) Artifact(org.sonatype.aether.artifact.Artifact) MetadataGenerator(org.sonatype.aether.impl.MetadataGenerator)

Aggregations

InstallResult (org.sonatype.aether.installation.InstallResult)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1 Test (org.junit.Test)1 RequestTrace (org.sonatype.aether.RequestTrace)1 Artifact (org.sonatype.aether.artifact.Artifact)1 MetadataGenerator (org.sonatype.aether.impl.MetadataGenerator)1 MergeableMetadata (org.sonatype.aether.metadata.MergeableMetadata)1 Metadata (org.sonatype.aether.metadata.Metadata)1 DefaultRequestTrace (org.sonatype.aether.util.DefaultRequestTrace)1