Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2013-06-14 04:01:17 -0400
committerIgor Fedorenko2013-06-14 04:01:17 -0400
commit073ee9daf7613bd0ec83b00f5f0bfa615f796e0d (patch)
tree291be50381fbfb79ce824a3bb812a60fc6e082e8 /org.eclipse.m2e.refactoring
parenta04f6f45fd741929effaebc0a207ef467c3b45d9 (diff)
downloadm2e-core-073ee9daf7613bd0ec83b00f5f0bfa615f796e0d.tar.gz
m2e-core-073ee9daf7613bd0ec83b00f5f0bfa615f796e0d.tar.xz
m2e-core-073ee9daf7613bd0ec83b00f5f0bfa615f796e0d.zip
Reworked ParentGatherer and related pom.xml manipulations
Introduced ParentHierarchyEntry that encapsulates MavenProject and corresponding IMavenProjectFacade and reworked all clients of ParentGatherer to use ParentHierarchyEntry instead of brittle mapping between MavenProject and IMavenProjectFacade instances. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
Diffstat (limited to 'org.eclipse.m2e.refactoring')
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/Messages.java2
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/dependencyset/DependencySetAction.java2
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/DependencyExcludeAction.java31
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeArtifactRefactoring.java187
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeWizardPage.java64
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/MavenExcludeWizard.java9
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/messages.properties1
7 files changed, 148 insertions, 148 deletions
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 74995dd2..97e3c1e2 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
@@ -33,8 +33,6 @@ public class Messages extends NLS {
public static String ExcludeArtifactRefactoring_failedToLocateArtifact;
- public static String ExcludeArtifactRefactoring_failedToLocatePom;
-
public static String ExcludeArtifactRefactoring_noTargets;
public static String ExcludeArtifactRefactoring_removeDependencyFrom;
diff --git a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/dependencyset/DependencySetAction.java b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/dependencyset/DependencySetAction.java
index 8a658652..91aaaf2b 100644
--- a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/dependencyset/DependencySetAction.java
+++ b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/dependencyset/DependencySetAction.java
@@ -50,7 +50,7 @@ public class DependencySetAction implements IActionDelegate {
RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
op.run(shell, titleForFailedChecks);
} catch(InterruptedException e) {
- // XXX
+ // do nothing
}
}
}
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 f1e6d784..f409996a 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
@@ -30,7 +30,9 @@ import org.eclipse.ui.PlatformUI;
import org.apache.maven.artifact.Artifact;
+import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.internal.actions.SelectionUtil;
@@ -49,17 +51,24 @@ public class DependencyExcludeAction implements IActionDelegate {
private ArtifactKey[] keys;
public void run(IAction action) {
- if(keys != null && file != null) {
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- ExcludeArtifactRefactoring r = new ExcludeArtifactRefactoring(file, keys);
- MavenExcludeWizard wizard = new MavenExcludeWizard(r);
- try {
- String titleForFailedChecks = ""; //$NON-NLS-1$
- RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
- op.run(shell, titleForFailedChecks);
- } catch(InterruptedException e) {
- // XXX
- }
+ if(keys == null || file == null) {
+ return;
+ }
+
+ IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getProject(file.getProject());
+ if(facade == null || !file.equals(facade.getPom())) {
+ return;
+ }
+
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ ExcludeArtifactRefactoring r = new ExcludeArtifactRefactoring(keys);
+ MavenExcludeWizard wizard = new MavenExcludeWizard(r, facade);
+ try {
+ String titleForFailedChecks = ""; //$NON-NLS-1$
+ RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
+ op.run(shell, titleForFailedChecks);
+ } catch(InterruptedException e) {
+ // do nothing
}
}
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 0ee0939c..a7045baf 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
@@ -25,7 +25,6 @@ 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;
@@ -46,7 +45,8 @@ import org.sonatype.aether.util.artifact.JavaScopes;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ArtifactKey;
-import org.eclipse.m2e.core.internal.M2EUtils;
+import org.eclipse.m2e.core.embedder.ICallable;
+import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
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;
@@ -54,84 +54,81 @@ 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.core.ui.internal.util.ParentHierarchyEntry;
import org.eclipse.m2e.refactoring.Messages;
+@SuppressWarnings("restriction")
public class ExcludeArtifactRefactoring extends Refactoring {
private static final String PLUGIN_ID = "org.eclipse.m2e.refactoring"; //$NON-NLS-1$
- private ArtifactKey[] keys;
+ /**
+ * Dependencies to exclude
+ */
+ final ArtifactKey[] excludes;
- private IFile pomFile;
+// private IFile pomFile;
- private MavenProject exclusionPoint;
+ /**
+ * Workspace Model to exclude dependencies from
+ */
+ private ParentHierarchyEntry exclusionPoint;
- private List<MavenProject> hierarchy;
+ private List<ParentHierarchyEntry> hierarchy;
- public ExcludeArtifactRefactoring(IFile pomFile, ArtifactKey[] keys) {
- this.pomFile = pomFile;
- this.keys = keys;
+ public ExcludeArtifactRefactoring(ArtifactKey[] keys) {
+ this.excludes = keys;
}
- public void setExclusionPoint(MavenProject exclusionPoint) {
+ public void setExclusionPoint(ParentHierarchyEntry exclusionPoint) {
this.exclusionPoint = exclusionPoint;
}
- public void setHierarchy(List<MavenProject> hierarchy) {
+ public void setHierarchy(List<ParentHierarchyEntry> hierarchy) {
this.hierarchy = hierarchy;
+ this.exclusionPoint = hierarchy != null ? hierarchy.get(hierarchy.size() - 1) : null;
}
- public IMavenProjectFacade getSource() {
- return getMavenProjectFacade(pomFile);
- }
-
- protected IMavenProjectFacade getMavenProjectFacade(IFile pom) {
- return MavenPlugin.getMavenProjectRegistry().create(pom, true, new NullProgressMonitor());
- }
-
- protected IMavenProjectFacade getMavenProjectFacade(MavenProject mavenProject) {
- return MavenPlugin.getMavenProjectRegistry().getMavenProject(mavenProject.getGroupId(),
- mavenProject.getArtifactId(), mavenProject.getVersion());
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.Refactoring#getName()
- */
+ @Override
public String getName() {
StringBuilder sb = new StringBuilder();
- for(ArtifactKey key : keys) {
+ for(ArtifactKey key : excludes) {
sb.append(key.toString()).append(',');
}
sb.deleteCharAt(sb.length() - 1);
return NLS.bind(Messages.MavenExcludeWizard_title, 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(Messages.ExcludeArtifactRefactoring_unableToLocateProject);
- }
+ @Override
+ public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws OperationCanceledException {
return new RefactoringStatus();
}
private List<Change> changes;
- /* (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.Refactoring#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor)
- */
+ @Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ return MavenPlugin.getMaven().execute(new ICallable<RefactoringStatus>() {
+ public RefactoringStatus call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
+ return checkFinalConditions0(monitor);
+ }
+ }, pm);
+ }
+
+ RefactoringStatus checkFinalConditions0(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ if(hierarchy == null || exclusionPoint == null) {
+ return RefactoringStatus.createFatalErrorStatus(Messages.ExcludeArtifactRefactoring_unableToLocateProject);
+ }
+
changes = new ArrayList<Change>();
Set<ArtifactKey> locatedKeys = new HashSet<ArtifactKey>();
List<IStatus> statuses = new ArrayList<IStatus>();
- SubMonitor monitor = SubMonitor.convert(pm, getHierarchy().size());
+ SubMonitor monitor = SubMonitor.convert(pm, 3);
List<Operation> exclusionOp = new ArrayList<Operation>();
// Exclusion point
- Visitor visitor = locate(exclusionPoint, monitor.newChild(1));
- for(Entry<Dependency, Set<ArtifactKey>> entry : visitor.getSourceMap().entrySet()) {
+ for(Entry<Dependency, Set<ArtifactKey>> entry : getDependencyExcludes(exclusionPoint, monitor.newChild(1))
+ .entrySet()) {
locatedKeys.addAll(entry.getValue());
Dependency dependency = entry.getKey();
if(contains(entry.getValue(), dependency)) {
@@ -146,10 +143,9 @@ public class ExcludeArtifactRefactoring extends Refactoring {
}
// Below exclusion point - pull up dependency to exclusion point
- for(MavenProject project : getDescendants()) {
- visitor = locate(project, monitor.newChild(1));
+ for(ParentHierarchyEntry project : getWorkspaceDescendants()) {
List<Operation> operations = new ArrayList<Operation>();
- for(Entry<Dependency, Set<ArtifactKey>> entry : visitor.getSourceMap().entrySet()) {
+ for(Entry<Dependency, Set<ArtifactKey>> entry : getDependencyExcludes(project, monitor.newChild(1)).entrySet()) {
locatedKeys.addAll(entry.getValue());
Dependency dependency = entry.getKey();
operations.add(new RemoveDependencyOperation(dependency));
@@ -165,26 +161,23 @@ public class ExcludeArtifactRefactoring extends Refactoring {
}
}
if(operations.size() > 0) {
- IFile pom = getFile(project);
+ IFile pom = project.getResource();
changes.add(PomHelper.createChange(pom,
new CompoundOperation(operations.toArray(new Operation[operations.size()])), getName(pom)));
}
}
// 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()) {
+ for(ParentHierarchyEntry project : getWorkspaceAncestors()) {
+ for(Entry<Dependency, Set<ArtifactKey>> entry : getDependencyExcludes(project, monitor.newChild(1)).entrySet()) {
locatedKeys.addAll(entry.getValue());
Dependency dependency = entry.getKey();
if(contains(entry.getValue(), dependency)) {
- if(project.getFile() != null) {
+ IFile pom = project.getResource();
+ if(pom != null) {
statuses.add(new Status(IStatus.INFO, PLUGIN_ID, NLS.bind(
- Messages.ExcludeArtifactRefactoring_removeDependencyFrom, toString(dependency),
- getMavenProjectFacade(project).getPom().getFullPath())));
- IFile pom = getFile(project);
- changes.add(PomHelper.createChange(getFile(project), new RemoveDependencyOperation(dependency),
- getName(pom)));
+ Messages.ExcludeArtifactRefactoring_removeDependencyFrom, toString(dependency), pom.getFullPath())));
+ changes.add(PomHelper.createChange(pom, new RemoveDependencyOperation(dependency), getName(pom)));
}
} else {
exclusionOp.add(new AddDependencyOperation(dependency));
@@ -197,7 +190,7 @@ public class ExcludeArtifactRefactoring extends Refactoring {
}
}
if(!exclusionOp.isEmpty()) {
- IFile pom = getFile(exclusionPoint);
+ IFile pom = exclusionPoint.getResource();
changes.add(PomHelper.createChange(pom,
new CompoundOperation(exclusionOp.toArray(new Operation[exclusionOp.size()])), getName(pom)));
}
@@ -209,9 +202,9 @@ public class ExcludeArtifactRefactoring extends Refactoring {
Messages.ExcludeArtifactRefactoring_errorCreatingRefactoring, null));
} else if(locatedKeys.isEmpty()) {
return RefactoringStatus.createFatalErrorStatus(Messages.ExcludeArtifactRefactoring_noTargets);
- } else if(locatedKeys.size() != keys.length) {
+ } else if(locatedKeys.size() != excludes.length) {
StringBuilder sb = new StringBuilder();
- for(ArtifactKey key : keys) {
+ for(ArtifactKey key : excludes) {
if(!locatedKeys.contains(key)) {
sb.append(key.toString()).append(',');
}
@@ -227,17 +220,23 @@ public class ExcludeArtifactRefactoring extends Refactoring {
return new StringBuilder().append(file.getName()).append(" - ").append(file.getProject().getName()).toString(); //$NON-NLS-1$
}
- private Visitor locate(MavenProject project, IProgressMonitor monitor) throws CoreException {
- DependencyNode root = MavenPlugin.getMavenModelManager().readDependencyTree(project, JavaScopes.TEST, monitor);
- Visitor visitor = new Visitor(project);
+ /**
+ * Map key is one of <dependency> element of specified (workspace) model. Map value is set of <excludes> element keys
+ * to be added to the <dependency>.
+ */
+ private Map<Dependency, Set<ArtifactKey>> getDependencyExcludes(ParentHierarchyEntry model, IProgressMonitor monitor)
+ throws CoreException {
+ IMavenProjectFacade facade = model.getFacade();
+ MavenProject project = model.getProject();
+ DependencyNode root = MavenPlugin.getMavenModelManager().readDependencyTree(facade, project, JavaScopes.TEST,
+ monitor);
+ Visitor visitor = new Visitor(model);
root.accept(visitor);
- return visitor;
+ return visitor.getSourceMap();
}
- /* (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.Refactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)
- */
- public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ @Override
+ public Change createChange(IProgressMonitor pm) throws OperationCanceledException {
CompositeChange change = new CompositeChange(Messages.ExcludeArtifactRefactoring_changeTitle);
change.addAll(changes.toArray(new Change[changes.size()]));
return change;
@@ -256,41 +255,33 @@ public class ExcludeArtifactRefactoring extends Refactoring {
return false;
}
- private Collection<MavenProject> getHierarchy() {
+ private Collection<ParentHierarchyEntry> getHierarchy() {
return hierarchy;
}
- private IFile getFile(MavenProject project) throws CoreException {
- IFile res = M2EUtils.getPomFile(project);
-
- if(res == null) {
- throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, NLS.bind(
- Messages.ExcludeArtifactRefactoring_failedToLocatePom, project.toString())));
- } else {
- return res;
- }
- }
-
- private Collection<MavenProject> getDescendants() {
- List<MavenProject> descendants = new ArrayList<MavenProject>();
- for(MavenProject project : getHierarchy()) {
+ private Collection<ParentHierarchyEntry> getWorkspaceDescendants() {
+ List<ParentHierarchyEntry> descendants = new ArrayList<ParentHierarchyEntry>();
+ for(ParentHierarchyEntry project : getHierarchy()) {
if(project == exclusionPoint) {
break;
- } else {
+ }
+ if(project.getFacade() != null) {
descendants.add(project);
}
}
return descendants;
}
- private Collection<MavenProject> getAncestors() {
- List<MavenProject> ancestors = new ArrayList<MavenProject>();
+ private Collection<ParentHierarchyEntry> getWorkspaceAncestors() {
+ List<ParentHierarchyEntry> ancestors = new ArrayList<ParentHierarchyEntry>();
boolean add = false;
- for(MavenProject project : getHierarchy()) {
+ for(ParentHierarchyEntry project : getHierarchy()) {
if(project == exclusionPoint) {
add = !add;
} else if(add) {
- ancestors.add(project);
+ if(project.getFacade() != null) {
+ ancestors.add(project);
+ }
}
}
return ancestors;
@@ -301,11 +292,12 @@ public class ExcludeArtifactRefactoring extends Refactoring {
"{0}:{1}:{2}", new String[] {dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()}); //$NON-NLS-1$
}
- private boolean hasDependency(MavenProject project, Dependency dependency) {
- if(project.getOriginalModel().getDependencies() == null) {
+ private boolean hasDependency(ParentHierarchyEntry project, Dependency dependency) {
+ List<Dependency> dependencies = project.getProject().getOriginalModel().getDependencies();
+ if(dependencies == null) {
return false;
}
- for(Dependency dep : project.getOriginalModel().getDependencies()) {
+ for(Dependency dep : dependencies) {
if(dep.getArtifactId().equals(dependency.getArtifactId()) && dep.getGroupId().equals(dependency.getGroupId())
&& (dep.getVersion() == null || dep.getVersion().equals(dependency.getVersion()))) {
return true;
@@ -314,12 +306,13 @@ public class ExcludeArtifactRefactoring extends Refactoring {
return false;
}
- private static boolean hasExclusion(MavenProject project, Dependency d, ArtifactKey exclusion) {
- if(project.getOriginalModel().getDependencies() == null) {
+ private static boolean hasExclusion(ParentHierarchyEntry project, Dependency d, ArtifactKey exclusion) {
+ List<Dependency> dependencies = project.getProject().getOriginalModel().getDependencies();
+ if(dependencies == null) {
return false;
}
Dependency dependency = null;
- for(Dependency dep : project.getOriginalModel().getDependencies()) {
+ for(Dependency dep : dependencies) {
if(dep.getArtifactId().equals(d.getArtifactId()) && dep.getGroupId().equals(d.getGroupId())
&& (dep.getVersion() == null || dep.getVersion().equals(d.getVersion()))) {
dependency = dep;
@@ -342,9 +335,9 @@ public class ExcludeArtifactRefactoring extends Refactoring {
private Map<Dependency, Set<ArtifactKey>> sourceMap = new HashMap<Dependency, Set<ArtifactKey>>();
- Visitor(MavenProject project) {
+ Visitor(ParentHierarchyEntry project) {
dependencies = new ArrayList<Dependency>();
- dependencies.addAll(project.getOriginalModel().getDependencies());
+ dependencies.addAll(project.getProject().getOriginalModel().getDependencies());
// for(Profile profile : project.getActiveProfiles()) {
// dependencies.addAll(profile.getDependencies());
// }
@@ -371,13 +364,13 @@ public class ExcludeArtifactRefactoring extends Refactoring {
if(node.getDependency() != null) {
Artifact a = node.getDependency().getArtifact();
- for(ArtifactKey key : keys) {
- if(a.getGroupId().equals(key.getGroupId()) && a.getArtifactId().equals(key.getArtifactId())) {
+ for(ArtifactKey exclude : excludes) {
+ if(a.getGroupId().equals(exclude.getGroupId()) && a.getArtifactId().equals(exclude.getArtifactId())) {
if(topLevel != null) {
// need to add exclusion to top-level dependency
Dependency dependency = findDependency(topLevel);
if(dependency != null) {
- put(dependency, key);
+ put(dependency, exclude);
}
}
return true;
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
index 1ff2a91e..d08003db 100644
--- 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
@@ -23,18 +23,20 @@ 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.swt.widgets.Label;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
-import org.apache.maven.project.MavenProject;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Model;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.internal.components.PomHierarchyComposite;
+import org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry;
import org.eclipse.m2e.refactoring.Messages;
+@SuppressWarnings("restriction")
public class ExcludeWizardPage extends UserInputWizardPage implements SelectionListener, ISelectionChangedListener {
private PomHierarchyComposite pomHierarchy;
@@ -52,9 +54,7 @@ public class ExcludeWizardPage extends UserInputWizardPage implements SelectionL
this.facade = facade;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
- */
+ @Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
setControl(composite);
@@ -89,17 +89,16 @@ public class ExcludeWizardPage extends UserInputWizardPage implements SelectionL
status = new CLabel(composite, SWT.WRAP);
status.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
- Display.getCurrent().asyncExec(new Runnable() {
- public void run() {
- pomHierarchy.computeHeirarchy(facade, getContainer());
- ((ExcludeArtifactRefactoring) getRefactoring()).setHierarchy(pomHierarchy.getHierarchy());
- }
- });
+ pomHierarchy.computeHeirarchy(facade, null);
+ getRefactoring().setHierarchy(pomHierarchy.getHierarchy());
+ }
+
+ @Override
+ protected ExcludeArtifactRefactoring getRefactoring() {
+ return (ExcludeArtifactRefactoring) super.getRefactoring();
}
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
+ @Override
public void widgetSelected(SelectionEvent e) {
if(e.getSource() == currentPom) {
pomHierarchy.setEnabled(false);
@@ -109,9 +108,7 @@ public class ExcludeWizardPage extends UserInputWizardPage implements SelectionL
updateState();
}
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- */
+ @Override
public void widgetDefaultSelected(SelectionEvent e) {
}
@@ -127,22 +124,21 @@ public class ExcludeWizardPage extends UserInputWizardPage implements SelectionL
}
private void updateState() {
- ExcludeArtifactRefactoring refactoring = (ExcludeArtifactRefactoring) getRefactoring();
+ ParentHierarchyEntry project;
if(hierarchy.getSelection()) {
- MavenProject project = pomHierarchy.fromSelection();
- updateStatusBar(project);
- refactoring.setExclusionPoint(project);
+ project = pomHierarchy.fromSelection();
} else {
- updateStatusBar(facade.getMavenProject());
- refactoring.setExclusionPoint(facade.getMavenProject());
+ project = pomHierarchy.getProject();
}
+ updateStatusBar(project);
+ getRefactoring().setExclusionPoint(project);
}
- private void updateStatusBar(MavenProject project) {
+ private void updateStatusBar(ParentHierarchyEntry project) {
if(project == null) {
setStatus(Messages.ExcludeWizardPage_errorSelectPom);
setPageComplete(false);
- } else if(project.getFile() == null) {
+ } else if(project.getResource() == null) {
setStatus(Messages.ExcludeWizardPage_errorNonWorkspacePom);
setPageComplete(false);
} else if((project = isAboveDependencyManagement(project)) != null) {
@@ -154,26 +150,26 @@ public class ExcludeWizardPage extends UserInputWizardPage implements SelectionL
}
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
- */
+ @Override
public void selectionChanged(SelectionChangedEvent event) {
updateState();
}
- private MavenProject isAboveDependencyManagement(MavenProject project) {
- for(MavenProject cProject : pomHierarchy.getHierarchy()) {
+ private ParentHierarchyEntry isAboveDependencyManagement(ParentHierarchyEntry project) {
+ for(ParentHierarchyEntry cProject : pomHierarchy.getHierarchy()) {
if(project == cProject) {
return null;
- } else if(cProject.getOriginalModel().getDependencyManagement() != null
- && !cProject.getOriginalModel().getDependencyManagement().getDependencies().isEmpty()) {
+ }
+ DependencyManagement dependencyManagement = cProject.getProject().getOriginalModel().getDependencyManagement();
+ if(dependencyManagement != null && !dependencyManagement.getDependencies().isEmpty()) {
return cProject;
}
}
return null;
}
- private static String toString(MavenProject project) {
- return NLS.bind("{0}:{1}:{2}", new String[] {project.getGroupId(), project.getArtifactId(), project.getVersion()}); //$NON-NLS-1$
+ private static String toString(ParentHierarchyEntry project) {
+ Model model = project.getProject().getModel();
+ return NLS.bind("{0}:{1}:{2}", new String[] {model.getGroupId(), model.getArtifactId(), model.getVersion()}); //$NON-NLS-1$
}
}
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 907e4f7f..5d4f0b45 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
@@ -13,22 +13,27 @@ package org.eclipse.m2e.refactoring.exclude;
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+
/**
* @author Anton Kraev
*/
public class MavenExcludeWizard extends RefactoringWizard {
+ private IMavenProjectFacade facade;
+
private ExcludeWizardPage excludePage;
- public MavenExcludeWizard(ExcludeArtifactRefactoring refactoring) {
+ public MavenExcludeWizard(ExcludeArtifactRefactoring refactoring, IMavenProjectFacade facade) {
super(refactoring, DIALOG_BASED_USER_INTERFACE);
+ this.facade = facade;
}
@Override
protected void addUserInputPages() {
setDefaultPageTitle(getRefactoring().getName());
- excludePage = new ExcludeWizardPage(((ExcludeArtifactRefactoring) getRefactoring()).getSource());
+ excludePage = new ExcludeWizardPage(facade);
addPage(excludePage);
}
}
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 9d555c52..1f7a2d7a 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,7 +6,6 @@ ExcludeArtifactRefactoring_unableToLocateProject=Maven pom cannot be resolved. C
ExcludeArtifactRefactoring_removeDependencyFrom=Dependency {0} will be removed from {1}
ExcludeArtifactRefactoring_errorCreatingRefactoring=Errors occurred creating refactoring
ExcludeArtifactRefactoring_failedToLocateArtifact=Unable to locate source for dependency {0} in the workspace.
-ExcludeArtifactRefactoring_failedToLocatePom=Failed to locate pom in workspace for: {0}
ExcludeArtifactRefactoring_noTargets=Unable to locate source for dependency.
ExcludeWizardPage_dependenciesManagedIn=Dependencies managed in {0}.
ExcludeWizardPage_errorNonWorkspacePom=Changes must occur within the workspace

Back to the top