Search in sources :

Example 1 with Transport

use of org.commonjava.maven.galley.spi.transport.Transport in project galley by Commonjava.

the class GalleyMavenFixture method setExtraTransports.

@Deprecated
public GalleyMavenFixture setExtraTransports(final Transport... transports) {
    checkInitialized();
    this.extraTransports = transports;
    for (final Transport transport : transports) {
        mavenBuilder.withAdditionalTransport(transport);
    }
    return this;
}
Also used : TestTransport(org.commonjava.maven.galley.testing.core.transport.TestTransport) Transport(org.commonjava.maven.galley.spi.transport.Transport)

Example 2 with Transport

use of org.commonjava.maven.galley.spi.transport.Transport in project galley by Commonjava.

the class TransferManagerImpl method getTransport.

private Transport getTransport(final ConcreteResource resource) throws TransferException {
    final Transport transport = transportManager.getTransport(resource);
    if (transport == null) {
        if (resource.getLocationUri() == null) {
            logger.debug("NFC: No remote URI. Marking as missing: {}", resource);
            nfc.addMissing(resource);
            return null;
        }
    }
    return transport;
}
Also used : Transport(org.commonjava.maven.galley.spi.transport.Transport)

Example 3 with Transport

use of org.commonjava.maven.galley.spi.transport.Transport in project galley by Commonjava.

the class SimpleUrlLocationResolver method resolve.

@Override
public final Location resolve(final String spec) throws TransferException {
    final Location location = new SimpleLocation(spec);
    final List<Location> locations = locationExpander.expand(location);
    if (locations == null || locations.isEmpty()) {
        throw new TransferException("Invalid location: '%s'. Location expansion returned no results.", spec);
    }
    for (final Iterator<Location> iterator = new ArrayList<Location>(locations).iterator(); iterator.hasNext(); ) {
        final Location loc = iterator.next();
        // normally, this will probably throw an exception if no transport is available.
        // in case it's not, remove the location if the transport is null.
        final Transport transport = transportManager.getTransport(loc);
        if (transport == null) {
            iterator.remove();
        }
    }
    if (locations == null || locations.isEmpty()) {
        throw new TransferException("Invalid location: '%s'. No transports available for expanded locations.", spec);
    }
    return location;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Transport(org.commonjava.maven.galley.spi.transport.Transport) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location)

Example 4 with Transport

use of org.commonjava.maven.galley.spi.transport.Transport in project galley by Commonjava.

the class TransportManagerImpl method setup.

@PostConstruct
protected void setup() {
    final List<Transport> transports = new ArrayList<Transport>();
    if (injected != null) {
        for (final Transport transport : injected) {
            transports.add(transport);
        }
    }
    this.transports = transports;
}
Also used : ArrayList(java.util.ArrayList) Transport(org.commonjava.maven.galley.spi.transport.Transport) PostConstruct(javax.annotation.PostConstruct)

Example 5 with Transport

use of org.commonjava.maven.galley.spi.transport.Transport in project galley by Commonjava.

the class TransferManagerImpl method doList.

