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
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>
-rw-r--r--org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java130
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/ParentGatherer.java28
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/ParentHierarchyEntry.java69
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/dialogs/SelectSPDXLicenseDialog.java12
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java31
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java6
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java73
-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
15 files changed, 339 insertions, 308 deletions
diff --git a/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF b/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF
index 407d0f8d..011a427a 100644
--- a/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF
@@ -9,7 +9,7 @@ Bundle-Vendor: %Bundle-Vendor
Bundle-Localization: plugin
Export-Package: org.eclipse.m2e.core.ui.internal;x-internal:=true,
org.eclipse.m2e.core.ui.internal.actions;x-friends:="org.eclipse.m2e.editor,org.eclipse.m2e.editor.xml",
- org.eclipse.m2e.core.ui.internal.components;x-internal:=true,
+ org.eclipse.m2e.core.ui.internal.components;x-friends:="org.eclipse.m2e.editor,org.eclipse.m2e.editor.xml",
org.eclipse.m2e.core.ui.internal.console;x-internal:=true,
org.eclipse.m2e.core.ui.internal.dialogs;x-friends:="org.eclipse.m2e.editor",
org.eclipse.m2e.core.ui.internal.editing;x-friends:="org.eclipse.m2e.editor.xml,org.eclipse.m2e.editor,org.eclipse.m2e.refactoring",
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java
index 1a880933..5f8d0caa 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/PomHierarchyComposite.java
@@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IColorProvider;
@@ -43,12 +42,12 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
-import org.apache.maven.project.MavenProject;
+import org.apache.maven.model.Model;
-import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.internal.MavenImages;
import org.eclipse.m2e.core.ui.internal.util.ParentGatherer;
+import org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry;
public class PomHierarchyComposite extends Composite implements IInputSelectionProvider {
@@ -56,7 +55,7 @@ public class PomHierarchyComposite extends Composite implements IInputSelectionP
private TreeViewer pomsViewer;
- private List<MavenProject> hierarchy;
+ private List<ParentHierarchyEntry> hierarchy;
public PomHierarchyComposite(Composite parent, int style) {
super(parent, style);
@@ -77,65 +76,58 @@ public class PomHierarchyComposite extends Composite implements IInputSelectionP
public void computeHeirarchy(final IMavenProjectFacade project, IRunnableContext context) {
try {
- if(context != null) {
- context.run(false, true, new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- try {
- computeHeirarchy(project, monitor);
- } catch(CoreException e) {
- throw new InvocationTargetException(e);
- }
- }
- });
- } else {
- computeHeirarchy(project, new NullProgressMonitor());
+ if(context == null) {
+ context = PlatformUI.getWorkbench().getProgressService();
}
+ context.run(false, true, new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ try {
+ computeHeirarchy(project, monitor);
+ } catch(CoreException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ });
} catch(Exception e) {
LOG.error("An error occurred building pom heirarchy", e); //$NON-NLS-1$
}
}
- private void computeHeirarchy(IMavenProjectFacade projectFacade, IProgressMonitor monitor) throws CoreException {
- LinkedList<MavenProject> hierarchy = new LinkedList<MavenProject>();
- hierarchy.addAll(new ParentGatherer(projectFacade.getMavenProject(monitor), projectFacade)
- .getParentHierarchy(monitor));
+ void computeHeirarchy(IMavenProjectFacade projectFacade, IProgressMonitor monitor) throws CoreException {
+ LinkedList<ParentHierarchyEntry> hierarchy = new LinkedList<ParentHierarchyEntry>();
+ hierarchy.addAll(new ParentGatherer(projectFacade).getParentHierarchy(monitor));
setHierarchy(hierarchy);
}
- public void setHierarchy(LinkedList<MavenProject> hierarchy) {
+ public void setHierarchy(List<ParentHierarchyEntry> hierarchy) {
this.hierarchy = hierarchy;
pomsViewer.setInput(hierarchy);
pomsViewer.expandAll();
}
public static class DepLabelProvider extends LabelProvider implements IColorProvider {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
- */
@Override
public String getText(Object element) {
- MavenProject project = null;
- if(element instanceof MavenProject) {
- project = (MavenProject) element;
+ ParentHierarchyEntry project = null;
+ if(element instanceof ParentHierarchyEntry) {
+ project = (ParentHierarchyEntry) element;
} else if(element instanceof Object[]) {
- project = (MavenProject) ((Object[]) element)[0];
+ project = (ParentHierarchyEntry) ((Object[]) element)[0];
} else {
return ""; //$NON-NLS-1$
}
- StringBuffer buffer = new StringBuffer();
- buffer.append(project.getGroupId() + " : " + project.getArtifactId() + " : " + project.getVersion()); //$NON-NLS-1$ //$NON-NLS-2$
+ StringBuilder buffer = new StringBuilder();
+ Model model = project.getProject().getModel();
+ buffer.append(model.getGroupId()).append(" : ") //$NON-NLS-1$
+ .append(model.getArtifactId()).append(" : ") //$NON-NLS-2$
+ .append(model.getVersion());
return buffer.toString();
}
public Color getForeground(Object element) {
- if(element instanceof MavenProject) {
- MavenProject project = (MavenProject) element;
- IMavenProjectFacade search = MavenPlugin.getMavenProjectRegistry().getMavenProject(project.getGroupId(),
- project.getArtifactId(), project.getVersion());
- if(search == null) {
+ if(element instanceof ParentHierarchyEntry) {
+ ParentHierarchyEntry project = (ParentHierarchyEntry) element;
+ if(project.getFacade() == null) {
// This project is not in the workspace
return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
}
@@ -148,31 +140,28 @@ public class PomHierarchyComposite extends Composite implements IInputSelectionP
}
public Image getImage(Object element) {
- if(element instanceof MavenProject) {
- MavenProject project = (MavenProject) element;
- IMavenProjectFacade search = MavenPlugin.getMavenProjectRegistry().getMavenProject(project.getGroupId(),
- project.getArtifactId(), project.getVersion());
- if(search == null) {
+ if(element instanceof ParentHierarchyEntry) {
+ ParentHierarchyEntry project = (ParentHierarchyEntry) element;
+ if(project.getFacade() == null) {
// This project is not in the workspace
return MavenImages.getOverlayImage(MavenImages.PATH_JAR, MavenImages.PATH_LOCK, IDecoration.BOTTOM_LEFT);
- } else {
- return PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
}
+ return PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
}
return null;
}
}
public static class PomHeirarchyContentProvider implements ITreeContentProvider {
- private LinkedList<MavenProject> projects;
+ private List<ParentHierarchyEntry> projects;
public PomHeirarchyContentProvider() {
}
@SuppressWarnings("unchecked")
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if(newInput instanceof LinkedList) {
- this.projects = (LinkedList<MavenProject>) newInput;
+ if(newInput instanceof List) {
+ this.projects = (List<ParentHierarchyEntry>) newInput;
}
}
@@ -186,57 +175,52 @@ public class PomHierarchyComposite extends Composite implements IInputSelectionP
}
public Object getParent(Object element) {
- if(element instanceof MavenProject) {
- MavenProject project = (MavenProject) element;
- return project.getParent();
+ if(element instanceof ParentHierarchyEntry) {
+ for(int i = 1; i < projects.size(); i++ ) {
+ if(projects.get(i) == element) {
+ return projects.get(i - 1);
+ }
+ }
}
return null;
}
- /*
- * Return root element (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang
- * .Object)
- */
@SuppressWarnings("unchecked")
public Object[] getElements(Object inputElement) {
-
if(inputElement instanceof LinkedList) {
- LinkedList<MavenProject> projects = (LinkedList<MavenProject>) inputElement;
+ List<ParentHierarchyEntry> projects = (List<ParentHierarchyEntry>) inputElement;
if(projects.isEmpty()) {
return new Object[0];
}
- return new Object[] {projects.getLast()};
+ return new Object[] {projects.get(projects.size() - 1)};
}
return new Object[0];
}
public Object[] getChildren(Object parentElement) {
- if(parentElement instanceof MavenProject) {
+ if(parentElement instanceof ParentHierarchyEntry) {
/*
* Walk the hierarchy list until we find the parentElement and
* return the previous element, which is the child.
*/
- MavenProject parent = (MavenProject) parentElement;
+ ParentHierarchyEntry parent = (ParentHierarchyEntry) parentElement;
if(projects.size() == 1) {
// No parent exists, only one element in the tree
return new Object[0];
}
- if(projects.getFirst().equals(parent)) {
+ if(projects.get(0).equals(parent)) {
// We are the final child
return new Object[0];
}
- ListIterator<MavenProject> iter = projects.listIterator();
+ ListIterator<ParentHierarchyEntry> iter = projects.listIterator();
while(iter.hasNext()) {
- MavenProject next = iter.next();
+ ParentHierarchyEntry next = iter.next();
if(next.equals(parent)) {
iter.previous();
- MavenProject previous = iter.previous();
+ ParentHierarchyEntry previous = iter.previous();
return new Object[] {previous};
}
}
@@ -265,18 +249,22 @@ public class PomHierarchyComposite extends Composite implements IInputSelectionP
pomsViewer.setSelection(selection);
}
- public List<MavenProject> getHierarchy() {
+ public List<ParentHierarchyEntry> getHierarchy() {
return hierarchy;
}
- public MavenProject fromSelection() {
+ public ParentHierarchyEntry fromSelection() {
ISelection selection = pomsViewer.getSelection();
if(selection instanceof IStructuredSelection) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
- if(obj instanceof MavenProject) {
- return (MavenProject) obj;
+ if(obj instanceof ParentHierarchyEntry) {
+ return (ParentHierarchyEntry) obj;
}
}
return null;
}
+
+ public ParentHierarchyEntry getProject() {
+ return hierarchy.get(hierarchy.size() - 1);
+ }
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/ParentGatherer.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/ParentGatherer.java
index ee184222..17644233 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/ParentGatherer.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/ParentGatherer.java
@@ -11,8 +11,10 @@
package org.eclipse.m2e.core.ui.internal.util;
-import java.util.LinkedList;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -22,6 +24,7 @@ import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ICallable;
import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
+import org.eclipse.m2e.core.internal.M2EUtils;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
@@ -29,13 +32,11 @@ import org.eclipse.m2e.core.project.IMavenProjectRegistry;
/**
* Helper class to get the parent chain given a pom
*/
+@SuppressWarnings("restriction")
public class ParentGatherer {
- final MavenProject mavenProject;
-
final IMavenProjectFacade projectFacade;
- public ParentGatherer(MavenProject leafProject, IMavenProjectFacade facade) {
- this.mavenProject = leafProject;
+ public ParentGatherer(IMavenProjectFacade facade) {
this.projectFacade = facade;
}
@@ -47,13 +48,15 @@ public class ParentGatherer {
* pom, the last one the ultimate parent.
* @throws CoreException
*/
- public LinkedList<MavenProject> getParentHierarchy(final IProgressMonitor monitor) throws CoreException {
- final LinkedList<MavenProject> hierarchy = new LinkedList<MavenProject>();
- final IMaven maven = MavenPlugin.getMaven();
+ public List<ParentHierarchyEntry> getParentHierarchy(final IProgressMonitor monitor) throws CoreException {
+ final List<ParentHierarchyEntry> hierarchy = new ArrayList<ParentHierarchyEntry>();
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
- maven.detachFromSession(mavenProject);
- hierarchy.add(mavenProject);
+ final IMaven maven = MavenPlugin.getMaven();
+
+ final MavenProject mavenProject = projectFacade.getMavenProject(monitor);
+
+ hierarchy.add(new ParentHierarchyEntry(mavenProject, projectFacade));
projectManager.execute(projectFacade, new ICallable<Void>() {
public Void call(IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
@@ -63,7 +66,10 @@ public class ParentGatherer {
return null;
}
project = maven.resolveParentProject(project, monitor);
- hierarchy.add(project);
+ IFile resource = M2EUtils.getPomFile(project); // resource is null if parent is not coming from workspace
+ IMavenProjectFacade facade = resource != null ? MavenPlugin.getMavenProjectRegistry().getProject(
+ resource.getProject()) : null;
+ hierarchy.add(new ParentHierarchyEntry(project, facade));
}
return null;
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/ParentHierarchyEntry.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/ParentHierarchyEntry.java
new file mode 100644
index 00000000..9758082e
--- /dev/null
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/util/ParentHierarchyEntry.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Igor Fedorenko
+ * 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:
+ * Igor Fedorenko - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.ui.internal.util;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFile;
+
+import org.apache.maven.project.MavenProject;
+
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+
+
+/**
+ * Represents single MavenProject in project parent hierarchy.
+ *
+ * @since 1.5
+ */
+public class ParentHierarchyEntry {
+
+ private final MavenProject project;
+
+ private final IMavenProjectFacade facade;
+
+ ParentHierarchyEntry(MavenProject project, IMavenProjectFacade facade) {
+ this.project = project;
+ this.facade = facade;
+ }
+
+ /**
+ * Returns MavenProject of this parent hierarchy entry. Never {@code null}.
+ */
+ public MavenProject getProject() {
+ return project;
+ }
+
+ /**
+ * Returns pom.xml file this parent hierarchy entry was read from. Shortcut for {@code getProject().getFile()}. Never
+ * {@code null}.
+ */
+ public File getFile() {
+ return project.getFile();
+ }
+
+ /**
+ * Returns IMavenProjectFacade that corresponds to this parent hierarchy entry. Returns {@code null} if the entry was
+ * resolved from a Maven repository and not from Eclipse workspace project.
+ */
+ public IMavenProjectFacade getFacade() {
+ return facade;
+ }
+
+ /**
+ * Returns IFile this parent hierarchy entry was read from. Returns {@code null} if the entry was resolved from a
+ * Maven repository and not from Eclipse workspace project.
+ */
+ public IFile getResource() {
+ return facade != null ? facade.getPom() : null;
+ }
+}
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/dialogs/SelectSPDXLicenseDialog.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/dialogs/SelectSPDXLicenseDialog.java
index 13e10cc8..861c2439 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/dialogs/SelectSPDXLicenseDialog.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/dialogs/SelectSPDXLicenseDialog.java
@@ -42,12 +42,10 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
-import org.apache.maven.project.MavenProject;
-
-import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.internal.components.PomHierarchyComposite;
import org.eclipse.m2e.core.ui.internal.dialogs.AbstractMavenDialog;
+import org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry;
import org.eclipse.m2e.editor.xml.MvnIndexPlugin;
import org.eclipse.m2e.editor.xml.internal.Messages;
@@ -180,15 +178,15 @@ public class SelectSPDXLicenseDialog extends AbstractMavenDialog {
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = parentComposite.getSelection();
if(selection instanceof IStructuredSelection && !selection.isEmpty()) {
- MavenProject mavenProject = (MavenProject) ((IStructuredSelection) selection).getFirstElement();
- targetProject = MavenPlugin.getMavenProjectRegistry().getMavenProject(mavenProject.getGroupId(),
- mavenProject.getArtifactId(), mavenProject.getVersion());
+ ParentHierarchyEntry mavenProject = (ParentHierarchyEntry) ((IStructuredSelection) selection)
+ .getFirstElement();
+ targetProject = mavenProject.getFacade();
updateStatus();
}
}
});
parentComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- parentComposite.computeHeirarchy(project, null); // FIXME proper progress monitor
+ parentComposite.computeHeirarchy(project, null);
parentComposite.setSelection(new StructuredSelection(parentComposite.getHierarchy().get(0)));
return container;
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java
index af53849b..1f1b041b 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/lifecycle/LifecycleMappingDialog.java
@@ -12,13 +12,10 @@
package org.eclipse.m2e.editor.xml.internal.lifecycle;
import java.io.File;
-import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.operation.IRunnableContext;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -38,9 +35,9 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.internal.M2EUtils;
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;
@SuppressWarnings("restriction")
@@ -62,7 +59,7 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
private String goal;
- private MavenProject pluginProject;
+ private ParentHierarchyEntry pluginProject;
public LifecycleMappingDialog(Shell parentShell, IFile pom, String pluginGroupId, String pluginArtifactId,
String pluginVersion, String goal) {
@@ -88,13 +85,7 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
pomComposite = new PomHierarchyComposite(container, SWT.BORDER);
pomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
pomComposite.addSelectionChangedListener(this);
- pomComposite.computeHeirarchy(facade, new IRunnableContext() {
-
- public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
- throws InvocationTargetException, InterruptedException {
- runnable.run(new NullProgressMonitor());
- }
- });
+ pomComposite.computeHeirarchy(facade, null);
status = new CLabel(container, SWT.WRAP);
status.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
@@ -115,15 +106,15 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
}
public void selectionChanged(SelectionChangedEvent event) {
- MavenProject project = pomComposite.fromSelection();
+ ParentHierarchyEntry project = pomComposite.fromSelection();
if(getButton(OK) != null) {
- getButton(OK).setEnabled(project != null && project.getFile() != null);
+ getButton(OK).setEnabled(project != null && project.getResource() != null);
}
updateStatus(project);
}
- private void updateStatus(MavenProject project) {
- if(project.getFile() == null) {
+ private void updateStatus(ParentHierarchyEntry project) {
+ if(project.getResource() == null) {
status.setText("Non-workspace pom");
status.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
} else if(project.equals(pluginProject)) {
@@ -137,7 +128,7 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
@Override
protected void okPressed() {
- pomFile = M2EUtils.getPomFile(pomComposite.fromSelection());
+ pomFile = pomComposite.fromSelection().getResource();
super.okPressed();
}
@@ -148,7 +139,7 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
return pomFile;
}
- private MavenProject locatePlugin() {
+ private ParentHierarchyEntry locatePlugin() {
MavenProject project = facade.getMavenProject(); // if we got here, facade.getMavenProject cannot be null
Plugin plugin = project.getPlugin(pluginGroupId + ":" + pluginArtifactId);
@@ -165,8 +156,8 @@ public class LifecycleMappingDialog extends Dialog implements ISelectionChangedL
}
File basedir = new File(location.getSource().getLocation()).getParentFile(); // should be canonical file already
- for(MavenProject other : pomComposite.getHierarchy()) {
- if(basedir.equals(other.getBasedir())) {
+ for(ParentHierarchyEntry other : pomComposite.getHierarchy()) {
+ if(basedir.equals(other.getFile().getParentFile())) {
return other;
}
}
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java
index 36b4ecde..75503d9b 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java
@@ -90,6 +90,7 @@ import org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation;
import org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple;
import org.eclipse.m2e.core.ui.internal.editing.PomHelper;
import org.eclipse.m2e.core.ui.internal.util.ParentGatherer;
+import org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry;
import org.eclipse.m2e.editor.MavenEditorImages;
import org.eclipse.m2e.editor.MavenEditorPlugin;
import org.eclipse.m2e.editor.dialogs.ManageDependenciesDialog;
@@ -651,7 +652,7 @@ public class DependenciesComposite extends Composite {
* A linked list representing the path from child to root parent pom.
* The head is the child, the tail is the root pom
*/
- final LinkedList<MavenProject> hierarchy = new LinkedList<MavenProject>();
+ final List<ParentHierarchyEntry> hierarchy = new ArrayList<ParentHierarchyEntry>();
IRunnableWithProgress projectLoader = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
@@ -659,8 +660,7 @@ public class DependenciesComposite extends Composite {
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
IMavenProjectFacade projectFacade = projectManager.create(pomEditor.getPomFile(), true, monitor);
if(projectFacade != null) {
- hierarchy.addAll(new ParentGatherer(projectFacade.getMavenProject(), projectFacade)
- .getParentHierarchy(monitor));
+ hierarchy.addAll(new ParentGatherer(projectFacade).getParentHierarchy(monitor));
}
} catch(CoreException e) {
throw new InvocationTargetException(e);
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java
index 35657975..61313d44 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java
@@ -34,7 +34,6 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -75,6 +74,7 @@ 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.PomEdits.OperationTuple;
import org.eclipse.m2e.core.ui.internal.editing.PomHelper;
+import org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry;
import org.eclipse.m2e.editor.MavenEditorPlugin;
import org.eclipse.m2e.editor.composites.DependencyLabelProvider;
import org.eclipse.m2e.editor.composites.ListEditorContentProvider;
@@ -94,7 +94,7 @@ public class ManageDependenciesDialog extends AbstractMavenDialog {
private TableViewer dependenciesViewer;
- private final LinkedList<MavenProject> projectHierarchy;
+ private final List<ParentHierarchyEntry> projectHierarchy;
private PomHierarchyComposite pomHierarchy;
@@ -109,12 +109,12 @@ public class ManageDependenciesDialog extends AbstractMavenDialog {
* The head of the list should be the child, while the tail should be the root parent, with the others in between.
*/
public ManageDependenciesDialog(Shell parent, ValueProvider<List<Dependency>> modelVProvider,
- LinkedList<MavenProject> hierarchy) {
+ List<ParentHierarchyEntry> hierarchy) {
this(parent, modelVProvider, hierarchy, null);
}
public ManageDependenciesDialog(Shell parent, ValueProvider<List<Dependency>> modelVProvider,
- LinkedList<MavenProject> hierarchy, List<Object> selection) {
+ List<ParentHierarchyEntry> hierarchy, List<Object> selection) {
super(parent, DIALOG_SETTINGS);
setShellStyle(getShellStyle() | SWT.RESIZE);
@@ -226,7 +226,7 @@ public class ManageDependenciesDialog extends AbstractMavenDialog {
pomHierarchy.addSelectionChangedListener(new PomViewerSelectionChangedListener());
if(getProjectHierarchy().size() > 0) {
- pomHierarchy.setSelection(new StructuredSelection(getProjectHierarchy().getLast()));
+ pomHierarchy.setSelection(new StructuredSelection(pomHierarchy.getProject()));
}
if(originalSelection != null && originalSelection.size() > 0) {
@@ -236,18 +236,14 @@ public class ManageDependenciesDialog extends AbstractMavenDialog {
return composite;
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult()
- */
+ @Override
protected void computeResult() {
- MavenProject targetPOM = getTargetPOM();
- IMavenProjectFacade targetFacade = MavenPlugin.getMavenProjectRegistry().getMavenProject(targetPOM.getGroupId(),
- targetPOM.getArtifactId(), targetPOM.getVersion());
- MavenProject currentPOM = projectHierarchy.getFirst();
- IMavenProjectFacade currentFacade = MavenPlugin.getMavenProjectRegistry().getMavenProject(currentPOM.getGroupId(),
- currentPOM.getArtifactId(), currentPOM.getVersion());
-
- if(targetFacade == null || currentFacade == null) {
+ final ParentHierarchyEntry currentPOM = getCurrentPOM();
+ final ParentHierarchyEntry targetPOM = getTargetPOM();
+ final IFile current = currentPOM.getResource();
+ final IFile target = targetPOM.getResource();
+
+ if(target == null || current == null) {
return;
}
final boolean same = targetPOM.equals(currentPOM);
@@ -260,8 +256,6 @@ public class ManageDependenciesDialog extends AbstractMavenDialog {
*/
//First we remove the version from the original dependency
- final IFile current = currentFacade.getPom();
- final IFile target = targetFacade.getPom();
Job perform = new Job("Updating POM file(s)") {
@Override
protected IStatus run(IProgressMonitor monitor) {
@@ -348,13 +342,17 @@ public class ManageDependenciesDialog extends AbstractMavenDialog {
return dependencies;
}
- protected LinkedList<MavenProject> getProjectHierarchy() {
+ protected List<ParentHierarchyEntry> getProjectHierarchy() {
return this.projectHierarchy;
}
- protected MavenProject getTargetPOM() {
+ protected ParentHierarchyEntry getTargetPOM() {
IStructuredSelection selection = (IStructuredSelection) pomHierarchy.getSelection();
- return (MavenProject) selection.getFirstElement();
+ return (ParentHierarchyEntry) selection.getFirstElement();
+ }
+
+ protected ParentHierarchyEntry getCurrentPOM() {
+ return pomHierarchy.getProject();
}
/**
@@ -396,38 +394,19 @@ public class ManageDependenciesDialog extends AbstractMavenDialog {
return false;
}
- protected void checkStatus(MavenProject targetProject, LinkedList<Dependency> selectedDependencies) {
+ protected void checkStatus(ParentHierarchyEntry targetProject, LinkedList<Dependency> selectedDependencies) {
if(targetProject == null || selectedDependencies.isEmpty()) {
updateStatus(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID,
Messages.ManageDependenciesDialog_emptySelectionError));
return;
}
boolean error = false;
- IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getMavenProject(targetProject.getGroupId(),
- targetProject.getArtifactId(), targetProject.getVersion());
- if(facade == null) {
+ if(targetProject.getFacade() == null) {
error = true;
updateStatus(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID,
Messages.ManageDependenciesDialog_projectNotPresentError));
} else {
- org.apache.maven.model.Model model = null;
- if(facade.getMavenProject() == null || facade.getMavenProject().getModel() == null) {
- try {
- model = MavenPlugin.getMavenModelManager().readMavenModel(facade.getPom());
- } catch(CoreException e) {
- Object[] arguments = {facade.getPom(), e.getLocalizedMessage()};
- String message = NLS.bind(Messages.ManageDependenciesDialog_pomReadingError, arguments);
- Status status = new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, message);
- LOG.info(message, e);
- updateStatus(status);
- error = true;
- }
- } else {
- model = facade.getMavenProject().getModel();
- }
- if(model != null) {
- error = checkDependencies(model, getDependenciesList());
- }
+ error = checkDependencies(targetProject.getProject().getModel(), getDependenciesList());
}
if(!error) {
@@ -548,17 +527,17 @@ public class ManageDependenciesDialog extends AbstractMavenDialog {
return new Object[0];
}
- if(getProjectHierarchy().getFirst().equals(parent)) {
+ if(getProjectHierarchy().get(0).equals(parent)) {
//We are the final child
return new Object[0];
}
- ListIterator<MavenProject> iter = getProjectHierarchy().listIterator();
+ ListIterator<ParentHierarchyEntry> iter = getProjectHierarchy().listIterator();
while(iter.hasNext()) {
- MavenProject next = iter.next();
+ ParentHierarchyEntry next = iter.next();
if(next.equals(parent)) {
iter.previous();
- MavenProject previous = iter.previous();
+ ParentHierarchyEntry previous = iter.previous();
return new Object[] {previous};
}
}
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