Search in sources :

Example 1 with RepositoryLocation

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"));
}
Also used : CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Before(org.junit.Before)

Example 2 with RepositoryLocation

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));
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ArrayList(java.util.ArrayList) Transfer(org.commonjava.maven.galley.model.Transfer) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 3 with RepositoryLocation

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));
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 4 with RepositoryLocation

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;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.atlas.maven.ident.util.JoinString) TransferException(org.commonjava.maven.galley.TransferException) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) Location(org.commonjava.maven.galley.model.Location)

Example 5 with RepositoryLocation

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;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) Location(org.commonjava.maven.galley.model.Location)

Aggregations

RepositoryLocation (org.commonjava.indy.model.galley.RepositoryLocation)6 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)4 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)4 CacheOnlyLocation (org.commonjava.indy.model.galley.CacheOnlyLocation)3 Transfer (org.commonjava.maven.galley.model.Transfer)3 ArrayList (java.util.ArrayList)2 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)2 GroupLocation (org.commonjava.indy.model.galley.GroupLocation)2 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)2 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)2 Location (org.commonjava.maven.galley.model.Location)2 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)2 Test (org.junit.Test)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1 JoinString (org.commonjava.atlas.maven.ident.util.JoinString)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 HostedRepository (org.commonjava.indy.model.core.HostedRepository)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1