Search in sources :

Example 1 with IMavenExecutionContext

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

the class ThemePluginBuildParticipant method build.

@Override
public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception {
    IMavenProjectFacade facade = getMavenProjectFacade();
    if (!shouldBuild(kind, facade)) {
        return null;
    }
    ICallable<IStatus> callable = new ICallable<IStatus>() {

        public IStatus call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
            return executeThemeMojo(facade, context, monitor);
        }
    };
    IStatus retval = null;
    try {
        retval = executeMaven(facade, callable, monitor);
    } catch (Exception e) {
        retval = LiferayMavenCore.createErrorStatus(getGoal() + " build error", e);
    }
    if ((retval != null) && !retval.isOK()) {
        LiferayMavenCore.log(retval);
    }
    try {
        facade.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
    } catch (CoreException ce) {
    }
    monitor.worked(10);
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IMavenExecutionContext(org.eclipse.m2e.core.embedder.IMavenExecutionContext) ICallable(org.eclipse.m2e.core.embedder.ICallable) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with IMavenExecutionContext

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

the class MavenProjectBuilder method execGoals.

public IStatus execGoals(List<String> goals, IProgressMonitor monitor) throws CoreException {
    IStatus retval = null;
    IMavenProjectFacade facade = MavenUtil.getProjectFacade(getProject(), monitor);
    ICallable<IStatus> callable = new ICallable<IStatus>() {

        public IStatus call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
            IStatus execStatus = MavenUtil.executeGoals(facade, context, goals, monitor);
            MavenSession session = context.getSession();
            List<Throwable> exceptions = session.getResult().getExceptions();
            MultiStatusBuilder multiStatusBuilder = LiferayMavenCore.newMultiStatus();
            multiStatusBuilder.add(execStatus);
            multiStatusBuilder.addAll(exceptions);
            return multiStatusBuilder.retval();
        }
    };
    retval = executeMaven(facade, callable, monitor);
    return retval;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MultiStatusBuilder(com.liferay.ide.core.util.MultiStatusBuilder) IMavenExecutionContext(org.eclipse.m2e.core.embedder.IMavenExecutionContext) ICallable(org.eclipse.m2e.core.embedder.ICallable) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade)

Example 3 with IMavenExecutionContext

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

the class MavenProjectBuilder method buildLang.

public IStatus buildLang(IFile langFile, IProgressMonitor monitor) throws CoreException {
    IProgressMonitor sub = SubMonitor.convert(monitor, 100);
    sub.beginTask(Msgs.buildingLanguages, 100);
    IMavenProjectFacade facade = MavenUtil.getProjectFacade(getProject(), sub);
    sub.worked(10);
    ICallable<IStatus> callable = new ICallable<IStatus>() {

        public IStatus call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
            return MavenUtil.executeMojoGoal(facade, context, ILiferayMavenConstants.PLUGIN_GOAL_BUILD_LANG, monitor);
        }
    };
    IStatus retval = executeMaven(facade, callable, sub);
    sub.worked(80);
    getProject().refreshLocal(IResource.DEPTH_INFINITE, sub);
    sub.worked(10);
    sub.done();
    return retval;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IMavenExecutionContext(org.eclipse.m2e.core.embedder.IMavenExecutionContext) ICallable(org.eclipse.m2e.core.embedder.ICallable) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade)

Example 4 with IMavenExecutionContext

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

the class MavenProjectBuilder method execJarMojo.

