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()]));
}
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;
}
Aggregations