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;
}
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;
}
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);
}
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));
}
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);
}
Aggregations