Search in sources :

Example 1 with ProjectRef

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()]));
}
Also used : SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Document(org.w3c.dom.Document)

Example 2 with ProjectRef

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;
}
Also used : PluginDependencyView(org.commonjava.maven.galley.maven.model.view.PluginDependencyView) Set(java.util.Set) HashSet(java.util.HashSet) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) HashSet(java.util.HashSet)

Example 3 with ProjectRef

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;
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Dependency(org.apache.maven.model.Dependency) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) Model(org.apache.maven.model.Model) PluginView(org.commonjava.maven.galley.maven.model.view.PluginView) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView) Plugin(org.apache.maven.model.Plugin) HashSet(java.util.HashSet)

Example 4 with ProjectRef

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());
}
Also used : SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) MavenXmlView(org.commonjava.maven.galley.maven.model.view.MavenXmlView) ByteArrayInputStream(java.io.ByteArrayInputStream) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) Document(org.w3c.dom.Document) SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef)

Example 5 with ProjectRef

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"));
}
Also used : SimpleProjectRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Test(org.junit.Test)

Aggregations

ProjectRef (org.commonjava.maven.atlas.ident.ref.ProjectRef)22 SimpleProjectRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectRef)15 HashMap (java.util.HashMap)6 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)4 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)4 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)3 Set (java.util.Set)2 Model (org.apache.maven.model.Model)2 Profile (org.apache.maven.model.Profile)2 InvalidRefException (org.commonjava.maven.atlas.ident.ref.InvalidRefException)2 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)2 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)2 Project (org.commonjava.maven.ext.common.model.Project)2