Search in sources :

Example 21 with Location

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

the class AbstractMavenXmlReader method getAllCached.

protected synchronized Map<Location, DocRef<T>> getAllCached(final T ref, final List<? extends Location> locations) {
    final Map<Location, DocRef<T>> result = new HashMap<Location, DocRef<T>>();
    for (final Location location : locations) {
        final DocCacheKey<T> key = new DocCacheKey<T>(ref, location);
        final WeakReference<DocRef<T>> reference = cache.get(key);
        if (reference != null) {
            final DocRef<T> dr = reference.get();
            if (dr == null) {
                cache.remove(key);
            } else {
                result.put(location, dr);
            }
        }
    }
    return result;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) Location(org.commonjava.maven.galley.model.Location)

Example 22 with Location

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

the class AbstractMavenXmlReader method getFirstCached.

protected synchronized DocRef<T> getFirstCached(final T ref, final Collection<? extends Location> locations) throws TransferException {
    for (final Location location : locationExpander.expand(locations)) {
        final DocCacheKey<T> key = new DocCacheKey<T>(ref, location);
        final WeakReference<DocRef<T>> reference = cache.get(key);
        if (reference != null) {
            final DocRef<T> dr = reference.get();
            if (dr == null) {
                cache.remove(key);
            } else {
                return dr;
            }
        }
    }
    return null;
}
Also used : DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) Location(org.commonjava.maven.galley.model.Location)

Example 23 with Location

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

the class ArtifactManagerImpl method store.

/* (non-Javadoc)
     * @see org.commonjava.maven.galley.ArtifactManager#store(org.commonjava.maven.galley.model.Location, org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef, java.io.InputStream)
     */
@Override
public Transfer store(final Location location, final ArtifactRef ref, final InputStream stream, final EventMetadata eventMetadata) throws TransferException {
    final List<Location> locations = expander.expand(location);
    final Location selected = ArtifactRules.selectStorageLocation(locations);
    if (selected == null) {
        return null;
    }
    final ConcreteResource resource = new ConcreteResource(selected, formatArtifactPath(ref, mapper));
    ArtifactRules.checkStorageAuthorization(resource);
    return transferManager.store(resource, stream, eventMetadata);
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Example 24 with Location

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

the class CacheProviderTCK method writeAndReadFile.

@Test
public void writeAndReadFile() 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 CacheProvider provider = getCacheProvider();
    final OutputStream out = provider.openOutputStream(new ConcreteResource(loc, fname));
    out.write(content.getBytes("UTF-8"));
    out.close();
    final InputStream in = provider.openInputStream(new ConcreteResource(loc, fname));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int read = -1;
    final byte[] buf = new byte[512];
    while ((read = in.read(buf)) > -1) {
        baos.write(buf, 0, read);
    }
    final String result = new String(baos.toByteArray(), "UTF-8");
    assertThat(result, equalTo(content));
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 25 with Location

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

the class AttributePasswordManager method getPassword.

@Override
public String getPassword(final PasswordEntry id) {
    final Location loc = id.getLocation();
    final String type = id.getPasswordType();
    return loc.getAttribute(PASSWORD_PREFIX + type, String.class);
}
Also used : Location(org.commonjava.maven.galley.model.Location)

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