Search in sources :

Example 1 with LifecycleMappingOperation

use of org.eclipse.m2e.core.ui.internal.editing.LifecycleMappingOperation in project m2e-core by eclipse-m2e.

the class LifecycleMappingResolution method createOperation.

private Operation createOperation(List<IMarker> markers) {
    List<LifecycleMappingOperation> lst = new ArrayList<>();
    for (IMarker m : markers) {
        // $NON-NLS-1$
        String pluginGroupId = m.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, "");
        // $NON-NLS-1$
        String pluginArtifactId = m.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, "");
        // $NON-NLS-1$
        String pluginVersion = m.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, "");
        // $NON-NLS-1$
        String[] goals = new String[] { m.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "") };
        lst.add(new LifecycleMappingOperation(pluginGroupId, pluginArtifactId, pluginVersion, action, goals));
    }
    return new CompoundOperation(lst.toArray(new Operation[lst.size()]));
}
Also used : LifecycleMappingOperation(org.eclipse.m2e.core.ui.internal.editing.LifecycleMappingOperation) CompoundOperation(org.eclipse.m2e.core.ui.internal.editing.PomEdits.CompoundOperation) ArrayList(java.util.ArrayList) IMarker(org.eclipse.core.resources.IMarker) LifecycleMappingOperation(org.eclipse.m2e.core.ui.internal.editing.LifecycleMappingOperation) CompoundOperation(org.eclipse.m2e.core.ui.internal.editing.PomEdits.CompoundOperation) Operation(org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation)

Example 2 with LifecycleMappingOperation

use of org.eclipse.m2e.core.ui.internal.editing.LifecycleMappingOperation in project m2e-core by eclipse-m2e.

the class MavenDiscoveryProposalWizard method performFinish.

