Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #11 from germanklf/master

Fixed sorting issue.
  • Loading branch information...
commit 3b1ec65bee49715559119f723ed545153aa3d527 2 parents e0253b7 + 9f9545c
David Bernard davidB authored
4 .settings/org.eclipse.m2e.core.prefs
... ... @@ -0,0 +1,4 @@
  1 +activeProfiles=
  2 +eclipse.preferences.version=1
  3 +resolveWorkspaceProjects=true
  4 +version=1
4 org.maven.ide.eclipse.scala/.settings/org.eclipse.m2e.core.prefs
... ... @@ -0,0 +1,4 @@
  1 +activeProfiles=
  2 +eclipse.preferences.version=1
  3 +resolveWorkspaceProjects=true
  4 +version=1
2  org.maven.ide.eclipse.scala/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
2 2 Bundle-ManifestVersion: 2
3 3 Bundle-Name: Maven Integration for Scala IDE
4 4 Bundle-SymbolicName: org.maven.ide.eclipse.scala;singleton:=true
5   -Bundle-Version: 0.3.1
  5 +Bundle-Version: 0.3.2
6 6 Bundle-RequiredExecutionEnvironment: J2SE-1.5
7 7 Require-Bundle:
8 8 org.eclipse.jdt.core,
2  org.maven.ide.eclipse.scala/pom.xml
@@ -5,7 +5,7 @@
5 5 <parent>
6 6 <groupId>org.maven.ide.eclipse.scala</groupId>
7 7 <artifactId>m2eclipse-scala</artifactId>
8   - <version>0.3.1</version>
  8 + <version>0.3.2</version>
9 9 </parent>
10 10 <artifactId>org.maven.ide.eclipse.scala</artifactId>
11 11 <packaging>eclipse-plugin</packaging>
168 org.maven.ide.eclipse.scala/src/org/maven/ide/eclipse/scala/ScalaProjectConfigurator.java
@@ -8,7 +8,13 @@
8 8
9 9 package org.maven.ide.eclipse.scala;
10 10
  11 +import java.util.ArrayList;
  12 +import java.util.Collections;
  13 +import java.util.Comparator;
  14 +import java.util.HashMap;
11 15 import java.util.List;
  16 +import java.util.Map;
  17 +import java.util.Map.Entry;
12 18
13 19 import org.apache.maven.model.Plugin;
14 20 import org.apache.maven.plugin.MojoExecution;
@@ -21,13 +27,13 @@
21 27 import org.eclipse.jdt.core.IClasspathEntry;
22 28 import org.eclipse.jdt.core.IJavaProject;
23 29 import org.eclipse.jdt.core.JavaCore;
24   -import org.eclipse.jdt.launching.JavaRuntime;
25   -import org.eclipse.m2e.jdt.IClasspathDescriptor;
26   -import org.eclipse.m2e.jdt.IClasspathEntryDescriptor;
27   -import org.eclipse.m2e.jdt.IJavaProjectConfigurator;
28 30 import org.eclipse.m2e.core.project.IMavenProjectFacade;
29 31 import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
30 32 import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
  33 +import org.eclipse.m2e.jdt.IClasspathDescriptor;
  34 +import org.eclipse.m2e.jdt.IClasspathEntryDescriptor;
  35 +import org.eclipse.m2e.jdt.IJavaProjectConfigurator;
  36 +
