Search in sources :

Example 91 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project pom-manipulation-ext by release-engineering.

the class ModelIO method processChildren.

/**
 * Recursively process the DOM elements to inline any property values from the model.
 * @param userProperties
 * @param model
 * @param parent
 */
private void processChildren(Properties userProperties, Model model, Xpp3Dom parent) {
    for (int i = 0; i < parent.getChildCount(); i++) {
        Xpp3Dom child = parent.getChild(i);
        if (child.getChildCount() > 0) {
            processChildren(userProperties, model, child);
        }
        if (child.getValue() != null && child.getValue().startsWith("${")) {
            String replacement = resolveProperty(userProperties, model.getProperties(), child.getValue());
            if (replacement != null && !replacement.isEmpty()) {
                logger.debug("Replacing child value " + child.getValue() + " with " + replacement);
                child.setValue(replacement);
            }
        }
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom)

Example 92 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project pom-manipulation-ext by release-engineering.

the class BOMBuilderManipulator method applyChanges.

/**
 * If enabled, grab the execution root pom (which will be the topmost POM in terms of directory structure). Within that
 * handle the manipulation of the bom injection.
 */
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
    final BOMInjectingState state = session.getState(BOMInjectingState.class);
    if (!session.isEnabled() || !state.isEnabled()) {
        logger.debug(getClass().getSimpleName() + ": Nothing to do!");
        return Collections.emptySet();
    }
    List<Dependency> projectArtifacts = getArtifacts(projects);
    for (final Project project : projects) {
        if (project.isExecutionRoot()) {
            logger.info("Examining {} to add BOM generation.", project);
            final Model model = project.getModel();
            Build build = model.getBuild();
            if (build == null) {
                build = new Build();
                model.setBuild(build);
            }
            Model bomModel = createModel(project, IDBOM);
            bomModel.setDescription("PME Generated BOM for other projects to use to align to.");
            DependencyManagement dm = new DependencyManagement();
            dm.setDependencies(projectArtifacts);
            bomModel.setDependencyManagement(dm);
            // Write new bom back out.
            File pmebom = new File(session.getTargetDir(), IDBOM + ".xml");
            session.getTargetDir().mkdir();
            pomIO.writeModel(bomModel, pmebom);
            final Map<String, Plugin> pluginMap = build.getPluginsAsMap();
            if (!pluginMap.containsKey(POM_DEPLOYER_COORD)) {
                final PluginExecution execution = new PluginExecution();
                execution.setId(IDBOM);
                execution.setPhase("install");
                execution.setGoals(Collections.singletonList("add-pom"));
                final Plugin plugin = new Plugin();
                plugin.setGroupId(POM_DEPLOYER_GID);
                plugin.setArtifactId(POM_DEPLOYER_AID);
                plugin.setVersion(POM_DEPLOYER_VID);
                plugin.addExecution(execution);
                plugin.setInherited(false);
                build.addPlugin(plugin);
                final Xpp3Dom xml = new Xpp3Dom("configuration");
                final Map<String, Object> config = new HashMap<>();
                config.put("pomName", "target" + File.separatorChar + pmebom.getName());
                config.put("errorOnMissing", false);
                config.put("artifactId", bomModel.getArtifactId());
                config.put("groupId", bomModel.getGroupId());
                for (final Map.Entry<String, Object> entry : config.entrySet()) {
                    final Xpp3Dom child = new Xpp3Dom(entry.getKey());
                    if (entry.getValue() != null) {
                        child.setValue(entry.getValue().toString());
                    }
                    xml.addChild(child);
                }
                execution.setConfiguration(xml);
            }
            return Collections.singleton(project);
        }
    }
    return Collections.emptySet();
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) HashMap(java.util.HashMap) Dependency(org.apache.maven.model.Dependency) Project(org.commonjava.maven.ext.common.model.Project) Build(org.apache.maven.model.Build) Model(org.apache.maven.model.Model) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) BOMInjectingState(org.commonjava.maven.ext.core.state.BOMInjectingState) DependencyManagement(org.apache.maven.model.DependencyManagement) Plugin(org.apache.maven.model.Plugin)

Example 93 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project meghanada-server by mopemope.

the class POMParser method parsePlugins.

