use of org.commonjava.maven.galley.model.Location in project indy by Commonjava.
the class ImpliedRepositoryDetector method initJob.
private boolean initJob(final ImplicationsJob job) {
switch(job.event.getType()) {
case DOWNLOAD:
case UPLOAD:
break;
default:
// we're not interested in these.
return false;
}
final Transfer transfer = job.transfer;
if (!transfer.getPath().endsWith(".pom")) {
return false;
}
final Location location = transfer.getLocation();
if (!(location instanceof KeyedLocation)) {
return false;
}
final StoreKey key = ((KeyedLocation) location).getKey();
try {
job.store = storeManager.getArtifactStore(key);
} catch (final IndyDataException e) {
logger.error(String.format("Cannot retrieve artifact store for: %s. Failed to process implied repositories.", key), e);
}
if (job.store == null) {
return false;
}
job.pathInfo = ArtifactPathInfo.parse(transfer.getPath());
if (job.pathInfo == null) {
return false;
}
try {
logger.debug("Parsing: {}", transfer);
job.pomView = pomReader.readLocalPom(job.pathInfo.getProjectId(), transfer, MavenPomView.ALL_PROFILES);
} catch (final GalleyMavenException e) {
logger.error(String.format("Cannot parse: %s from: %s. Failed to process implied repositories.", job.pathInfo.getProjectId(), transfer), e);
}
return job.pomView != null;
}
use of org.commonjava.maven.galley.model.Location in project indy by Commonjava.
the class PromotionValidationTools method getRelationshipsForPom.
public Set<ProjectRelationship<?, ?>> getRelationshipsForPom(final String path, final ModelProcessorConfig config, final ValidationRequest request, final StoreKey... extraLocations) throws IndyWorkflowException, GalleyMavenException, IndyDataException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Retrieving relationships for POM: {} (using extra locations: {})", path, Arrays.asList(extraLocations));
ArtifactRef artifactRef = getArtifact(path);
if (artifactRef == null) {
logger.trace("{} is not a valid artifact reference. Skipping.", path);
return null;
}
StoreKey key = request.getSourceRepository().getKey();
Transfer transfer = retrieve(request.getSourceRepository(), path);
if (transfer == null) {
logger.trace("Could not retrieve Transfer instance for: {} (path: {}, extra locations: {})", key, path, Arrays.asList(extraLocations));
return null;
}
List<Location> locations = new ArrayList<>(extraLocations.length + 1);
locations.add(transfer.getLocation());
addLocations(locations, extraLocations);
MavenPomView pomView = pomReader.read(artifactRef.asProjectVersionRef(), transfer, locations, MavenPomView.ALL_PROFILES);
try {
URI source = new URI("indy:" + key.getType().name() + ":" + key.getName());
return modelProcessor.readRelationships(pomView, source, config).getAllRelationships();
} catch (final URISyntaxException e) {
throw new IllegalStateException("Failed to construct URI for ArtifactStore: " + key + ". Reason: " + e.getMessage(), e);
}
}
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);
}
use of org.commonjava.maven.galley.model.Location in project galley by Commonjava.
the class FastLocalCacheProviderTest method testSimultaneousWritesResourceExistence.
@Test
@BMScript("SimultaneousWritesResourceExistence.btm")
public void testSimultaneousWritesResourceExistence() throws Exception {
final String content = "This is a test";
final Location loc = new SimpleLocation("http://foo.com");
final String dir = "/path/to/my/";
final String fname1 = dir + "file1.txt";
final String fname2 = dir + "file2.txt";
CountDownLatch latch = new CountDownLatch(2);
start(new WriteFileThread(content, loc, fname1, latch));
start(new WriteFileThread(content, loc, fname2, latch));
latchWait(latch);
assertThat(provider.exists(new ConcreteResource(loc, fname1)), equalTo(true));
assertThat(provider.exists(new ConcreteResource(loc, fname2)), equalTo(true));
assertThat(provider.isDirectory(new ConcreteResource(loc, dir)), equalTo(true));
final Set<String> listing = new HashSet<String>(Arrays.asList(provider.list(new ConcreteResource(loc, dir))));
assertThat(listing.size() > 1, equalTo(true));
assertThat(listing.contains("file1.txt"), equalTo(true));
assertThat(listing.contains("file2.txt"), equalTo(true));
}
Aggregations