Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Piggott2011-04-14 10:07:23 -0400
committerMatthew Piggott2011-04-14 15:50:59 -0400
commit8eaaec7cefcb9b92a9a6bc9c4afc1dd11b10c082 (patch)
tree2691d0397371e12d190c99b42c6348c47f44c49c /org.eclipse.m2e.editor.xml
parent6b988a280d7575eda1fc19a1faedfdd92f4abe8c (diff)
downloadm2e-core-8eaaec7cefcb9b92a9a6bc9c4afc1dd11b10c082.tar.gz
m2e-core-8eaaec7cefcb9b92a9a6bc9c4afc1dd11b10c082.tar.xz
m2e-core-8eaaec7cefcb9b92a9a6bc9c4afc1dd11b10c082.zip
Move LifecycleMappingOperation to org.eclipse.m2e.core.ui
Diffstat (limited to 'org.eclipse.m2e.editor.xml')
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingOperation.java146
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingProposal.java1
2 files changed, 1 insertions, 146 deletions
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
deleted file mode 100644
index 08be2bfd..00000000
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingOperation.java
+++ /dev/null
@@ -1,146 +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 static org.eclipse.m2e.core.ui.internal.editing.PomEdits.*;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
-import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
-import org.apache.maven.artifact.versioning.VersionRange;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Comment;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
-import org.eclipse.m2e.core.lifecyclemapping.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;
-
- private static final String LIFECYCLE_PLUGIN_ARTIFACTID = LifecycleMappingFactory.LIFECYCLE_MAPPING_PLUGIN_ARTIFACTID;
-
- private static final String LIFECYCLE_PLUGIN_GROUPID = LifecycleMappingFactory.LIFECYCLE_MAPPING_PLUGIN_GROUPID;
-
- private String version;
- private String groupId;
- private String artifactId;
-
- private PluginExecutionAction action;
- private String[] goals;
-
- public LifecycleMappingOperation(String pluginGroupId, String pluginArtifactId, String pluginVersion,
- PluginExecutionAction action, String[] goals) {
- this.artifactId = pluginArtifactId;
- this.groupId = pluginGroupId;
- this.version = pluginVersion;
- assert !PluginExecutionAction.configurator.equals(action);
- this.action = action;
- this.goals = goals;
- }
-
- public void process(Document document) {
- Element root = document.getDocumentElement();
- Element managedPlugins = getChild(root, BUILD, PLUGIN_MANAGEMENT, PLUGINS);
- //now find the lifecycle stuff if it's there.
- Element lifecyclePlugin = findChild(managedPlugins, PLUGIN,
- childEquals(GROUP_ID, LIFECYCLE_PLUGIN_GROUPID),
- childEquals(ARTIFACT_ID, LIFECYCLE_PLUGIN_ARTIFACTID));
- if (lifecyclePlugin == null) {
- //not found, create
- 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");
- //now find the plugin execution for the plugin we have..
- Element execution = null;
- for (Element exec : findChilds(pluginExecutions, "pluginExecution")) {
- Element filter = findChild(exec, "pluginExecutionFilter",
- childEquals("groupId", groupId),
- childEquals("artifactId", artifactId));
- //the action needs to match the action we want..
- Element actionEl = findChild(findChild(exec, "action"), action.toString());
- if (filter != null && actionEl != null) {
- String versionRange = getTextValue(getChild(filter, "versionRange"));
- if (versionRange != null) { // paranoid null check
- //now we shall do some smart matching on the existing versionRange and our version..
- //so far the "smart" thing involves just overwriting the range.
- try {
- VersionRange range = VersionRange.createFromVersionSpec(versionRange);
- if (!range.containsVersion(new DefaultArtifactVersion(version))) {
- Element rangeEl = findChild(filter, "versionRange");
- setText(rangeEl, "[" + version + ",)");
- }
- } catch(InvalidVersionSpecificationException e) {
- log.error("Failed to parse version range:" + versionRange, e);
- }
- }
- execution = exec;
- break;
- }
- }
- if (execution == null) {
- execution = createPluginExecution(document, pluginExecutions);
- }
- //now enter/update the goal(s)..
- Element goalsEl = getChild(execution, "pluginExecutionFilter", "goals");
- List<String> toAddGoals = new ArrayList<String>(Arrays.asList(goals));
- for (Element existingGoal : findChilds(goalsEl, "goal")) {
- String glValue = getTextValue(existingGoal);
- if (glValue != null && toAddGoals.contains(glValue)) {
- toAddGoals.remove(glValue);
- }
- }
- if (toAddGoals.size() > 0) {
- for (String goal : toAddGoals) {
- format(createElementWithText(goalsEl, "goal", goal));
- }
- }
-
- }
-
- private Element createPluginExecution(Document document, Element parent) {
- Element exec = document.createElement("pluginExecution");
- parent.appendChild(exec);
- Element filter = document.createElement("pluginExecutionFilter");
- exec.appendChild(filter);
- createElementWithText(filter, "groupId", groupId);
- createElementWithText(filter, "artifactId", artifactId);
- createElementWithText(filter, "versionRange", "[" + version + ",)");
-
- Element actionEl = document.createElement("action");
- exec.appendChild(actionEl);
- Element actionEl2 = document.createElement(action.toString());
- actionEl.appendChild(actionEl2);
- if(PluginExecutionAction.execute.equals(action)) {
- actionEl2.appendChild(document.createComment("use <runOnIncremental>false</runOnIncremental>to only execute the mojo during full/clean build"));
- }
-
- format(exec);
- return exec;
- }
-
-}
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 ec84fe42..16c283c8 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
@@ -39,6 +39,7 @@ import org.eclipse.ui.texteditor.MarkerAnnotation;
import org.eclipse.m2e.core.core.IMavenConstants;
import org.eclipse.m2e.core.lifecyclemapping.model.PluginExecutionAction;
+import org.eclipse.m2e.core.ui.internal.editing.LifecycleMappingOperation;
import org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple;
import org.eclipse.m2e.editor.xml.internal.Messages;

Back to the top