private void parsePlugins(POMInfo pomInfo, Build build) {
    for (Plugin plugin : build.getPlugins()) {
        if (plugin.getArtifactId().equals("build-helper-maven-plugin")) {
            for (PluginExecution pluginExecution : plugin.getExecutions()) {
                Object conf = pluginExecution.getConfiguration();
                if (nonNull(conf) && conf instanceof Xpp3Dom) {
                    Xpp3Dom confDom = (Xpp3Dom) conf;
                    Xpp3Dom sources = confDom.getChild("sources");
                    if (nonNull(sources)) {
                        Xpp3Dom[] children = sources.getChildren();
                        if (nonNull(children)) {
                            for (Xpp3Dom s : sources.getChildren()) {
                                String value = s.getValue();
                                if (!Strings.isNullOrEmpty(value)) {
                                    pomInfo.sourceDirectory.add(normalize(pomInfo, value));
                                }
                            }
                        }
                    }
                }
            }
        }
        if (plugin.getArtifactId().equals("maven-compiler-plugin")) {
            Object conf = plugin.getConfiguration();
            if (nonNull(conf) && conf instanceof Xpp3Dom) {
                Xpp3Dom confDom = (Xpp3Dom) conf;
                Xpp3Dom source = confDom.getChild("source");
                if (nonNull(source)) {
                    pomInfo.compileSource = source.getValue();
                }
                Xpp3Dom target = confDom.getChild("target");
                if (nonNull(target)) {
                    pomInfo.compileTarget = target.getValue();
                }
            }
        }
    }
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Plugin(org.apache.maven.model.Plugin)

Example 94 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project fabric8 by jboss-fuse.

the class AetherBasedResolver method addServerConfig.

private void addServerConfig(DefaultRepositorySystemSession session, Server server) {
    Map<String, String> headers = new HashMap<String, String>();
    Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration();
    Xpp3Dom httpHeaders = configuration.getChild("httpHeaders");
    for (Xpp3Dom httpHeader : httpHeaders.getChildren("httpHeader")) {
        Xpp3Dom name = httpHeader.getChild("name");
        String headerName = name.getValue();
        Xpp3Dom value = httpHeader.getChild("value");
        String headerValue = value.getValue();
        headers.put(headerName, headerValue);
    }
    session.setConfigProperty(String.format("%s.%s", ConfigurationProperties.HTTP_HEADERS, server.getId()), headers);
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 95 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project liferay-ide by liferay.

the class LiferayMavenProjectConfigurator method _findLiferayMavenPluginProblems.

private List<MavenProblemInfo> _findLiferayMavenPluginProblems(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
    List<MavenProblemInfo> warnings = new ArrayList<>();
    // first check to make sure that the AppServer* properties are available and
    // pointed to valid location
    Plugin liferayMavenPlugin = MavenUtil.getPlugin(request.getMavenProjectFacade(), ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_KEY, monitor);
    if (liferayMavenPlugin != null) {
        Xpp3Dom config = (Xpp3Dom) liferayMavenPlugin.getConfiguration();
        MavenProblemInfo validLiferayProblemInfo = _checkValidVersion(liferayMavenPlugin, config, ILiferayMavenConstants.PLUGIN_CONFIG_LIFERAY_VERSION);
        if (validLiferayProblemInfo != null) {
            warnings.add(validLiferayProblemInfo);
        }
        Version mavenPluginVersion = new Version(MavenUtil.getVersion(liferayMavenPlugin.getVersion()));
        if ((mavenPluginVersion == null) || mavenPluginVersion.equals(ILiferayConstants.EMPTY_VERSION)) {
            // could not get valid version for liferaymavenPlugin
            SourceLocation location = SourceLocationHelper.findLocation(liferayMavenPlugin, "version");
            String problemMsg = NLS.bind(Msgs.invalidVersion, "liferay-maven-plugin", liferayMavenPlugin.getVersion());
            MavenProblemInfo versionProblem = new MavenProblemInfo(problemMsg, IMarker.SEVERITY_WARNING, location);
            warnings.add(versionProblem);
        }
        String[] configDirParams = { ILiferayMavenConstants.PLUGIN_CONFIG_APP_SERVER_PORTAL_DIR };
        for (String configParam : configDirParams) {
            MavenProblemInfo configProblemInfo = _checkValidConfigDir(liferayMavenPlugin, config, configParam);
            if (configProblemInfo != null) {
                warnings.add(configProblemInfo);
            }
        }
    }
    return warnings;
}
Also used : SourceLocation(org.eclipse.m2e.core.internal.markers.SourceLocation) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Version(org.osgi.framework.Version) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) ArrayList(java.util.ArrayList) MavenProblemInfo(org.eclipse.m2e.core.internal.markers.MavenProblemInfo) Plugin(org.apache.maven.model.Plugin)

Aggregations

Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)156 Plugin (org.apache.maven.model.Plugin)39 File (java.io.File)26 ArrayList (java.util.ArrayList)18 PluginExecution (org.apache.maven.model.PluginExecution)18 IOException (java.io.IOException)13 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 MavenSession (org.apache.maven.execution.MavenSession)10 MavenProject (org.apache.maven.project.MavenProject)10 Model (org.apache.maven.model.Model)9 Reader (java.io.Reader)8 Build (org.apache.maven.model.Build)8 TargetPlatformConfiguration (org.eclipse.tycho.core.TargetPlatformConfiguration)8 BuildFailureException (org.eclipse.tycho.core.shared.BuildFailureException)8 MojoExecution (org.apache.maven.plugin.MojoExecution)7 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)7 Map (java.util.Map)6 Dependency (org.apache.maven.model.Dependency)6 StringReader (java.io.StringReader)5