Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Eisenberg2012-07-19 13:42:25 -0400
committerIgor Fedorenko2012-08-13 07:22:43 -0400
commit2e7413e5f2b6b0bb98df5fb0699c148320deeeea (patch)
tree153b6c03a3628710ccfec79541b4066346bc9a67 /org.eclipse.m2e.editor.xml
parentee868734f9715035106123b37d86af0e3d847115 (diff)
downloadm2e-core-2e7413e5f2b6b0bb98df5fb0699c148320deeeea.tar.gz
m2e-core-2e7413e5f2b6b0bb98df5fb0699c148320deeeea.tar.xz
m2e-core-2e7413e5f2b6b0bb98df5fb0699c148320deeeea.zip
This commit contains most of the work for bug 350414.
This includes adding workspace settings to the chain of lookups for determining lifecycle mappings for m2e projects. There are changes to existing quickfixes, and a new workspace preferences page that allows users to view their workspace mappings and edit the raw text file. There is partial work done for displaying a table of workspace lifecycle mappings in the preferences page. The refactoring of the project lifecycle mappings table is complete, but I just don't know how to populate the viewer with workspace mappings only For compliance with Eclipse.org's contribution rules: (1) I (Andrew Eisenberg) wrote 100% of the code; (2) I have the right to contribute the code to Eclipse; (3) the file header contains the appropriate License header. Also, this patch is built on top of the SHA 170c7936da947d28e7824bc1d2375903dbda9b17
Diffstat (limited to 'org.eclipse.m2e.editor.xml')
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MavenMarkerResolutionGenerator.java2
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java2
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/Messages.java12
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java45
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java74
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java275
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/messages.properties8
7 files changed, 115 insertions, 303 deletions
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MavenMarkerResolutionGenerator.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MavenMarkerResolutionGenerator.java
index 8438b1b2..07b630e0 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MavenMarkerResolutionGenerator.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MavenMarkerResolutionGenerator.java
@@ -19,7 +19,6 @@ import org.eclipse.ui.IMarkerResolutionGenerator2;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction;
import org.eclipse.m2e.editor.xml.internal.lifecycle.LifecycleMappingProposal;
-import org.eclipse.m2e.editor.xml.internal.lifecycle.WorkspaceLifecycleMappingProposal;
/**
@@ -56,7 +55,6 @@ public class MavenMarkerResolutionGenerator implements IMarkerResolutionGenerato
if(hint.equals(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION)) {
return new IMarkerResolution[] {
new LifecycleMappingProposal(marker, PluginExecutionAction.ignore),
- new WorkspaceLifecycleMappingProposal(marker, PluginExecutionAction.ignore)
// new LifecycleMappingProposal(marker, PluginExecutionAction.execute)
};
}
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java
index 964ef47f..4ea8e323 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java
@@ -62,7 +62,6 @@ import org.eclipse.m2e.editor.xml.internal.Messages;
import org.eclipse.m2e.editor.xml.internal.NodeOperation;
import org.eclipse.m2e.editor.xml.internal.XmlUtils;
import org.eclipse.m2e.editor.xml.internal.lifecycle.LifecycleMappingProposal;
-import org.eclipse.m2e.editor.xml.internal.lifecycle.WorkspaceLifecycleMappingProposal;
public class PomQuickAssistProcessor implements IQuickAssistProcessor {
private static final Logger log = LoggerFactory.getLogger(PomQuickAssistProcessor.class);
@@ -121,7 +120,6 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor {
} else if (hint.equals(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION)) {
extractedFromMarkers(proposals, mark); //having this first sort of helps for 335490
proposals.add(new LifecycleMappingProposal(context, mark, PluginExecutionAction.ignore));
- proposals.add(new WorkspaceLifecycleMappingProposal(context, mark, PluginExecutionAction.ignore));
// proposals.add(new LifecycleMappingProposal(context, mark, PluginExecutionAction.execute));
} else if(mark.getMarker().getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_ERROR
&& hint.equals(IMavenConstants.EDITOR_HINT_IMPLICIT_LIFECYCLEMAPPING)) {
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/Messages.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/Messages.java
index f0aa3c69..3924eb8c 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/Messages.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/Messages.java
@@ -41,6 +41,18 @@ public class Messages extends NLS {
public static String InsertSPDXLicenseProposal_0;
+ public static String LifecycleMappingDialog_Ignore;
+
+ public static String LifecycleMappingDialog_LocationToIgnore;
+
+ public static String LifecycleMappingDialog_NonWorkspacePom;
+
+ public static String LifecycleMappingDialog_PluginDefinitionInSelectedPom;
+
+ public static String LifecycleMappingDialog_UseWorkspaceSettings;
+
+ public static String LifecycleMappingDialog_UseWorkspaceSettingsDesc;
+
public static String LifecycleMappingProposal_all_desc;
public static String LifecycleMappingProposal_execute_desc;
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java
index 59a55028..406e83fe 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
+ * Andrew Eisenberg - Work on Bug 350414
*******************************************************************************/
package org.eclipse.m2e.editor.xml.internal.lifecycle;
@@ -29,7 +30,10 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
@@ -41,6 +45,7 @@ import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.internal.M2EUtils;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.internal.components.PomHierarchyComposite;
+import org.eclipse.m2e.editor.xml.internal.Messages;
@SuppressWarnings("restriction")
@@ -58,33 +63,36 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
private String pluginArtifactId;
- private String pluginVersion;
+ // TODO Unused...consider deleting
+// private String pluginVersion;
private String goal;
private MavenProject pluginProject;
+ private boolean workspaceSettings = false;
+
public LifecycleMappingDialog(Shell parentShell, IFile pom, String pluginGroupId, String pluginArtifactId,
String pluginVersion, String goal) {
super(parentShell);
facade = MavenPlugin.getMavenProjectRegistry().create(pom, true, new NullProgressMonitor());
this.pluginGroupId = pluginGroupId;
this.pluginArtifactId = pluginArtifactId;
- this.pluginVersion = pluginVersion;
+// this.pluginVersion = pluginVersion;
this.goal = goal;
}
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
- shell.setText(NLS.bind("Ignore {0}", goal));
+ shell.setText(NLS.bind(Messages.LifecycleMappingDialog_Ignore, goal));
}
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
Label label = new Label(container, SWT.NONE);
- label.setText("Select location to place ignore");
+ label.setText(Messages.LifecycleMappingDialog_LocationToIgnore);
pomComposite = new PomHierarchyComposite(container, SWT.BORDER);
pomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
pomComposite.addSelectionChangedListener(this);
@@ -98,9 +106,28 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
status = new CLabel(container, SWT.WRAP);
status.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
+ // separator
+ new Label(container, SWT.NONE);
+
+ final Button workspaceSettingsButton = new Button(container, SWT.CHECK);
+ workspaceSettingsButton.setText(Messages.LifecycleMappingDialog_UseWorkspaceSettings);
+ workspaceSettingsButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ pomComposite.setEnabled(!workspaceSettingsButton.getSelection());
+ workspaceSettings = workspaceSettingsButton.getSelection();
+ }
+ });
+ new Label(container, SWT.NONE).
+ setText(Messages.LifecycleMappingDialog_UseWorkspaceSettingsDesc);
+
pluginProject = locatePlugin();
return container;
}
+
+ public boolean useWorkspaceSettings() {
+ return workspaceSettings;
+ }
@Override
protected void createButtonsForButtonBar(Composite parent) {
@@ -124,13 +151,13 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
private void updateStatus(MavenProject project) {
if(project.getFile() == null) {
- status.setText("Non-workspace pom");
+ status.setText(Messages.LifecycleMappingDialog_NonWorkspacePom);
status.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
} else if(project.equals(pluginProject)) {
- status.setText("Plugin definition in selected pom.");
+ status.setText(Messages.LifecycleMappingDialog_PluginDefinitionInSelectedPom);
status.setImage(null);
} else {
- status.setText("");
+ status.setText(""); //$NON-NLS-1$
status.setImage(null);
}
}
@@ -151,13 +178,13 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
private MavenProject locatePlugin() {
MavenProject project = facade.getMavenProject(); // if we got here, facade.getMavenProject cannot be null
- Plugin plugin = project.getPlugin(pluginGroupId + ":" + pluginArtifactId);
+ Plugin plugin = project.getPlugin(pluginGroupId + ":" + pluginArtifactId); //$NON-NLS-1$
if(plugin == null) {
return null; // can't really happy
}
- InputLocation location = plugin.getLocation("");
+ InputLocation location = plugin.getLocation(""); //$NON-NLS-1$
if(location == null || location.getSource() == null || location.getSource().getLocation() == null) {
// that's odd. where does this come from???
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java
index 6c14f625..6947e1ea 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
+ * Andrew Eisenberg - Work on Bug 350414
*******************************************************************************/
@@ -14,7 +15,9 @@ package org.eclipse.m2e.editor.xml.internal.lifecycle;
import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
@@ -23,6 +26,7 @@ import org.slf4j.LoggerFactory;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -36,17 +40,21 @@ import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.MarkerAnnotation;
import org.eclipse.ui.views.markers.WorkbenchMarkerResolution;
+import org.eclipse.wst.sse.core.internal.encoding.EncodingRule;
+import org.eclipse.wst.xml.core.internal.modelhandler.XMLModelLoader;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.m2e.core.internal.IMavenConstants;
+import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction;
+import org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob;
import org.eclipse.m2e.core.ui.internal.editing.LifecycleMappingOperation;
import org.eclipse.m2e.core.ui.internal.editing.PomEdits.CompoundOperation;
-import org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple;
import org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation;
+import org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple;
import org.eclipse.m2e.editor.xml.internal.Messages;
public class LifecycleMappingProposal extends WorkbenchMarkerResolution implements ICompletionProposal, ICompletionProposalExtension5 {
@@ -74,7 +82,7 @@ public class LifecycleMappingProposal extends WorkbenchMarkerResolution implemen
if(PluginExecutionAction.ignore.equals(action)) {
performIgnore(new IMarker[] {marker});
} else {
- performOnDOMDocument(new OperationTuple(doc, createOperation(marker)));
+ performOnDOMDocument(new OperationTuple(doc, createOperation(marker, false)));
}
} catch(IOException e) {
log.error("Error generating code in pom.xml", e); //$NON-NLS-1$
@@ -85,34 +93,72 @@ public class LifecycleMappingProposal extends WorkbenchMarkerResolution implemen
private void performIgnore(IMarker[] marks) throws IOException, CoreException {
final IFile[] pomFile = new IFile[1];
+ final boolean[] useWorkspace = new boolean[1];
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
-
public void run() {
LifecycleMappingDialog dialog = new LifecycleMappingDialog(Display.getCurrent().getActiveShell(),
- (IFile) marker.getResource(), marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""), marker
- .getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""), marker.getAttribute(
- IMavenConstants.MARKER_ATTR_VERSION, ""), marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, ""));
+ (IFile) marker.getResource(), marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""), marker //$NON-NLS-1$
+ .getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""), marker.getAttribute( //$NON-NLS-1$
+ IMavenConstants.MARKER_ATTR_VERSION, ""), marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "")); //$NON-NLS-1$ //$NON-NLS-2$
dialog.setBlockOnOpen(true);
if(dialog.open() == Window.OK) {
- pomFile[0] = dialog.getPomFile();
+ if (dialog.useWorkspaceSettings()) {
+ // store in workspace, not in pom file
+ useWorkspace[0] = true;
+ } else {
+ pomFile[0] = dialog.getPomFile();
+ }
}
}
});
- if(pomFile[0] != null) {
+
+ if (pomFile[0] != null || useWorkspace[0]) {
List<LifecycleMappingOperation> lst = new ArrayList<LifecycleMappingOperation>();
for (IMarker m : marks) {
- lst.add(createOperation(m));
+ lst.add(createOperation(m, useWorkspace[0]));
+ }
+
+ OperationTuple operationTuple;
+ IDOMModel model = null;
+ if (useWorkspace[0]) {
+ // write to workspace preferences
+ model = loadWorkspaceMappingsModel();
+ operationTuple = new OperationTuple(model, new CompoundOperation(lst.toArray(new Operation[0])));
+ } else {
+ operationTuple = new OperationTuple(pomFile[0], new CompoundOperation(lst.toArray(new Operation[0])));
+ }
+ performOnDOMDocument(operationTuple);
+
+ if (useWorkspace[0]) {
+ // now save the workspace file if necessary
+ MavenPluginActivator.getDefault().getMavenConfiguration().setWorkspaceMappings(model.getDocument().getSource());
+
+ // must kick off an update project job since the pom isn't modified.
+ // Only update the project from where this quick fix was executed.
+ // Other projects can be updated manually
+ new UpdateMavenProjectJob(new IProject[] { marker.getResource().getProject() }).schedule();
}
- performOnDOMDocument(new OperationTuple(pomFile[0], new CompoundOperation(lst.toArray(new Operation[0]))));
}
}
- private LifecycleMappingOperation createOperation(IMarker mark) {
+ /**
+ * Loads the workspace lifecycle mappings file as a dom model
+ */
+ private IDOMModel loadWorkspaceMappingsModel() throws UnsupportedEncodingException, IOException {
+ IDOMModel model;
+ XMLModelLoader loader = new XMLModelLoader();
+ model = (IDOMModel) loader.createModel();
+ loader.load(new ByteArrayInputStream(MavenPluginActivator.getDefault().getMavenConfiguration()
+ .getWorkspaceMappings().getBytes()), model, EncodingRule.CONTENT_BASED);
+ return model;
+ }
+
+ private LifecycleMappingOperation createOperation(IMarker mark, boolean createAtTopLevel) {
String pluginGroupId = mark.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""); //$NON-NLS-1$
String pluginArtifactId = mark.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""); //$NON-NLS-1$
String pluginVersion = mark.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, ""); //$NON-NLS-1$
String[] goals = new String[] { mark.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "")}; //$NON-NLS-1$
- return new LifecycleMappingOperation(pluginGroupId, pluginArtifactId, pluginVersion, action, goals);
+ return new LifecycleMappingOperation(pluginGroupId, pluginArtifactId, pluginVersion, action, goals, createAtTopLevel);
}
@@ -201,7 +247,7 @@ public class LifecycleMappingProposal extends WorkbenchMarkerResolution implemen
} else {
List<LifecycleMappingOperation> lst = new ArrayList<LifecycleMappingOperation>();
for (IMarker m : markers) {
- lst.add(createOperation(m));
+ lst.add(createOperation(m, false));
}
performOnDOMDocument(new OperationTuple((IFile) marker.getResource(), new CompoundOperation(lst.toArray(new Operation[0]))));
}
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java
deleted file mode 100644
index 4e807c42..00000000
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008-2011 Sonatype, Inc.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Sonatype, Inc. - initial API and implementation
- *******************************************************************************/
-
-
-package org.eclipse.m2e.editor.xml.internal.lifecycle;
-
-
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
-import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
-import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.repository.internal.DefaultVersionRangeResolver;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension5;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.ui.IMarkerResolution;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.texteditor.MarkerAnnotation;
-import org.eclipse.ui.views.markers.WorkbenchMarkerResolution;
-
-import org.eclipse.m2e.core.internal.IMavenConstants;
-import org.eclipse.m2e.core.internal.MavenPluginActivator;
-import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadataSource;
-import org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionFilter;
-import org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionMetadata;
-import org.eclipse.m2e.core.internal.lifecyclemapping.model.io.xpp3.LifecycleMappingMetadataSourceXpp3Reader;
-import org.eclipse.m2e.core.internal.lifecyclemapping.model.io.xpp3.LifecycleMappingMetadataSourceXpp3Writer;
-import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction;
-import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
-import org.eclipse.m2e.core.ui.internal.UpdateConfigurationJob;
-import org.eclipse.m2e.editor.xml.internal.Messages;
-
-public class WorkspaceLifecycleMappingProposal extends WorkbenchMarkerResolution implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution {
- private static final Logger log = LoggerFactory.getLogger(WorkspaceLifecycleMappingProposal.class);
-
-
- private IQuickAssistInvocationContext context;
- private final IMarker marker;
-
- private final PluginExecutionAction action;
-
- public WorkspaceLifecycleMappingProposal(IQuickAssistInvocationContext context, MarkerAnnotation mark,
- PluginExecutionAction action) {
- this.context = context;
- marker = mark.getMarker();
- this.action = action;
- }
-
- public WorkspaceLifecycleMappingProposal(IMarker marker, PluginExecutionAction action) {
- this.marker = marker;
- this.action = action;
- }
-
- public void apply(final IDocument doc) {
- run(marker);
- }
-
- /**
- * @return
- */
- private static LifecycleMappingMetadataSource getWorkspacePreferencesMetadataSources() {
- LifecycleMappingMetadataSource source = new LifecycleMappingMetadataSource();
- String mapp = MavenPluginActivator.getDefault().getPluginPreferences().getString("XXX_mappings");
- if (mapp != null) {
- LifecycleMappingMetadataSourceXpp3Reader reader = new LifecycleMappingMetadataSourceXpp3Reader();
- try {
- source = reader.read(new StringReader(mapp));
- } catch(IOException ex) {
- // TODO Auto-generated catch block
- log.error(ex.getMessage(), ex);
- } catch(XmlPullParserException ex) {
- // TODO Auto-generated catch block
- log.error(ex.getMessage(), ex);
- }
- }
- return source;
- }
-
-
- private static void performIgnore(IMarker mark, LifecycleMappingMetadataSource source) throws IOException, CoreException {
- String pluginGroupId = mark.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""); //$NON-NLS-1$
- String pluginArtifactId = mark.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""); //$NON-NLS-1$
- String pluginVersion = mark.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, ""); //$NON-NLS-1$
- String goal = mark.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, ""); //$NON-NLS-1$
- String id = pluginGroupId + ":" + pluginArtifactId;
- MojoExecutionKey key = new MojoExecutionKey(pluginGroupId, pluginArtifactId, pluginVersion, goal, null, null);
- boolean found = false;
- for (PluginExecutionMetadata pem : source.getPluginExecutions()) {
- PluginExecutionFilter filter = pem.getFilter();
- if (PluginExecutionAction.ignore.equals(pem.getAction())) {
- if (filter.getGroupId().equals(pluginGroupId) && filter.getArtifactId().equals(pluginArtifactId)) {
- found = true;
- try {
- VersionRange range = VersionRange.createFromVersionSpec(filter.getVersionRange());
- DefaultArtifactVersion version = new DefaultArtifactVersion(pluginVersion);
- if (!range.containsVersion(version)) {
- filter.setVersionRange("[" + pluginVersion + ",)");
- }
- } catch(InvalidVersionSpecificationException e) {
- log.error(e.getMessage(), e);
- }
- if (!filter.getGoals().contains(goal)) {
- filter.addGoal(goal);
- }
- break;
- }
- }
- }
- if (!found) {
- PluginExecutionMetadata pe = new PluginExecutionMetadata();
- PluginExecutionFilter fil = new PluginExecutionFilter(pluginGroupId, pluginArtifactId, "[" + pluginVersion + ",)", goal);
- pe.setFilter(fil);
- source.addPluginExecution(pe);
- Xpp3Dom actionDom = new Xpp3Dom("action");
- actionDom.addChild(new Xpp3Dom(PluginExecutionAction.ignore.name()));
- pe.setActionDom(actionDom);
- }
-
-
-
- }
-
-
-
- public String getAdditionalProposalInfo() {
- return null;
- }
-
- public IContextInformation getContextInformation() {
- return null;
- }
-
- public String getDisplayString() {
- String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, ""); //$NON-NLS-1$
- return PluginExecutionAction.ignore.equals(action) ? NLS.bind("Mark goal {0} in workspace as ignored in Eclipse build", goal)
- : NLS.bind(Messages.LifecycleMappingProposal_execute_label, goal);
- }
-
- public Image getImage() {
- return PluginExecutionAction.ignore.equals(action) ? PlatformUI.getWorkbench().getSharedImages()
- .getImage(org.eclipse.ui.ISharedImages.IMG_TOOL_DELETE) : PlatformUI.getWorkbench().getSharedImages()
- .getImage(org.eclipse.ui.ISharedImages.IMG_TOOL_FORWARD);
- }
-
- public Point getSelection(IDocument arg0) {
- return null;
- }
-
- public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
- if (context == null) {
- //no context in markerresolution, just to be sure..
- return null;
- }
- String pluginGroupId = marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""); //$NON-NLS-1$
- String pluginArtifactId = marker.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""); //$NON-NLS-1$
- String pluginVersion = marker.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, ""); //$NON-NLS-1$
- String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, ""); //$NON-NLS-1$
- String execution = marker.getAttribute(IMavenConstants.MARKER_ATTR_EXECUTION_ID, "-"); //$NON-NLS-1$
- String phase = marker.getAttribute(IMavenConstants.MARKER_ATTR_LIFECYCLE_PHASE, "-"); //$NON-NLS-1$
- String info = NLS.bind(Messages.LifecycleMappingProposal_all_desc,
- new Object[] {goal, execution, phase, pluginGroupId + ":" + pluginArtifactId + ":" + pluginVersion, //$NON-NLS-1$ //$NON-NLS-2$
- (PluginExecutionAction.ignore.equals(action)
- ? "This quickfix generates a plugin configuration snippet recognized by the m2e integration during project configuration. It marks the given goal as ignored for the purposes of the Eclipse build."
- : Messages.LifecycleMappingProposal_execute_desc)});
-
- return info;
- }
-
- public String getLabel() {
- return getDisplayString();
- }
-
- public void run(final IMarker marker) {
- try {
- if(PluginExecutionAction.ignore.equals(action)) {
- LifecycleMappingMetadataSource source = getWorkspacePreferencesMetadataSources();
- performIgnore(marker, source);
- LifecycleMappingMetadataSourceXpp3Writer writer = new LifecycleMappingMetadataSourceXpp3Writer();
- StringWriter sw = new StringWriter();
- writer.write(sw, source);
- MavenPluginActivator.getDefault().getPluginPreferences().setValue("XXX_mappings", sw.toString());
-
- //now update the project
- new UpdateConfigurationJob(new IProject[] {marker.getResource().getProject()}).schedule();
- MavenPluginActivator.getDefault().savePluginPreferences();
-
- }
- } catch(IOException e) {
- log.error("Error generating code in pom.xml", e); //$NON-NLS-1$
- } catch(CoreException e) {
- log.error(e.getMessage(), e);
- }
- }
-
- public String getDescription() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public IMarker[] findOtherMarkers(IMarker[] markers) {
- List<IMarker> handled = new ArrayList<IMarker>();
-
- for (IMarker marker : markers) {
- if (marker == this.marker) {
- continue;
- }
- String hint = marker.getAttribute(IMavenConstants.MARKER_ATTR_EDITOR_HINT, null);
- if ( hint != null && hint.equals(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION)) {
- handled.add(marker);
- }
- }
- return handled.toArray(new IMarker[handled.size()]);
- }
-
- @Override
- public void run(IMarker[] markers, IProgressMonitor monitor) {
- try {
- if(PluginExecutionAction.ignore.equals(action)) {
- Set<IProject> prjs = new HashSet<IProject>();
- LifecycleMappingMetadataSource source = getWorkspacePreferencesMetadataSources();
- for (IMarker mark : markers) {
- performIgnore(mark, source);
- prjs.add(mark.getResource().getProject());
- }
- LifecycleMappingMetadataSourceXpp3Writer writer = new LifecycleMappingMetadataSourceXpp3Writer();
- StringWriter sw = new StringWriter();
- writer.write(sw, source);
- MavenPluginActivator.getDefault().getPluginPreferences().setValue("XXX_mappings", sw.toString());
-
- MavenPluginActivator.getDefault().savePluginPreferences();
- for (IMarker mark : markers) {
- mark.delete();
- }
- //now update the projects
- new UpdateConfigurationJob(prjs.toArray(new IProject[0])).schedule();
-
- }
- } catch(IOException e) {
- log.error("Error generating code in pom.xml", e); //$NON-NLS-1$
- } catch(CoreException e) {
- log.error(e.getMessage(), e);
- }
- }
-
-} \ No newline at end of file
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/messages.properties b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/messages.properties
index 3cf16b38..640e7c0c 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/messages.properties
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/messages.properties
@@ -10,11 +10,17 @@ InsertArtifactProposal_searchDialog_title=Select Parent
InsertExpressionProposal_hint1=The expression evaluates to <b>{0}</b> in the current effective pom.
InsertExpressionProposal_hint2=<br>It is based on property defined in <b>{0}</b>
InsertSPDXLicenseProposal_0=Insert SPDX License
+LifecycleMappingDialog_Ignore=Ignore {0}
+LifecycleMappingDialog_LocationToIgnore=Select location to place ignore
+LifecycleMappingDialog_NonWorkspacePom=Non-workspace pom
+LifecycleMappingDialog_PluginDefinitionInSelectedPom=Plugin definition in selected pom.
+LifecycleMappingDialog_UseWorkspaceSettings=Place in workspace settings
+LifecycleMappingDialog_UseWorkspaceSettingsDesc=Checking this box will place the lifecycle mapping metadata in workspace settings.\nTo edit this, go to Preferences -> Maven and click on Open workspace lifecycle mappings metadata
LifecycleMappingProposal_all_desc=<html>Goal: <b>{0}</b><br/>ExecutionId: <b>{1}</b><br/>Phase: <b>{2}</b><br/>Plugin: {3}<br/><br/>{4}</html>
LifecycleMappingProposal_execute_desc=This quickfix generates a plugin configuration snippet recognized by the m2e integration during project configuration. It marks the given goal to be executed during the Eclipse build.
LifecycleMappingProposal_execute_label=Execute goal {0} as part of Eclipse build
LifecycleMappingProposal_ignore_desc=This quickfix generates a plugin configuration snippet recognized by the m2e integration during project configuration. It marks the given goal as ignored for the purposes of the Eclipse build.
-LifecycleMappingProposal_ignore_label=Permanently mark goal {0} in pom.xml as ignored in Eclipse build
+LifecycleMappingProposal_ignore_label=Permanently mark goal {0} in pom.xml or workspace preferences as ignored in Eclipse build
MavenMarkerResolution_error=Unable to apply the quick fix. The file may have unsaved changes that invalidate the current quick fix.
MavenMarkerResolution_error_title=Error
MavenMarkerResolution_schema_label=Add Schema information to the specified pom.xml

Back to the top