Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Tanasenko2015-05-07 04:03:51 -0400
committerAnton Tanasenko2015-05-07 15:06:49 -0400
commit4ab95272aa74d79d39e252b6ce97714146e03e6a (patch)
treea929c9284843c239328e11c1215dcabd31e1a6bb
parentf66eb3e6265ff62d45e4d9e4893953489d86c96b (diff)
downloadm2e-core-4ab95272aa74d79d39e252b6ce97714146e03e6a.tar.gz
m2e-core-4ab95272aa74d79d39e252b6ce97714146e03e6a.tar.xz
m2e-core-4ab95272aa74d79d39e252b6ce97714146e03e6a.zip
466518 Fix ordering of jre classpath entry
Change-Id: I0e01774a6c1dc18e2fdc75b2781b21e1962e1160 Signed-off-by: Anton Tanasenko <atg.sleepless@gmail.com>
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathDescriptor.java9
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java13
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java16
3 files changed, 30 insertions, 8 deletions
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathDescriptor.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathDescriptor.java
index 4f033224..00d9d8ab 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathDescriptor.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathDescriptor.java
@@ -58,6 +58,13 @@ public interface IClasspathDescriptor {
public IClasspathEntryDescriptor addEntry(IClasspathEntry entry);
/**
+ * Replaces a single ClasspathEntry instance matched by filter. Returns null if none were replaced.
+ *
+ * @since 1.6
+ */
+ public IClasspathEntryDescriptor replaceEntry(EntryFilter filter, IClasspathEntry entry);
+
+ /**
* Adds and returns new project classpath entry.
*/
public IClasspathEntryDescriptor addProjectEntry(IPath entryPath);
@@ -76,7 +83,7 @@ public interface IClasspathDescriptor {
public List<IClasspathEntryDescriptor> removeEntry(IPath path);
/**
- * Removed entries that match EntryFilter (i.e. EntryFilter#accept(entry) returns true) from the classpath
+ * Removes entries that match EntryFilter (i.e. EntryFilter#accept(entry) returns true) from the classpath
*
* @TODO should really be removeEntries (i.e. plural)
*/
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
index 65e3f0e1..d9a90b18 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
@@ -189,16 +189,15 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
cpe = JavaCore.newContainerEntry(containerPath);
}
- final IPath pathToKeep = cpe.getPath();
- // remove existing JRE entry, only if the path is different from the entry we are going to add. See bug398121
- classpath.removeEntry(new ClasspathDescriptor.EntryFilter() {
+ IClasspathEntryDescriptor cped = classpath.replaceEntry(new ClasspathDescriptor.EntryFilter() {
public boolean accept(IClasspathEntryDescriptor descriptor) {
- return JavaRuntime.JRE_CONTAINER.equals(descriptor.getPath().segment(0))
- && !descriptor.getPath().equals(pathToKeep);
+ return JavaRuntime.JRE_CONTAINER.equals(descriptor.getPath().segment(0));
}
- });
+ }, cpe);
- classpath.addEntry(cpe);
+ if(cped == null) {
+ classpath.addEntry(cpe);
+ }
}
private IExecutionEnvironment getExecutionEnvironment(String environmentId) {
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java
index c866cf06..5a0f0eb1 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathDescriptor.java
@@ -148,6 +148,22 @@ public class ClasspathDescriptor implements IClasspathDescriptor {
return entry;
}
+ public IClasspathEntryDescriptor replaceEntry(EntryFilter filter, IClasspathEntry cpe) {
+
+ ListIterator<IClasspathEntryDescriptor> iter = entries.listIterator();
+ while(iter.hasNext()) {
+ IClasspathEntryDescriptor descriptor = iter.next();
+ if(filter.accept(descriptor)) {
+ staleEntries.remove(descriptor.getPath());
+ ClasspathEntryDescriptor entry = new ClasspathEntryDescriptor(cpe);
+ entry.setPomDerived(true);
+ iter.set(entry);
+ return entry;
+ }
+ }
+ return null;
+ }
+
@SuppressWarnings("deprecation")
public ClasspathEntryDescriptor addProjectEntry(Artifact a, IMavenProjectFacade projectFacade) {
ClasspathEntryDescriptor entry = addProjectEntry(projectFacade.getFullPath());

Back to the top