use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project galley by Commonjava.
the class AbstractMavenViewTest method loadDocs.
protected MavenXmlView<ProjectRef> loadDocs(final Set<String> localOnlyPaths, final String... docNames) throws Exception {
final List<DocRef<ProjectRef>> stack = new ArrayList<DocRef<ProjectRef>>();
final ProjectRef pr = new SimpleProjectRef("not.used", "project-ref");
for (final String pomName : docNames) {
final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(getBaseResource() + pomName);
final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
final DocRef<ProjectRef> dr = new DocRef<ProjectRef>(pr, new SimpleLocation("http://localhost:8080/"), document);
stack.add(dr);
}
return new MavenXmlView<ProjectRef>(stack, xpath, xml, localOnlyPaths.toArray(new String[localOnlyPaths.size()]));
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project galley by Commonjava.
the class AbstractMavenPluginImplications method getImpliedPluginDependencies.
@Override
public Set<PluginDependencyView> getImpliedPluginDependencies(final PluginView pv) throws GalleyMavenException {
final Map<ProjectRef, Set<ProjectRef>> impliedDepMap = getImpliedRefMap();
final ProjectRef ref = pv.asProjectRef();
final Set<ProjectRef> implied = impliedDepMap.get(ref);
if (implied == null || implied.isEmpty()) {
return null;
}
final Set<PluginDependencyView> views = new HashSet<>(implied.size());
for (final ProjectRef impliedRef : implied) {
final PluginDependencyView pd = createPluginDependency(pv, impliedRef);
views.add(pd);
}
return views;
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project pom-manipulation-ext by release-engineering.
the class ModelIO method getRemotePluginVersionOverrides.
private Set<Plugin> getRemotePluginVersionOverrides(final PluginType type, final ProjectVersionRef ref, final Properties userProperties) throws ManipulationException {
logger.debug("Resolving remote {} POM: {}", type, ref);
final Set<Plugin> pluginOverrides = new HashSet<>();
final Map<ProjectRef, ProjectVersionRef> pluginOverridesPomView = new HashMap<>();
final Model m = resolveRawModel(ref);
try {
final MavenPomView pomView = galleyWrapper.readPomView(ref);
final List<PluginView> deps;
if (type == PluginType.PluginMgmt) {
deps = pomView.getAllManagedBuildPlugins();
} else {
deps = pomView.getAllBuildPlugins();
}
for (final PluginView p : deps) {
pluginOverridesPomView.put(p.asProjectRef(), p.asProjectVersionRef());
}
} catch (GalleyMavenException e) {
throw new ManipulationException("Unable to resolve: %s", e, ref);
}
logger.debug("Found pluginOverridesResolvedVersions {} ", pluginOverridesPomView);
// set of plugins with versions to handle those.
for (Map.Entry<ProjectRef, ProjectVersionRef> entry : pluginOverridesPomView.entrySet()) {
Plugin p = new Plugin();
p.setArtifactId(entry.getKey().getArtifactId());
p.setGroupId(entry.getKey().getGroupId());
p.setVersion(entry.getValue().getVersionString());
pluginOverrides.add(p);
}
// TODO: active profiles!
if (m.getBuild() != null && m.getBuild().getPluginManagement() != null) {
Iterator<Plugin> plit = null;
if (type == PluginType.PluginMgmt && m.getBuild().getPluginManagement() != null) {
logger.debug("Returning override of " + m.getBuild().getPluginManagement().getPlugins());
plit = m.getBuild().getPluginManagement().getPlugins().iterator();
} else if (type == PluginType.Plugins && m.getBuild().getPlugins() != null) {
logger.debug("Returning override of " + m.getBuild().getPlugins());
plit = m.getBuild().getPlugins().iterator();
}
while (plit != null && plit.hasNext()) {
Plugin p = plit.next();
ProjectRef pr = new SimpleProjectRef(p.getGroupId(), p.getArtifactId());
if ((isNotEmpty(p.getVersion()) && p.getVersion().startsWith("${")) || isEmpty(p.getVersion())) {
// Property reference to something in the remote pom. Resolve and inline it now.
String newVersion = resolveProperty(userProperties, m.getProperties(), p.getVersion());
// TODO: Complete replacement with PomView
if (newVersion.startsWith("${") || newVersion.length() == 0) {
// Use PomView as that contains a pre-resolved list of plugins.
newVersion = pluginOverridesPomView.get(pr).getVersionString();
}
logger.debug("Replacing plugin override version " + p.getVersion() + " with " + newVersion);
p.setVersion(newVersion);
}
// Replacing the element with the fully parsed element from the Model.
pluginOverrides.remove(p);
pluginOverrides.add(p);
// resolve any properties.
if (p.getConfiguration() != null) {
processChildren(userProperties, m, (Xpp3Dom) p.getConfiguration());
}
if (p.getExecutions() != null) {
List<PluginExecution> exes = p.getExecutions();
for (PluginExecution pe : exes) {
if (pe.getConfiguration() != null) {
processChildren(userProperties, m, (Xpp3Dom) pe.getConfiguration());
}
}
}
if (p.getDependencies() != null) {
for (Dependency d : p.getDependencies()) {
if (!isEmpty(d.getVersion()) && d.getVersion().startsWith("${")) {
logger.debug("Processing dependency {} and updating with {} ", d, resolveProperty(userProperties, m.getProperties(), d.getVersion()));
d.setVersion(resolveProperty(userProperties, m.getProperties(), d.getVersion()));
}
}
}
logger.debug("Added plugin override for {} with configuration \n" + p.getConfiguration() + " and executions " + p.getExecutions() + " and dependencies " + p.getDependencies(), p.getId());
}
} else {
throw new ManipulationException("Attempting to align to a BOM that does not have a " + type.toString() + " section");
}
return pluginOverrides;
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project pom-manipulation-ext by release-engineering.
the class GalleyAPIWrapper method parseXmlView.
public MavenXmlView<ProjectRef> parseXmlView(final String xml) throws GalleyMavenXMLException {
final Document document = infra.getXml().parseDocument(xml, new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
final DocRef<ProjectRef> ref = new DocRef<ProjectRef>(new SimpleProjectRef("unknown", "unknown"), xml, document);
return new MavenXmlView<>(Collections.singletonList(ref), infra.getXPath(), infra.getXml());
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project pom-manipulation-ext by release-engineering.
the class WildcardMapTest method testPutWildcard.
@Test
public void testPutWildcard() throws Exception {
ProjectRef key1 = SimpleProjectRef.parse("org.group:*");
ProjectRef key2 = SimpleProjectRef.parse("org.group:artifact");
ProjectRef key3 = SimpleProjectRef.parse("org.group:new-artifact");
map.put(key1, "1.1");
assertTrue("Should have retrieved wildcard value", map.containsKey(key2));
assertTrue("Should have retrieved wildcard value", map.containsKey(key1));
map.put(key3, "1.2");
assertTrue("Should have retrieved wildcard value", map.containsKey(key2));
assertTrue("Should have retrieved wildcard value", map.containsKey(key1));
assertThat(m_listAppender.list.toString(), containsString("Unable to add org.group:new-artifact with value 1.2 as wildcard mapping for org.group already exists"));
}
Aggregations