Search in sources :

Example 31 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project galley by Commonjava.

the class ArtifactManagerImplTest method resolveSnapshot_FirstMatch_SingletonLocationList_TwoSnapshotList_LatestVersionStrategy.

@Test
public void resolveSnapshot_FirstMatch_SingletonLocationList_TwoSnapshotList_LatestVersionStrategy() throws Exception {
    final String base = "2-snapshots-1-location/";
    final String testResource = base + "two-snapshots.xml";
    final String testPomResource = base + "two-snapshots-pom.xml";
    final ProjectVersionRef ref = new SimpleProjectVersionRef("org.group2", "artifact", "1.0-SNAPSHOT");
    final ConcreteResource metadataResource = new ConcreteResource(LOCATION, fixture.snapshotMetadataPath(ref));
    final ConcreteResource pomResource = new ConcreteResource(LOCATION, fixture.pomPath(ref.selectVersion("1.0-20140604.102909-1").asPomArtifact()));
    fixture.getTransport().registerDownload(metadataResource, new TestDownload(ROOT + testResource));
    fixture.getTransport().registerDownload(pomResource, new TestDownload(ROOT + testPomResource));
    final Transfer retrieved = fixture.getArtifactManager().retrieve(LOCATION, ref.asPomArtifact(), new EventMetadata());
    final Document document = fixture.getXml().parse(retrieved, new EventMetadata());
    final ProjectVersionRef result = fixture.getXml().getProjectVersionRef(document);
    System.out.println(result);
    assertThat(result, notNullValue());
    assertThat(result.getVersionString(), equalTo("1.0-20140604.102909-1"));
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Document(org.w3c.dom.Document) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 32 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project galley by Commonjava.

the class VersionResolverImplTest method resolveSnapshot_FirstMatch_SingletonLocationList_SingletonSnapshotList_LatestVersionStrategy.

@Test
public void resolveSnapshot_FirstMatch_SingletonLocationList_SingletonSnapshotList_LatestVersionStrategy() throws Exception {
    final String testResource = "single-snapshot/single-snapshot.xml";
    final ProjectVersionRef ref = new SimpleProjectVersionRef("org.group", "artifact", "1.0-SNAPSHOT");
    final ConcreteResource cr = new ConcreteResource(LOCATION, fixture.snapshotMetadataPath(ref));
    final TestDownload download = new TestDownload(ROOT + testResource);
    fixture.getTransport().registerDownload(cr, download);
    final ProjectVersionRef result = fixture.getVersionResolver().resolveFirstMatchVariableVersion(ONE_LOCATION, ref, LatestVersionSelectionStrategy.INSTANCE, new EventMetadata());
    assertThat(result, notNullValue());
    assertThat(result.getVersionString(), equalTo("1.0-20140604.101244-1"));
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 33 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class ArchetypeCatalogGenerator method generateGroupFileContent.

@Override
public Transfer generateGroupFileContent(final Group group, final List<ArtifactStore> members, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    if (!canProcess(path)) {
        return null;
    }
    final Transfer target = fileManager.getTransfer(group, path);
    if (!target.exists()) {
        String toMergePath = path;
        if (!path.endsWith(ArchetypeCatalogMerger.CATALOG_NAME)) {
            toMergePath = normalize(normalize(parentPath(toMergePath)), ArchetypeCatalogMerger.CATALOG_NAME);
        }
        final List<Transfer> sources = fileManager.retrieveAllRaw(members, toMergePath, new EventMetadata());
        final byte[] merged = merger.merge(sources, group, toMergePath);
        if (merged != null) {
            OutputStream fos = null;
            try {
                fos = target.openOutputStream(TransferOperation.GENERATE, true, eventMetadata);
                fos.write(merged);
            } catch (final IOException e) {
                throw new IndyWorkflowException("Failed to write merged archetype catalog to: {}.\nError: {}", e, target, e.getMessage());
            } finally {
                closeQuietly(fos);
            }
        //                helper.writeChecksumsAndMergeInfo( merged, sources, group, toMergePath );
        }
    }
    if (target.exists()) {
        return target;
    }
    return null;
}
Also used : OutputStream(java.io.OutputStream) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 34 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class AutoProxDataManagerDecorator method getRemoteRepository.

private RemoteRepository getRemoteRepository(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
    logger.debug("DECORATED (getRemoteRepository: {})", key);
    RemoteRepository repo = (RemoteRepository) dataManager.getArtifactStore(key);
    if (!catalog.isEnabled()) {
        logger.debug("AutoProx decorator disabled; returning: {}", repo);
        return repo;
    }
    logger.debug("AutoProx decorator active");
    if (repo == null) {
        logger.info("AutoProx: creating repository for: {}", key);
        try {
            repo = catalog.createRemoteRepository(key);
            if (repo != null) {
                if (!checkValidity(key)) {
                    return null;
                }
                final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? repo.getKey() : impliedBy);
                dataManager.storeArtifactStore(repo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating remote repository for: '" + key + "'"), false, true, eventMetadata);
            }
        } catch (final AutoProxRuleException e) {
            throw new IndyDataException("[AUTOPROX] Failed to create new remote repository from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
        }
    }
    return repo;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 35 with EventMetadata

use of org.commonjava.maven.galley.event.EventMetadata in project indy by Commonjava.

the class AutoProxDataManagerDecorator method getGroup.

private Group getGroup(final StoreKey key, final StoreKey impliedBy) throws IndyDataException {
    logger.debug("DECORATED (getGroup: {})", key);
    Group g = (Group) dataManager.getArtifactStore(key);
    if (!catalog.isEnabled()) {
        logger.debug("AutoProx decorator disabled; returning: {}", g);
        return g;
    }
    logger.debug("AutoProx decorator active");
    if (g == null) {
        logger.debug("AutoProx: creating repository for: {}", key);
        if (!checkValidity(key)) {
            return null;
        }
        try {
            g = catalog.createGroup(key);
        } catch (final AutoProxRuleException e) {
            throw new IndyDataException("[AUTOPROX] Failed to create new group from factory matching: '%s'. Reason: %s", e, key, e.getMessage());
        }
        if (g != null) {
            logger.info("Validating group: {}", g);
            for (final StoreKey memberKey : new ArrayList<>(g.getConstituents())) {
                final ArtifactStore store = getArtifactStore(memberKey, impliedBy == null ? g.getKey() : impliedBy);
                if (store == null) {
                    g.removeConstituent(memberKey);
                }
            }
            if (g.getConstituents().isEmpty()) {
                return null;
            }
            final EventMetadata eventMetadata = new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, AutoProxConstants.STORE_ORIGIN).set(AutoProxConstants.ORIGINATING_STORE, impliedBy == null ? g.getKey() : impliedBy);
            dataManager.storeArtifactStore(g, new ChangeSummary(ChangeSummary.SYSTEM_USER, "AUTOPROX: Creating group for: '" + key + "'"), false, true, eventMetadata);
        }
    }
    return g;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Aggregations

EventMetadata (org.commonjava.maven.galley.event.EventMetadata)95 Transfer (org.commonjava.maven.galley.model.Transfer)38 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)37 Test (org.junit.Test)37 IndyDataException (org.commonjava.indy.data.IndyDataException)27 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)27 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)20 StoreKey (org.commonjava.indy.model.core.StoreKey)18 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)17 Group (org.commonjava.indy.model.core.Group)17 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)15 Logger (org.slf4j.Logger)15 IOException (java.io.IOException)13 Inject (javax.inject.Inject)11 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)10 Path (javax.ws.rs.Path)10 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)9