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