31 37
32 38 //TODO check the jre/java version compliance (>= 1.5)
33 39 //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" )
@@ -37,6 +43,7 @@
37 43 /**
38 44 * @author Sonatype Inc (http://github.com/sonatype/m2eclipse-scala)
39 45 * @author davidB (http://github.com/davidB)
  46 + * @author germanklf (http://github.com/germanklf)
40 47 */
41 48 public class ScalaProjectConfigurator extends AbstractProjectConfigurator implements IJavaProjectConfigurator {
42 49
@@ -45,31 +52,79 @@
45 52 /////////////////////////////////////////////////////////////////////////////
46 53
47 54 private static String MOJO_GROUP_ID = "org.scala-tools";
  55 +
48 56 private static String MOJO_ARTIFACT_ID = "maven-scala-plugin";
49 57
  58 + private Map<String, Integer> mapSourceTypeWeight;
  59 +
  60 + private Map<String, Integer> mapResourceWeight;
  61 +
  62 + private Comparator<IClasspathEntry> comparator;
  63 +
  64 + public ScalaProjectConfigurator() {
  65 + mapSourceTypeWeight = new HashMap<String, Integer>();
  66 + mapSourceTypeWeight.put("src/main/", 9000);
  67 + mapSourceTypeWeight.put("src/test/", 1000);
  68 +
  69 + mapResourceWeight = new HashMap<String, Integer>();
  70 + mapResourceWeight.put("java", 100);
  71 + mapResourceWeight.put("resources", -10);
  72 +
  73 + comparator = new Comparator<IClasspathEntry>() {
  74 + public int compare(IClasspathEntry o1, IClasspathEntry o2) {
  75 + Integer w1 = getWeight(o1);
  76 + Integer w2 = getWeight(o2);
  77 + if(w1 > 0 || w2 > 0) {
  78 + if(w1.equals(w2))
  79 + return o1.getPath().toString().compareTo(o2.getPath().toString());
  80 + else
  81 + return w1.compareTo(w2) * -1;
  82 + }
  83 + return 0;
  84 + }
  85 +
  86 + private Integer getWeight(IClasspathEntry ce) {
  87 + int value = 0;
  88 + if(ce.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
  89 + for(Entry<String, Integer> e : mapSourceTypeWeight.entrySet()) {
  90 + if(ce.getPath().toString().contains(e.getKey())) {
  91 + value += e.getValue();
  92 + }
  93 + }
  94 + for(Entry<String, Integer> e : mapResourceWeight.entrySet()) {
  95 + if(ce.getPath().toString().endsWith(e.getKey())) {
  96 + value += e.getValue();
  97 + }
  98 + }
  99 + }
  100 + return value;
  101 + }
  102 + };
  103 + }
  104 +
50 105 /////////////////////////////////////////////////////////////////////////////
51 106 // INSTANCE
52 107 /////////////////////////////////////////////////////////////////////////////
53 108
54 109 private String scalaNatureId() {
55 110 ScalaPluginIds ids = Activator.getInstance().scalaPluginIds();
56   - return (ids == null)?null : ids.natureId;
  111 + return (ids == null) ? null : ids.natureId;
57 112 }
58 113
59 114 private String scalaLibId() {
60 115 ScalaPluginIds ids = Activator.getInstance().scalaPluginIds();
61   - return (ids == null)?null : ids.containerLibId;
  116 + return (ids == null) ? null : ids.containerLibId;
62 117 }
63 118
64 119 @Override
65 120 public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
66 121 String scalaNature = scalaNatureId();
67   - if (scalaNature == null) {
  122 + if(scalaNature == null) {
68 123 //TODO show an alert to user that he should to install scala-ide plugin;
69 124 return;
70 125 }
71 126 try {
72   - if (request != null) {
  127 + if(request != null) {
73 128 IProject project = request.getProject();
74 129 if(!project.hasNature(scalaNature) && isScalaProject(request.getMavenProjectFacade(), monitor)) {
75 130 addNature(project, scalaNature, monitor);
@@ -83,18 +138,19 @@ public void configure(ProjectConfigurationRequest request, IProgressMonitor moni
83 138 /**
84 139 * configure Classpath : contain of "Maven Dependencies" Librairies Container.
85 140 */
86   - public void configureClasspath(IMavenProjectFacade facade, IClasspathDescriptor classpath, IProgressMonitor monitor) throws CoreException {
  141 + public void configureClasspath(IMavenProjectFacade facade, IClasspathDescriptor classpath, IProgressMonitor monitor)
  142 + throws CoreException {
87 143 String scalaNature = scalaNatureId();
88   - if (scalaNature == null) {
  144 + if(scalaNature == null) {
89 145 //TODO show an alert to user that he should to install scala-ide plugin;
90 146 return;
91 147 }
92   - if (!isLaunchConfigurationCtx()) {
  148 + if(!isLaunchConfigurationCtx()) {
93 149 IProject project = facade.getProject();
94 150 if(isScalaProject(project)) {
95   - // if(!project.hasNature(ID_NATURE)) {
96   - // addNature(project, ID_NATURE, monitor);
97   - // }
  151 + // if(!project.hasNature(ID_NATURE)) {
  152 + // addNature(project, ID_NATURE, monitor);
  153 + // }
98 154 removeScalaFromMavenContainer(classpath);
99 155 addDefaultScalaSourceDirs(facade, classpath, monitor);
100 156 sortContainerScalaJre(project, monitor); //
@@ -104,12 +160,13 @@ public void configureClasspath(IMavenProjectFacade facade, IClasspathDescriptor
104 160
105 161 /**
106 162 * To work as maven-scala-plugin, src/main/scala and src/test/scala are added if directory exists
107   - *
  163 + *
108 164 * @param facade
109 165 * @throws CoreException
110 166 */
111 167 //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
112   - private void addDefaultScalaSourceDirs(IMavenProjectFacade facade, IClasspathDescriptor classpath, IProgressMonitor monitor) throws CoreException {
  168 + private void addDefaultScalaSourceDirs(IMavenProjectFacade facade, IClasspathDescriptor classpath,
  169 + IProgressMonitor monitor) throws CoreException {
113 170 IProject project = facade.getProject();
114 171 IJavaProject javaProject = JavaCore.create(project);
115 172 IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
@@ -117,18 +174,18 @@ private void addDefaultScalaSourceDirs(IMavenProjectFacade facade, IClasspathDes
117 174
118 175 // can't use classpath.addSourceEntry because source entry are append under "Maven Dependencies" container
119 176 IFolder defaultMainSrc = project.getFolder("src/main/scala");
120   - if (defaultMainSrc != null && defaultMainSrc.exists()) {
  177 + if(defaultMainSrc != null && defaultMainSrc.exists()) {
121 178 IPath p = defaultMainSrc.getFullPath();
122 179 rawClasspath = addSourceEntry(rawClasspath, p, facade.getOutputLocation());
123 180 }
124 181
125 182 IFolder defaultTestSrc = project.getFolder("src/test/scala");
126   - if (defaultTestSrc != null && defaultTestSrc.exists()) {
  183 + if(defaultTestSrc != null && defaultTestSrc.exists()) {
127 184 IPath p = defaultTestSrc.getFullPath();
128 185 rawClasspath = addSourceEntry(rawClasspath, p, facade.getTestOutputLocation());
129 186 }
130 187
131   - if (rawClasspath.length != initSize) {
  188 + if(rawClasspath.length != initSize) {
132 189 javaProject.setRawClasspath(rawClasspath, monitor);
133 190 }
134 191
@@ -143,18 +200,17 @@ private void addDefaultScalaSourceDirs(IMavenProjectFacade facade, IClasspathDes
143 200 new IPath[0], //
144 201 new IPath[0], //
145 202 outputLocation, //
146   - new IClasspathAttribute[0]
147   - );
148   - if (!contains(rawClasspath, entry)) {
  203 + new IClasspathAttribute[0]);
  204 + if(!contains(rawClasspath, entry)) {
149 205 back = add(rawClasspath, entry);
150 206 }
151 207 return back;
152 208 }
153 209
154 210 private boolean contains(IClasspathEntry[] rawClasspath, IClasspathEntry entry) {
155   - if (entry != null && rawClasspath != null) {
  211 + if(entry != null && rawClasspath != null) {
156 212 for(IClasspathEntry e : rawClasspath) {
157   - if (entry.equals(e)) {
  213 + if(entry.equals(e)) {
158 214 return true;
159 215 }
160 216 }
@@ -175,12 +231,9 @@ private void removeScalaFromMavenContainer(IClasspathDescriptor classpath) {
175 231 public boolean accept(IClasspathEntryDescriptor descriptor) {
176 232 boolean back = "org.scala-lang".equals(descriptor.getGroupId());
177 233 //TODO, use content of Scala Library Container instead of hardcoded value
178   - back = back && (
179   - "scala-library".equals(descriptor.getArtifactId())
180   - //|| "scala-compiler".equals(descriptor.getArtifactId())
181   - || "scala-dbc".equals(descriptor.getArtifactId())
182   - || "scala-swing".equals(descriptor.getArtifactId())
183   - );
  234 + back = back && ("scala-library".equals(descriptor.getArtifactId())
  235 + //|| "scala-compiler".equals(descriptor.getArtifactId())
  236 + || "scala-dbc".equals(descriptor.getArtifactId()) || "scala-swing".equals(descriptor.getArtifactId()));
184 237 return back;
185 238 }
186 239 });
@@ -210,12 +263,12 @@ public boolean accept(IClasspathEntryDescriptor descriptor) {
210 263 // }
211 264 // }
212 265
213   -
214 266 /**
215   - * Not called with m2eclipse 0.10.0
216   - * Configure the eclipse project classpath (similar to eclipse IJavaProject.getRawClasspath).
  267 + * Not called with m2eclipse 0.10.0 Configure the eclipse project classpath (similar to eclipse
  268 + * IJavaProject.getRawClasspath).
217 269 */
218   - public void configureRawClasspath(ProjectConfigurationRequest request, IClasspathDescriptor classpath, IProgressMonitor monitor) throws CoreException {
  270 + public void configureRawClasspath(ProjectConfigurationRequest request, IClasspathDescriptor classpath,
  271 + IProgressMonitor monitor) throws CoreException {
219 272 // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
220 273 // IProject project = request.getProject();
221 274 // if(isScalaProject(project)) {
@@ -226,42 +279,20 @@ public void configureRawClasspath(ProjectConfigurationRequest request, IClasspat
226 279 }
227 280
228 281 /**
229   - * Check and reorder Containers : "Scala Lib" should be before "JRE Sys",
230   - * else 'Run Scala Application' set Boot Entries JRE before Scala and failed with scala.* NotFound Exception.
231   - * Should already be done when adding nature
  282 + * Check and reorder Containers : "Scala Lib" should be before "JRE Sys", else 'Run Scala Application' set Boot
  283 + * Entries JRE before Scala and failed with scala.* NotFound Exception. Should already be done when adding nature
  284 + *
232 285 * @see scala.tools.eclipse.Nature#configure()
233 286 */
234 287 private void sortContainerScalaJre(IProject project, IProgressMonitor monitor) throws CoreException {
235 288 IJavaProject javaProject = JavaCore.create(project);
236   - IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
  289 + IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
237 290
238   - int posScalaContainer = -1;
239   - int posJreContainer = -1;
240   - for (int i = 0; i < rawClasspath.length; i++) {
241   - IClasspathEntry e = rawClasspath[i];
242   - if (IClasspathEntry.CPE_CONTAINER == e.getEntryKind()) {
243   - // "org.eclipse.jdt.launching.JRE_CONTAINER"
244   - if (JavaRuntime.JRE_CONTAINER.equals(e.getPath().segment(0))) {
245   - posJreContainer = i;
246   - }
247   - // ""
248   - if (scalaLibId().equals(e.getPath().segment(0))) {
249   - posScalaContainer = i;
250   - }
251   - }
252   - }
253   - if (posScalaContainer != -1 && posJreContainer != -1 && posScalaContainer > posJreContainer) {
254   - // swap position to have scalaContainer first
255   - IClasspathEntry tmp = rawClasspath[posScalaContainer];
256   - rawClasspath[posScalaContainer] = rawClasspath[posJreContainer];
257   - rawClasspath[posJreContainer]= tmp;
258   - javaProject.setRawClasspath(rawClasspath, monitor);
259   - } else if (posScalaContainer == -1) {
260   - System.out.println("no scala container !!!");
261   -// rawClasspath[posScalaContainer] = rawClasspath[posJreContainer];
262   -// rawClasspath[posJreContainer]= tmp;
263   -// javaProject.setRawClasspath(rawClasspath, monitor);
264   - }
  291 + List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(classpathEntries.length);
  292 + Collections.addAll(entries, classpathEntries);
  293 +
  294 + Collections.sort(entries, comparator);
  295 + javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);
265 296 }
266 297
267 298 private boolean isScalaProject(IProject project) {
@@ -272,8 +303,7 @@ private boolean isScalaProject(IProject project) {
272 303 }
273 304 }
274 305
275   - private boolean isScalaProject(IMavenProjectFacade facade, IProgressMonitor monitor)
276   - throws CoreException {
  306 + private boolean isScalaProject(IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException {
277 307 List<Plugin> plugins = facade.getMavenProject(monitor).getBuildPlugins();
278 308 if(plugins != null) {
279 309 for(Plugin plugin : plugins) {
@@ -286,8 +316,8 @@ private boolean isScalaProject(IMavenProjectFacade facade, IProgressMonitor moni
286 316 }
287 317
288 318 protected boolean isLaunchConfigurationCtx() {
289   - for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
290   - if ("launch".equals(e.getMethodName())) {
  319 + for(StackTraceElement e : Thread.currentThread().getStackTrace()) {
  320 + if("launch".equals(e.getMethodName())) {
291 321 return true;
292 322 }
293 323 }
4 org.maven.ide.eclipse.scala_feature/.settings/org.eclipse.m2e.core.prefs
... ... @@ -0,0 +1,4 @@
  1 +activeProfiles=
  2 +eclipse.preferences.version=1
  3 +resolveWorkspaceProjects=true
  4 +version=1
2  org.maven.ide.eclipse.scala_feature/feature.xml
@@ -2,7 +2,7 @@
2 2 <feature
3 3 id="org.maven.ide.eclipse.scala_feature"
4 4 label="Maven Integration for Scala IDE"
5   - version="0.3.1"
  5 + version="0.3.2"
6 6 provider-name="Sonatype, Inc.">
7 7
8 8 <description url="github.com/sonatype/m2eclipse-scala/">
2  org.maven.ide.eclipse.scala_feature/pom.xml
@@ -5,7 +5,7 @@
5 5 <parent>
6 6 <groupId>org.maven.ide.eclipse.scala</groupId>
7 7 <artifactId>m2eclipse-scala</artifactId>
8   - <version>0.3.1</version>
  8 + <version>0.3.2</version>
9 9 </parent>
10 10
11 11 <artifactId>org.maven.ide.eclipse.scala_feature</artifactId>
4 org.maven.ide.eclipse.scala_site/.settings/org.eclipse.m2e.core.prefs
... ... @@ -0,0 +1,4 @@
  1 +activeProfiles=
  2 +eclipse.preferences.version=1
  3 +resolveWorkspaceProjects=true
  4 +version=1
2  org.maven.ide.eclipse.scala_site/pom.xml
@@ -5,7 +5,7 @@
5 5 <parent>
6 6 <groupId>org.maven.ide.eclipse.scala</groupId>
7 7 <artifactId>m2eclipse-scala</artifactId>
8   - <version>0.3.1</version>
  8 + <version>0.3.2</version>
9 9 <relativePath>../pom.xml</relativePath>
10 10 </parent>
11 11
5 pom.xml
@@ -4,7 +4,7 @@
4 4 <modelVersion>4.0.0</modelVersion>
5 5 <groupId>org.maven.ide.eclipse.scala</groupId>
6 6 <artifactId>m2eclipse-scala</artifactId>
7   - <version>0.3.1</version>
  7 + <version>0.3.2</version>
8 8 <packaging>pom</packaging>
9 9
10 10 <properties>
@@ -58,7 +58,8 @@
58 58 <repository>
59 59 <id>scala-ide</id>
60 60 <layout>p2</layout>
61   - <url>http://download.scala-ide.org/update-1.0.0-milestones-2.8.1.final</url>
  61 + <!--<url>http://download.scala-ide.org/update-1.0.0-milestones-2.8.1.final</url>-->
  62 + <url>http://download.scala-ide.org/releases-28/stable/site</url>
62 63 </repository>
63 64 </repositories>
64 65

0 comments on commit 3b1ec65

Please sign in to comment.
Something went wrong with that request. Please try again.