use of org.commonjava.maven.galley.model.SpecialPathInfo in project indy by Commonjava.
the class PathMappedMavenGACacheGroupRepositoryFilter method getGAPath.
private String getGAPath(String rawPath) {
if (isBlank(rawPath)) {
return null;
}
Path gaPath = null;
Path parent = Paths.get(rawPath).getParent();
if (parent != null) {
SpecialPathInfo pathInfo = specialPathManager.getSpecialPathInfo(rawPath);
if (pathInfo != null && pathInfo.isMetadata()) {
// Metadata may be at two levels, e.g., foo/bar/maven-metadata.xml, foo/bar/3.0.0-SNAPSHOT/maven-metadata.xml
if (parent.endsWith(LOCAL_SNAPSHOT_VERSION_PART)) {
gaPath = parent.getParent();
} else {
gaPath = parent;
}
} else {
// gaPath will be two layers upwards, e.g., foo/bar/3.0.0/bar-3.0.0.pom
gaPath = parent.getParent();
}
}
if (gaPath != null) {
return gaPath.toString();
}
return null;
}
use of org.commonjava.maven.galley.model.SpecialPathInfo 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<>();
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) {
// this will avoid some package.json redirect path empty errors, especially for the group.
if (metadata.get(STORAGE_PATH) != null) {
filenames.add(fname);
continue;
}
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 && remoteListing.length > 0) {
final TransferDecorator decorator = cachedListing.getDecorator();
if (decorator != null) {
try {
Logger logger = LoggerFactory.getLogger(getClass());
// noinspection ConfusingArgumentToVarargsMethod
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 && remoteListing.length > 0) {
if (transport != null && 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<>(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()]));
}
use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.
the class TransferManagerImpl method store.
@Override
public Transfer store(ConcreteResource resource, final InputStream stream, final EventMetadata eventMetadata) throws TransferException {
if (eventMetadata.get(STORAGE_PATH) != null) {
resource = ResourceUtils.storageResource(resource, eventMetadata);
}
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(resource, eventMetadata.getPackageType());
if (!resource.allowsStoring() || (specialPathInfo != null && !specialPathInfo.isStorable())) {
throw new TransferException("Storing not allowed for: {}", resource);
}
final Transfer target = getCacheReference(resource);
logger.info("STORE {}", target.getResource());
OutputStream out = null;
try {
out = target.openOutputStream(TransferOperation.UPLOAD, true, eventMetadata);
copy(stream, out);
nfc.clearMissing(resource);
} catch (final IOException e) {
throw new TransferException("Failed to store: {}. Reason: {}", e, resource, e.getMessage());
} finally {
closeQuietly(out);
}
return target;
}
use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.
the class NoCacheTransferDecorator method decorateRead.
@SuppressWarnings("RedundantThrows")
@Override
public InputStream decorateRead(final InputStream stream, final Transfer transfer, final EventMetadata eventMetadata) throws IOException {
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(transfer, eventMetadata.getPackageType());
logger.trace("SpecialPathInfo for: {} is: {} (cachable? {})", transfer, specialPathInfo, (specialPathInfo == null || specialPathInfo.isCachable()));
if (specialPathInfo != null && !specialPathInfo.isCachable()) {
logger.trace("Decorating read with NoCacheTransferDecorator for: {}", transfer);
return new NoCacheInputStream(stream, transfer);
}
return stream;
}
use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.
the class UploadMetadataGenTransferDecorator method decorateWrite.
@Override
public OutputStream decorateWrite(OutputStream stream, Transfer transfer, TransferOperation op, EventMetadata metadata) throws IOException {
final SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(transfer, metadata.getPackageType());
final Boolean isMetadata = specialPathInfo != null && specialPathInfo.isMetadata();
final Boolean isUpload = op == TransferOperation.UPLOAD;
final Boolean hasRequestHeaders = metadata.get(STORE_HTTP_HEADERS) != null && metadata.get(STORE_HTTP_HEADERS) instanceof Map;
// We only care about non-metadata artifact uploading for http-metadata generation
if (isUpload && !isMetadata && hasRequestHeaders) {
@SuppressWarnings("unchecked") Map<String, List<String>> storeHttpHeaders = (Map<String, List<String>>) metadata.get(STORE_HTTP_HEADERS);
writeMetadata(transfer, new ObjectMapper(), storeHttpHeaders);
}
return super.decorateWrite(stream, transfer, op, metadata);
}
Aggregations