Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2012-08-14 11:05:20 +0000
committerIgor Fedorenko2012-08-16 11:45:47 +0000
commit0ca9fa120c251db1bf613383788af4775fce1692 (patch)
treee77ecc92ea7cd0a13f0170bd3e3ab35b1c735333 /org.eclipse.m2e.editor.xml/src/main/java/org/eclipse
parent4f4c40b364e952c5f57321d997476a70d9b35a1a (diff)
downloadm2e-core-0ca9fa120c251db1bf613383788af4775fce1692.tar.gz
m2e-core-0ca9fa120c251db1bf613383788af4775fce1692.tar.xz
m2e-core-0ca9fa120c251db1bf613383788af4775fce1692.zip
350414 separate quick-fix for workspace mapping; cleanup
Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
Diffstat (limited to 'org.eclipse.m2e.editor.xml/src/main/java/org/eclipse')
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MavenMarkerResolutionGenerator.java10
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java4
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/Messages.java14
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/AbstractLifecycleMappingProposal.java84
-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.java128
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java121
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/messages.properties9
8 files changed, 244 insertions, 171 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 07b630e0..7ae433af 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,6 +19,7 @@ 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;
/**
@@ -53,14 +54,13 @@ public class MavenMarkerResolutionGenerator implements IMarkerResolutionGenerato
new PomQuickAssistProcessor.IgnoreWarningProposal(marker, IMavenConstants.MARKER_IGNORE_MANAGED)};
}
if(hint.equals(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION)) {
- return new IMarkerResolution[] {
- new LifecycleMappingProposal(marker, PluginExecutionAction.ignore),
-// new LifecycleMappingProposal(marker, PluginExecutionAction.execute)
- };
+ return new IMarkerResolution[] {new LifecycleMappingProposal(marker, PluginExecutionAction.ignore),
+ new WorkspaceLifecycleMappingProposal(marker, PluginExecutionAction.ignore),};
}
if(marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_ERROR
&& hint.equals(IMavenConstants.EDITOR_HINT_IMPLICIT_LIFECYCLEMAPPING)) {
- return new IMarkerResolution[] {new LifecycleMappingProposal(marker, PluginExecutionAction.ignore)};
+ return new IMarkerResolution[] {new LifecycleMappingProposal(marker, PluginExecutionAction.ignore),
+ new WorkspaceLifecycleMappingProposal(marker, PluginExecutionAction.ignore)};
}
}
return new IMarkerResolution[0];
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 4ea8e323..495edcba 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,6 +62,7 @@ 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);
@@ -120,11 +121,12 @@ 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 LifecycleMappingProposal(context, mark, PluginExecutionAction.execute));
+ proposals.add(new WorkspaceLifecycleMappingProposal(mark.getMarker(), PluginExecutionAction.ignore));
} else if(mark.getMarker().getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_ERROR
&& hint.equals(IMavenConstants.EDITOR_HINT_IMPLICIT_LIFECYCLEMAPPING)) {
extractedFromMarkers(proposals, mark); //having this first sort of helps for 335490
proposals.add(new LifecycleMappingProposal(context, mark, PluginExecutionAction.ignore));
+ proposals.add(new WorkspaceLifecycleMappingProposal(mark.getMarker(), PluginExecutionAction.ignore));
}
}
}
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 3924eb8c..d8be49b5 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
@@ -17,6 +17,8 @@ import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.m2e.editor.xml.internal.messages"; //$NON-NLS-1$
+ public static String LifecycleMappingProposal_workspaceIgnore_label;
+
public static String InsertArtifactProposal_additionals;
public static String InsertArtifactProposal_display_name;
@@ -41,18 +43,6 @@ 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/AbstractLifecycleMappingProposal.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/AbstractLifecycleMappingProposal.java
new file mode 100644
index 00000000..8789c3bd
--- /dev/null
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/AbstractLifecycleMappingProposal.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * 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.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.views.markers.WorkbenchMarkerResolution;
+
+import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction;
+
+
+abstract class AbstractLifecycleMappingProposal extends WorkbenchMarkerResolution {
+ private static final Logger log = LoggerFactory.getLogger(AbstractLifecycleMappingProposal.class);
+
+ protected final IMarker marker;
+
+ protected final PluginExecutionAction action;
+
+ protected AbstractLifecycleMappingProposal(IMarker marker, PluginExecutionAction action) {
+ this.marker = marker;
+ this.action = action;
+ }
+
+ 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 String getLabel() {
+ return getDisplayString();
+ }
+
+ public String getDescription() {
+ return getDisplayString();
+ }
+
+ @Override
+ public IMarker[] findOtherMarkers(IMarker[] markers) {
+ List<IMarker> toRet = new ArrayList<IMarker>();
+
+ for(IMarker mark : markers) {
+ if(mark == this.marker) {
+ continue;
+ }
+ try {
+ if(mark.getType().equals(this.marker.getType()) && mark.getResource().equals(this.marker.getResource())) {
+ toRet.add(mark);
+ }
+ } catch(CoreException e) {
+ log.error(e.getMessage(), e);
+ }
+ }
+ return toRet.toArray(new IMarker[0]);
+ }
+
+ public void run(final IMarker marker) {
+ run(new IMarker[] {marker}, new NullProgressMonitor());
+ }
+
+ @Override
+ public abstract void run(IMarker[] markers, IProgressMonitor monitor);
+
+ public abstract String getDisplayString();
+}
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 406e83fe..59a55028 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,7 +7,6 @@
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
- * Andrew Eisenberg - Work on Bug 350414
*******************************************************************************/
package org.eclipse.m2e.editor.xml.internal.lifecycle;
@@ -30,10 +29,7 @@ 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;
@@ -45,7 +41,6 @@ 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")
@@ -63,36 +58,33 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
private String pluginArtifactId;
- // TODO Unused...consider deleting
-// private String pluginVersion;
+ 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(Messages.LifecycleMappingDialog_Ignore, goal));
+ shell.setText(NLS.bind("Ignore {0}", goal));
}
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
Label label = new Label(container, SWT.NONE);
- label.setText(Messages.LifecycleMappingDialog_LocationToIgnore);
+ label.setText("Select location to place ignore");
pomComposite = new PomHierarchyComposite(container, SWT.BORDER);
pomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
pomComposite.addSelectionChangedListener(this);
@@ -106,28 +98,9 @@ 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) {
@@ -151,13 +124,13 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
private void updateStatus(MavenProject project) {
if(project.getFile() == null) {
- status.setText(Messages.LifecycleMappingDialog_NonWorkspacePom);
+ status.setText("Non-workspace pom");
status.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
} else if(project.equals(pluginProject)) {
- status.setText(Messages.LifecycleMappingDialog_PluginDefinitionInSelectedPom);
+ status.setText("Plugin definition in selected pom.");
status.setImage(null);
} else {
- status.setText(""); //$NON-NLS-1$
+ status.setText("");
status.setImage(null);
}
}
@@ -178,13 +151,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); //$NON-NLS-1$
+ Plugin plugin = project.getPlugin(pluginGroupId + ":" + pluginArtifactId);
if(plugin == null) {
return null; // can't really happy
}
- InputLocation location = plugin.getLocation(""); //$NON-NLS-1$
+ InputLocation location = plugin.getLocation("");
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 6947e1ea..710f9308 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,7 +7,6 @@
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
- * Andrew Eisenberg - Work on Bug 350414
*******************************************************************************/
@@ -15,9 +14,7 @@ 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;
@@ -26,10 +23,8 @@ 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;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension5;
@@ -37,44 +32,34 @@ import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
import org.eclipse.jface.window.Window;
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.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.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 {
+
+public class LifecycleMappingProposal extends AbstractLifecycleMappingProposal implements ICompletionProposal,
+ ICompletionProposalExtension5 {
private static final Logger log = LoggerFactory.getLogger(LifecycleMappingProposal.class);
private IQuickAssistInvocationContext context;
- private final IMarker marker;
-
- private final PluginExecutionAction action;
public LifecycleMappingProposal(IQuickAssistInvocationContext context, MarkerAnnotation mark,
PluginExecutionAction action) {
+ super(mark.getMarker(), action);
this.context = context;
- marker = mark.getMarker();
- this.action = action;
}
public LifecycleMappingProposal(IMarker marker, PluginExecutionAction action) {
- this.marker = marker;
- this.action = action;
+ super(marker, action);
}
public void apply(final IDocument doc) {
@@ -82,7 +67,7 @@ public class LifecycleMappingProposal extends WorkbenchMarkerResolution implemen
if(PluginExecutionAction.ignore.equals(action)) {
performIgnore(new IMarker[] {marker});
} else {
- performOnDOMDocument(new OperationTuple(doc, createOperation(marker, false)));
+ performOnDOMDocument(new OperationTuple(doc, createOperation(marker)));
}
} catch(IOException e) {
log.error("Error generating code in pom.xml", e); //$NON-NLS-1$
@@ -93,72 +78,34 @@ 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 //$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$
+ (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, ""));
dialog.setBlockOnOpen(true);
if(dialog.open() == Window.OK) {
- if (dialog.useWorkspaceSettings()) {
- // store in workspace, not in pom file
- useWorkspace[0] = true;
- } else {
- pomFile[0] = dialog.getPomFile();
- }
+ pomFile[0] = dialog.getPomFile();
}
}
});
-
- if (pomFile[0] != null || useWorkspace[0]) {
+ if(pomFile[0] != null) {
List<LifecycleMappingOperation> lst = new ArrayList<LifecycleMappingOperation>();
for (IMarker m : marks) {
- 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();
+ lst.add(createOperation(m));
}
+ performOnDOMDocument(new OperationTuple(pomFile[0], new CompoundOperation(lst.toArray(new Operation[0]))));
}
}
- /**
- * 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) {
+ private LifecycleMappingOperation createOperation(IMarker mark) {
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, createAtTopLevel);
+ return new LifecycleMappingOperation(pluginGroupId, pluginArtifactId, pluginVersion, action, goals);
}
@@ -176,13 +123,7 @@ public class LifecycleMappingProposal extends WorkbenchMarkerResolution implemen
: 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) {
+ public Point getSelection(IDocument document) {
return null;
}
@@ -206,39 +147,6 @@ public class LifecycleMappingProposal extends WorkbenchMarkerResolution implemen
return info;
}
- public String getLabel() {
- return getDisplayString();
- }
-
- public void run(final IMarker marker) {
- run(new IMarker[] {marker}, new NullProgressMonitor());
- }
-
- public String getDescription() {
- // TODO Auto-generated method stub
- return getDisplayString();
- }
-
- @Override
- public IMarker[] findOtherMarkers(IMarker[] markers) {
- List<IMarker> toRet = new ArrayList<IMarker>();
-
- for (IMarker mark : markers) {
- if (mark == this.marker) {
- continue;
- }
- try {
- if (mark.getType().equals(this.marker.getType()) && mark.getResource().equals(this.marker.getResource())) {
- toRet.add(mark);
- }
- } catch(CoreException e) {
- log.error(e.getMessage(), e);
- }
- }
- return toRet.toArray(new IMarker[0]);
-
- }
-
@Override
public void run(IMarker[] markers, IProgressMonitor monitor) {
try {
@@ -247,7 +155,7 @@ public class LifecycleMappingProposal extends WorkbenchMarkerResolution implemen
} else {
List<LifecycleMappingOperation> lst = new ArrayList<LifecycleMappingOperation>();
for (IMarker m : markers) {
- lst.add(createOperation(m, false));
+ lst.add(createOperation(m));
}
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
new file mode 100644
index 00000000..2ec6deb6
--- /dev/null
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/WorkspaceLifecycleMappingProposal.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2012 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
+ * Andrew Eisenberg - Work on Bug 350414
+ *******************************************************************************/
+
+package org.eclipse.m2e.editor.xml.internal.lifecycle;
+
+import java.util.HashSet;
+
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+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.IContextInformation;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Point;
+
+import org.eclipse.m2e.core.internal.IMavenConstants;
+import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
+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.lifecyclemapping.model.PluginExecutionAction;
+import org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob;
+import org.eclipse.m2e.editor.xml.internal.Messages;
+
+
+@SuppressWarnings("restriction")
+public class WorkspaceLifecycleMappingProposal extends AbstractLifecycleMappingProposal implements ICompletionProposal {
+
+ public WorkspaceLifecycleMappingProposal(IMarker marker, PluginExecutionAction action) {
+ super(marker, action);
+ }
+
+ @Override
+ public void run(IMarker[] markers, IProgressMonitor monitor) {
+ LifecycleMappingMetadataSource mapping = LifecycleMappingFactory.getWorkspaceMetadata();
+ for(IMarker marker : markers) {
+ addMapping(mapping, marker);
+ }
+ LifecycleMappingFactory.writeWorkspaceMetadata(mapping);
+
+ // 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();
+ }
+
+ private void addMapping(LifecycleMappingMetadataSource mapping, IMarker marker) {
+ String groupId = marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""); //$NON-NLS-1$
+ String artifactId = marker.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""); //$NON-NLS-1$
+ String version = marker.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, ""); //$NON-NLS-1$
+ String[] goals = new String[] {marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "")}; //$NON-NLS-1$
+
+ PluginExecutionMetadata execution = getPluginExecutionMetadata(mapping, groupId, artifactId, version);
+
+ if(execution == null) {
+ execution = new PluginExecutionMetadata();
+ execution.setSource(mapping);
+ execution.setFilter(new PluginExecutionFilter(groupId, artifactId, version, new HashSet<String>()));
+
+ Xpp3Dom actionDom = new Xpp3Dom("action");
+ actionDom.addChild(new Xpp3Dom(action.toString()));
+ execution.setActionDom(actionDom);
+
+ mapping.addPluginExecution(execution);
+ }
+
+ for(String goal : goals) {
+ execution.getFilter().addGoal(goal);
+ }
+ }
+
+ private PluginExecutionMetadata getPluginExecutionMetadata(LifecycleMappingMetadataSource mapping, String groupId,
+ String artifactId, String version) {
+ for(PluginExecutionMetadata execution : mapping.getPluginExecutions()) {
+ PluginExecutionFilter filter = execution.getFilter();
+ if(eq(groupId, filter.getGroupId()) && eq(artifactId, filter.getArtifactId())
+ && eq(version, filter.getVersionRange()) && action == execution.getAction()) {
+ return execution;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String getDisplayString() {
+ String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, ""); //$NON-NLS-1$
+ return NLS.bind(Messages.LifecycleMappingProposal_workspaceIgnore_label, goal);
+ }
+
+ private static <S> boolean eq(S a, S b) {
+ return a != null ? a.equals(b) : b == null;
+ }
+
+ public void apply(IDocument document) {
+ run(marker);
+ }
+
+ public Point getSelection(IDocument document) {
+ return null;
+ }
+
+ public String getAdditionalProposalInfo() {
+ return null;
+ }
+
+ public IContextInformation getContextInformation() {
+ return null;
+ }
+}
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 640e7c0c..68321426 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,17 +10,12 @@ 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 or workspace preferences as ignored in Eclipse build
+LifecycleMappingProposal_ignore_label=Permanently mark goal {0} in pom.xml as ignored in Eclipse build
+LifecycleMappingProposal_workspaceIgnore_label=Mark goal {0} as ignored in Eclipse build in Eclipse preferences (experimental)
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