use of org.commonjava.maven.galley.model.ListingResult in project galley by Commonjava.
the class ArtifactManagerImpl method listAvailableArtifacts.
// TODO: This may be incompatible with snapshots, which will have LOTS of entries...
@Override
public Map<TypeAndClassifier, ConcreteResource> listAvailableArtifacts(final Location location, final ProjectVersionRef ref, final EventMetadata metadata) throws TransferException {
final List<ListingResult> listingResults = transferManager.listAll(new VirtualResource(expander.expand(location), formatArtifactPath(ref.asProjectVersionRef(), mapper)), metadata);
if (listingResults == null || listingResults.isEmpty()) {
return Collections.emptyMap();
}
final Map<TypeAndClassifier, ConcreteResource> result = new LinkedHashMap<>();
final String prefix = String.format("%s-%s", ref.getArtifactId(), ref.getVersionString());
for (final ListingResult listingResult : listingResults) {
// FIXME: snapshot handling.
for (final String fname : listingResult.getListing()) {
if (fname.startsWith(prefix)) {
final String remainder = fname.substring(prefix.length());
String classifier = null;
String type = null;
if (remainder.startsWith("-")) {
// must have a classifier.
final int extPos = remainder.indexOf('.');
if (extPos < 2) {
logger.warn("Listing found unparsable filename: '{}' from: {}. Skipping", fname, location);
continue;
}
classifier = remainder.substring(1, extPos);
type = remainder.substring(extPos + 1);
} else if (remainder.startsWith(".")) {
type = remainder.substring(1);
}
final ConcreteResource res = listingResult.getResource().getChild(fname);
result.put(new SimpleTypeAndClassifier(type, classifier), res);
}
}
}
return result;
}
Aggregations