private ListingResult doList(final ConcreteResource resource, final boolean suppressFailures, EventMetadata metadata) throws TransferException {
    final Transfer cachedListing = getCacheReference(resource.getChild(".listing.txt"));
    Set<String> filenames = new HashSet<String>();
    if (cachedListing.exists()) {
        InputStream stream = null;
        try {
            stream = cachedListing.openInputStream();
            filenames.addAll(IOUtils.readLines(stream, "UTF-8"));
            Logger logger = LoggerFactory.getLogger(getClass());
            logger.debug("Got cached listing:\n\n{}\n\n", filenames);
        } catch (final IOException e) {
            throw new TransferException("Failed to read listing from cached file: %s. Reason: %s", e, cachedListing, e.getMessage());
        } finally {
            closeQuietly(stream);
        }
    } else {
        final Transfer cached = getCacheReference(resource);
        if (cached.exists()) {
            if (cached.isFile()) {
                throw new TransferException("Cannot list: {}. It does not appear to be a directory.", resource);
            } else {
                try {
                    // This is fairly stupid, but we need to append '/' to the end of directories in the listing so content processors can figure
                    // out what to do with them.
                    String[] fnames = cached.list();
                    if (fnames != null && fnames.length > 0) {
                        for (String fname : fnames) {
                            final ConcreteResource child = resource.getChild(fname);
                            final Transfer childRef = getCacheReference(child);
                            if (childRef.isFile()) {
                                filenames.add(fname);
                            } else {
                                filenames.add(fname + "/");
                            }
                        }
                    }
                } catch (final IOException e) {
                    throw new TransferException("Listing failed: {}. Reason: {}", e, resource, e.getMessage());
                }
            }
        }
        if (resource.getLocation().allowsDownloading()) {
            final int timeoutSeconds = getTimeoutSeconds(resource);
            Transport transport = getTransport(resource);
            final ListingResult remoteResult = lister.list(resource, cachedListing, timeoutSeconds, transport, suppressFailures);
            if (remoteResult != null) {
                String[] remoteListing = remoteResult.getListing();
                if (remoteListing != null) {
                    final TransferDecorator decorator = cachedListing.getDecorator();
                    if (decorator != null) {
                        try {
                            Logger logger = LoggerFactory.getLogger(getClass());
                            logger.debug("Un-decorated listing:\n\n{}\n\n", remoteListing);
                            remoteListing = decorator.decorateListing(cachedListing.getParent(), remoteListing, metadata);
                        } catch (final IOException e) {
                            logger.error("Failed to decorate directory listing for: {}. Reason: {}", e, resource, e.getMessage());
                            remoteListing = null;
                        }
                    }
                }
                if (remoteListing != null) {
                    if (transport.allowsCaching()) {
                        OutputStream stream = null;
                        try {
                            Logger logger = LoggerFactory.getLogger(getClass());
                            logger.debug("Writing listing:\n\n{}\n\nto: {}", remoteListing, cachedListing);
                            stream = cachedListing.openOutputStream(TransferOperation.DOWNLOAD);
                            stream.write(join(remoteListing, "\n").getBytes("UTF-8"));
                        } catch (final IOException e) {
                            logger.debug("Failed to store directory listing for: {}. Reason: {}", e, resource, e.getMessage());
                        } finally {
                            closeQuietly(stream);
                        }
                    }
                    filenames.addAll(Arrays.asList(remoteListing));
                }
            }
        }
    }
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Listing before non-listable file removal:\n\n{}\n\n", filenames);
    List<String> resultingNames = new ArrayList<String>(filenames.size());
    for (String fname : filenames) {
        ConcreteResource child = resource.getChild(fname);
        SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(child, metadata.getPackageType());
        if (specialPathInfo != null && !specialPathInfo.isListable()) {
            continue;
        }
        resultingNames.add(fname);
    }
    logger.debug("Final listing result:\n\n{}\n\n", resultingNames);
    return new ListingResult(resource, resultingNames.toArray(new String[resultingNames.size()]));
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) IOException(java.io.IOException) Logger(org.slf4j.Logger) ListingResult(org.commonjava.maven.galley.model.ListingResult) TransferDecorator(org.commonjava.maven.galley.spi.io.TransferDecorator) TransferException(org.commonjava.maven.galley.TransferException) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transport(org.commonjava.maven.galley.spi.transport.Transport) HashSet(java.util.HashSet)

Aggregations

Transport (org.commonjava.maven.galley.spi.transport.Transport)7 TestTransport (org.commonjava.maven.galley.testing.core.transport.TestTransport)3 ArrayList (java.util.ArrayList)2 TransferException (org.commonjava.maven.galley.TransferException)2 Logger (org.slf4j.Logger)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 PostConstruct (javax.annotation.PostConstruct)1 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)1 FileCacheProvider (org.commonjava.maven.galley.cache.FileCacheProvider)1 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)1 ListingResult (org.commonjava.maven.galley.model.ListingResult)1 Location (org.commonjava.maven.galley.model.Location)1 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)1 SpecialPathInfo (org.commonjava.maven.galley.model.SpecialPathInfo)1 Transfer (org.commonjava.maven.galley.model.Transfer)1 TransferDecorator (org.commonjava.maven.galley.spi.io.TransferDecorator)1