use of org.commonjava.maven.galley.maven.model.view.DependencyView in project galley by Commonjava.
the class MavenModelProcessorTest method resolveExpressionsBothInDepAndProfile.
@Test
public void resolveExpressionsBothInDepAndProfile() 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 + "resolve-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));
String url = pomView.resolveExpressions("${repo.url}", "test.oracle");
assertThat(url, equalTo("http://test.oracle.repository"));
List<DependencyView> dvs = pomView.getAllDirectDependencies();
assertThat(dvs.get(0).getVersion(), equalTo("2.5"));
String version = pomView.resolveExpressions("${commons.lang.value}");
assertThat(version, equalTo("2.5"));
}
use of org.commonjava.maven.galley.maven.model.view.DependencyView in project galley by Commonjava.
the class MavenModelProcessor method addDependencyRelationships.
protected void addDependencyRelationships(final URI source, final Builder builder, final MavenPomView pomView, final ProjectVersionRef projectRef, final boolean includeManagedDependencies) {
// regardless of whether we're processing managed info, this is STRUCTURAL, so always grab it!
List<DependencyView> boms = null;
try {
boms = pomView.getAllBOMs();
} catch (final GalleyMavenException e) {
logger.error(String.format("%s: Failed to retrieve BOM declarations: %s. Skipping", pomView.getRef(), e.getMessage()), e);
} catch (final InvalidVersionSpecificationException e) {
logger.error(String.format("%s: Failed to retrieve BOM declarations: %s. Skipping", pomView.getRef(), e.getMessage()), e);
} catch (final InvalidRefException e) {
logger.error(String.format("%s: Failed to retrieve BOM declarations: %s. Skipping", pomView.getRef(), e.getMessage()), e);
}
if (boms != null) {
for (int i = 0; i < boms.size(); i++) {
final DependencyView bomView = boms.get(i);
try {
builder.withBoms(new SimpleBomRelationship(source, projectRef, bomView.asProjectVersionRef(), i, bomView.getOriginInfo().isInherited(), bomView.getOriginInfo().isMixin()));
} catch (final InvalidRefException e) {
logger.error(String.format("%s dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", pomView.getRef(), e.getMessage(), bomView.toXML()), e);
} catch (final InvalidVersionSpecificationException e) {
logger.error(String.format("%s dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", pomView.getRef(), e.getMessage(), bomView.toXML()), e);
} catch (final GalleyMavenException e) {
logger.error(String.format("%s dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", pomView.getRef(), e.getMessage(), bomView.toXML()), e);
}
}
}
if (includeManagedDependencies) {
List<DependencyView> deps = null;
try {
deps = pomView.getAllManagedDependencies();
} catch (final GalleyMavenException e) {
logger.error(String.format("%s: Failed to retrieve managed dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
} catch (final InvalidVersionSpecificationException e) {
logger.error(String.format("%s: Failed to retrieve managed dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
} catch (final InvalidRefException e) {
logger.error(String.format("%s: Failed to retrieve managed dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
}
addDependencies(deps, projectRef, builder, source, true);
}
List<DependencyView> deps = null;
try {
deps = pomView.getAllDirectDependencies();
} catch (final GalleyMavenException e) {
logger.error(String.format("%s: Failed to retrieve direct dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
} catch (final InvalidVersionSpecificationException e) {
logger.error(String.format("%s: Failed to retrieve direct dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
} catch (final InvalidRefException e) {
logger.error(String.format("%s: Failed to retrieve direct dependencies: %s. Skipping", pomView.getRef(), e.getMessage()), e);
}
addDependencies(deps, projectRef, builder, source, false);
}
use of org.commonjava.maven.galley.maven.model.view.DependencyView in project pom-manipulation-ext by release-engineering.
the class ModelIO method getRemoteDependencyVersionOverrides.
public Map<ArtifactRef, String> getRemoteDependencyVersionOverrides(final ProjectVersionRef ref) throws ManipulationException {
logger.debug("Resolving dependency management GAV: " + ref);
final Map<ArtifactRef, String> versionOverrides = new LinkedHashMap<>();
try {
final MavenPomView pomView = galleyWrapper.readPomView(ref);
// TODO: active profiles!
final List<DependencyView> deps = pomView.getAllManagedDependencies();
if (deps == null || deps.isEmpty()) {
logger.warn("Attempting to align to a BOM that does not have a dependencyManagement section");
} else {
for (final DependencyView dep : deps) {
versionOverrides.put(dep.asArtifactRef(), dep.getVersion());
logger.debug("Added version override for: " + dep.asProjectRef().toString() + ":" + dep.getVersion());
}
}
} catch (final GalleyMavenException e) {
throw new ManipulationException("Unable to resolve: %s", e, ref);
}
return versionOverrides;
}
use of org.commonjava.maven.galley.maven.model.view.DependencyView in project galley by Commonjava.
the class MavenModelProcessor method addDependencies.
private void addDependencies(final List<DependencyView> deps, final ProjectVersionRef projectRef, final Builder builder, final URI source, final boolean managed) {
if (deps != null) {
for (final DependencyView dep : deps) {
try {
final ProjectVersionRef ref = dep.asProjectVersionRef();
final String profileId = dep.getProfileId();
final URI location = RelationshipUtils.profileLocation(profileId);
final ArtifactRef artifactRef = new SimpleArtifactRef(ref, dep.getType(), dep.getClassifier());
// force the InvalidVersionSpecificationException.
artifactRef.getVersionSpec();
Set<ProjectRefView> exclusionsView = dep.getExclusions();
ProjectRef[] excludes;
if (exclusionsView != null && !exclusionsView.isEmpty()) {
excludes = new ProjectRef[exclusionsView.size()];
int i = 0;
for (ProjectRefView exclusionView : exclusionsView) {
excludes[i] = exclusionView.asProjectRef();
i++;
}
} else {
excludes = new ProjectRef[0];
}
builder.withDependencies(new SimpleDependencyRelationship(source, location, projectRef, artifactRef, dep.getScope(), builder.getNextDependencyIndex(managed), managed, dep.getOriginInfo().isInherited(), dep.isOptional(), excludes));
} catch (final InvalidRefException e) {
logger.error(String.format("%s: dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), dep.toXML()), e);
} catch (final InvalidVersionSpecificationException e) {
logger.error(String.format("%s: dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), dep.toXML()), e);
} catch (final GalleyMavenException e) {
logger.error(String.format("%s: dependency is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), dep.toXML()), e);
}
}
}
}
use of org.commonjava.maven.galley.maven.model.view.DependencyView in project galley by Commonjava.
the class MavenPomReader method assembleImportedInformation.
private void assembleImportedInformation(final MavenPomView view, final List<? extends Location> locations) throws GalleyMavenException {
final List<DependencyView> md = view.getAllBOMs();
for (final DependencyView dv : md) {
final ProjectVersionRef ref = dv.asProjectVersionRef();
logger.debug("Found BOM: {} for: {}", ref, view.getRef());
// This is a BOM, it's likely to be used in multiple locations...cache this.
final MavenPomView imp = read(ref, locations, true);
view.addMixin(new MavenXmlMixin<>(imp, MavenXmlMixin.DEPENDENCY_MIXIN));
}
}
Aggregations