Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Piggott2011-03-02 22:29:27 +0000
committerPascal Rapicault2011-03-03 21:35:21 +0000
commitd72dde2c91da6d04a18455e291adc804b87dbdee (patch)
tree8be728149105ed3f8d0dfd4de688a2d97bf78e84 /org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude
parent98b50bf774feaad18250c77c2f8ab904e048ff2e (diff)
downloadm2e-core-d72dde2c91da6d04a18455e291adc804b87dbdee.tar.gz
m2e-core-d72dde2c91da6d04a18455e291adc804b87dbdee.tar.xz
m2e-core-d72dde2c91da6d04a18455e291adc804b87dbdee.zip
bug 337565 - Exclude Refactoring Issues
Diffstat (limited to 'org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude')
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/DependencyExcludeAction.java2
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeArtifactRefactoring.java411
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeWizardPage.java149
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/MavenExcludeWizard.java8
4 files changed, 419 insertions, 151 deletions
diff --git a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/DependencyExcludeAction.java b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/DependencyExcludeAction.java
index 490aabc5..fbbd5fa4 100644
--- a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/DependencyExcludeAction.java
+++ b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/DependencyExcludeAction.java
@@ -48,7 +48,7 @@ public class DependencyExcludeAction implements IActionDelegate {
public void run(IAction action) {
if(keys != null && file != null) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- ExcludeArtifactRefactoring r = new ExcludeArtifactRefactoring(keys, file);
+ ExcludeArtifactRefactoring r = new ExcludeArtifactRefactoring(file, keys);
MavenExcludeWizard wizard = new MavenExcludeWizard(r);
try {
String titleForFailedChecks = ""; //$NON-NLS-1$
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 c25cdfc8..0d61efd7 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
@@ -11,6 +11,7 @@
package org.eclipse.m2e.refactoring.exclude;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -21,25 +22,28 @@ 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.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.core.IMavenConstants;
import org.eclipse.m2e.core.embedder.ArtifactKey;
-import org.eclipse.m2e.core.embedder.MavenModelManager;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.core.ui.internal.editing.AddDependencyOperation;
import org.eclipse.m2e.core.ui.internal.editing.AddExclusionOperation;
import org.eclipse.m2e.core.ui.internal.editing.PomEdits.CompoundOperation;
import org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation;
import org.eclipse.m2e.core.ui.internal.editing.PomHelper;
import org.eclipse.m2e.core.ui.internal.editing.RemoveDependencyOperation;
-import org.eclipse.m2e.refactoring.AbstractPomHeirarchyRefactoring;
import org.eclipse.m2e.refactoring.Messages;
import org.eclipse.osgi.util.NLS;
import org.sonatype.aether.artifact.Artifact;
@@ -48,203 +52,316 @@ import org.sonatype.aether.graph.DependencyVisitor;
import org.sonatype.aether.util.artifact.JavaScopes;
-public class ExcludeArtifactRefactoring extends AbstractPomHeirarchyRefactoring {
+public class ExcludeArtifactRefactoring extends Refactoring {
- private final ArtifactKey[] keys;
+ private ArtifactKey[] keys;
- private Map<ArtifactKey, Boolean> locatedKeys;
+ private IFile pomFile;
- private Map<IFile, Change> operationMap;
+ private MavenProject exclusionPoint;
- public ExcludeArtifactRefactoring(ArtifactKey[] keys, IFile pom) {
- super(pom);
+ private List<MavenProject> hierarchy;
+
+ private Set<ArtifactKey> locatedKeys;
+
+ public ExcludeArtifactRefactoring(IFile pomFile, ArtifactKey[] keys) {
+ this.pomFile = pomFile;
this.keys = keys;
}
+ public void setExclusionPoint(MavenProject exclusionPoint) {
+ this.exclusionPoint = exclusionPoint;
+ }
+
+ public void setHierarchy(List<MavenProject> hierarchy) {
+ this.hierarchy = hierarchy;
+ }
+
+ public IMavenProjectFacade getSource() {
+ return getMavenProjectFacade(pomFile);
+ }
+
+ protected IMavenProjectFacade getMavenProjectFacade(IFile pom) {
+ return MavenPlugin.getDefault().getMavenProjectManager().create(pom, true, new NullProgressMonitor());
+ }
+
+ protected IMavenProjectFacade getMavenProjectFacade(MavenProject mavenProject) {
+ return MavenPlugin.getDefault().getMavenProjectManager()
+ .getMavenProject(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion());
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.Refactoring#getName()
*/
public String getName() {
- StringBuilder builder = new StringBuilder();
+ StringBuilder sb = new StringBuilder();
+ sb.append("Exclude: ");
for(ArtifactKey key : keys) {
- builder.append(key.toString()).append(", ");
+ sb.append(key.toString()).append(',');
+ }
+ sb.deleteCharAt(sb.length() - 1);
+ return sb.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Refactoring#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ exclusionPoint = getMavenProjectFacade(pomFile).getMavenProject(pm);
+ if(exclusionPoint == null) {
+ return RefactoringStatus
+ .createFatalErrorStatus("MavenProject does not exist, try cleaning workspace & rebuilding");
}
- builder.delete(builder.length() - 2, builder.length());
- return NLS.bind(Messages.ExcludeArtifactRefactoring_refactoringName, builder.toString());
+ return new RefactoringStatus();
}
+ private List<Change> changes;
+
/* (non-Javadoc)
- * @see org.eclipse.m2e.refactoring.exclude.AbstractRefactoring#isReady(org.eclipse.core.runtime.IProgressMonitor)
+ * @see org.eclipse.ltk.core.refactoring.Refactoring#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor)
*/
- protected RefactoringStatusEntry[] isReady(IProgressMonitor pm) {
- 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.containsKey(key)) {
- entries.add(new RefactoringStatusEntry(RefactoringStatus.INFO, NLS.bind(
- Messages.ExcludeArtifactRefactoring_failedToLocateArtifact, key.toString())));
+ public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ changes = new ArrayList<Change>();
+ locatedKeys = new HashSet<ArtifactKey>();
+ List<IStatus> statuses = new ArrayList<IStatus>();
+ SubMonitor monitor = SubMonitor.convert(pm, getHierarchy().size());
+
+ List<Operation> exclusionOp = new ArrayList<Operation>();
+ // Exclusion point
+ Visitor visitor = locate(exclusionPoint, monitor.newChild(1));
+ for(Entry<Dependency, Set<ArtifactKey>> entry : visitor.getSourceMap().entrySet()) {
+ exclusionPoint.getOriginalModel().getDependencies();
+ locatedKeys.addAll(entry.getValue());
+ if(contains(entry.getValue(), entry.getKey())) {
+ exclusionOp.add(new RemoveDependencyOperation(entry.getKey()));
+ } else {
+ for(ArtifactKey key : entry.getValue()) {
+ exclusionOp.add(new AddExclusionOperation(entry.getKey(), key));
+ }
+ }
+ }
+
+ // Below exclusion point - pull up dependency to exclusion point
+ for(MavenProject project : getDescendants()) {
+ visitor = locate(project, monitor.newChild(1));
+ for(Entry<Dependency, Set<ArtifactKey>> entry : visitor.getSourceMap().entrySet()) {
+ locatedKeys.addAll(entry.getValue());
+ if(contains(entry.getValue(), entry.getKey())) {
+ changes.add(PomHelper.createChange(getFile(project), new RemoveDependencyOperation(entry.getKey()),
+ "Remove dependency {0}"));
+ } else {
+ CompositeChange change = new CompositeChange("Move dependency {0}");
+ change.add(PomHelper.createChange(getFile(project), new RemoveDependencyOperation(entry.getKey()),
+ "Remove dependency {0}"));
+ exclusionOp.add(new AddDependencyOperation(entry.getKey()));
+ for(ArtifactKey key : entry.getValue()) {
+ exclusionOp.add(new AddExclusionOperation(entry.getKey(), key));
+ }
+ }
+ }
+ if(!visitor.getStatus().isOK()) {
+ statuses.add(visitor.getStatus());
}
}
- for(Entry<ArtifactKey, Boolean> entry : locatedKeys.entrySet()) {
- if(entry.getValue()) {
- entries.add(new RefactoringStatusEntry(RefactoringStatus.INFO, NLS.bind(
- Messages.ExcludeArtifactRefactoring_transitiveDependency, entry.getKey().toString())));
+
+ // Above exclusion - Add dep to exclusionPoint
+ for(MavenProject project : getAncestors()) {
+ visitor = locate(project, monitor.newChild(1));
+ for(Entry<Dependency, Set<ArtifactKey>> entry : locate(project, monitor.newChild(1)).getSourceMap().entrySet()) {
+ locatedKeys.addAll(entry.getValue());
+ if(contains(entry.getValue(), entry.getKey())) {
+ if(project.getFile() != null) {
+ changes.add(PomHelper.createChange(getFile(project), new RemoveDependencyOperation(entry.getKey()),
+ "Remove dependency {0}"));
+ }
+ } else {
+ exclusionOp.add(new AddDependencyOperation(entry.getKey()));
+ for(ArtifactKey key : entry.getValue()) {
+ exclusionOp.add(new AddExclusionOperation(entry.getKey(), key));
+ }
+ }
}
+ if(!visitor.getStatus().isOK()) {
+ statuses.add(visitor.getStatus());
+ }
+ }
+ changes.add(PomHelper.createChange(getFile(exclusionPoint),
+ new CompoundOperation(exclusionOp.toArray(new Operation[exclusionOp.size()])), getName()));
+
+ if(statuses.size() == 1) {
+ return RefactoringStatus.create(statuses.get(0));
+ } else if(statuses.size() > 1) {
+ return RefactoringStatus.create(new MultiStatus("org.eclipse.m2e.refactoring", 0, statuses
+ .toArray(new IStatus[statuses.size()]), "Errors occurred creating refactoring", null));
+ } else if(locatedKeys.isEmpty()) {
+ return RefactoringStatus.createFatalErrorStatus(Messages.AbstractPomHeirarchyRefactoring_noTargets);
+ } else if(locatedKeys.size() != keys.length) {
+ StringBuilder sb = new StringBuilder();
+ for(ArtifactKey key : keys) {
+ if(!locatedKeys.contains(key)) {
+ sb.append(key.toString()).append(',');
+ }
+ }
+ sb.deleteCharAt(sb.length() - 1);
+ return RefactoringStatus.createErrorStatus(NLS.bind(Messages.ExcludeArtifactRefactoring_failedToLocateArtifact,
+ sb.toString()));
}
- return entries.toArray(new RefactoringStatusEntry[entries.size()]);
+ return new RefactoringStatus();
}
- /* (non-Javadoc)
- * @see org.eclipse.m2e.refactoring.AbstractRefactoring#getChange(org.apache.maven.project.MavenProject, org.eclipse.core.runtime.IProgressMonitor)
- */
- protected Change getChange(IFile file, IProgressMonitor pm) {
- return operationMap.get(file);
+ private Visitor locate(MavenProject project, IProgressMonitor monitor) throws CoreException {
+ DependencyNode root = MavenPlugin.getDefault().getMavenModelManager()
+ .readDependencyTree(project, JavaScopes.TEST, monitor);
+ Visitor visitor = new Visitor(project);
+ root.accept(visitor);
+ return visitor;
}
/* (non-Javadoc)
- * @see org.eclipse.m2e.refactoring.AbstractPomHeirarchyRefactoring#checkInitial(org.eclipse.core.runtime.IProgressMonitor)
+ * @see org.eclipse.ltk.core.refactoring.Refactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)
*/
- protected void checkInitial(IProgressMonitor pm) {
- locatedKeys = new HashMap<ArtifactKey, Boolean>(keys.length);
- operationMap = new HashMap<IFile, Change>();
+ public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ CompositeChange change = new CompositeChange(getName());
+ change.addAll(changes.toArray(new Change[changes.size()]));
+ return change;
}
- /* (non-Javadoc)
- * @see org.eclipse.m2e.refactoring.AbstractPomHeirarchyRefactoring#checkFinal(org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void checkFinal(IProgressMonitor pm) {
- // Do nothing
+ private static boolean matches(Dependency d, ArtifactKey a) {
+ return d.getArtifactId().equals(a.getArtifactId()) && d.getGroupId().equals(a.getGroupId());
}
- /* (non-Javadoc)
- * @see org.eclipse.m2e.refactoring.AbstractPomHeirarchyRefactoring#isAffected(org.eclipse.m2e.core.project.IMavenProjectFacade, org.eclipse.core.runtime.IProgressMonitor)
- */
- protected boolean isAffected(IFile pomFile, IProgressMonitor progressMonitor) throws CoreException {
+ private static boolean contains(Set<ArtifactKey> keys, Dependency d) {
+ for(ArtifactKey key : keys) {
+ if(matches(d, key)) {
+ return true;
+ }
+ }
+ return false;
+ }
- final SubMonitor monitor = SubMonitor.convert(progressMonitor);
- final IStatus[] status = new IStatus[1];
+ private Collection<MavenProject> getHierarchy() {
+ return hierarchy;
+ }
- final IMavenProjectFacade facade = MavenPlugin.getDefault().getMavenProjectManagerImpl()
- .create(pomFile, true, monitor);
- final MavenProject project = facade.getMavenProject(progressMonitor);
- final org.apache.maven.model.Model m = project.getModel();
+ private IFile getFile(MavenProject project) {
+ IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(project.getFile().toURI());
+ if(files.length == 0) {
+ // TODO something
+ return null;
+ } else {
+ return files[0];
+ }
+ }
- final List<Operation> operations = new ArrayList<Operation>();
+ private Collection<MavenProject> getDescendants() {
+ List<MavenProject> descendants = new ArrayList<MavenProject>();
+ boolean add = true;
+ for(MavenProject project : getHierarchy()) {
+ if(project == exclusionPoint) {
+ add = !add;
+ } else if(add) {
+ descendants.add(project);
+ }
+ }
+ return descendants;
+ }
- 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>>();
+ private Collection<MavenProject> getAncestors() {
+ List<MavenProject> ancestors = new ArrayList<MavenProject>();
+ boolean add = false;
+ for(MavenProject project : getHierarchy()) {
+ if(project == exclusionPoint) {
+ add = !add;
+ } else if(add) {
+ ancestors.add(project);
+ }
+ }
+ return ancestors;
+ }
- MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager();
- DependencyNode root = modelManager.readDependencyTree(project, JavaScopes.TEST, monitor.newChild(1));
- root.accept(new DependencyVisitor() {
+ private class Visitor implements DependencyVisitor {
+ private List<IStatus> statuses = new ArrayList<IStatus>();
- private int depth;
+ private List<Dependency> dependencies;
- private DependencyNode topLevel;
+ private Map<Dependency, Set<ArtifactKey>> sourceMap = new HashMap<Dependency, Set<ArtifactKey>>();
- private int exclusionDepth = -1;
+ Visitor(MavenProject project) {
+ dependencies = project.getOriginalModel().getDependencies();
+ }
- public boolean visitLeave(DependencyNode node) {
- depth-- ;
- if(depth <= exclusionDepth) {
- exclusionDepth = -1;
- }
- return status[0] == null;
+ IStatus getStatus() {
+ if(statuses.isEmpty()) {
+ return Status.OK_STATUS;
}
+ return new MultiStatus("org.eclipse.m2e.refactoring", 0, statuses.toArray(new IStatus[statuses.size()]),
+ "Errors occurred", null);
+ }
- public boolean visitEnter(DependencyNode node) {
- if(depth == 1) {
- topLevel = node;
- }
- depth++ ;
-
- if(node.getDependency() != null) {
- Artifact a = node.getDependency().getArtifact();
- for(ArtifactKey key : keys) {
- if(a.getGroupId().equals(key.getGroupId()) && a.getArtifactId().equals(key.getArtifactId())) {
- if(topLevel == null) {
- // do not touch itself
- } else if(node == topLevel) {
- msg.append(key.toString()).append(',');
- // need to remove top-level dependency
- operations.add(new RemoveDependencyOperation(findDependency(topLevel)));
- locatedKeys.put(key, Boolean.FALSE);
- } else {
- // need to add exclusion to top-level dependency
- 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 {
- locatedKeys.put(key, Boolean.TRUE);
- }
- }
- return true;
- }
- }
- }
+ Map<Dependency, Set<ArtifactKey>> getSourceMap() {
+ return sourceMap;
+ }
- return true;
- }
+ private int depth;
- 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;
- }
- }
- return null;
+ private DependencyNode topLevel;
+
+ public boolean visitLeave(DependencyNode node) {
+ depth-- ;
+ return true;
+ // TODO return status == null;
+ }
+
+ public boolean visitEnter(DependencyNode node) {
+ if(depth == 1) {
+ topLevel = node;
}
+ depth++ ;
- private Dependency findDependency(DependencyNode node) {
- Artifact artifact;
- if(node.getRelocations().isEmpty()) {
- artifact = node.getDependency().getArtifact();
- } else {
- artifact = node.getRelocations().get(0);
+ if(node.getDependency() != null) {
+ Artifact a = node.getDependency().getArtifact();
+ for(ArtifactKey key : keys) {
+ if(a.getGroupId().equals(key.getGroupId()) && a.getArtifactId().equals(key.getArtifactId())) {
+ if(topLevel != null) {
+ // need to add exclusion to top-level dependency
+ Dependency dependency = findDependency(topLevel);
+ if(dependency != null) {
+ put(dependency, key);
+ }
+ }
+ return true;
+ }
}
- return findDependency(artifact.getGroupId(), artifact.getArtifactId());
}
- });
+ return true;
+ }
- for(Entry<Dependency, Set<ArtifactKey>> entry : toAdd.entrySet()) {
- for(ArtifactKey key : entry.getValue()) {
- operations.add(new AddExclusionOperation(entry.getKey(), key));
+ private void put(Dependency dep, ArtifactKey key) {
+ Set<ArtifactKey> keys = sourceMap.get(dep);
+ if(keys == null) {
+ keys = new HashSet<ArtifactKey>();
+ sourceMap.put(dep, keys);
}
+ keys.add(key);
}
- if(operations.size() > 0) {
- operationMap.put(pomFile, PomHelper.createChange(pomFile,
- new CompoundOperation(operations.toArray(new Operation[operations.size()])), msg.toString()));
+ private Dependency findDependency(String groupId, String artifactId) {
+ for(Dependency d : dependencies) {
+ if(d.getGroupId().equals(groupId) && d.getArtifactId().equals(artifactId)) {
+ return d;
+ }
+ }
+ return null;
}
- 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);
+ private Dependency findDependency(DependencyNode node) {
+ Artifact artifact;
+ if(node.getRelocations().isEmpty()) {
+ artifact = node.getDependency().getArtifact();
+ } else {
+ artifact = node.getRelocations().get(0);
+ }
+ return findDependency(artifact.getGroupId(), artifact.getArtifactId());
}
}
} \ No newline at end of file
diff --git a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeWizardPage.java b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeWizardPage.java
new file mode 100644
index 00000000..f4b7917f
--- /dev/null
+++ b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeWizardPage.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.refactoring.exclude;
+
+import org.apache.maven.project.MavenProject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.editor.composites.PomHierarchyComposite;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+
+public class ExcludeWizardPage extends UserInputWizardPage implements SelectionListener, ISelectionChangedListener {
+
+ private PomHierarchyComposite pomHierarchy;
+
+ private Button currentPom;
+
+ private Button hierarchy;
+
+ private IMavenProjectFacade facade;
+
+ private CLabel label;
+
+ protected ExcludeWizardPage(IMavenProjectFacade facade) {
+ super("Place to exclude");
+ this.facade = facade;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ setControl(composite);
+ composite.setLayout(new GridLayout(1, false));
+
+ currentPom = new Button(composite, SWT.RADIO);
+ currentPom.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
+ currentPom.setText("Selected pom");
+ currentPom.setSelection(true);
+ currentPom.addSelectionListener(this);
+
+ hierarchy = new Button(composite, SWT.RADIO);
+ hierarchy.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
+ hierarchy.setText("Choose from project hierarchy");
+ hierarchy.addSelectionListener(this);
+
+ pomHierarchy = new PomHierarchyComposite(composite, SWT.BORDER);
+ GridData gd_pomHierarchy = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gd_pomHierarchy.horizontalIndent = 15;
+ pomHierarchy.setLayoutData(gd_pomHierarchy);
+ pomHierarchy.setEnabled(false);
+ pomHierarchy.addSelectionChangedListener(this);
+
+ label = new CLabel(composite, SWT.NONE);
+ label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
+
+ Display.getCurrent().asyncExec(new Runnable() {
+ public void run() {
+ pomHierarchy.computeHeirarchy(facade, getContainer());
+ ((ExcludeArtifactRefactoring) getRefactoring()).setHierarchy(pomHierarchy.getHierarchy());
+ }
+ });
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+ if(e.getSource() == currentPom) {
+ pomHierarchy.setEnabled(false);
+ } else if(e.getSource() == hierarchy) {
+ pomHierarchy.setEnabled(true);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+
+ private void setStatus(String msg) {
+ if(msg == null) {
+ label.setImage(null);
+ label.setText("");
+ } else {
+ label.setText(msg);
+ label.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
+ }
+ }
+
+ private void updateState() {
+ ExcludeArtifactRefactoring refactoring = (ExcludeArtifactRefactoring) getRefactoring();
+ if(pomHierarchy.isEnabled()) {
+ MavenProject project = fromSelection(pomHierarchy.getSelection());
+ setPageComplete(project != null && project.getFile() != null);
+ if(project != null && project.getFile() == null) {
+ setStatus("Changes must occur within the workspace");
+ } else {
+ setStatus(null);
+ refactoring.setExclusionPoint(fromSelection(pomHierarchy.getSelection()));
+ }
+ } else {
+ setStatus(null);
+ refactoring.setExclusionPoint(facade.getMavenProject());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ updateState();
+ }
+
+ private MavenProject fromSelection(ISelection selection) {
+ if(selection instanceof IStructuredSelection) {
+ Object obj = ((IStructuredSelection) selection).getFirstElement();
+ if(obj instanceof MavenProject) {
+ return (MavenProject) obj;
+ }
+ }
+ return null;
+ }
+}
diff --git a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/MavenExcludeWizard.java b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/MavenExcludeWizard.java
index f707929f..803be06e 100644
--- a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/MavenExcludeWizard.java
+++ b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/MavenExcludeWizard.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
+ * 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
@@ -13,12 +13,13 @@ package org.eclipse.m2e.refactoring.exclude;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
-
/**
* @author Anton Kraev
*/
public class MavenExcludeWizard extends RefactoringWizard {
+ private ExcludeWizardPage excludePage;
+
public MavenExcludeWizard(ExcludeArtifactRefactoring refactoring) {
super(refactoring, DIALOG_BASED_USER_INTERFACE);
}
@@ -26,6 +27,7 @@ public class MavenExcludeWizard extends RefactoringWizard {
@Override
protected void addUserInputPages() {
setDefaultPageTitle(getRefactoring().getName());
+ excludePage = new ExcludeWizardPage(((ExcludeArtifactRefactoring) getRefactoring()).getSource());
+ addPage(excludePage);
}
-
}

Back to the top