Permalink
Browse files

Fixed sorting issue for Classpath.

  • Loading branch information...
1 parent ea97119 commit d0cef9f1570322180635bc08be2261aae474f883 @germanklf germanklf committed Mar 20, 2012
View
4 .settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
View
4 org.maven.ide.eclipse.scala/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
View
2 org.maven.ide.eclipse.scala/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Maven Integration for Scala IDE
Bundle-SymbolicName: org.maven.ide.eclipse.scala;singleton:=true
-Bundle-Version: 0.3.1
+Bundle-Version: 0.3.2
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle:
org.eclipse.jdt.core,
View
2 org.maven.ide.eclipse.scala/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.maven.ide.eclipse.scala</groupId>
<artifactId>m2eclipse-scala</artifactId>
- <version>0.3.1</version>
+ <version>0.3.2</version>
</parent>
<artifactId>org.maven.ide.eclipse.scala</artifactId>
<packaging>eclipse-plugin</packaging>
View
174 org.maven.ide.eclipse.scala/src/org/maven/ide/eclipse/scala/ScalaProjectConfigurator.java
@@ -8,7 +8,13 @@
package org.maven.ide.eclipse.scala;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecution;
@@ -21,14 +27,13 @@
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.m2e.jdt.IClasspathDescriptor;
-import org.eclipse.m2e.jdt.IClasspathEntryDescriptor;
-import org.eclipse.m2e.jdt.IJavaProjectConfigurator;
-import org.eclipse.m2e.jdt.internal.MavenClasspathHelpers;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
+import org.eclipse.m2e.jdt.IClasspathDescriptor;
+import org.eclipse.m2e.jdt.IClasspathEntryDescriptor;
+import org.eclipse.m2e.jdt.IJavaProjectConfigurator;
+
//TODO check the jre/java version compliance (>= 1.5)
//TODO check JDT Weaving is enabled (if not enabled, icon of scala file is [J] same as java (and property of the file display "Type :... Java Source File" )
@@ -46,31 +51,79 @@
/////////////////////////////////////////////////////////////////////////////
private static String MOJO_GROUP_ID = "org.scala-tools";
+
private static String MOJO_ARTIFACT_ID = "maven-scala-plugin";
+ private Map<String, Integer> mapSourceTypeWeight;
+
+ private Map<String, Integer> mapResourceWeight;
+
+ private Comparator<IClasspathEntry> comparator;
+
+ public ScalaProjectConfigurator() {
+ mapSourceTypeWeight = new HashMap<String, Integer>();
+ mapSourceTypeWeight.put("src/main/", 9000);
+ mapSourceTypeWeight.put("src/test/", 1000);
+
+ mapResourceWeight = new HashMap<String, Integer>();
+ mapResourceWeight.put("java", 100);
+ mapResourceWeight.put("resources", -10);
+
+ comparator = new Comparator<IClasspathEntry>() {
+ public int compare(IClasspathEntry o1, IClasspathEntry o2) {
+ Integer w1 = getWeight(o1);
+ Integer w2 = getWeight(o2);
+ if(w1 > 0 || w2 > 0) {
+ if(w1.equals(w2))
+ return o1.getPath().toString().compareTo(o2.getPath().toString());
+ else
+ return w1.compareTo(w2) * -1;
+ }
+ return 0;
+ }
+
+ private Integer getWeight(IClasspathEntry ce) {
+ int value = 0;
+ if(ce.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ for(Entry<String, Integer> e : mapSourceTypeWeight.entrySet()) {
+ if(ce.getPath().toString().contains(e.getKey())) {
+ value += e.getValue();
+ }
+ }
+ for(Entry<String, Integer> e : mapResourceWeight.entrySet()) {
+ if(ce.getPath().toString().endsWith(e.getKey())) {
+ value += e.getValue();
+ }
+ }
+ }
+ return value;
+ }
+ };
+ }
+
/////////////////////////////////////////////////////////////////////////////
// INSTANCE
/////////////////////////////////////////////////////////////////////////////
private String scalaNatureId() {
ScalaPluginIds ids = Activator.getInstance().scalaPluginIds();
- return (ids == null)?null : ids.natureId;
+ return (ids == null) ? null : ids.natureId;
}
private String scalaLibId() {
ScalaPluginIds ids = Activator.getInstance().scalaPluginIds();
- return (ids == null)?null : ids.containerLibId;
+ return (ids == null) ? null : ids.containerLibId;
}
@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
String scalaNature = scalaNatureId();
- if (scalaNature == null) {
+ if(scalaNature == null) {
//TODO show an alert to user that he should to install scala-ide plugin;
return;
}
try {
- if (request != null) {
+ if(request != null) {
IProject project = request.getProject();
if(!project.hasNature(scalaNature) && isScalaProject(request.getMavenProjectFacade(), monitor)) {
addNature(project, scalaNature, monitor);
@@ -84,18 +137,19 @@ public void configure(ProjectConfigurationRequest request, IProgressMonitor moni
/**
* configure Classpath : contain of "Maven Dependencies" Librairies Container.
*/
- public void configureClasspath(IMavenProjectFacade facade, IClasspathDescriptor classpath, IProgressMonitor monitor) throws CoreException {
+ public void configureClasspath(IMavenProjectFacade facade, IClasspathDescriptor classpath, IProgressMonitor monitor)
+ throws CoreException {
String scalaNature = scalaNatureId();
- if (scalaNature == null) {
+ if(scalaNature == null) {
//TODO show an alert to user that he should to install scala-ide plugin;
return;
}
- if (!isLaunchConfigurationCtx()) {
+ if(!isLaunchConfigurationCtx()) {
IProject project = facade.getProject();
if(isScalaProject(project)) {
- // if(!project.hasNature(ID_NATURE)) {
- // addNature(project, ID_NATURE, monitor);
- // }
+ // if(!project.hasNature(ID_NATURE)) {
+ // addNature(project, ID_NATURE, monitor);
+ // }
removeScalaFromMavenContainer(classpath);
addDefaultScalaSourceDirs(facade, classpath, monitor);
sortContainerScalaJre(project, monitor); //
@@ -105,31 +159,32 @@ public void configureClasspath(IMavenProjectFacade facade, IClasspathDescriptor
/**
* To work as maven-scala-plugin, src/main/scala and src/test/scala are added if directory exists
- *
+ *
* @param facade
* @throws CoreException
*/
//TODO take a look at http://github.com/sonatype/m2eclipse-extras/blob/master/org.maven.ide.eclipse.temporary.mojos/src/org/maven/ide/eclipse/buildhelper/BuildhelperProjectConfigurator.java
- private void addDefaultScalaSourceDirs(IMavenProjectFacade facade, IClasspathDescriptor classpath, IProgressMonitor monitor) throws CoreException {
+ private void addDefaultScalaSourceDirs(IMavenProjectFacade facade, IClasspathDescriptor classpath,
+ IProgressMonitor monitor) throws CoreException {
IProject project = facade.getProject();
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
int initSize = rawClasspath.length;
// can't use classpath.addSourceEntry because source entry are append under "Maven Dependencies" container
IFolder defaultMainSrc = project.getFolder("src/main/scala");
- if (defaultMainSrc != null && defaultMainSrc.exists()) {
+ if(defaultMainSrc != null && defaultMainSrc.exists()) {
IPath p = defaultMainSrc.getFullPath();
rawClasspath = addSourceEntry(rawClasspath, p, facade.getOutputLocation());
}
IFolder defaultTestSrc = project.getFolder("src/test/scala");
- if (defaultTestSrc != null && defaultTestSrc.exists()) {
+ if(defaultTestSrc != null && defaultTestSrc.exists()) {
IPath p = defaultTestSrc.getFullPath();
rawClasspath = addSourceEntry(rawClasspath, p, facade.getTestOutputLocation());
}
- if (rawClasspath.length != initSize) {
+ if(rawClasspath.length != initSize) {
javaProject.setRawClasspath(rawClasspath, monitor);
}
@@ -144,18 +199,17 @@ private void addDefaultScalaSourceDirs(IMavenProjectFacade facade, IClasspathDes
new IPath[0], //
new IPath[0], //
outputLocation, //
- new IClasspathAttribute[0]
- );
- if (!contains(rawClasspath, entry)) {
+ new IClasspathAttribute[0]);
+ if(!contains(rawClasspath, entry)) {
back = add(rawClasspath, entry);
}
return back;
}
private boolean contains(IClasspathEntry[] rawClasspath, IClasspathEntry entry) {
- if (entry != null && rawClasspath != null) {
+ if(entry != null && rawClasspath != null) {
for(IClasspathEntry e : rawClasspath) {
- if (entry.equals(e)) {
+ if(entry.equals(e)) {
return true;
}
}
@@ -176,12 +230,9 @@ private void removeScalaFromMavenContainer(IClasspathDescriptor classpath) {
public boolean accept(IClasspathEntryDescriptor descriptor) {
boolean back = "org.scala-lang".equals(descriptor.getGroupId());
//TODO, use content of Scala Library Container instead of hardcoded value
- back = back && (
- "scala-library".equals(descriptor.getArtifactId())
- //|| "scala-compiler".equals(descriptor.getArtifactId())
- || "scala-dbc".equals(descriptor.getArtifactId())
- || "scala-swing".equals(descriptor.getArtifactId())
- );
+ back = back && ("scala-library".equals(descriptor.getArtifactId())
+ //|| "scala-compiler".equals(descriptor.getArtifactId())
+ || "scala-dbc".equals(descriptor.getArtifactId()) || "scala-swing".equals(descriptor.getArtifactId()));
return back;
}
});
@@ -211,12 +262,12 @@ public boolean accept(IClasspathEntryDescriptor descriptor) {
// }
// }
-
/**
- * Not called with m2eclipse 0.10.0
- * Configure the eclipse project classpath (similar to eclipse IJavaProject.getRawClasspath).
+ * Not called with m2eclipse 0.10.0 Configure the eclipse project classpath (similar to eclipse
+ * IJavaProject.getRawClasspath).
*/
- public void configureRawClasspath(ProjectConfigurationRequest request, IClasspathDescriptor classpath, IProgressMonitor monitor) throws CoreException {
+ public void configureRawClasspath(ProjectConfigurationRequest request, IClasspathDescriptor classpath,
+ IProgressMonitor monitor) throws CoreException {
// System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
// IProject project = request.getProject();
// if(isScalaProject(project)) {
@@ -227,56 +278,64 @@ public void configureRawClasspath(ProjectConfigurationRequest request, IClasspat
}
/**
- * Check and reorder Containers : "Scala Lib" should be before "JRE Sys",
- * else 'Run Scala Application' set Boot Entries JRE before Scala and failed with scala.* NotFound Exception.
- * Should already be done when adding nature
+ * Check and reorder Containers : "Scala Lib" should be before "JRE Sys", else 'Run Scala Application' set Boot
+ * Entries JRE before Scala and failed with scala.* NotFound Exception. Should already be done when adding nature
+ *
* @see scala.tools.eclipse.Nature#configure()
*/
private void sortContainerScalaJre(IProject project, IProgressMonitor monitor) throws CoreException {
IJavaProject javaProject = JavaCore.create(project);
- IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
+ IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
+
+ List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(classpathEntries.length);
+ Collections.addAll(entries, classpathEntries);
+ Collections.sort(entries, comparator);
+ javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);
+
+ /*
int posScalaContainer = -1;
int posJreContainer = -1;
int posMavenContainer = -1;
-
- for (int i = 0; i < rawClasspath.length; i++) {
+
+ for(int i = 0; i < rawClasspath.length; i++ ) {
IClasspathEntry e = rawClasspath[i];
- if (IClasspathEntry.CPE_CONTAINER == e.getEntryKind()) {
+ if(IClasspathEntry.CPE_CONTAINER == e.getEntryKind()) {
// "org.eclipse.jdt.launching.JRE_CONTAINER"
- if (JavaRuntime.JRE_CONTAINER.equals(e.getPath().segment(0))) {
+ if(JavaRuntime.JRE_CONTAINER.equals(e.getPath().segment(0))) {
posJreContainer = i;
}
- if (scalaLibId().equals(e.getPath().segment(0))) {
+ if(scalaLibId().equals(e.getPath().segment(0))) {
posScalaContainer = i;
}
- if (e.equals(MavenClasspathHelpers.getDefaultContainerEntry()))
+ if(e.equals(MavenClasspathHelpers.getDefaultContainerEntry()))
posMavenContainer = i;
}
}
- if (posMavenContainer != -1 && posJreContainer != -1 && posJreContainer > posMavenContainer) {
+ if(posMavenContainer != -1 && posJreContainer != -1 && posJreContainer > posMavenContainer) {
// swap position to have jre before maven
IClasspathEntry tmp = rawClasspath[posMavenContainer];
rawClasspath[posMavenContainer] = rawClasspath[posJreContainer];
- rawClasspath[posJreContainer]= tmp;
+ rawClasspath[posJreContainer] = tmp;
javaProject.setRawClasspath(rawClasspath, monitor);
}
- if (posScalaContainer != -1 && posJreContainer != -1 && posScalaContainer > posJreContainer) {
+ if(posScalaContainer != -1 && posJreContainer != -1 && posScalaContainer > posJreContainer) {
// swap position to have scalaContainer first
IClasspathEntry tmp = rawClasspath[posScalaContainer];
rawClasspath[posScalaContainer] = rawClasspath[posJreContainer];
- rawClasspath[posJreContainer]= tmp;
+ rawClasspath[posJreContainer] = tmp;
javaProject.setRawClasspath(rawClasspath, monitor);
}
-
- if (posScalaContainer == -1) {
+
+ if(posScalaContainer == -1) {
System.out.println("no scala container !!!");
-// rawClasspath[posScalaContainer] = rawClasspath[posJreContainer];
-// rawClasspath[posJreContainer]= tmp;
-// javaProject.setRawClasspath(rawClasspath, monitor);
+ // rawClasspath[posScalaContainer] = rawClasspath[posJreContainer];
+ // rawClasspath[posJreContainer]= tmp;
+ // javaProject.setRawClasspath(rawClasspath, monitor);
}
+ */
}
private boolean isScalaProject(IProject project) {
@@ -287,8 +346,7 @@ private boolean isScalaProject(IProject project) {
}
}
- private boolean isScalaProject(IMavenProjectFacade facade, IProgressMonitor monitor)
- throws CoreException {
+ private boolean isScalaProject(IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException {
List<Plugin> plugins = facade.getMavenProject(monitor).getBuildPlugins();
if(plugins != null) {
for(Plugin plugin : plugins) {
@@ -301,8 +359,8 @@ private boolean isScalaProject(IMavenProjectFacade facade, IProgressMonitor moni
}
protected boolean isLaunchConfigurationCtx() {
- for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
- if ("launch".equals(e.getMethodName())) {
+ for(StackTraceElement e : Thread.currentThread().getStackTrace()) {
+ if("launch".equals(e.getMethodName())) {
return true;
}
}
View
4 org.maven.ide.eclipse.scala_feature/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
View
2 org.maven.ide.eclipse.scala_feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.maven.ide.eclipse.scala_feature"
label="Maven Integration for Scala IDE"
- version="0.3.1"
+ version="0.3.2"
provider-name="Sonatype, Inc.">
<description url="github.com/sonatype/m2eclipse-scala/">
View
2 org.maven.ide.eclipse.scala_feature/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.maven.ide.eclipse.scala</groupId>
<artifactId>m2eclipse-scala</artifactId>
- <version>0.3.1</version>
+ <version>0.3.2</version>
</parent>
<artifactId>org.maven.ide.eclipse.scala_feature</artifactId>
View
4 org.maven.ide.eclipse.scala_site/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
View
2 org.maven.ide.eclipse.scala_site/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.maven.ide.eclipse.scala</groupId>
<artifactId>m2eclipse-scala</artifactId>
- <version>0.3.1</version>
+ <version>0.3.2</version>
<relativePath>../pom.xml</relativePath>
</parent>
View
5 pom.xml
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.maven.ide.eclipse.scala</groupId>
<artifactId>m2eclipse-scala</artifactId>
- <version>0.3.1</version>
+ <version>0.3.2</version>
<packaging>pom</packaging>
<properties>
@@ -58,7 +58,8 @@
<repository>
<id>scala-ide</id>
<layout>p2</layout>
- <url>http://download.scala-ide.org/update-1.0.0-milestones-2.8.1.final</url>
+ <!--<url>http://download.scala-ide.org/update-1.0.0-milestones-2.8.1.final</url>-->
+ <url>http://download.scala-ide.org/releases-28/stable/site</url>
</repository>
</repositories>

0 comments on commit d0cef9f

Please sign in to comment.