aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Piggott2011-02-24 14:24:37 (EST)
committerPascal Rapicault2011-03-03 16:35:20 (EST)
commit07fb9045d55d0f6e56798b52093e8d7e281c60b7 (patch)
treee2def71e1f64080904f0c57f0c085517eeed41a0
parent909cd54299758dbbd2d188230b4edc58e3d3a54d (diff)
downloadm2e-core-07fb9045d55d0f6e56798b52093e8d7e281c60b7.zip
m2e-core-07fb9045d55d0f6e56798b52093e8d7e281c60b7.tar.gz
m2e-core-07fb9045d55d0f6e56798b52093e8d7e281c60b7.tar.bz2
bug 337565 - Issues with Exclude Refactoring
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/AddExclusionOperation.java14
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/Messages.java4
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeArtifactRefactoring.java66
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/messages.properties6
4 files changed, 73 insertions, 17 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/AddExclusionOperation.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/AddExclusionOperation.java
index 9b5301c..967217c 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/AddExclusionOperation.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/AddExclusionOperation.java
@@ -8,9 +8,18 @@
package org.eclipse.m2e.core.ui.internal.editing;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.EXCLUSION;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.EXCLUSIONS;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.GROUP_ID;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.createElement;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.createElementWithText;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.format;
+import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.getChild;
+
import org.apache.maven.model.Dependency;
import org.eclipse.m2e.core.embedder.ArtifactKey;
-import static org.eclipse.m2e.core.ui.internal.editing.PomEdits.*;
+import org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -38,8 +47,7 @@ public class AddExclusionOperation implements Operation {
createElementWithText(exclusionElement, ARTIFACT_ID, exclusion.getArtifactId());
createElementWithText(exclusionElement, GROUP_ID, exclusion.getGroupId());
- //TODO mkleint: are there really exclusion versions??
- createElementWithText(exclusionElement, VERSION, exclusion.getVersion());
+ format(exclusionElement);
}
}
}
diff --git a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/Messages.java b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/Messages.java
index 50c8571..2b6b103 100644
--- a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/Messages.java
+++ b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/Messages.java
@@ -70,6 +70,10 @@ public class Messages extends NLS {
public static String SaveDirtyFilesDialog_title;
public static String SaveDirtyFilesDialog_title_error;
+
+ public static String ExcludeArtifactRefactoring_failedToLocateAnyArtifacts;
+
+ public static String ExcludeArtifactRefactoring_transitiveDependency;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeArtifactRefactoring.java b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeArtifactRefactoring.java
index 1e95e8d..c25cdfc 100644
--- a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeArtifactRefactoring.java
+++ b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeArtifactRefactoring.java
@@ -15,8 +15,10 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
+import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
@@ -50,7 +52,7 @@ public class ExcludeArtifactRefactoring extends AbstractPomHeirarchyRefactoring
private final ArtifactKey[] keys;
- private Set<ArtifactKey> locatedKeys;
+ private Map<ArtifactKey, Boolean> locatedKeys;
private Map<IFile, Change> operationMap;
@@ -78,14 +80,24 @@ public class ExcludeArtifactRefactoring extends AbstractPomHeirarchyRefactoring
if(keys == null || keys.length == 0) {
return new RefactoringStatusEntry[] {new RefactoringStatusEntry(RefactoringStatus.FATAL,
Messages.ExcludeArtifactRefactoring_noArtifactsSet)};
- }
+ }
+ if(locatedKeys.isEmpty()) {
+ return new RefactoringStatusEntry[] {new RefactoringStatusEntry(RefactoringStatus.FATAL,
+ Messages.ExcludeArtifactRefactoring_failedToLocateAnyArtifacts)};
+ }
List<RefactoringStatusEntry> entries = new ArrayList<RefactoringStatusEntry>();
for (ArtifactKey key : keys) {
- if (!locatedKeys.contains(key)) {
- entries.add(new RefactoringStatusEntry(RefactoringStatus.FATAL, NLS.bind(
+ if(!locatedKeys.containsKey(key)) {
+ entries.add(new RefactoringStatusEntry(RefactoringStatus.INFO, NLS.bind(
Messages.ExcludeArtifactRefactoring_failedToLocateArtifact, key.toString())));
}
}
+ for(Entry<ArtifactKey, Boolean> entry : locatedKeys.entrySet()) {
+ if(entry.getValue()) {
+ entries.add(new RefactoringStatusEntry(RefactoringStatus.INFO, NLS.bind(
+ Messages.ExcludeArtifactRefactoring_transitiveDependency, entry.getKey().toString())));
+ }
+ }
return entries.toArray(new RefactoringStatusEntry[entries.size()]);
}
@@ -100,7 +112,7 @@ public class ExcludeArtifactRefactoring extends AbstractPomHeirarchyRefactoring
* @see org.eclipse.m2e.refactoring.AbstractPomHeirarchyRefactoring#checkInitial(org.eclipse.core.runtime.IProgressMonitor)
*/
protected void checkInitial(IProgressMonitor pm) {
- locatedKeys = new HashSet<ArtifactKey>(keys.length);
+ locatedKeys = new HashMap<ArtifactKey, Boolean>(keys.length);
operationMap = new HashMap<IFile, Change>();
}
@@ -128,6 +140,7 @@ public class ExcludeArtifactRefactoring extends AbstractPomHeirarchyRefactoring
final StringBuilder msg = new StringBuilder();
final List<org.apache.maven.model.Dependency> dependencies = m.getDependencies();
+ final Map<Dependency, Set<ArtifactKey>> toAdd = new HashMap<Dependency, Set<ArtifactKey>>();
MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager();
DependencyNode root = modelManager.readDependencyTree(project, JavaScopes.TEST, monitor.newChild(1));
@@ -137,8 +150,13 @@ public class ExcludeArtifactRefactoring extends AbstractPomHeirarchyRefactoring
private DependencyNode topLevel;
+ private int exclusionDepth = -1;
+
public boolean visitLeave(DependencyNode node) {
depth-- ;
+ if(depth <= exclusionDepth) {
+ exclusionDepth = -1;
+ }
return status[0] == null;
}
@@ -158,20 +176,29 @@ public class ExcludeArtifactRefactoring extends AbstractPomHeirarchyRefactoring
msg.append(key.toString()).append(',');
// need to remove top-level dependency
operations.add(new RemoveDependencyOperation(findDependency(topLevel)));
- locatedKeys.add(key);
+ locatedKeys.put(key, Boolean.FALSE);
} else {
// need to add exclusion to top-level dependency
- org.apache.maven.model.Dependency dependency = findDependency(topLevel);
+ Dependency dependency = findDependency(topLevel);
if(dependency == null) {
status[0] = new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, NLS.bind(
Messages.ExcludeRefactoring_error_parent, topLevel.getDependency().getArtifact().getGroupId(),
topLevel.getDependency().getArtifact().getArtifactId()));
+ } else if(exclusionDepth == -1) {
+ // Used to avoid errors for transitive dependencies of excluded dependencies.
+ Set<ArtifactKey> keys = toAdd.get(dependency);
+ if(keys == null) {
+ keys = new HashSet<ArtifactKey>();
+ toAdd.put(dependency, keys);
+ }
+ keys.add(key);
+ exclusionDepth = depth;
+ locatedKeys.put(key, Boolean.FALSE);
} else {
- operations.add(new AddExclusionOperation(dependency, key));
- locatedKeys.add(key);
+ locatedKeys.put(key, Boolean.TRUE);
}
}
- return false;
+ return true;
}
}
}
@@ -179,7 +206,7 @@ public class ExcludeArtifactRefactoring extends AbstractPomHeirarchyRefactoring
return true;
}
- private org.apache.maven.model.Dependency findDependency(String groupId, String artifactId) {
+ private Dependency findDependency(String groupId, String artifactId) {
for(org.apache.maven.model.Dependency d : dependencies) {
if(d.getGroupId().equals(groupId) && d.getArtifactId().equals(artifactId)) {
return d;
@@ -188,7 +215,7 @@ public class ExcludeArtifactRefactoring extends AbstractPomHeirarchyRefactoring
return null;
}
- private org.apache.maven.model.Dependency findDependency(DependencyNode node) {
+ private Dependency findDependency(DependencyNode node) {
Artifact artifact;
if(node.getRelocations().isEmpty()) {
artifact = node.getDependency().getArtifact();
@@ -199,10 +226,25 @@ public class ExcludeArtifactRefactoring extends AbstractPomHeirarchyRefactoring
}
});
+ for(Entry<Dependency, Set<ArtifactKey>> entry : toAdd.entrySet()) {
+ for(ArtifactKey key : entry.getValue()) {
+ operations.add(new AddExclusionOperation(entry.getKey(), key));
+ }
+ }
+
if(operations.size() > 0) {
operationMap.put(pomFile, PomHelper.createChange(pomFile,
new CompoundOperation(operations.toArray(new Operation[operations.size()])), msg.toString()));
}
return !operations.isEmpty();
}
+
+ private void set(ArtifactKey key, Boolean bool) {
+ Boolean old = locatedKeys.get(key);
+ if(old == null) {
+ locatedKeys.put(key, bool);
+ } else {
+ locatedKeys.put(key, old & bool);
+ }
+ }
} \ No newline at end of file
diff --git a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/messages.properties b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/messages.properties
index f8a24e9..bcfadc3 100644
--- a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/messages.properties
+++ b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/messages.properties
@@ -6,11 +6,13 @@ ExcludeRefactoring_name=Exclude Maven Artifact
ExcludeRefactoring_task_loading=Loading dependency tree
ExcludeRefactoring_title=Excluding {0}:{1} from {2}
AbstractPomHeirarchyRefactoring_failedToLoadModel=Failed to load model
-ExcludeArtifactRefactoring_failedToLocateArtifact=Failed to locate: {0}
+ExcludeArtifactRefactoring_failedToLocateAnyArtifacts=Unable to locate any dependencies in workspace
+ExcludeArtifactRefactoring_failedToLocateArtifact=Unable to locate source for dependency {0} in the workspace.
ExcludeArtifactRefactoring_noArtifactsSet=No Artifacts to exclude
+ExcludeArtifactRefactoring_refactoringName=Exclude Artifacts: {0}
+ExcludeArtifactRefactoring_transitiveDependency={0} is a transitive dependency of another exclusion and won't be explicitly set.
AbstractPomHeirarchyRefactoring_noModelOrPom=Model does not exist
AbstractPomHeirarchyRefactoring_noTargets=No pom found for operation
-ExcludeArtifactRefactoring_refactoringName=Exclude Artifacts: {0}
MavenRenameWizardPage_cbRenameWorkspace=&Rename Eclipse project in Workspace
MavenRenameWizardPage_desc=Specify new group Id, artifact Id or version
MavenRenameWizardPage_lblArtifactId=&Artifact Id: