Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2011-02-21 03:16:30 -0500
committerMilos Kleint2011-02-21 03:16:30 -0500
commit11413b73a1a99a31a64a0a09cbc5a4c847be8d89 (patch)
treeaaf44cc020bbeccde1ab24d26b3a12f12c103a7a /org.eclipse.m2e.editor.xml
parent6ebbf4907dd0b0c5d110f7dda28cae363f214adc (diff)
downloadm2e-core-11413b73a1a99a31a64a0a09cbc5a4c847be8d89.tar.gz
m2e-core-11413b73a1a99a31a64a0a09cbc5a4c847be8d89.tar.xz
m2e-core-11413b73a1a99a31a64a0a09cbc5a4c847be8d89.zip
refactoring, introduce constants for elements, move some methods to PomHelper
Diffstat (limited to 'org.eclipse.m2e.editor.xml')
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertArtifactProposal.java29
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingOperation.java25
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java18
3 files changed, 35 insertions, 37 deletions
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertArtifactProposal.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertArtifactProposal.java
index ab812e06..9a356077 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertArtifactProposal.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/InsertArtifactProposal.java
@@ -11,13 +11,7 @@
package org.eclipse.m2e.editor.xml;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.elementAtOffset;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChild;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.format;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.getChild;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.insertAt;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.setText;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.*;
import java.io.IOException;
@@ -107,13 +101,13 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP
final int fOffset = offset;
performOnDOMDocument(new OperationTuple(document, new Operation() {
public void process(Document doc) {
- Element parent = insertAt(doc.createElement("parent"), fOffset);
- setText(getChild(parent, "groupId"), af.group);
- setText(getChild(parent, "artifactId"), af.artifact);
- setText(getChild(parent, "version"), af.version);
+ Element parent = insertAt(doc.createElement(PARENT), fOffset);
+ setText(getChild(parent, GROUP_ID), af.group);
+ setText(getChild(parent, ARTIFACT_ID), af.artifact);
+ setText(getChild(parent, VERSION), af.version);
String relativePath = PomContentAssistProcessor.findRelativePath(sourceViewer, af.group, af.artifact, af.version);
if (relativePath != null) {
- setText(getChild(parent, "relativePath"), relativePath);
+ setText(getChild(parent, RELATIVE_PATH), relativePath);
}
format(parent);
generatedOffset = ((IndexedRegion)parent).getStartOffset();
@@ -142,14 +136,12 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP
Element plugin = null;
Element toFormat = null;
if("project".equals(currentName)) { //$NON-NLS-1$
- Element build = findChild(currentNode, "build");
+ Element build = findChild(currentNode, BUILD);
if(build == null) {
- build = insertAt(doc.createElement("build"), fOffset);
+ build = insertAt(doc.createElement(BUILD), fOffset);
toFormat = build;
}
- Element plugins = getChild(build, "plugins");
- plugin = doc.createElement("plugin");
- plugins.appendChild(plugin);
+ plugin = createElement(getChild(build, PLUGINS), PLUGIN);
}
if("build".equals(currentName) || "pluginManagement".equals(currentName)) { //$NON-NLS-1$ //$NON-NLS-2$
Element plugins = findChild(currentNode, "plugins");
@@ -157,8 +149,7 @@ public class InsertArtifactProposal implements ICompletionProposal, ICompletionP
plugins = insertAt(doc.createElement("plugins"), fOffset);
toFormat = plugins;
}
- plugin = doc.createElement("plugin");
- plugins.appendChild(plugin);
+ plugin = createElement(plugins, PLUGIN);
}
if("plugins".equals(currentName)) {
plugin = insertAt(doc.createElement("plugin"), fOffset);
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 c9e75330..3441d068 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
@@ -11,15 +11,7 @@
package org.eclipse.m2e.editor.xml.internal.lifecycle;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.childEquals;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.createElementWithText;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.createPlugin;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChild;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChilds;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.format;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.getChild;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.getTextValue;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.setText;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.*;
import java.util.ArrayList;
import java.util.Arrays;
@@ -37,8 +29,11 @@ import org.w3c.dom.Element;
import org.eclipse.m2e.core.internal.lifecycle.LifecycleMappingFactory;
import org.eclipse.m2e.core.internal.lifecycle.model.PluginExecutionAction;
import org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation;
+import org.eclipse.m2e.core.ui.internal.editing.PomHelper;
public class LifecycleMappingOperation implements Operation {
+
+
private static final Logger log = LoggerFactory.getLogger(LifecycleMappingOperation.class);
private static final String LIFECYCLE_PLUGIN_VERSION = LifecycleMappingFactory.LIFECYCLE_MAPPING_PLUGIN_VERSION;
@@ -66,20 +61,20 @@ public class LifecycleMappingOperation implements Operation {
public void process(Document document) {
Element root = document.getDocumentElement();
- Element managedPlugins = getChild(root, "build", "pluginManagement", "plugins");
+ Element managedPlugins = getChild(root, BUILD, PLUGIN_MANAGEMENT, PLUGINS);
//now find the lifecycle stuff if it's there.
- Element lifecyclePlugin = findChild(managedPlugins, "plugin",
- childEquals("groupId", LIFECYCLE_PLUGIN_GROUPID),
- childEquals("artifactId", LIFECYCLE_PLUGIN_ARTIFACTID));
+ Element lifecyclePlugin = findChild(managedPlugins, PLUGIN,
+ childEquals(GROUP_ID, LIFECYCLE_PLUGIN_GROUPID),
+ childEquals(ARTIFACT_ID, LIFECYCLE_PLUGIN_ARTIFACTID));
if (lifecyclePlugin == null) {
//not found, create
- lifecyclePlugin = createPlugin(managedPlugins, LIFECYCLE_PLUGIN_GROUPID, LIFECYCLE_PLUGIN_ARTIFACTID, LIFECYCLE_PLUGIN_VERSION);
+ lifecyclePlugin = PomHelper.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");
+ Element pluginExecutions = getChild(lifecyclePlugin, CONFIGURATION, "lifecycleMappingMetadata", "pluginExecutions");
//now find the plugin execution for the plugin we have..
Element execution = null;
for (Element exec : findChilds(pluginExecutions, "pluginExecution")) {
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 73367286..8fc9676d 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
@@ -1,3 +1,15 @@
+/*******************************************************************************
+ * 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;
@@ -23,7 +35,7 @@ import org.eclipse.ui.texteditor.MarkerAnnotation;
import org.eclipse.m2e.core.core.IMavenConstants;
import org.eclipse.m2e.core.internal.lifecycle.model.PluginExecutionAction;
-import org.eclipse.m2e.core.ui.internal.editing.PomEdits;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.*;
import org.eclipse.m2e.editor.xml.internal.Messages;
public class LifecycleMappingProposal implements ICompletionProposal, ICompletionProposalExtension5, IMarkerResolution {
@@ -48,7 +60,7 @@ public class LifecycleMappingProposal implements ICompletionProposal, ICompletio
public void apply(final IDocument doc) {
try {
- PomEdits.performOnDOMDocument(new PomEdits.OperationTuple(doc, createOperation()));
+ performOnDOMDocument(new OperationTuple(doc, createOperation()));
marker.delete();
} catch(IOException e) {
log.error("Error generating code in pom.xml", e); //$NON-NLS-1$
@@ -116,7 +128,7 @@ public class LifecycleMappingProposal implements ICompletionProposal, ICompletio
public void run(final IMarker marker) {
try {
- PomEdits.performOnDOMDocument(new PomEdits.OperationTuple((IFile) marker.getResource(), createOperation()));
+ performOnDOMDocument(new OperationTuple((IFile) marker.getResource(), createOperation()));
marker.delete();
} catch(IOException e) {
log.error("Error generating code in pom.xml", e); //$NON-NLS-1$

Back to the top