Search in sources :

Example 1 with ResolverConfiguration

use of org.eclipse.m2e.core.project.ResolverConfiguration in project liferay-ide by liferay.

the class MavenUtil method executeGoals.

public static IStatus executeGoals(IMavenProjectFacade facade, IMavenExecutionContext context, List<String> goals, IProgressMonitor monitor) throws CoreException {
    IMaven maven = MavenPlugin.getMaven();
    MavenProject mavenProject = facade.getMavenProject(monitor);
    MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, goals, true, monitor);
    List<MojoExecution> mojos = plan.getMojoExecutions();
    ResolverConfiguration configuration = facade.getResolverConfiguration();
    configuration.setResolveWorkspaceProjects(true);
    for (MojoExecution mojo : mojos) {
        maven.execute(mavenProject, mojo, monitor);
    }
    return Status.OK_STATUS;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) MavenExecutionPlan(org.apache.maven.lifecycle.MavenExecutionPlan) IMaven(org.eclipse.m2e.core.embedder.IMaven)

Example 2 with ResolverConfiguration

use of org.eclipse.m2e.core.project.ResolverConfiguration 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 3 with ResolverConfiguration

use of org.eclipse.m2e.core.project.ResolverConfiguration in project liferay-ide by liferay.

the class MavenUIProjectBuilder method runMavenGoal.

public IStatus runMavenGoal(IMavenProjectFacade projectFacade, String goal, String mode, IProgressMonitor monitor) throws CoreException {
    IStatus retval = Status.OK_STATUS;
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType(MavenLaunchConstants.LAUNCH_CONFIGURATION_TYPE_ID);
    IPath basedirLocation = getProject().getLocation();
    String newName = launchManager.generateLaunchConfigurationName(basedirLocation.lastSegment());
    ILaunchConfigurationWorkingCopy workingCopy = launchConfigurationType.newInstance(null, newName);
    workingCopy.setAttribute(MavenLaunchConstants.ATTR_POM_DIR, basedirLocation.toString());
    workingCopy.setAttribute(MavenLaunchConstants.ATTR_GOALS, goal);
    workingCopy.setAttribute(MavenLaunchConstants.ATTR_UPDATE_SNAPSHOTS, Boolean.TRUE);
    workingCopy.setAttribute(MavenLaunchConstants.ATTR_WORKSPACE_RESOLUTION, Boolean.TRUE);
    workingCopy.setAttribute(MavenLaunchConstants.ATTR_SKIP_TESTS, Boolean.TRUE);
    if (projectFacade != null) {
        ResolverConfiguration configuration = projectFacade.getResolverConfiguration();
        String selectedProfiles = configuration.getSelectedProfiles();
        if ((selectedProfiles != null) && (selectedProfiles.length() > 0)) {
            workingCopy.setAttribute(MavenLaunchConstants.ATTR_PROFILES, selectedProfiles);
        }
        /*
			 * <?xml version="1.0" encoding="UTF-8" standalone="no"?> <launchConfiguration
			 * type="org.eclipse.m2e.Maven2LaunchConfigurationType"> <booleanAttribute
			 * key="M2_DEBUG_OUTPUT" value="false"/> <booleanAttribute
			 * key="M2_NON_RECURSIVE" value="false"/> <booleanAttribute key="M2_OFFLINE"
			 * value="false"/> <stringAttribute key="M2_PROFILES" value="v6.2.0"/>
			 * <listAttribute key="M2_PROPERTIES"/> <stringAttribute key="M2_RUNTIME"
			 * value="EMBEDDED"/> <intAttribute key="M2_THREADS" value="1"/>
			 * <stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY"
			 * value="D:/dev java/workspaces/runtime-eclipse-ide-juno-sr2/WorldDatabase/WorldDatabase-portlet"
			 * /> </launchConfiguration>
			 */
        UIJob launchJob = new UIJob("maven launch") {

            @Override
            public IStatus runInUIThread(IProgressMonitor monitor) {
                DebugUITools.launch(workingCopy, mode);
                return Status.OK_STATUS;
            }
        };
        boolean[] launchTerminated = new boolean[1];
        ILaunchListener[] listener = new ILaunchListener[1];
        listener[0] = new LaunchAdapter() {

            public void launchChanged(ILaunch launch) {
                if (launch.getLaunchConfiguration().equals(workingCopy)) {
                    Thread t = new Thread() {

                        @Override
                        public void run() {
                            while ((launch.getProcesses().length > 0) && !launch.getProcesses()[0].isTerminated()) {
                                try {
                                    sleep(100);
                                } catch (InterruptedException ie) {
                                }
                            }
                            launchTerminated[0] = true;
                            ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
                            launchManager.removeLaunchListener(listener[0]);
                        }
                    };
                    t.start();
                }
            }
        };
        launchManager = DebugPlugin.getDefault().getLaunchManager();
        launchManager.addLaunchListener(listener[0]);
        launchJob.schedule();
        while ((Display.getCurrent() == null) && !launchTerminated[0]) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
            }
        }
    }
    return retval;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunch(org.eclipse.debug.core.ILaunch) UIJob(org.eclipse.ui.progress.UIJob) LaunchAdapter(com.liferay.ide.core.adapter.LaunchAdapter) ILaunchListener(org.eclipse.debug.core.ILaunchListener)

