Search in sources :

Example 1 with FileAccessEvent

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

the class MergedFileUploadListener method reMergeUploaded.

// NOTE: Disabling @Observes on this because I'm pretty sure the ContentManager is handling it now.
public void reMergeUploaded(/*@Observes*/
final FileEvent event) {
    if (event instanceof FileAccessEvent) {
        return;
    }
    final String path = event.getTransfer().getPath();
    final StoreKey key = getKey(event);
    if (!path.endsWith(MavenMetadataMerger.METADATA_NAME) && !path.endsWith(ArchetypeCatalogMerger.CATALOG_NAME)) {
        return;
    }
    try {
        final Set<Group> groups = dataManager.query().getGroupsContaining(key);
        if (groups != null) {
            for (final Group group : groups) {
                try {
                    reMerge(group, path);
                } catch (final IOException e) {
                    logger.error(String.format("Failed to delete: %s from group: %s. Error: %s", path, group, e.getMessage()), e);
                }
            }
        }
    } catch (final IndyDataException e) {
        logger.warn("Failed to regenerate maven-metadata.xml for groups after deployment to: {}" + "\nCannot retrieve associated groups: {}", e, key, e.getMessage());
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) IOException(java.io.IOException) FileAccessEvent(org.commonjava.maven.galley.event.FileAccessEvent) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 2 with FileAccessEvent

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

the class Transfer method openInputStream.

public InputStream openInputStream(final boolean fireEvents, final EventMetadata eventMetadata) throws IOException {
    provider.waitForReadUnlock(resource);
    try {
        InputStream stream = provider.openInputStream(resource);
        if (stream == null) {
            return null;
        }
        if (fireEvents) {
            stream = new TransferInputStream(stream, new FileAccessEvent(this, eventMetadata), fileEventManager);
        }
        stream = decorator == null ? stream : decorator.decorateRead(stream, this, eventMetadata);
        logger.trace("Returning stream: {} for transfer: {}", stream.getClass().getName(), this);
        return stream;
    } catch (final IOException e) {
        if (fireEvents) {
            fileEventManager.fire(new FileErrorEvent(this, e, eventMetadata));
        }
        throw e;
    }
}
Also used : TransferInputStream(org.commonjava.maven.galley.util.TransferInputStream) InputStream(java.io.InputStream) FileErrorEvent(org.commonjava.maven.galley.event.FileErrorEvent) IOException(java.io.IOException) FileAccessEvent(org.commonjava.maven.galley.event.FileAccessEvent) TransferInputStream(org.commonjava.maven.galley.util.TransferInputStream)

Aggregations

IOException (java.io.IOException)2 FileAccessEvent (org.commonjava.maven.galley.event.FileAccessEvent)2 InputStream (java.io.InputStream)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 Group (org.commonjava.indy.model.core.Group)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 FileErrorEvent (org.commonjava.maven.galley.event.FileErrorEvent)1 TransferInputStream (org.commonjava.maven.galley.util.TransferInputStream)1