Search in sources :

Example 16 with Location

use of org.commonjava.maven.galley.model.Location in project galley by Commonjava.

the class FileCacheProviderTest method testGetDetachedFile.

@Test
public void testGetDetachedFile() throws Exception {
    final String content = "This is a test";
    final Location loc = new SimpleLocation("http://foo.com");
    final String fname = "/path/to/my/file.txt";
    final ConcreteResource resource = new ConcreteResource(loc, fname);
    final CacheProvider provider = getCacheProvider();
    final OutputStream out = provider.openOutputStream(resource);
    out.write(content.getBytes("UTF-8"));
    out.close();
    File file = provider.asAdminView().getDetachedFile(resource);
    assertThat(provider.exists(resource), equalTo(true));
    assertTrue(file.exists());
}
Also used : OutputStream(java.io.OutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) File(java.io.File) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 17 with Location

use of org.commonjava.maven.galley.model.Location in project galley by Commonjava.

the class VersionResolverImpl method resolveLatestMultiRefWithLocation.

private ProjectVersionRefLocation resolveLatestMultiRefWithLocation(final List<? extends Location> locations, final ProjectVersionRef ref, final VersionSelectionStrategy selectionStrategy, final EventMetadata eventMetadata) throws TransferException {
    final Map<SingleVersion, Location> available = new TreeMap<SingleVersion, Location>();
    for (final Location location : locations) {
        try {
            final MavenMetadataView metadata = metadataReader.getMetadata(ref.asProjectRef(), Collections.singletonList(location), eventMetadata);
            if (metadata != null) {
                final List<String> versions = metadata.resolveValues("/metadata/versioning/versions/version");
                if (versions != null) {
                    for (final String version : versions) {
                        try {
                            final SingleVersion spec = VersionUtils.createSingleVersion(version);
                            if (!available.containsKey(spec)) {
                                available.put(spec, location);
                            }
                        } catch (final InvalidVersionSpecificationException e) {
                            debug("Unparsable version spec found in metadata: '%s' for: %s from: %s.", e, version, ref, location);
                        }
                    }
                }
            }
        } catch (final GalleyMavenException e) {
            debug("Failed to resolve/parse metadata for variable version of: '%s' from: %s.", e, ref, location);
        }
    }
    if (!available.isEmpty()) {
        final VersionSpec spec = ref.getVersionSpec();
        final List<SingleVersion> versions = new ArrayList<SingleVersion>(available.keySet());
        Collections.sort(versions);
        while (!versions.isEmpty()) {
            final SingleVersion selected = selectionStrategy.select(versions);
            if (selected == null) {
                return null;
            }
            versions.remove(selected);
            if (selected.isConcrete() && spec.contains(selected)) {
                return new ProjectVersionRefLocation(ref.selectVersion(selected), available.get(selected));
            }
        }
    }
    return null;
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ArrayList(java.util.ArrayList) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) TreeMap(java.util.TreeMap) VersionSpec(org.commonjava.maven.atlas.ident.version.VersionSpec) MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Example 18 with Location

use of org.commonjava.maven.galley.model.Location in project galley by Commonjava.

the class VersionResolverImpl method resolveAllSnapshotRefsWithLocations.

