Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

issue #8 : Add basic WTP support #22

Merged
merged 2 commits into from

2 participants

@fbricon

Adds the same deployable attribute to the Scala classpath container as the one added to the Maven container by m2e-wtp. If m2e-wtp or WTP is not installed, this will be ignored.

This could still be improved by setting deployment attribute on a more fine grained level, i.e. on each classpath entry from the scala lib.

PR also updates the tycho version and m2e-scala version used to build.

fbricon added some commits
@fbricon fbricon Update version to 0.4.2-SNAPSHOT
Signed-off-by: Fred Bricon <fbricon@gmail.com>
1be8795
@fbricon fbricon Add initial WTP support
Signed-off-by: Fred Bricon <fbricon@gmail.com>
b69842b
@davidB davidB merged commit 02d3644 into sonatype:master
@davidB
Owner

Thanks, sorry I didn't reveive notification.

@fbricon

Thx for merging. Any ETA on a 0.4.2 release or do you at least provide CI builds?

@davidB
Owner

There is no CI builds. I wait a feedback about an other change from a user. I'll deploy on update-site this week (may be tonight).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 4, 2012
  1. @fbricon

    Update version to 0.4.2-SNAPSHOT

    fbricon authored
    Signed-off-by: Fred Bricon <fbricon@gmail.com>
  2. @fbricon

    Add initial WTP support

    fbricon authored
    Signed-off-by: Fred Bricon <fbricon@gmail.com>
This page is out of date. Refresh to see the latest.
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.4.1
+Bundle-Version: 0.4.2.qualifier
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.4.1</version>
+ <version>0.4.2-SNAPSHOT</version>
</parent>
<artifactId>org.maven.ide.eclipse.scala</artifactId>
<packaging>eclipse-plugin</packaging>
View
93 org.maven.ide.eclipse.scala/src/org/maven/ide/eclipse/scala/ScalaProjectConfigurator.java
@@ -12,6 +12,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -27,6 +28,8 @@
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.ClasspathAttribute;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
@@ -43,10 +46,19 @@
* @author Sonatype Inc (http://github.com/sonatype/m2eclipse-scala)
* @author davidB (http://github.com/davidB)
* @author germanklf (http://github.com/germanklf)
+ * @author Fred Bricon
*/
public class ScalaProjectConfigurator extends AbstractProjectConfigurator implements IJavaProjectConfigurator {
+ private static final String SCALA_CONTAINER_PATH = "org.scala-ide.sdt.launching.SCALA_CONTAINER";
+
+ private static final String MAVEN_CONTAINER_PATH = "org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER";
+
+ private static String DEPLOYABLE_KEY = "org.eclipse.jst.component.dependency";
+
+ private static String NON_DEPLOYABLE_KEY = "org.eclipse.jst.component.nondependency";
+
private Map<String, Integer> mapSourceTypeWeight;
private Map<String, Integer> mapResourceWeight;
@@ -139,6 +151,7 @@ public void configureClasspath(IMavenProjectFacade facade, IClasspathDescriptor
removeScalaFromMavenContainer(classpath);
addDefaultScalaSourceDirs(facade, classpath, monitor);
sortContainerScalaJre(project, monitor); //
+ makeScalaLibDeployable(facade, classpath, monitor);
}
}
}
@@ -326,4 +339,84 @@ private boolean isMavenBundlePluginMojo(String groupId, String artifactId) {
|| ("net.alchim31.maven".equals(groupId) && "scala-maven-plugin".equals(artifactId));
}
+ @SuppressWarnings("restriction")
+ private void makeScalaLibDeployable(IMavenProjectFacade facade, IClasspathDescriptor classpath,
+ IProgressMonitor monitor) throws CoreException {
+
+ IJavaProject javaProject = JavaCore.create(facade.getProject());
+ if (javaProject == null) {
+ return;
+ }
+
+ IClasspathEntry scalaLibrary = getContainer(javaProject, SCALA_CONTAINER_PATH);
+
+ if (scalaLibrary == null) {
+ //Really nothing to do here
+ return;
+ }
+
+ IClasspathEntry mavenLibrary = getContainer(javaProject, MAVEN_CONTAINER_PATH);
+
+ IClasspathAttribute deployableAttribute = getDeployableAttribute(mavenLibrary);
+ //If the Maven Classpath Container is set to be deployed in WTP, then do the same for the Scala one
+ if (deployableAttribute != null) {
+ //Add the deployable attribute only if it's not set already.
+ if (getDeployableAttribute(scalaLibrary) == null) {
+ addDeployableAttribute(javaProject, deployableAttribute, monitor);
+ }
+ }
+
+ }
+
+ private static void addDeployableAttribute(IJavaProject javaProject, IClasspathAttribute deployableAttribute, IProgressMonitor monitor)
+ throws JavaModelException {
+ if (javaProject == null) return;
+ IClasspathEntry[] cp = javaProject.getRawClasspath();
+ for(int i = 0; i < cp.length; i++ ) {
+ if(IClasspathEntry.CPE_CONTAINER == cp[i].getEntryKind()
+ && SCALA_CONTAINER_PATH.equals(cp[i].getPath().lastSegment())) {
+ LinkedHashMap<String, IClasspathAttribute> attrs = new LinkedHashMap<String, IClasspathAttribute>();
+ for(IClasspathAttribute attr : cp[i].getExtraAttributes()) {
+ //Keep all existing attributes except the non_deployable key
+ if (!attr.getName().equals(NON_DEPLOYABLE_KEY)) {
+ attrs.put(attr.getName(), attr);
+ }
+ }
+ attrs.put(deployableAttribute.getName(), deployableAttribute);
+ IClasspathAttribute[] newAttrs = attrs.values().toArray(new IClasspathAttribute[attrs.size()]);
+ cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newAttrs, cp[i].isExported());
+ break;
+ }
+ }
+ javaProject.setRawClasspath(cp, monitor);
+ }
+
+ private static IClasspathEntry getContainer(IJavaProject javaProject, String containerPath) throws JavaModelException {
+ IClasspathEntry[] cp = javaProject.getRawClasspath();
+ for(int i = 0; i < cp.length; i++ ) {
+ if(IClasspathEntry.CPE_CONTAINER == cp[i].getEntryKind()
+ && containerPath.equals(cp[i].getPath().lastSegment())) {
+ return cp[i];
+ }
+ }
+ return null;
+ }
+
+ private static IClasspathAttribute getDeployableAttribute(IClasspathEntry library) {
+ if (library == null) {
+ return null;
+ }
+
+ IClasspathAttribute[] attributes = library.getExtraAttributes();
+ if (attributes == null || attributes.length == 0) {
+ return null;
+ }
+
+ for(IClasspathAttribute attr : attributes) {
+ if (DEPLOYABLE_KEY.equals(attr.getName())) {
+ return new ClasspathAttribute(attr.getName(), attr.getValue());
+ }
+ }
+ return null;
+ }
}
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.4.1"
+ version="0.4.2.qualifier"
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.4.1</version>
+ <version>0.4.2-SNAPSHOT</version>
</parent>
<artifactId>org.maven.ide.eclipse.scala_feature</artifactId>
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.4.1</version>
+ <version>0.4.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
View
4 pom.xml
@@ -4,11 +4,11 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.maven.ide.eclipse.scala</groupId>
<artifactId>m2eclipse-scala</artifactId>
- <version>0.4.1</version>
+ <version>0.4.2-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
- <tycho.version>0.14.1</tycho.version>
+ <tycho.version>0.15.0</tycho.version>
<encoding>UTF-8</encoding>
</properties>
Something went wrong with that request. Please try again.