Search in sources :

Example 1 with EProjectDirectRelationships

use of org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships in project indy by Commonjava.

the class PomDownloadSimpleDepTest method run.

@Test
public void run() throws Exception {
    String depPom = readTestResource(repo + "/" + pathDep);
    server.expect(server.formatUrl(repo1, pathDep), 200, depPom);
    String consumerPom = readTestResource(repo + "/" + pathConsumer);
    server.expect(server.formatUrl(repo1, pathConsumer), 200, consumerPom);
    // Create remote repository
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    client.stores().create(remote1, "adding remote1", RemoteRepository.class);
    // Add to a group
    client.stores().create(new Group(group1, remote1.getKey()), "adding group", Group.class);
    // Get consumer pom via group
    InputStream is = client.content().get(group, group1, pathConsumer);
    String s = IOUtils.toString(is);
    logger.debug(">>> " + s);
    assertThat(s, equalTo(consumerPom));
    waitForEventPropagation();
    boolean exists = false;
    // Check consumer pom exists on group
    exists = client.content().exists(group, group1, pathConsumer, true);
    assertThat(exists, equalTo(true));
    // Check consumer rel exists on group
    exists = client.content().exists(group, group1, pathConsumerRel);
    assertThat(exists, equalTo(true));
    // Check consumer rel exists on remote
    exists = client.content().exists(remote, repo1, pathConsumerRel, true);
    assertThat(exists, equalTo(true));
    // Check consumer rel content is not empty via group
    InputStream ris = client.content().get(group, group1, pathConsumerRel);
    String rel = IOUtils.toString(ris);
    logger.debug(">>> " + rel);
    assertThat(StringUtils.isNotEmpty(rel), equalTo(true));
    // Check consumer rel output
    String output = readTestResource(resource + "/output/rel.json");
    EProjectDirectRelationships eRel = mapper.readValue(rel, EProjectDirectRelationships.class);
    EProjectDirectRelationships eRelOutput = mapper.readValue(output, EProjectDirectRelationships.class);
    assertThat(eRel.getDependencies(), equalTo(eRelOutput.getDependencies()));
}
Also used : Group(org.commonjava.indy.model.core.Group) InputStream(java.io.InputStream) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 2 with EProjectDirectRelationships

use of org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships in project indy by Commonjava.

the class PomDownloadDepFromParentTest method run.

@Test
public void run() throws Exception {
    String depPom = readTestResource(repo + "/" + pathDep);
    server.expect(server.formatUrl(repo1, pathDep), 200, depPom);
    String consumerPom = readTestResource(repo + "/" + pathConsumer);
    server.expect(server.formatUrl(repo1, pathConsumer), 200, consumerPom);
    String consumerParentPom = readTestResource(repo + "/" + pathConsumerParent);
    server.expect(server.formatUrl(repo1, pathConsumerParent), 200, consumerParentPom);
    // Create remote repositories
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    client.stores().create(remote1, "adding remote1", RemoteRepository.class);
    // Get consumer pom
    InputStream is = client.content().get(remote, repo1, pathConsumer);
    assertThat(is, notNullValue());
    String s = IOUtils.toString(is);
    logger.debug(">>> " + s);
    assertThat(s, equalTo(consumerPom));
    waitForEventPropagation();
    boolean exists = false;
    // Check consumer rel exists
    exists = client.content().exists(remote, repo1, pathConsumerRel, true);
    assertThat(exists, equalTo(true));
    // Check consumer's parent pom exists
    exists = client.content().exists(remote, repo1, pathConsumerParent, true);
    assertThat(exists, equalTo(true));
    // Check consumer's parent rel exists
    exists = client.content().exists(remote, repo1, pathConsumerParentRel, true);
    assertThat(exists, equalTo(true));
    // Check consumer rel content
    InputStream ris = client.content().get(remote, repo1, pathConsumerRel);
    assertThat(ris, notNullValue());
    String rel = IOUtils.toString(ris);
    logger.debug(">>> " + rel);
    String output = readTestResource(resource + "/output/rel.json");
    EProjectDirectRelationships eRel = mapper.readValue(rel, EProjectDirectRelationships.class);
    EProjectDirectRelationships eRelOutput = mapper.readValue(output, EProjectDirectRelationships.class);
    assertThat(eRel.getParent(), equalTo(eRelOutput.getParent()));
}
Also used : InputStream(java.io.InputStream) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 3 with EProjectDirectRelationships

use of org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships in project galley by Commonjava.

the class MavenModelProcessorTest method resolvePluginVersionFromManagementExpression.

