diff options
author | Milos Kleint | 2011-01-19 20:55:45 +0000 |
---|---|---|
committer | Milos Kleint | 2011-01-19 20:56:49 +0000 |
commit | adefba4ff66a2867d10e7f509dbf6008ffd16c30 (patch) | |
tree | 64feb321e877b5af5b7c7b632be2d1c362fc97e0 /org.eclipse.m2e.editor.xml | |
parent | 0944597a555f5ba12106b7a4d1bfb984f234baab (diff) | |
download | m2e-core-adefba4ff66a2867d10e7f509dbf6008ffd16c30.tar.gz m2e-core-adefba4ff66a2867d10e7f509dbf6008ffd16c30.tar.xz m2e-core-adefba4ff66a2867d10e7f509dbf6008ffd16c30.zip |
MNGECLIPSE-2658 add the actual quickfix proposal/marker generator for executing/ignoring mojo executions.
Diffstat (limited to 'org.eclipse.m2e.editor.xml')
5 files changed, 170 insertions, 12 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 97df839b..33a57209 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 @@ -17,6 +17,7 @@ import org.eclipse.ui.IMarkerResolutionGenerator; import org.eclipse.ui.IMarkerResolutionGenerator2; import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.editor.xml.internal.lifecycle.LifecycleMappingProposal; /** @@ -55,8 +56,10 @@ public class MavenMarkerResolutionGenerator implements IMarkerResolutionGenerato }; } if (hint.equals(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION)) { - //TODO - return new IMarkerResolution[] {}; + return new IMarkerResolution[] { + new LifecycleMappingProposal(marker, LifecycleMappingProposal.IGNORE), + new LifecycleMappingProposal(marker, LifecycleMappingProposal.EXECUTE) + }; } } 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 c7db55a2..cb2b48c8 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 @@ -52,6 +52,7 @@ import org.eclipse.m2e.core.core.MavenLogger; 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; public class PomQuickAssistProcessor implements IQuickAssistProcessor { private static final String GROUP_ID_NODE = "groupId"; //$NON-NLS-1$ @@ -107,7 +108,8 @@ public class PomQuickAssistProcessor implements IQuickAssistProcessor { proposals.add(new SchemaCompletionProposal(context, mark)); } else if (hint.equals(IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION)) { - //TODO.. + proposals.add(new LifecycleMappingProposal(context, mark, LifecycleMappingProposal.IGNORE)); + proposals.add(new LifecycleMappingProposal(context, mark, LifecycleMappingProposal.EXECUTE)); } } } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/PomEdits.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/PomEdits.java index 2e158f10..9b140be4 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/PomEdits.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/PomEdits.java @@ -22,6 +22,7 @@ import org.w3c.dom.Text; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.IDocument; import org.eclipse.wst.sse.core.StructuredModelManager; import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager; @@ -59,10 +60,10 @@ public class PomEdits { * @return */ public static Element findChild(Element parent, String name, Matcher... matchers) { - for (Element el : findChilds(parent, name)) { + OUTTER: for (Element el : findChilds(parent, name)) { for (Matcher match : matchers) { if (!match.matches(el)) { - continue; + continue OUTTER; } } return el; @@ -212,7 +213,9 @@ public class PomEdits { //add a new line to get the newly generated content correctly formatted. newNode.getParentNode().appendChild(newNode.getParentNode().getOwnerDocument().createTextNode("\n")); } - IStructuredFormatProcessor formatProcessor = new FormatProcessorXML(); + FormatProcessorXML formatProcessor = new FormatProcessorXML(); + //ignore any line width settings, causes wrong formatting of <foo>bar</foo> + formatProcessor.getFormatPreferences().setLineWidth(2000); formatProcessor.formatNode(newNode); } @@ -229,7 +232,9 @@ public class PomEdits { //TODO we might want to attempt iterating opened editors and somehow initialize those // that were not yet initialized. Then we could avoid saving a file that is actually opened, but was never used so far (after restart) try { - domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tuple.getFile()); + domModel = tuple.getFile() != null + ? (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tuple.getFile()) + : (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForEdit(tuple.getDocument()); domModel.aboutToChangeModel(); IStructuredTextUndoManager undo = domModel.getStructuredDocument().getUndoManager(); undo.beginRecording(domModel); @@ -254,13 +259,23 @@ public class PomEdits { public static final class OperationTuple { private final PomEdits.Operation operation; private final IFile file; + private final IDocument document; public OperationTuple(IFile file, PomEdits.Operation operation) { assert file != null; assert operation != null; this.file = file; this.operation = operation; + document = null; } + + public OperationTuple(IDocument document, PomEdits.Operation operation) { + assert operation != null; + this.document = document; + this.operation = operation; + file = null; + } + public IFile getFile() { return file; @@ -269,6 +284,10 @@ public class PomEdits { public PomEdits.Operation getOperation() { return operation; } + + public IDocument getDocument() { + return document; + } } @@ -303,7 +322,7 @@ public class PomEdits { } /** - * an interface for indentifying child elements that fulfil conditions expressed by the matcher. + * an interface for identifying child elements that fulfill conditions expressed by the matcher. * @author mkleint * */ @@ -321,7 +340,7 @@ public class PomEdits { public boolean matches(Element child) { String toMatch = PomEdits.getTextValue(PomEdits.findChild(child, elementName)); - return matchingValue.equals(toMatch); + return toMatch != null && toMatch.trim().equals(matchingValue); } }; } diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingOperation.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingOperation.java index 91b3a496..b7177d43 100644 --- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingOperation.java +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingOperation.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -50,6 +51,9 @@ public class LifecycleMappingOperation implements Operation { if (lifecyclePlugin == null) { //not found, create lifecyclePlugin = createPlugin(managedPlugins, LIFECYCLE_PLUGIN_GROUPID, LIFECYCLE_PLUGIN_ARTIFACTID, LIFECYCLE_PLUGIN_VERSION); + Comment comment = document.createComment("TODO TEXT. This plugin's configuration is used in m2e only."); + managedPlugins.insertBefore(comment, lifecyclePlugin); + format(comment); } Element pluginExecutions = getChild(lifecyclePlugin, "configuration", "lifecycleMappingMetadata", "pluginExecutions"); @@ -92,9 +96,9 @@ public class LifecycleMappingOperation implements Operation { parent.appendChild(exec); Element filter = document.createElement("pluginExecutionFilter"); exec.appendChild(filter); - createElementWithText(exec, "groupId", groupId); - createElementWithText(exec, "artifactId", artifactId); - createElementWithText(exec, "versionRange", "[" + version + ",)"); + createElementWithText(filter, "groupId", groupId); + createElementWithText(filter, "artifactId", artifactId); + createElementWithText(filter, "versionRange", "[" + version + ",)"); Element actionEl = document.createElement("action"); exec.appendChild(actionEl); 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 new file mode 100644 index 00000000..4b50df2c --- /dev/null +++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java @@ -0,0 +1,130 @@ +package org.eclipse.m2e.editor.xml.internal.lifecycle; + +import java.io.IOException; + +import org.w3c.dom.Element; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +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.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.IMarkerResolution; +import org.eclipse.ui.internal.WorkbenchPlugin; +import org.eclipse.ui.texteditor.MarkerAnnotation; +import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; + +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.editor.xml.internal.Messages; +import org.eclipse.m2e.editor.xml.internal.PomEdits; +import org.eclipse.m2e.editor.xml.internal.XmlUtils; + +public class LifecycleMappingProposal implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution { + + public static final String EXECUTE = "execute"; + + public static final String IGNORE = "ignore"; + + private IQuickAssistInvocationContext context; + private final IMarker marker; + private final String action; + + public LifecycleMappingProposal(IQuickAssistInvocationContext context, MarkerAnnotation mark, String action) { + this.context = context; + marker = mark.getMarker(); + this.action = action; + } + + public LifecycleMappingProposal(IMarker marker, String action) { + this.marker = marker; + this.action = action; + } + + public void apply(final IDocument doc) { + try { + PomEdits.performOnDOMDocument(new PomEdits.OperationTuple(doc, createOperation())); + } catch(IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch(CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private LifecycleMappingOperation createOperation() { + String pluginGroupId = marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, ""); + String pluginArtifactId = marker.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, ""); + String pluginVersion = marker.getAttribute(IMavenConstants.MARKER_ATTR_VERSION, ""); + String[] goals = new String[] { marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "")}; + return new LifecycleMappingOperation(pluginGroupId, pluginArtifactId, pluginVersion, action, goals); + } + + + public String getAdditionalProposalInfo() { + return null; + } + + public IContextInformation getContextInformation() { + return null; + } + + public String getDisplayString() { + return IGNORE.equals(action) ? "Ignore TODO" : "Execute TODO"; + } + + public Image getImage() { + return IGNORE.equals(action) ? WorkbenchPlugin.getDefault().getImageRegistry().get(org.eclipse.ui.internal.SharedImages.IMG_TOOL_DELETE) + : WorkbenchPlugin.getDefault().getImageRegistry().get(org.eclipse.ui.internal.SharedImages.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; + } + final IDocument doc = context.getSourceViewer().getDocument(); + //oh, how do I miss scala here.. + final String[] toRet = new String[1]; +// XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() { +// public void process(Element root) { +// //now check parent version and groupid against the current project's ones.. +// if (root.getNodeName().equals(PomQuickAssistProcessor.PROJECT_NODE)) { //$NON-NLS-1$ +// Element value = XmlUtils.findChildElement(root, isVersion ? VERSION_NODE : GROUP_ID_NODE); //$NON-NLS-1$ //$NON-NLS-2$ +// toRet[0] = previewForRemovedElement(doc, value); +// } +// }}); + if (toRet[0] != null) { + return toRet[0]; + } + + return "TODO"; + } + + public String getLabel() { + return getDisplayString(); + } + + public void run(final IMarker marker) { + try { + PomEdits.performOnDOMDocument(new PomEdits.OperationTuple((IFile) marker.getResource(), createOperation())); + } catch(IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch(CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } +}
\ No newline at end of file |