use of org.commonjava.indy.model.galley.RepositoryLocation in project indy by Commonjava.
the class IndyLocationExpander method expand.
/**
* For group references, expand into a list of concrete repository locations (hosted or remote). For remote repository references that are
* specified as cache-only locations (see: {@link CacheOnlyLocation}), lookup the corresponding {@link RemoteRepository} and use it to create a
* {@link RepositoryLocation} that contains any relevant SSL, authentication, proxy, etc. attbributes.
*/
@Override
public <T extends Location> List<Location> expand(final Collection<T> locations) throws TransferException {
final List<Location> result = new ArrayList<Location>();
for (final Location location : locations) {
if (location instanceof GroupLocation) {
final GroupLocation gl = (GroupLocation) location;
try {
logger.debug("Expanding group: {}", gl.getKey());
final List<ArtifactStore> members = data.query().packageType(gl.getKey().getPackageType()).getOrderedConcreteStoresInGroup(gl.getKey().getName());
if (members != null) {
for (final ArtifactStore member : members) {
if (!result.contains(member)) {
logger.debug("expansion += {}", member.getKey());
result.add(LocationUtils.toLocation(member));
}
}
logger.debug("Expanded group: {} to:\n {}", gl.getKey(), new JoinString("\n ", result));
}
} catch (final IndyDataException e) {
throw new TransferException("Failed to lookup ordered concrete artifact stores contained in group: {}. Reason: {}", e, gl, e.getMessage());
}
} else if (location instanceof CacheOnlyLocation && !((CacheOnlyLocation) location).isHostedRepository()) {
final StoreKey key = ((KeyedLocation) location).getKey();
try {
final ArtifactStore store = data.getArtifactStore(key);
if (store == null) {
throw new TransferException("Cannot find ArtifactStore to match key: %s.", key);
}
logger.debug("Adding single store: {} for location: {}", store, location);
result.add(LocationUtils.toLocation(store));
} catch (final IndyDataException e) {
throw new TransferException("Failed to lookup store for key: {}. Reason: {}", e, key, e.getMessage());
}
} else {
logger.debug("No expansion available for location: {}", location);
result.add(location);
}
}
return result;
}
Aggregations