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;
}
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;
}
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;
}
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;
}
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()]));
}
Aggregations