@Test
public void resolvePluginVersionFromManagementExpression() throws Exception {
    final URI src = new URI("http://nowhere.com/path/to/repo");
    final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-child", "1.0");
    final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
    lineage.put(childRef, "child.pom.xml");
    lineage.put(new SimpleProjectVersionRef("org.test", "test-parent", "1.0"), "parent.pom.xml");
    final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true, false);
    final String base = PROJ_BASE + "version-expression-managed-parent-plugin/";
    for (final Entry<ProjectVersionRef, String> entry : lineage.entrySet()) {
        final ProjectVersionRef ref = entry.getKey();
        final String filename = entry.getValue();
        final String path = ArtifactPathUtils.formatArtifactPath(ref.asPomArtifact(), fixture.getTypeMapper());
        fixture.getTransport().registerDownload(new ConcreteResource(location, path), new TestDownload(base + filename));
    }
    final Transfer transfer = fixture.getArtifactManager().retrieve(location, childRef.asPomArtifact());
    final MavenPomView pomView = fixture.getPomReader().read(childRef, transfer, Collections.singletonList(location));
    final List<PluginView> buildPlugins = pomView.getAllBuildPlugins();
    assertThat(buildPlugins, notNullValue());
    assertThat(buildPlugins.size(), equalTo(1));
    final PluginView pv = buildPlugins.get(0);
    assertThat(pv, notNullValue());
    assertThat(pv.getVersion(), equalTo("1.0"));
    final ModelProcessorConfig discoveryConfig = new ModelProcessorConfig();
    discoveryConfig.setIncludeManagedDependencies(true);
    discoveryConfig.setIncludeBuildSection(true);
    discoveryConfig.setIncludeManagedPlugins(false);
    EProjectDirectRelationships result = fixture.getModelProcessor().readRelationships(pomView, src, discoveryConfig);
    final Set<ProjectRelationship<?, ?>> rels = result.getExactAllRelationships();
    logger.info("Found {} relationships:\n\n  {}", rels.size(), new JoinString("\n  ", rels));
    boolean seen = false;
    for (final ProjectRelationship<?, ?> rel : rels) {
        if (rel.getType() == RelationshipType.PLUGIN && !rel.isManaged()) {
            if (seen) {
                fail("Multiple plugins found!");
            }
            seen = true;
            assertThat(rel.getTarget().getVersionString(), equalTo("1.0"));
        }
    }
    if (!seen) {
        fail("Plugin relationship not found!");
    }
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ProjectRelationship(org.commonjava.maven.atlas.graph.rel.ProjectRelationship) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 4 with EProjectDirectRelationships

use of org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships in project galley by Commonjava.

the class MavenModelProcessorTest method resolvePluginVersionFromPropertyInProfile.

@Test
public void resolvePluginVersionFromPropertyInProfile() throws Exception {
    final URI src = new URI("http://nowhere.com/path/to/repo");
    final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-pom", "1.0");
    final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
    lineage.put(childRef, "test-pom-1.0.pom.xml");
    final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true, false);
    final String base = PROJ_BASE + "version-expression-in-a-profile/";
    for (final Entry<ProjectVersionRef, String> entry : lineage.entrySet()) {
        final ProjectVersionRef ref = entry.getKey();
        final String filename = entry.getValue();
        final String path = ArtifactPathUtils.formatArtifactPath(ref.asPomArtifact(), fixture.getTypeMapper());
        fixture.getTransport().registerDownload(new ConcreteResource(location, path), new TestDownload(base + filename));
    }
    final Transfer transfer = fixture.getArtifactManager().retrieve(location, childRef.asPomArtifact());
    final MavenPomView pomView = fixture.getPomReader().read(childRef, transfer, Collections.singletonList(location));
    final List<PluginView> buildPlugins = pomView.getAllBuildPlugins();
    assertThat(buildPlugins, notNullValue());
    assertThat(buildPlugins.size(), equalTo(1));
    final PluginView pv = buildPlugins.get(0);
    assertThat(pv, notNullValue());
    assertThat(pv.getVersion(), equalTo("2.0"));
    final ModelProcessorConfig discoveryConfig = new ModelProcessorConfig();
    discoveryConfig.setIncludeManagedDependencies(true);
    discoveryConfig.setIncludeBuildSection(true);
    discoveryConfig.setIncludeManagedPlugins(false);
    EProjectDirectRelationships result = fixture.getModelProcessor().readRelationships(pomView, src, discoveryConfig);
    final Set<ProjectRelationship<?, ?>> rels = result.getExactAllRelationships();
    logger.info("Found {} relationships:\n\n  {}", rels.size(), new JoinString("\n  ", rels));
    boolean seen = false;
    for (final ProjectRelationship<?, ?> rel : rels) {
        if (rel.getType() == RelationshipType.PLUGIN && !rel.isManaged()) {
            if (seen) {
                fail("Multiple plugins found!");
            }
            seen = true;
            assertThat(rel.getTarget().getVersionString(), equalTo("2.0"));
        }
    }
    if (!seen) {
        fail("Plugin relationship not found!");
    }
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ProjectRelationship(org.commonjava.maven.atlas.graph.rel.ProjectRelationship) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 5 with EProjectDirectRelationships

