Search in sources :

Example 1 with BndProjectInfo

use of org.bndtools.build.api.IProjectDecorator.BndProjectInfo 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

ArrayList (java.util.ArrayList)1 List (java.util.List)1 MavenExecutionPlan (org.apache.maven.lifecycle.MavenExecutionPlan)1 MojoExecution (org.apache.maven.plugin.MojoExecution)1 MavenProject (org.apache.maven.project.MavenProject)1 IProjectDecorator (org.bndtools.build.api.IProjectDecorator)1 BndProjectInfo (org.bndtools.build.api.IProjectDecorator.BndProjectInfo)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IMaven (org.eclipse.m2e.core.embedder.IMaven)1 IMavenExecutionContext (org.eclipse.m2e.core.embedder.IMavenExecutionContext)1 ProjectRegistryManager (org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager)1 ResolverConfiguration (org.eclipse.m2e.core.project.ResolverConfiguration)1