Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2011-03-10 09:50:03 +0000
committerMilos Kleint2011-03-10 09:50:03 +0000
commit824b5b4cca8ff1524cf7489fa22b3716e1bafd74 (patch)
tree463c02ed3f24688e3a51d5149b32752945777556
parentaa508686c8a384b6b34bd6e7e0256efaaa5fb177 (diff)
downloadm2e-core-824b5b4cca8ff1524cf7489fa22b3716e1bafd74.tar.gz
m2e-core-824b5b4cca8ff1524cf7489fa22b3716e1bafd74.tar.xz
m2e-core-824b5b4cca8ff1524cf7489fa22b3716e1bafd74.zip
shall always find the IFile closest to root (the project's own pom file). Have I already mentioned I don't like IFile and the workspace concept in general?
Ideally we should find a match for the fie in open editors but this shall be sufficient.
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java19
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/dependencyset/DependencySetRefactoring.java1
-rw-r--r--org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/exclude/ExcludeArtifactRefactoring.java30
3 files changed, 37 insertions, 13 deletions
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java
index 924bf505..dfce5ce0 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java
@@ -95,23 +95,22 @@ public class XmlUtils {
IFileStore folder = buf.getFileStore();
File file = new File(folder.toURI());
IPath path = Path.fromOSString(file.getAbsolutePath());
- Stack<IResource> stack = new Stack<IResource>();
+ Stack<IFile> stack = new Stack<IFile>();
//here we need to find the most inner project to the path.
//we do so by shortening the path and remembering all the resources identified.
// at the end we pick the last one from the stack. is there a catch to it?
- IResource ifile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
+ IFile ifile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
if (ifile != null) {
stack.push(ifile);
- } else {
- while(path.segmentCount() > 1) {
- ResourcesPlugin.getWorkspace().getRoot().findMember(path);
- if(ifile != null) {
- stack.push(ifile);
- }
- path = path.removeFirstSegments(1);
+ }
+ while(path.segmentCount() > 1) {
+ IResource ires = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ if(ires != null && ires instanceof IFile) {
+ stack.push((IFile)ires);
}
+ path = path.removeFirstSegments(1);
}
- IResource res = stack.empty() ? null : stack.pop();
+ IFile res = stack.empty() ? null : stack.pop();
if (res != null) {
IProject prj = res.getProject();
//the project returned is in a way unrelated to nested child poms that don't have an opened project,
diff --git a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/dependencyset/DependencySetRefactoring.java b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/dependencyset/DependencySetRefactoring.java
index b2d87bf1..c0784866 100644
--- a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/dependencyset/DependencySetRefactoring.java
+++ b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/dependencyset/DependencySetRefactoring.java
@@ -102,6 +102,7 @@ public class DependencySetRefactoring extends Refactoring {
public void process(Document document) {
//TODO handle activated profiles?
Element deps = findChild(document.getDocumentElement(), DEPENDENCIES);
+ //TODO expressions in fields..
Element existing = findChild(deps, DEPENDENCY, childEquals(GROUP_ID, groupId),
childEquals(ARTIFACT_ID, artifactId));
if(existing != null) {
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 4ed428aa..d12c0dc0 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
@@ -10,25 +10,30 @@
*******************************************************************************/
package org.eclipse.m2e.refactoring.exclude;
+import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Stack;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
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.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.ltk.core.refactoring.Change;
@@ -244,12 +249,31 @@ public class ExcludeArtifactRefactoring extends Refactoring {
}
private IFile getFile(MavenProject project) throws CoreException {
- IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(project.getFile().toURI());
- if(files.length == 0) {
+ //XXX copied from XmlUtils.extractProject()
+ File file = new File(project.getFile().toURI());
+ IPath path = Path.fromOSString(file.getAbsolutePath());
+ Stack<IFile> stack = new Stack<IFile>();
+ //here we need to find the most inner project to the path.
+ //we do so by shortening the path and remembering all the resources identified.
+ // at the end we pick the last one from the stack. is there a catch to it?
+ IFile ifile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
+ if (ifile != null) {
+ stack.push(ifile);
+ }
+ while(path.segmentCount() > 1) {
+ IResource ires = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ if(ires != null && ires instanceof IFile) {
+ stack.push((IFile)ires);
+ }
+ path = path.removeFirstSegments(1);
+ }
+ IFile res = stack.empty() ? null : stack.pop();
+
+ if(res == null) {
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, NLS.bind(
Messages.ExcludeArtifactRefactoring_failedToLocatePom, project.toString())));
} else {
- return files[0];
+ return res;
}
}

Back to the top