Search in sources :

Example 31 with Location

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;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Transfer(org.commonjava.maven.galley.model.Transfer) StoreKey(org.commonjava.indy.model.core.StoreKey) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 32 with Location

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);
    }
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) URI(java.net.URI) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) Location(org.commonjava.maven.galley.model.Location)

Example 33 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 34 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)

Example 35 with Location

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));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CountDownLatch(java.util.concurrent.CountDownLatch) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) HashSet(java.util.HashSet) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

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