use of org.commonjava.indy.model.galley.CacheOnlyLocation in project indy by Commonjava.
the class RouteSelectorPerfTest method setUp.
@Before
public void setUp() {
hostedResource = new ConcreteResource(new CacheOnlyLocation(new HostedRepository(MAVEN_PKG_KEY, "hosted")), String.format("/path/to/my/hosted/%s", "index.html"));
remoteResource = new ConcreteResource(new RepositoryLocation(new RemoteRepository(MAVEN_PKG_KEY, "remote", "http://foo.bar/")), String.format("/path/to/my/remote/%s", "index.html"));
}
use of org.commonjava.indy.model.galley.CacheOnlyLocation 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().getOrderedConcreteStoresInGroup(gl.getKey().getPackageType(), 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;
}
use of org.commonjava.indy.model.galley.CacheOnlyLocation in project indy by Commonjava.
the class LocationUtils method getNonReadonlyLocation.
public static Location getNonReadonlyLocation(final Location location) {
if (location instanceof CacheOnlyLocation) {
CacheOnlyLocation ret = CacheOnlyLocation.copyOf((CacheOnlyLocation) location);
ret.setReadonly(false);
return ret;
}
return location;
}
use of org.commonjava.indy.model.galley.CacheOnlyLocation in project indy by Commonjava.
the class LocationUtils method toLocation.
public static KeyedLocation toLocation(final ArtifactStore store) {
if (store == null) {
return null;
}
KeyedLocation location = (KeyedLocation) store.getTransientMetadata(KEYED_LOCATION_METADATA);
if (location != null) {
return location;
}
final StoreType type = store.getKey().getType();
switch(type) {
case group:
{
location = new GroupLocation(store.getPackageType(), store.getName());
break;
}
case hosted:
{
location = new CacheOnlyLocation((HostedRepository) store);
break;
}
case remote:
default:
{
final RemoteRepository repository = (RemoteRepository) store;
location = new RepositoryLocation(repository);
AttributePasswordManager.bind(location, PasswordEntry.KEY_PASSWORD, repository.getKeyPassword());
AttributePasswordManager.bind(location, PasswordEntry.PROXY_PASSWORD, repository.getProxyPassword());
AttributePasswordManager.bind(location, PasswordEntry.USER_PASSWORD, repository.getPassword());
}
}
if (location != null) {
location.setAttribute(PATH_STYLE, store.getPathStyle());
Map<String, String> metadata = store.getMetadata();
if (metadata != null) {
Location loc = location;
metadata.forEach((k, v) -> {
if (!loc.getAttributes().containsKey(k)) {
loc.setAttribute(k, v);
}
});
}
}
store.setTransientMetadata(KEYED_LOCATION_METADATA, location);
return location;
}
Aggregations