Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2011-01-21 16:49:24 +0000
committerMilos Kleint2011-01-21 17:01:31 +0000
commitfe17aa1a349b018122ae59e3ca90a84e59713396 (patch)
tree5c307d1f7b85f167ade793940e99481cba9b50df
parent525ec3f15a8ac37fb56dfa505a89bb976d560985 (diff)
downloadm2e-core-fe17aa1a349b018122ae59e3ca90a84e59713396.tar.gz
m2e-core-fe17aa1a349b018122ae59e3ca90a84e59713396.tar.xz
m2e-core-fe17aa1a349b018122ae59e3ca90a84e59713396.zip
cannot use StructuredDocument afer releasing it..
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomQuickAssistProcessor.java70
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerLocationService.java117
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java41
3 files changed, 128 insertions, 100 deletions
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 c6daf15f..c4b839c9 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
@@ -11,6 +11,7 @@
package org.eclipse.m2e.editor.xml;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -19,6 +20,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -351,15 +353,18 @@ static class IdPartRemovalProposal implements ICompletionProposal, ICompletionPr
}
public void run(final IMarker marker) {
- final IStructuredDocument doc = XmlUtils.getDocument(marker);
- if (doc != null) {
- XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() {
- public void process(Element node, IStructuredDocument structured) {
- processFix(doc, node, isVersion, marker);
- }
- });
+ try {
+ XmlUtils.performOnRootElement((IFile)marker.getResource(), new NodeOperation<Element>() {
+ public void process(Element node, IStructuredDocument structured) {
+ processFix(structured, node, isVersion, marker);
+ }
+ });
+ } catch(IOException e) {
+ MavenLogger.log("Error processing marker", e);
+ } catch(CoreException e) {
+ MavenLogger.log("Error processing marker", e);
+ }
}
- }
}
static class ManagedVersionRemovalProposal implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution {
@@ -512,15 +517,18 @@ static class ManagedVersionRemovalProposal implements ICompletionProposal, IComp
}
public void run(final IMarker marker) {
- final IStructuredDocument doc = XmlUtils.getDocument(marker);
- if (doc != null) {
- XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() {
- public void process(Element node, IStructuredDocument structured) {
- processFix(doc, node, isDependency, marker);
- }
- });
- }
- }
+ try {
+ XmlUtils.performOnRootElement((IFile)marker.getResource(), new NodeOperation<Element>() {
+ public void process(Element node, IStructuredDocument structured) {
+ processFix(structured, node, isDependency, marker);
+ }
+ });
+ } catch(IOException e) {
+ MavenLogger.log("Error processing marker", e);
+ } catch(CoreException e) {
+ MavenLogger.log("Error processing marker", e);
+ }
+ }
}
static class IgnoreWarningProposal implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution {
@@ -540,14 +548,11 @@ static class IgnoreWarningProposal implements ICompletionProposal, ICompletionPr
}
public void apply(IDocument doc) {
- if (doc instanceof IStructuredDocument) {
- processFix((IStructuredDocument) doc, marker);
- } else {
- IStructuredDocument strdoc = XmlUtils.getDocument(marker);
- if (strdoc != null) {
- processFix(strdoc, marker);
+ XmlUtils.performOnRootElement(doc, new NodeOperation<Element>() {
+ public void process(Element node, IStructuredDocument structured) {
+ processFix(structured, marker);
}
- }
+ });
}
private void processFix(IStructuredDocument doc, IMarker marker) {
@@ -663,11 +668,18 @@ static class IgnoreWarningProposal implements ICompletionProposal, ICompletionPr
return getDisplayString();
}
- public void run(IMarker marker) {
- IStructuredDocument doc = XmlUtils.getDocument(marker);
- if (doc != null) {
- processFix(doc, marker);
- }
+ public void run(final IMarker marker) {
+ try {
+ XmlUtils.performOnRootElement((IFile)marker.getResource(), new NodeOperation<Element>() {
+ public void process(Element node, IStructuredDocument structured) {
+ processFix(structured, marker);
+ }
+ });
+ } catch(IOException e) {
+ MavenLogger.log("Error processing marker", e);
+ } catch(CoreException e) {
+ MavenLogger.log("Error processing marker", e);
+ }
}
}
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerLocationService.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerLocationService.java
index 5d99f4a7..2691f2a6 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerLocationService.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerLocationService.java
@@ -1,5 +1,6 @@
package org.eclipse.m2e.editor.xml.internal;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -54,74 +55,84 @@ public class MarkerLocationService implements IMarkerLocationService, IEditorMar
String hint = marker.getAttribute(IMavenConstants.MARKER_ATTR_EDITOR_HINT, null);
if (IMavenConstants.EDITOR_HINT_UNKNOWN_PACKAGING.equals(hint)) {
- IDocument document = XmlUtils.getDocument(marker);
- XmlUtils.performOnRootElement(document, new NodeOperation<Element>() {
- public void process(Element root, IStructuredDocument structuredDocument) {
- Element markEl = findChild(root, "packaging");
- if (markEl == null) {
- markEl = root;
+ try {
+ XmlUtils.performOnRootElement((IFile)marker.getResource(), new NodeOperation<Element>() {
+ public void process(Element root, IStructuredDocument structuredDocument) {
+ Element markEl = findChild(root, "packaging");
+ if (markEl == null) {
+ markEl = root;
+ }
+ annotateMarker(marker, structuredDocument, markEl);
}
- annotateMarker(marker, structuredDocument, markEl);
- }
- });
+ });
+ } catch(IOException e) {
+ MavenLogger.log("Error locating marker", e);
+ } catch(CoreException e) {
+ MavenLogger.log("Error locating marker", e);
+ }
}
if (IMavenConstants.EDITOR_HINT_NOT_COVERED_MOJO_EXECUTION.equals(hint)) {
- IDocument document = XmlUtils.getDocument(marker);
- XmlUtils.performOnRootElement(document, new NodeOperation<Element>() {
- public void process(Element root, IStructuredDocument structuredDocument) {
- String groupId = marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, "");
- String artifactId = marker.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, "");
- String exec = marker.getAttribute(IMavenConstants.MARKER_ATTR_EXECUTION_ID, "");
- String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "");
- Element build = findChild(root, "build");
- Element plugin = findPlugin(build, groupId, artifactId);
- Element ourMarkerPlacement = null;
- if (plugin == null) {
- //look in profiles
- List<Element> profiles = findChilds(findChild(root, "profiles"), "profile");
- //TODO eventually we should only process the activated profiles.. but need MavenProject for it.
- for (Element profile : profiles) {
- Element profBuild = findChild(profile, "build");
- plugin = findPlugin(profBuild, groupId, artifactId);
- if (plugin != null) {
- //TODO what is multiple profiles have the plugin with same or different execution ids?
- break;
+ try {
+ XmlUtils.performOnRootElement((IFile)marker.getResource(), new NodeOperation<Element>() {
+ public void process(Element root, IStructuredDocument structuredDocument) {
+ String groupId = marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, "");
+ String artifactId = marker.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, "");
+ String exec = marker.getAttribute(IMavenConstants.MARKER_ATTR_EXECUTION_ID, "");
+ String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, "");
+ Element build = findChild(root, "build");
+ Element plugin = findPlugin(build, groupId, artifactId);
+ Element ourMarkerPlacement = null;
+ if (plugin == null) {
+ //look in profiles
+ List<Element> profiles = findChilds(findChild(root, "profiles"), "profile");
+ //TODO eventually we should only process the activated profiles.. but need MavenProject for it.
+ for (Element profile : profiles) {
+ Element profBuild = findChild(profile, "build");
+ plugin = findPlugin(profBuild, groupId, artifactId);
+ if (plugin != null) {
+ //TODO what is multiple profiles have the plugin with same or different execution ids?
+ break;
+ }
}
}
- }
- if (plugin != null) {
- Element execution = findChild(findChild(plugin, "executions"), "execution", childEquals("id", exec));
- if (execution != null) {
- Element goalEl = findChild(findChild(execution, "goals"), "goal", textEquals(goal));
- if (goalEl != null) {
- ourMarkerPlacement = goalEl;
+ if (plugin != null) {
+ Element execution = findChild(findChild(plugin, "executions"), "execution", childEquals("id", exec));
+ if (execution != null) {
+ Element goalEl = findChild(findChild(execution, "goals"), "goal", textEquals(goal));
+ if (goalEl != null) {
+ ourMarkerPlacement = goalEl;
+ } else {
+ ourMarkerPlacement = findChild(execution, "id");
+ if (ourMarkerPlacement == null) { //just old plain paranoia
+ ourMarkerPlacement = execution;
+ }
+ }
} else {
- ourMarkerPlacement = findChild(execution, "id");
+ //execution not here (eg. in PM or parent PM), just mark the plugin's artifactId
+ ourMarkerPlacement = findChild(plugin, "artifactId");
if (ourMarkerPlacement == null) { //just old plain paranoia
- ourMarkerPlacement = execution;
+ ourMarkerPlacement = plugin;
}
}
} else {
- //execution not here (eg. in PM or parent PM), just mark the plugin's artifactId
- ourMarkerPlacement = findChild(plugin, "artifactId");
- if (ourMarkerPlacement == null) { //just old plain paranoia
- ourMarkerPlacement = plugin;
- }
+ //what are the strategies for placement when no plugin is found?
+ // we could.. search pluginManagement, but it's unlikely to be there..
+ ourMarkerPlacement = build != null ? build : root;
}
- } else {
- //what are the strategies for placement when no plugin is found?
- // we could.. search pluginManagement, but it's unlikely to be there..
- ourMarkerPlacement = build != null ? build : root;
+ annotateMarker(marker, structuredDocument, ourMarkerPlacement);
}
- annotateMarker(marker, structuredDocument, ourMarkerPlacement);
- }
- private Element findPlugin(Element build, String groupId, String artifactId) {
- return findChild(findChild(build, "plugins"), "plugin", childEquals("groupId", groupId), childEquals("artifactId", artifactId));
- }
- });
+ private Element findPlugin(Element build, String groupId, String artifactId) {
+ return findChild(findChild(build, "plugins"), "plugin", childEquals("groupId", groupId), childEquals("artifactId", artifactId));
+ }
+ });
+ } catch(IOException e) {
+ MavenLogger.log("Error locating marker", e);
+ } catch(CoreException e) {
+ MavenLogger.log("Error locating marker", e);
+ }
}
}
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java
index c6951b3f..00162b95 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java
@@ -12,6 +12,7 @@
package org.eclipse.m2e.editor.xml.internal;
import java.io.File;
+import java.io.IOException;
import java.util.List;
import java.util.Stack;
@@ -236,6 +237,9 @@ public class XmlUtils {
IDOMModel domModel = null;
try {
domModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(doc);
+ if (domModel == null) {
+ throw new IllegalArgumentException("Document is not structured: " + doc);
+ }
IStructuredDocument document = domModel.getStructuredDocument();
Element root = domModel.getDocument().getDocumentElement();
operation.process(root, document);
@@ -245,25 +249,24 @@ public class XmlUtils {
}
}
}
-
- public static IStructuredDocument getDocument(IMarker marker) {
- if (marker.getResource().getType() == IResource.FILE)
- {
- IDOMModel domModel = null;
- try {
- domModel = (IDOMModel)StructuredModelManager.getModelManager().getModelForRead((IFile)marker.getResource());
- return domModel.getStructuredDocument();
- } catch(Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- if (domModel != null) {
- domModel.releaseFromRead();
- }
+
+ public static void performOnRootElement(IFile resource, NodeOperation<Element> operation) throws IOException, CoreException {
+ assert resource != null;
+ assert operation != null;
+ IDOMModel domModel = null;
+ try {
+ domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(resource);
+ if (domModel == null) {
+ throw new IllegalArgumentException("Document is not structured: " + resource);
}
- }
- return null;
- }
+ IStructuredDocument document = domModel.getStructuredDocument();
+ Element root = domModel.getDocument().getDocumentElement();
+ operation.process(root, document);
+ } finally {
+ if (domModel != null) {
+ domModel.releaseFromRead();
+ }
+ } }
/*
* calculates the path of the node up in the hierarchy, example of result is project/build/plugins/plugin
@@ -286,4 +289,6 @@ public class XmlUtils {
return buf.toString();
}
+
+
}

Back to the top