@Override
public boolean performFinish() {
    if (lifecycleMappingPage != null && !lifecycleMappingPage.isMappingComplete() && !warnIncompleteMapping()) {
        return false;
    }
    final List<IMavenDiscoveryProposal> proposals = getMavenDiscoveryProposals();
    boolean doIgnore = !lifecycleMappingPage.getIgnore().isEmpty() || !lifecycleMappingPage.getIgnoreParent().isEmpty() || !lifecycleMappingPage.getIgnoreWorkspace().isEmpty();
    IMavenDiscoveryUI discovery = getPageFactory();
    if (discovery != null && !proposals.isEmpty()) {
        Set<String> projectsToConfigure = new HashSet<>();
        for (IProject project : projects) {
            projectsToConfigure.add(project.getName());
        }
        doIgnore = discovery.implement(proposals, null, getContainer(), projectsToConfigure);
    }
    if (doIgnore) {
        final IRunnableWithProgress ignoreJob = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) {
                List<IProject> changed = new LinkedList<>();
                for (ILifecycleMappingLabelProvider prov : lifecycleMappingPage.getIgnore()) {
                    ILifecycleMappingRequirement req = prov.getKey();
                    if (req instanceof MojoExecutionMappingRequirement) {
                        changed.addAll(getProject(prov.getProjects()));
                        ignore(((MojoExecutionMappingRequirement) req).getExecution(), prov.getProjects());
                    }
                }
                for (ILifecycleMappingLabelProvider prov : lifecycleMappingPage.getIgnoreParent()) {
                    ILifecycleMappingRequirement req = prov.getKey();
                    if (req instanceof MojoExecutionMappingRequirement) {
                        changed.addAll(getProject(prov.getProjects()));
                        ignoreAtDefinition(((MojoExecutionMappingRequirement) req).getExecution(), prov.getProjects());
                    }
                }
                for (ILifecycleMappingLabelProvider prov : lifecycleMappingPage.getIgnoreWorkspace()) {
                    ILifecycleMappingRequirement req = prov.getKey();
                    if (req instanceof MojoExecutionMappingRequirement) {
                        changed.addAll(getProject(prov.getProjects()));
                        ignoreWorkspace(((MojoExecutionMappingRequirement) req).getExecution());
                    }
                }
                new UpdateMavenProjectJob(changed.toArray(new IProject[changed.size()])).schedule();
            }

            private Collection<IProject> getProject(Collection<MavenProject> projects) {
                List<IProject> workspaceProjects = new LinkedList<>();
                for (MavenProject project : projects) {
                    IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getMavenProject(project.getGroupId(), project.getArtifactId(), project.getVersion());
                    if (facade != null) {
                        workspaceProjects.add(facade.getProject());
                    }
                }
                return workspaceProjects;
            }

            private void ignore(MojoExecutionKey key, Collection<MavenProject> projects) {
                String pluginGroupId = key.getGroupId();
                String pluginArtifactId = key.getArtifactId();
                String pluginVersion = key.getVersion();
                String[] goals = new String[] { key.getGoal() };
                for (MavenProject project : projects) {
                    IFile pomFile = M2EUtils.getPomFile(project);
                    try {
                        PomEdits.performOnDOMDocument(new OperationTuple(pomFile, new LifecycleMappingOperation(pluginGroupId, pluginArtifactId, pluginVersion, PluginExecutionAction.ignore, goals)));
                    } catch (IOException ex) {
                        LOG.error(ex.getMessage(), ex);
                    } catch (CoreException ex) {
                        LOG.error(ex.getMessage(), ex);
                    }
                }
            }

            private void ignoreAtDefinition(MojoExecutionKey key, Collection<MavenProject> projects) {
                ignore(key, M2EUtils.getDefiningProjects(key, projects));
            }

            private void ignoreWorkspace(MojoExecutionKey key) {
                LifecycleMappingMetadataSource mapping = LifecycleMappingFactory.getWorkspaceMetadata(true);
                LifecycleMappingFactory.addLifecyclePluginExecution(mapping, key.getGroupId(), key.getArtifactId(), key.getVersion(), new String[] { key.getGoal() }, PluginExecutionAction.ignore);
                LifecycleMappingFactory.writeWorkspaceMetadata(mapping);
            }
        };
        Job job = new WorkspaceJob("Apply Lifecycle Mapping Changes") {

            @Override
            public IStatus runInWorkspace(IProgressMonitor monitor) {
                try {
                    ignoreJob.run(monitor);
                } catch (InvocationTargetException e) {
                    return AbstractCreateMavenProjectsOperation.toStatus(e);
                } catch (InterruptedException e) {
                    return Status.CANCEL_STATUS;
                }
                return Status.OK_STATUS;
            }
        };
        job.setRule(MavenPlugin.getProjectConfigurationManager().getRule());
        job.schedule();
    }
    return true;
}
Also used : LifecycleMappingMetadataSource(org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadataSource) IFile(org.eclipse.core.resources.IFile) OperationTuple(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple) ILifecycleMappingRequirement(org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) LifecycleMappingOperation(org.eclipse.m2e.core.ui.internal.editing.LifecycleMappingOperation) MavenProject(org.apache.maven.project.MavenProject) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) Job(org.eclipse.core.runtime.jobs.Job) UpdateMavenProjectJob(org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) HashSet(java.util.HashSet) IMavenDiscoveryProposal(org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscoveryProposal) MojoExecutionKey(org.eclipse.m2e.core.project.configurator.MojoExecutionKey) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) LinkedList(java.util.LinkedList) InvocationTargetException(java.lang.reflect.InvocationTargetException) ILifecycleMappingLabelProvider(org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) UpdateMavenProjectJob(org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob) Collection(java.util.Collection) MojoExecutionMappingRequirement(org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration.MojoExecutionMappingRequirement)

Aggregations

LifecycleMappingOperation (org.eclipse.m2e.core.ui.internal.editing.LifecycleMappingOperation)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 MavenProject (org.apache.maven.project.MavenProject)1 IFile (org.eclipse.core.resources.IFile)1 IMarker (org.eclipse.core.resources.IMarker)1 IProject (org.eclipse.core.resources.IProject)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 ILifecycleMappingRequirement (org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement)1 IMavenDiscoveryProposal (org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscoveryProposal)1 MojoExecutionMappingRequirement (org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration.MojoExecutionMappingRequirement)1 LifecycleMappingMetadataSource (org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadataSource)1