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

Commit

Permalink
add support of scala-maven-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
davidB committed Apr 1, 2012
1 parent 3b1ec65 commit dc9b646
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 131 deletions.
53 changes: 52 additions & 1 deletion org.maven.ide.eclipse.scala/lifecycle-mapping-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,58 @@
<lifecycleMappingMetadata>

<pluginExecutions>
<!-- scala maven plugins -->
<!-- scala-maven-plugin -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<versionRange>[3.0,)</versionRange>
</pluginExecutionFilter>
<action>
<configurator>
<id>org.maven.ide.eclipse.scala</id>
</configurator>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<goals>
<goal>add-source</goal>
<goal>doc</goal>
<goal>genjson</goal>
<goal>run</goal>
<goal>script</goal>
</goals>
<versionRange>[3.0,)</versionRange>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<goals>
<goal>console</goal>
<goal>cc</goal>
<goal>cctest</goal>
<goal>help</goal>
</goals>
<versionRange>[3.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
<!-- maven-scala-plugin -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.scala-tools</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
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" )
//TODO check that pom.xml and ScalaLib Container declare the same scala version
Expand All @@ -47,13 +46,6 @@
*/
public class ScalaProjectConfigurator extends AbstractProjectConfigurator implements IJavaProjectConfigurator {

/////////////////////////////////////////////////////////////////////////////
// STATIC
/////////////////////////////////////////////////////////////////////////////

private static String MOJO_GROUP_ID = "org.scala-tools";

private static String MOJO_ARTIFACT_ID = "maven-scala-plugin";

private Map<String, Integer> mapSourceTypeWeight;

Expand Down Expand Up @@ -102,29 +94,25 @@ private Integer getWeight(IClasspathEntry ce) {
};
}

/////////////////////////////////////////////////////////////////////////////
// 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);
Expand All @@ -138,19 +126,18 @@ 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); //
Expand All @@ -160,32 +147,31 @@ 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);
}

Expand All @@ -200,17 +186,18 @@ private IClasspathEntry[] addSourceEntry(IClasspathEntry[] rawClasspath, IPath s
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;
}
}
Expand All @@ -231,9 +218,12 @@ 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;
}
});
Expand Down Expand Up @@ -263,12 +253,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)) {
Expand All @@ -279,9 +269,9 @@ 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 {
Expand All @@ -303,7 +293,8 @@ 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) {
Expand All @@ -316,8 +307,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;
}
}
Expand All @@ -333,7 +324,8 @@ private boolean isMavenBundlePluginMojo(Plugin plugin) {
}

private boolean isMavenBundlePluginMojo(String groupId, String artifactId) {
return MOJO_GROUP_ID.equals(groupId) && MOJO_ARTIFACT_ID.equals(artifactId);
return ("org.scala-tools".equals(groupId) && "maven-scala-plugin".equals(artifactId))
|| ("net.alchim31.maven".equals(groupId) && "scala-maven-plugin".equals(artifactId));
}

}
6 changes: 3 additions & 3 deletions samples/prj-custom-layout/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>scala-compile-first</id>
Expand Down
6 changes: 3 additions & 3 deletions samples/prj-java-test-in-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<goals>
Expand Down
44 changes: 3 additions & 41 deletions samples/prj-liftbased/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,6 @@
<vscaladoc.links.liftweb.baseurl>http://scala-tools.org/mvnsites-snapshots/liftweb</vscaladoc.links.liftweb.baseurl>
</properties>

<repositories>
<repository>
<id>scala-tools.releases</id>
<name>Scala-Tools Dependencies Repository for Releases</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>scala-tools.snapshots</id>
<name>Scala-Tools Dependencies Repository for Snapshots</name>
<url>http://scala-tools.org/repo-snapshots</url>
<snapshots/>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>scala-tools.releases</id>
<name>Scala-Tools Plugins Repository for Releases</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>net.liftweb</groupId>
Expand Down Expand Up @@ -94,9 +72,9 @@
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.13.1</version>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<charset>${project.build.sourceEncoding}</charset>
<jvmArgs>
Expand Down Expand Up @@ -174,20 +152,4 @@
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.13.1</version>
<configuration>
<charset>${project.build.sourceEncoding}</charset>
<jvmArgs>
<jvmArg>-Xmx1024m</jvmArg>
<jvmArg>-DpackageLinkDefs=file://${project.build.directory}/packageLinkDefs.properties</jvmArg>
</jvmArgs>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
7 changes: 3 additions & 4 deletions samples/prj-scala-after-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@

<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<goals>
Expand Down
Loading

0 comments on commit dc9b646

Please sign in to comment.