Search in sources :

Example 81 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.

the class KojiContentManagerDecorator method retrieve.

@Override
@IndyMetrics(measure = @Measure(timers = @MetricNamed(name = IndyMetricsKojiNames.METHOD_CONTENTMANAGER_RETRIEVE + IndyMetricsNames.TIMER), meters = @MetricNamed(name = IndyMetricsKojiNames.METHOD_CONTENTMANAGER_RETRIEVE + IndyMetricsNames.METER)))
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.info("KOJI: Delegating initial retrieval attempt for: {}/{}", store.getKey(), path);
    Transfer result = delegate.retrieve(store, path, eventMetadata);
    if (result == null && StoreType.group == store.getKey().getType()) {
        logger.info("KOJI: Checking for Koji build matching: {}", path);
        Group group = (Group) store;
        RemoteRepository kojiProxy = findKojiBuildAnd(store, path, eventMetadata, null, this::createRemoteRepository);
        if (kojiProxy != null) {
            adjustTargetGroup(kojiProxy, group);
            result = delegate.retrieve(kojiProxy, path, eventMetadata);
        }
        if (result != null) {
            nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
        }
    }
    // Finally, pass the Transfer back.
    return result;
}
Also used : Group(org.commonjava.indy.model.core.Group) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Logger(org.slf4j.Logger) IndyMetrics(org.commonjava.indy.measure.annotation.IndyMetrics)

Example 82 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.

the class ImpliedRepositoryDetector method initJob.

private boolean initJob(final ImplicationsJob job) {
    switch(job.event.getType()) {
        case DOWNLOAD:
        case UPLOAD:
            break;
        default:
            // we're not interested in these.
            return false;
    }
    final Transfer transfer = job.transfer;
    if (!transfer.getPath().endsWith(".pom")) {
        return false;
    }
    final Location location = transfer.getLocation();
    if (!(location instanceof KeyedLocation)) {
        return false;
    }
    final StoreKey key = ((KeyedLocation) location).getKey();
    try {
        job.store = storeManager.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Cannot retrieve artifact store for: %s. Failed to process implied repositories.", key), e);
    }
    if (job.store == null) {
        return false;
    }
    job.pathInfo = ArtifactPathInfo.parse(transfer.getPath());
    if (job.pathInfo == null) {
        return false;
    }
    try {
        logger.debug("Parsing: {}", transfer);
        job.pomView = pomReader.readLocalPom(job.pathInfo.getProjectId(), transfer, MavenPomView.ALL_PROFILES);
    } catch (final GalleyMavenException e) {
        logger.error(String.format("Cannot parse: %s from: %s. Failed to process implied repositories.", job.pathInfo.getProjectId(), transfer), e);
    }
    return job.pomView != null;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Transfer(org.commonjava.maven.galley.model.Transfer) StoreKey(org.commonjava.indy.model.core.StoreKey) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 83 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.

the class MergedFileUploadListener method reMerge.

private void reMerge(final Group group, final String path) throws IOException {
    logger.debug("Updating merged metadata file: {} in group: {}", path, group.getKey());
    final Transfer[] toDelete = { fileManager.getStorageReference(group, path), fileManager.getStorageReference(group, path + GroupMergeHelper.MERGEINFO_SUFFIX), fileManager.getStorageReference(group, path + GroupMergeHelper.SHA_SUFFIX), fileManager.getStorageReference(group, path + GroupMergeHelper.MD5_SUFFIX) };
    for (final Transfer item : toDelete) {
        logger.debug("Attempting to delete: {}", item);
        if (item.exists()) {
            final boolean result = item.delete();
            logger.debug("Deleted: {} (success? {})", item, result);
            if (fileEvent != null) {
                logger.debug("Firing deletion event for: {}", item);
                fileEvent.fire(new FileDeletionEvent(item, new EventMetadata()));
            }
        }
    }
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) FileDeletionEvent(org.commonjava.maven.galley.event.FileDeletionEvent) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 84 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.

the class MavenMetadataGenerator 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);
    logger.debug("Working on metadata file: {} (already exists? {})", target, target != null && target.exists());
    if (!target.exists()) {
        String toMergePath = path;
        if (!path.endsWith(MavenMetadataMerger.METADATA_NAME)) {
            toMergePath = normalize(normalize(parentPath(toMergePath)), MavenMetadataMerger.METADATA_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 metadata to: {}.\nError: {}", e, target, e.getMessage());
            } finally {
                closeQuietly(fos);
            }
            helper.writeMergeInfo(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 85 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.

the class ArchetypeCatalogMerger method merge.

@Override
public byte[] merge(final Collection<Transfer> sources, final Group group, final String path) {
    final ArchetypeCatalog master = new ArchetypeCatalog();
    final ArchetypeCatalogXpp3Reader reader = new ArchetypeCatalogXpp3Reader();
    final FileReader fr = null;
    InputStream stream = null;
    boolean merged = false;
    final Set<String> seen = new HashSet<String>();
    for (final Transfer src : sources) {
        try {
            stream = src.openInputStream();
            final ArchetypeCatalog catalog = reader.read(stream, false);
            for (final Archetype arch : catalog.getArchetypes()) {
                final String key = arch.getGroupId() + ":" + arch.getArtifactId() + ":" + arch.getVersion();
                if (seen.add(key)) {
                    master.addArchetype(arch);
                }
            }
            merged = true;
        } catch (final IOException e) {
            final StoreKey key = getKey(src);
            logger.error(String.format("Cannot read archetype catalog: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
        } catch (final XmlPullParserException e) {
            final StoreKey key = getKey(src);
            logger.error(String.format("Cannot parse archetype catalog: %s from artifact-store: %s. Reason: %s", src.getPath(), key, e.getMessage()), e);
        } finally {
            closeQuietly(fr);
        }
    }
    if (merged) {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            new ArchetypeCatalogXpp3Writer().write(baos, master);
            return baos.toByteArray();
        } catch (final IOException e) {
            logger.error(String.format("Cannot write consolidated archetype catalog: %s to: %s. Reason: %s", path, group.getKey(), e.getMessage()), e);
        }
    }
    return null;
}
Also used : Archetype(org.apache.maven.archetype.catalog.Archetype) InputStream(java.io.InputStream) ArchetypeCatalogXpp3Writer(org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Writer) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StoreKey(org.commonjava.indy.model.core.StoreKey) ArchetypeCatalogXpp3Reader(org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Reader) Transfer(org.commonjava.maven.galley.model.Transfer) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArchetypeCatalog(org.apache.maven.archetype.catalog.ArchetypeCatalog) HashSet(java.util.HashSet)

Aggregations

Transfer (org.commonjava.maven.galley.model.Transfer)154 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)63 Test (org.junit.Test)62 IOException (java.io.IOException)39 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)38 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)37 InputStream (java.io.InputStream)27 StoreKey (org.commonjava.indy.model.core.StoreKey)27 Logger (org.slf4j.Logger)26 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)22 ByteArrayInputStream (java.io.ByteArrayInputStream)21 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)21 HostedRepository (org.commonjava.indy.model.core.HostedRepository)21 Group (org.commonjava.indy.model.core.Group)20 ArrayList (java.util.ArrayList)19 IndyDataException (org.commonjava.indy.data.IndyDataException)19 OutputStream (java.io.OutputStream)15 HashSet (java.util.HashSet)15 Location (org.commonjava.maven.galley.model.Location)14 TransferException (org.commonjava.maven.galley.TransferException)12