Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #22 from fbricon/wtp-support
Browse files Browse the repository at this point in the history
issue #8 : Add basic WTP support
  • Loading branch information
davidB committed Sep 30, 2012
2 parents c61328b + b69842b commit 02d3644
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 7 deletions.
2 changes: 1 addition & 1 deletion org.maven.ide.eclipse.scala/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion org.maven.ide.eclipse.scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -139,6 +151,7 @@ public void configureClasspath(IMavenProjectFacade facade, IClasspathDescriptor
removeScalaFromMavenContainer(classpath);
addDefaultScalaSourceDirs(facade, classpath, monitor);
sortContainerScalaJre(project, monitor); //
makeScalaLibDeployable(facade, classpath, monitor);
}
}
}
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion org.maven.ide.eclipse.scala_feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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/">
Expand Down
2 changes: 1 addition & 1 deletion org.maven.ide.eclipse.scala_feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion org.maven.ide.eclipse.scala_site/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down

0 comments on commit 02d3644

Please sign in to comment.