Search in sources :

Example 11 with Xpp3Dom

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

the class ThemePluginBuildParticipant method executeThemeMojo.

protected IStatus executeThemeMojo(IMavenProjectFacade facade, IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
    IStatus retval = null;
    List<String> goals = Collections.singletonList(getGoal());
    MavenProject mavenProject = facade.getMavenProject(monitor);
    MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, goals, true, monitor);
    monitor.worked(10);
    MojoExecution liferayMojoExecution = MavenUtil.getExecution(plan, ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_ARTIFACT_ID);
    Xpp3Dom originalConfig = liferayMojoExecution.getConfiguration();
    Xpp3Dom config = Xpp3DomUtils.mergeXpp3Dom(new Xpp3Dom("configuration"), originalConfig);
    configureExecution(facade, config);
    boolean parentHierarchyLoaded = false;
    try {
        parentHierarchyLoaded = MavenUtil.loadParentHierarchy(facade, monitor);
        monitor.worked(10);
        ResolverConfiguration configuration = facade.getResolverConfiguration();
        configuration.setResolveWorkspaceProjects(true);
        liferayMojoExecution.setConfiguration(config);
        maven.execute(mavenProject, liferayMojoExecution, monitor);
        monitor.worked(50);
        MavenSession mavenSession = context.getSession();
        List<Throwable> exceptions = mavenSession.getResult().getExceptions();
        if (exceptions.size() == 1) {
            retval = LiferayMavenCore.createErrorStatus(exceptions.get(0));
        } else if (exceptions.size() > 1) {
            List<IStatus> statuses = new ArrayList<>();
            for (Throwable t : exceptions) {
                statuses.add(LiferayMavenCore.createErrorStatus(t));
            }
            retval = LiferayMavenCore.createMultiStatus(IStatus.ERROR, statuses.toArray(new IStatus[0]));
        }
        retval = retval == null ? Status.OK_STATUS : retval;
    } catch (CoreException ce) {
        retval = LiferayMavenCore.createErrorStatus(ce);
    } finally {
        liferayMojoExecution.setConfiguration(originalConfig);
        if (parentHierarchyLoaded) {
            mavenProject.setParent(null);
        }
    }
    return retval;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IStatus(org.eclipse.core.runtime.IStatus) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) MojoExecution(org.apache.maven.plugin.MojoExecution) ArrayList(java.util.ArrayList) List(java.util.List) MavenExecutionPlan(org.apache.maven.lifecycle.MavenExecutionPlan)

Example 12 with Xpp3Dom

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

the class LiferayMavenProjectConfigurator method _warSourceDirectory.

private IFolder _warSourceDirectory(IProject project, MavenProject mavenProject) {
    IFolder retval = null;
    Xpp3Dom warPluginConfiguration = (Xpp3Dom) mavenProject.getPlugin(_mavenWarPluginKey).getConfiguration();
    if (warPluginConfiguration != null) {
        Xpp3Dom[] warSourceDirs = warPluginConfiguration.getChildren("warSourceDirectory");
        if (ListUtil.isNotEmpty(warSourceDirs)) {
            String resourceLocation = warSourceDirs[0].getValue();
            retval = project.getFolder(resourceLocation);
        }
    }
    if (retval == null) {
        /*
			 * if no explicit warSourceDirectory set we assume the default warSource
			 * directory ${basedir}/src/main/webapp refer to
			 * http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html for more
			 * information
			 */
        retval = project.getFolder(_warSourceFolder);
    }
    return retval;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) IFolder(org.eclipse.core.resources.IFolder)

Example 13 with Xpp3Dom

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

the class MavenProjectBuilder method initBundle.

