use of org.commonjava.indy.model.galley.RepositoryLocation 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.RepositoryLocation in project indy by Commonjava.
the class DownloadManagerTest method downloadOnePOMFromSecondRepositoryAfterDummyRepoFails.
@Test
public void downloadOnePOMFromSecondRepositoryAfterDummyRepoFails() throws Exception {
final RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, "dummy", "http://www.nowhere.com/");
final String content = "This is a test";
final String path = "/org/apache/maven/maven-model/3.0.3/maven-model-3.0.3.pom";
final RemoteRepository repo2 = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2");
fixture.getTransport().registerDownload(new ConcreteResource(new RepositoryLocation(repo2), path), new TestDownload(content.getBytes()));
data.storeArtifactStore(repo, summary, false, true, new EventMetadata());
data.storeArtifactStore(repo2, summary, false, true, new EventMetadata());
final List<ArtifactStore> repos = new ArrayList<ArtifactStore>();
repos.add(repo);
repos.add(repo2);
final Transfer stream = downloader.retrieveFirst(repos, path, new EventMetadata());
final String downloaded = IOUtils.toString(stream.openInputStream());
assertThat(downloaded, equalTo(content));
}
use of org.commonjava.indy.model.galley.RepositoryLocation in project indy by Commonjava.
the class DownloadManagerTest method downloadOnePOMFromSingleRepository.
@Test
public void downloadOnePOMFromSingleRepository() throws Exception {
final String content = "This is a test";
final String path = "/org/apache/maven/maven-model/3.0.3/maven-model-3.0.3.pom";
final RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2");
fixture.getTransport().registerDownload(new ConcreteResource(new RepositoryLocation(repo), path), new TestDownload(content.getBytes()));
data.storeArtifactStore(repo, summary, false, true, new EventMetadata());
final Transfer stream = downloader.retrieve(repo, path, new EventMetadata());
final String downloaded = IOUtils.toString(stream.openInputStream());
assertThat(downloaded, equalTo(content));
}
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().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.RepositoryLocation 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