private List<ProjectVersionRefLocation> resolveAllSnapshotRefsWithLocations(final List<? extends Location> locations, final ProjectVersionRef ref, final VersionSelectionStrategy selectionStrategy, final EventMetadata eventMetadata) throws TransferException {
    final Map<SingleVersion, Location> available = new TreeMap<SingleVersion, Location>();
    for (final Location location : locations) {
        try {
            final MavenMetadataView metadata = metadataReader.getMetadata(ref, Collections.singletonList(location), eventMetadata);
            if (metadata != null) {
                final String latest = metadata.resolveSingleValue("/metadata/versioning/latest");
                if (latest != null) {
                    try {
                        final SingleVersion ver = VersionUtils.createSingleVersion(latest);
                        if (ver.isSnapshot()) {
                            if (!available.containsKey(ver)) {
                                available.put(ver, location);
                            }
                        }
                    } catch (final InvalidVersionSpecificationException e) {
                        debug("Unparsable version spec found in metadata: '%s' for: %s from: %s", e, latest, ref, location);
                    }
                }
            }
        } catch (final GalleyMavenException e) {
            debug("Failed to resolve/parse metadata for snapshot version of: %s from: %s.", e, ref, location);
        }
    }
    if (!available.isEmpty()) {
        return Collections.emptyList();
    }
    final List<SingleVersion> versions = new ArrayList<SingleVersion>(available.keySet());
    Collections.sort(versions);
    final List<ProjectVersionRefLocation> result = new ArrayList<ProjectVersionRefLocation>();
    while (!versions.isEmpty()) {
        final SingleVersion selected = selectionStrategy.select(versions);
        if (selected != null) {
            versions.remove(selected);
            result.add(new ProjectVersionRefLocation(ref.selectVersion(selected), available.get(selected)));
        }
    }
    return result;
}
Also used : MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) ArrayList(java.util.ArrayList) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) TreeMap(java.util.TreeMap) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Example 19 with Location

use of org.commonjava.maven.galley.model.Location in project galley by Commonjava.

the class SimpleUrlLocationResolver method resolve.

@Override
public final Location resolve(final String spec) throws TransferException {
    final Location location = new SimpleLocation(spec);
    final List<Location> locations = locationExpander.expand(location);
    if (locations == null || locations.isEmpty()) {
        throw new TransferException("Invalid location: '%s'. Location expansion returned no results.", spec);
    }
    for (final Iterator<Location> iterator = new ArrayList<Location>(locations).iterator(); iterator.hasNext(); ) {
        final Location loc = iterator.next();
        // normally, this will probably throw an exception if no transport is available.
        // in case it's not, remove the location if the transport is null.
        final Transport transport = transportManager.getTransport(loc);
        if (transport == null) {
            iterator.remove();
        }
    }
    if (locations == null || locations.isEmpty()) {
        throw new TransferException("Invalid location: '%s'. No transports available for expanded locations.", spec);
    }
    return location;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Transport(org.commonjava.maven.galley.spi.transport.Transport) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location)

Example 20 with Location

use of org.commonjava.maven.galley.model.Location in project galley by Commonjava.

the class AbstractTransferManagerTest method retrieve_cacheIfMissing.

/**
     * Test that remote content will be downloaded then cached.
     */
@Test
public void retrieve_cacheIfMissing() throws Exception {
    final String testContent = "This is a test " + System.currentTimeMillis();
    final Location loc = new SimpleLocation("file:///test-repo");
    final String path = "/path/to/test.txt";
    final ConcreteResource resource = new ConcreteResource(loc, path);
    // put in the content that we want to "download"
    getTransport().registerDownload(resource, new TestDownload(testContent.getBytes()));
    // now, use the manager to retrieve() the path...the remote content should come through here.
    Transfer transfer = getTransferManagerImpl().retrieve(resource);
    assertTransferContent(transfer, testContent);
    // now, the right content should be cached.
    // So, we'll put in some wrong content that will cause problems if the cache isn't used.
    getTransport().registerDownload(resource, new TestDownload("This is WRONG".getBytes()));
    // now, use the manager to retrieve() the path again...the cached content should come through here.
    transfer = getTransferManagerImpl().retrieve(resource);
    assertTransferContent(transfer, testContent);
}
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) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Aggregations

Location (org.commonjava.maven.galley.model.Location)58 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)28 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)26 Test (org.junit.Test)25 Transfer (org.commonjava.maven.galley.model.Transfer)14 ArrayList (java.util.ArrayList)13 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)11 CacheProvider (org.commonjava.maven.galley.spi.cache.CacheProvider)11 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 OutputStream (java.io.OutputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)7 URI (java.net.URI)6 RepositoryLocation (org.commonjava.indy.model.galley.RepositoryLocation)6 TransferException (org.commonjava.maven.galley.TransferException)6 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)6 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)5 ProjectVersionRefLocation (org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation)5