public IStatus execJarMojo(IMavenProjectFacade projectFacade, IProgressMonitor monitor) throws CoreException {
    IStatus retval = null;
    ICallable<IStatus> callable = new ICallable<IStatus>() {

        public IStatus call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
            MavenProject mavenProject = projectFacade.getMavenProject();
            if (mavenProject == null) {
                mavenProject = projectFacade.getMavenProject(monitor);
            }
            IMaven maven = MavenPlugin.getMaven();
            MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, Arrays.asList("jar:jar"), true, monitor);
            List<MojoExecution> mojoExecutions = plan.getMojoExecutions();
            if (mojoExecutions != null) {
                for (MojoExecution mojoExecution : mojoExecutions) {
                    MavenPlugin.getMaven().execute(mavenProject, mojoExecution, monitor);
                }
            }
            return Status.OK_STATUS;
        }
    };
    retval = executeMaven(projectFacade, callable, monitor);
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) IMavenExecutionContext(org.eclipse.m2e.core.embedder.IMavenExecutionContext) ICallable(org.eclipse.m2e.core.embedder.ICallable) MavenExecutionPlan(org.apache.maven.lifecycle.MavenExecutionPlan) IMaven(org.eclipse.m2e.core.embedder.IMaven)

Example 5 with IMavenExecutionContext

use of org.eclipse.m2e.core.embedder.IMavenExecutionContext in project bndtools by bndtools.

the class BndConfigurator method execJarMojo.

private void execJarMojo(final IMavenProjectFacade projectFacade, IProgressMonitor monitor) throws CoreException {
    final IMaven maven = MavenPlugin.getMaven();
    ProjectRegistryManager projectRegistryManager = MavenPluginActivator.getDefault().getMavenProjectManagerImpl();
    ResolverConfiguration resolverConfiguration = new ResolverConfiguration();
    resolverConfiguration.setResolveWorkspaceProjects(true);
    IMavenExecutionContext context = projectRegistryManager.createExecutionContext(projectFacade.getPom(), resolverConfiguration);
    context.execute(new ICallable<Void>() {

        @Override
        public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
            SubMonitor progress = SubMonitor.convert(monitor);
            MavenProject mavenProject = getMavenProject(projectFacade, progress.newChild(1));
            MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, Arrays.asList("jar:jar"), true, monitor);
            List<MojoExecution> mojoExecutions = plan.getMojoExecutions();
            if (mojoExecutions != null) {
                for (MojoExecution mojoExecution : mojoExecutions) {
                    maven.execute(mavenProject, mojoExecution, progress.newChild(1));
                }
            }
            // We can now decorate based on the build we just did.
            try {
                IProjectDecorator decorator = Injector.ref.get();
                if (decorator != null) {
                    BndProjectInfo info = new MavenProjectInfo(mavenProject);
                    decorator.updateDecoration(projectFacade.getProject(), info);
                }
            } catch (Exception e) {
                logger.logError("Failed to decorate project " + projectFacade.getProject().getName(), e);
            }
            return null;
        }
    }, monitor);
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProjectDecorator(org.bndtools.build.api.IProjectDecorator) CoreException(org.eclipse.core.runtime.CoreException) BndProjectInfo(org.bndtools.build.api.IProjectDecorator.BndProjectInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) ProjectRegistryManager(org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager) IMavenExecutionContext(org.eclipse.m2e.core.embedder.IMavenExecutionContext) ArrayList(java.util.ArrayList) List(java.util.List) MavenExecutionPlan(org.apache.maven.lifecycle.MavenExecutionPlan) IMaven(org.eclipse.m2e.core.embedder.IMaven)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IMavenExecutionContext (org.eclipse.m2e.core.embedder.IMavenExecutionContext)6 IStatus (org.eclipse.core.runtime.IStatus)5 ICallable (org.eclipse.m2e.core.embedder.ICallable)5 IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)4 MojoExecution (org.apache.maven.plugin.MojoExecution)3 MavenProject (org.apache.maven.project.MavenProject)3 CoreException (org.eclipse.core.runtime.CoreException)3 IMaven (org.eclipse.m2e.core.embedder.IMaven)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MavenExecutionPlan (org.apache.maven.lifecycle.MavenExecutionPlan)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 Exceptions (aQute.lib.exceptions.Exceptions)1 MultiStatusBuilder (com.liferay.ide.core.util.MultiStatusBuilder)1 File (java.io.File)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1