Example 4 with ResolverConfiguration

use of org.eclipse.m2e.core.project.ResolverConfiguration in project liferay-ide by liferay.

the class MavenProjectRemoteServerPublisher method _execMavenLaunch.

private boolean _execMavenLaunch(IProject project, String goal, IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException {
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType(_launchConfigurationTypeId);
    IPath basedirLocation = project.getLocation();
    String newName = launchManager.generateLaunchConfigurationName(basedirLocation.lastSegment());
    ILaunchConfigurationWorkingCopy workingCopy = launchConfigurationType.newInstance(null, newName);
    workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "-Dmaven.multiModuleProjectDirectory");
    workingCopy.setAttribute(_attrPomDir, basedirLocation.toString());
    workingCopy.setAttribute(_attrGoals, goal);
    workingCopy.setAttribute(_attrUpdateSnapshots, Boolean.TRUE);
    workingCopy.setAttribute(_attrWorkspaceResolution, Boolean.TRUE);
    workingCopy.setAttribute(_attrSkipTests, Boolean.TRUE);
    if (facade != null) {
        ResolverConfiguration configuration = facade.getResolverConfiguration();
        String selectedProfiles = configuration.getSelectedProfiles();
        if ((selectedProfiles != null) && (selectedProfiles.length() > 0)) {
            workingCopy.setAttribute(_attrProfiles, selectedProfiles);
        }
        new LaunchHelper().launch(workingCopy, "run", monitor);
        return true;
    } else {
        return false;
    }
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IPath(org.eclipse.core.runtime.IPath) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) LaunchHelper(com.liferay.ide.core.util.LaunchHelper) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 5 with ResolverConfiguration

use of org.eclipse.m2e.core.project.ResolverConfiguration in project mdw-designer by CenturyLinkCloud.

the class ProjectConfigurator method addMavenNature.

@SuppressWarnings("deprecation")
public void addMavenNature(IProgressMonitor monitor) throws CoreException {
    ResolverConfiguration configuration = new ResolverConfiguration();
    configuration.setResolveWorkspaceProjects(false);
    configuration.setActiveProfiles("");
    IProjectConfigurationManager configurationManager = MavenPlugin.getProjectConfigurationManager();
    configurationManager.enableMavenNature(project.getSourceProject(), configuration, monitor);
    configurationManager.updateProjectConfiguration(project.getSourceProject(), monitor);
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IProjectConfigurationManager(org.eclipse.m2e.core.project.IProjectConfigurationManager)

Aggregations

ResolverConfiguration (org.eclipse.m2e.core.project.ResolverConfiguration)15 CoreException (org.eclipse.core.runtime.CoreException)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 MavenProject (org.apache.maven.project.MavenProject)5 IPath (org.eclipse.core.runtime.IPath)5 MavenExecutionPlan (org.apache.maven.lifecycle.MavenExecutionPlan)4 MojoExecution (org.apache.maven.plugin.MojoExecution)4 IStatus (org.eclipse.core.runtime.IStatus)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IMaven (org.eclipse.m2e.core.embedder.IMaven)3 IProjectConfigurationManager (org.eclipse.m2e.core.project.IProjectConfigurationManager)3 LaunchHelper (com.liferay.ide.core.util.LaunchHelper)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MavenSession (org.apache.maven.execution.MavenSession)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)2