use of org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships in project indy by Commonjava.

the class RelateGenerationManager method generateRelationshipFile.

/**
     * Generate relationship file for pom transfer.
     * @param transfer
     * @param op
     * @return transfer pointing to the generated rel file.
     */
public Transfer generateRelationshipFile(Transfer transfer, TransferOperation op) {
    final Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Relate generation for {}", transfer);
    if (transfer == null) {
        logger.debug("No transfer. No .rel generation performed.");
        return null;
    }
    String txfrPath = transfer.getPath();
    if (!txfrPath.endsWith(".pom")) {
        logger.debug("This is not a pom transfer.");
        return null;
    }
    ArtifactPathInfo artPathInfo = ArtifactPathInfo.parse(txfrPath);
    if (artPathInfo == null) {
        logger.debug("Not an artifact download ({}). No .rel generation performed.", txfrPath);
        return null;
    }
    ConcreteResource pomResource = transfer.getResource();
    StoreKey storeKey = StoreKey.fromString(transfer.getLocation().getName());
    ArtifactStore store;
    try {
        store = storeManager.getArtifactStore(storeKey);
    } catch (final IndyDataException ex) {
        logger.error("Error retrieving artifactStore with key " + storeKey, ex);
        return null;
    }
    logger.debug("Generate .rel corresponding to associated POM download: {}/{}", storeKey, pomResource.getPath());
    try {
        URI source = new URI(pomResource.getLocation().getUri() + REL_SUFFIX);
        ProjectVersionRef ref = artPathInfo.getProjectId();
        // get all groups that this store is a member of
        Set<ArtifactStore> stores = new HashSet<>();
        stores.add(store);
        stores.addAll(storeManager.query().getGroupsContaining(store.getKey()));
        List<? extends Location> supplementalLocations = LocationUtils.toLocations(stores.toArray(new ArtifactStore[0]));
        MavenPomView pomView = mavenPomReader.read(ref, transfer, supplementalLocations, ALL_PROFILES);
        EProjectDirectRelationships rel = mavenModelProcessor.readRelationships(pomView, source, new ModelProcessorConfig());
        Transfer transferRel = transfer.getSiblingMeta(REL_SUFFIX);
        writeRelationships(rel, transferRel, op);
        return transferRel;
    } catch (Exception e) {
        logger.error("Error generating .rel file for " + txfrPath + " from store " + store, e);
        return null;
    }
}
Also used : Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) URI(java.net.URI) IOException(java.io.IOException) IndyDataException(org.commonjava.indy.data.IndyDataException) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) ArtifactPathInfo(org.commonjava.maven.atlas.ident.util.ArtifactPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) EProjectDirectRelationships(org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships) ModelProcessorConfig(org.commonjava.maven.galley.maven.rel.ModelProcessorConfig) Transfer(org.commonjava.maven.galley.model.Transfer) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) HashSet(java.util.HashSet)

Aggregations

EProjectDirectRelationships (org.commonjava.maven.atlas.graph.model.EProjectDirectRelationships)7 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)5 Test (org.junit.Test)5 URI (java.net.URI)4 MavenPomView (org.commonjava.maven.galley.maven.model.view.MavenPomView)4 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)4 Transfer (org.commonjava.maven.galley.model.Transfer)4 LinkedHashMap (java.util.LinkedHashMap)3 ProjectRelationship (org.commonjava.maven.atlas.graph.rel.ProjectRelationship)3 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)3 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)3 PluginView (org.commonjava.maven.galley.maven.model.view.PluginView)3 Location (org.commonjava.maven.galley.model.Location)3 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)3 TestDownload (org.commonjava.maven.galley.testing.core.transport.job.TestDownload)3 InputStream (java.io.InputStream)2 AbstractIndyFunctionalTest (org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest)2 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1