use of org.commonjava.maven.galley.transport.htcli.model.HttpLocation in project galley by Commonjava.
the class ContentsFilteringTransferDecorator method decorateWrite.
public OutputStream decorateWrite(final OutputStream stream, final Transfer transfer, final TransferOperation op) throws IOException {
final Location loc = transfer.getLocation();
final boolean allowsSnapshots = loc.allowsSnapshots();
final boolean allowsReleases = loc.allowsReleases();
if (loc instanceof HttpLocation && (!allowsSnapshots || !allowsReleases) && transfer.getFullPath().endsWith("maven-metadata.xml")) {
return new MetadataFilteringOutputStream(stream, allowsSnapshots, allowsReleases, transfer);
} else {
return stream;
}
}
use of org.commonjava.maven.galley.transport.htcli.model.HttpLocation in project galley by Commonjava.
the class ContentsFilteringTransferDecorator method decorateExists.
public OverriddenBooleanValue decorateExists(final Transfer transfer) {
final Location loc = transfer.getLocation();
final boolean allowsSnapshots = loc.allowsSnapshots();
final boolean allowsReleases = loc.allowsReleases();
if (loc instanceof HttpLocation && (!allowsSnapshots || !allowsReleases)) {
if (transfer.isFile()) {
final String path = transfer.getPath();
// pattern for "groupId path/(artifactId)/(version)/(filename)"
// where the filename starts with artifactId-version and is followed by - or .
final Pattern pattern = Pattern.compile(".*/([^/]+)/([^/]+)/(\\1-\\2[-.][^/]+)$");
final Matcher matcher = pattern.matcher(path);
if (matcher.find()) {
String version = matcher.group(2);
final boolean isSnapshot = SnapshotUtils.isSnapshotVersion(version);
if (isSnapshot && !allowsSnapshots || !isSnapshot && !allowsReleases) {
return OverriddenBooleanValue.OVERRIDE_FALSE;
}
}
}
}
return OverriddenBooleanValue.DEFER;
}
use of org.commonjava.maven.galley.transport.htcli.model.HttpLocation in project galley by Commonjava.
the class ContentsFilteringTransferDecorator method decorateListing.
/**
* Alters the listing to filter out artifacts belonging to a version that
* should not be provided via the proxy.
*/
public String[] decorateListing(final Transfer transfer, final String[] listing) throws IOException {
final Location loc = transfer.getLocation();
final boolean allowsSnapshots = loc.allowsSnapshots();
final boolean allowsReleases = loc.allowsReleases();
// process only proxied locations, i.e. HttpLocation instances
if (loc instanceof HttpLocation && (!allowsSnapshots || !allowsReleases)) {
final String[] pathElements = transfer.getPath().split("/");
// process only paths that *can* be a GAV
if (pathElements.length >= 3) {
final String artifactId = pathElements[pathElements.length - 2];
final String version = pathElements[pathElements.length - 1];
final boolean snapshotVersion = SnapshotUtils.isSnapshotVersion(version);
if (!allowsSnapshots && snapshotVersion || !allowsReleases && !snapshotVersion) {
final List<String> result = new ArrayList<String>(listing.length);
for (final String element : listing) {
// do not include artifacts in the list
if (!isArtifact(element, artifactId, version)) {
result.add(element);
}
}
return result.toArray(new String[result.size()]);
}
}
}
return listing;
}
Aggregations