public IStatus initBundle(IProject project, String bundleUrl, IProgressMonitor monitor) throws CoreException {
    if (bundleUrl != null) {
        File pomFile = FileUtil.getFile(project.getFile("pom.xml"));
        MavenXpp3Reader mavenReader = new MavenXpp3Reader();
        MavenXpp3Writer mavenWriter = new MavenXpp3Writer();
        try (FileReader reader = new FileReader(pomFile)) {
            Model model = mavenReader.read(reader);
            if (model != null) {
                Build build = model.getBuild();
                Plugin plugin = build.getPluginsAsMap().get("com.liferay:com.liferay.portal.tools.bundle.support");
                if (plugin != null) {
                    try (FileWriter fileWriter = new FileWriter(pomFile)) {
                        Xpp3Dom origin = (Xpp3Dom) plugin.getConfiguration();
                        Xpp3Dom newConfiguration = new Xpp3Dom("configuration");
                        Xpp3Dom url = new Xpp3Dom("url");
                        url.setValue(bundleUrl);
                        newConfiguration.addChild(url);
                        plugin.setConfiguration(Xpp3Dom.mergeXpp3Dom(newConfiguration, origin));
                        mavenWriter.write(fileWriter, model);
                    }
                }
            }
        } catch (Exception e) {
            LiferayMavenCore.logError("Could not write file in" + pomFile, e);
        }
    }
    IMavenProjectFacade facade = MavenUtil.getProjectFacade(project, monitor);
    if (_execMavenLaunch(project, MavenGoalUtil.getMavenInitBundleGoal(project), facade, monitor)) {
        return Status.OK_STATUS;
    }
    return LiferayMavenCore.createErrorStatus("run init-bundle error");
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Build(org.apache.maven.model.Build) FileWriter(java.io.FileWriter) Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer) DebugPlugin(org.eclipse.debug.core.DebugPlugin) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Plugin(org.apache.maven.model.Plugin) MavenPlugin(org.eclipse.m2e.core.MavenPlugin)

Example 14 with Xpp3Dom

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

the class MavenProjectBuilder method getPortletProject.

public IProject getPortletProject(IMavenProjectFacade projectFacade, IProgressMonitor monitor) {
    IProject retVal = null;
    try {
        Xpp3Dom config = MavenUtil.getLiferayMavenPluginConfig(projectFacade.getMavenProject());
        if (config != null) {
            Xpp3Dom webAppDir = config.getChild(ILiferayMavenConstants.PLUGIN_CONFIG_WEBAPPBASE_DIR);
            Xpp3Dom pluginName = config.getChild(ILiferayMavenConstants.PLUGIN_CONFIG_PLUGIN_NAME);
            if (webAppDir != null) {
                String webAppDirValue = webAppDir.getValue();
                String projectPath = Path.fromOSString(webAppDirValue).lastSegment();
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                retVal = workspace.getRoot().getProject(projectPath);
            } else if (pluginName != null) {
                String pluginNameValue = pluginName.getValue();
                retVal = CoreUtil.getProject(pluginNameValue);
            }
        }
    } catch (Exception e) {
        LiferayMavenCore.logError("Could not refresh sibling service project.", e);
    }
    return retVal;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException)

Example 15 with Xpp3Dom

use of org.codehaus.plexus.util.xml.Xpp3Dom in project fabric8-maven-plugin by fabric8io.

the class DockerServerUtilTest method createSettings.

private Settings createSettings() {
    Settings settings = new Settings();
    Server server = new Server();
    server.setId("docker.io");
    server.setUsername("username");
    server.setPassword("password");
    settings.addServer(server);
    Server server1 = new Server();
    server1.setId("docker1.io");
    server1.setUsername("username1");
    server1.setPassword("password1");
    Xpp3Dom mail = new Xpp3Dom("email");
    mail.setValue("bar@bar.com");
    Xpp3Dom configuration = new Xpp3Dom("configuration");
    configuration.addChild(mail);
    server1.setConfiguration(configuration);
    settings.addServer(server1);
    Server server2 = new Server();
    server2.setId("docker2.io");
    server2.setUsername("username2");
    server2.setPassword("password2");
    Xpp3Dom configuration1 = new Xpp3Dom("configuration");
    server2.setConfiguration(configuration1);
    settings.addServer(server2);
    return settings;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Server(org.apache.maven.settings.Server) Settings(org.apache.maven.settings.Settings)

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