Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ScalaIDE container to the Eclipse classpath for Scala projects #99

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions subprojects/docs/src/docs/release/notes.md
Expand Up @@ -104,6 +104,10 @@ Groovy: [`ScalaCompile.fork = true`](dsl/org.gradle.api.tasks.scala.ScalaCompile
activates external compilation, and [`ScalaCompile.forkOptions`](dsl/org.gradle.api.tasks.scala.ScalaCompile.html#org.gradle.api.tasks.scala.ScalaCompile:forkOptions) activates external compilation, and [`ScalaCompile.forkOptions`](dsl/org.gradle.api.tasks.scala.ScalaCompile.html#org.gradle.api.tasks.scala.ScalaCompile:forkOptions)
allows to adjust memory settings. allows to adjust memory settings.


### ScalaIDE integration

The [Eclipse Plugin](http://gradle.org/docs/current/userguide/eclipse_plugin.html) has improved Scala support by generating classpath entries for the [Scala IDE](http://scala-ide.org).

## Promoted features ## Promoted features


Promoted features are features that were incubating in previous versions of Gradle but are now supported and subject to our backwards compatibility policy. Promoted features are features that were incubating in previous versions of Gradle but are now supported and subject to our backwards compatibility policy.
Expand Down Expand Up @@ -210,5 +214,6 @@ We would like to thank the following community members for making contributions
* Gerd Aschemann - fixes for `application` plugins generated shell scripts (GRADLE-2501) * Gerd Aschemann - fixes for `application` plugins generated shell scripts (GRADLE-2501)
* Cruz Fernandez - fixes to the properties sample project * Cruz Fernandez - fixes to the properties sample project
* Fadeev Alexandr - fixes for Gradle Daemon on Win 7 when `PATH` env var is not set (GRADLE-2461) * Fadeev Alexandr - fixes for Gradle Daemon on Win 7 when `PATH` env var is not set (GRADLE-2461)
* Ben Manes - ScalaIDE integration


We love getting contributions from the Gradle community. For information on contributing, please see (gradle.org/contribute)[http://gradle.org/contribute] We love getting contributions from the Gradle community. For information on contributing, please see (gradle.org/contribute)[http://gradle.org/contribute]
2 changes: 1 addition & 1 deletion subprojects/docs/src/docs/userguide/eclipsePlugin.xml
Expand Up @@ -44,7 +44,7 @@
<td><link linkend="groovy_plugin">Groovy</link></td><td>Adds Groovy configuration to <filename>.project</filename> file.</td> <td><link linkend="groovy_plugin">Groovy</link></td><td>Adds Groovy configuration to <filename>.project</filename> file.</td>
</tr> </tr>
<tr> <tr>
<td><link linkend="scala_plugin">Scala</link></td><td>Adds Scala support to <filename>.project</filename> file.</td> <td><link linkend="scala_plugin">Scala</link></td><td>Adds Scala support to <filename>.project</filename> and <filename>.classpath</filename> files.</td>
</tr> </tr>
<tr> <tr>
<td><link linkend="war_plugin">War</link></td><td>Adds web application support to <filename>.project</filename> file. <td><link linkend="war_plugin">War</link></td><td>Adds web application support to <filename>.project</filename> file.
Expand Down
Expand Up @@ -631,4 +631,47 @@ dependencies {
libraries[1].assertHasJar(file('unresolved dependency - i.dont Exist 1.0')) libraries[1].assertHasJar(file('unresolved dependency - i.dont Exist 1.0'))
libraries[2].assertHasJar(localJar) libraries[2].assertHasJar(localJar)
} }

@Test
void classpathIsConfiguredForScalaIDE() {
//given
def scalaCompilerJar = mavenRepo.module('org.scala-lang', 'scala-compiler', '2.9.2').publish().artifactFile
def scalaLibraryJar = mavenRepo.module('org.scala-lang', 'scala-library', '2.9.2').publish().artifactFile
def scalaSwingJar = mavenRepo.module('org.scala-lang', 'scala-swing', '2.9.2').publish().artifactFile
def scalaDbcJar = mavenRepo.module('org.scala-lang', 'scala-dbc', '2.9.2').publish().artifactFile
def scalaJlineJar = mavenRepo.module('org.scala-lang', 'jline', '2.9.2').publish().artifactFile

//when
runEclipseTask """
apply plugin: 'scala'
apply plugin: 'eclipse'

repositories {
maven { url "${mavenRepo.uri}" }
mavenCentral()
}

dependencies {
def libraries = [
scala_compiler: "org.scala-lang:scala-compiler:2.9.2",
scala_library: "org.scala-lang:scala-library:2.9.2",
scala_swing: "org.scala-lang:scala-swing:2.9.2",
scala_dbc: "org.scala-lang:scala-dbc:2.9.2",
scala_jline: "org.scala-lang:jline:2.9.2",
]

scalaTools libraries.scala_compiler
scalaTools libraries.scala_library
scalaTools libraries.scala_jline

compile libraries.scala_library
compile libraries.scala_swing
compile libraries.scala_dbc
}
"""

//then
assert classpath.libs.isEmpty()
assert classpath.containers == ['org.eclipse.jdt.launching.JRE_CONTAINER', 'org.scala-ide.sdt.launching.SCALA_CONTAINER']
}
} }
Expand Up @@ -16,6 +16,7 @@
package org.gradle.plugins.ide.eclipse package org.gradle.plugins.ide.eclipse


import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.internal.reflect.Instantiator import org.gradle.internal.reflect.Instantiator
import org.gradle.api.plugins.GroovyBasePlugin import org.gradle.api.plugins.GroovyBasePlugin
import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaBasePlugin
Expand Down Expand Up @@ -143,6 +144,20 @@ class EclipsePlugin extends IdePlugin {
project.sourceSets.main.output.dirs + project.sourceSets.test.output.dirs project.sourceSets.main.output.dirs + project.sourceSets.test.output.dirs
} }
} }
project.plugins.withType(ScalaBasePlugin) {
classpath.containers 'org.scala-ide.sdt.launching.SCALA_CONTAINER'

//remove the dependencies also provided by ScalaIDE
project.gradle.projectsEvaluated {
def provided = ["scala-library", "scala-swing", "scala-dbc"] as Set
def dependencies = project.configurations.collectMany {
it.getAllDependencies()
}.grep{ it.name in provided }.unique().toArray([] as Dependency[])
if (dependencies != []) {
classpath.minusConfigurations += project.configurations.detachedConfiguration(dependencies)
}
}
}
} }
} }
} }
Expand Down
Expand Up @@ -45,8 +45,8 @@ class EclipsePluginTest extends Specification {


def applyToJavaProject_shouldOnlyHaveProjectAndClasspathTaskForJava() { def applyToJavaProject_shouldOnlyHaveProjectAndClasspathTaskForJava() {
when: when:
project.apply(plugin: 'java-base')
eclipsePlugin.apply(project) eclipsePlugin.apply(project)
project.apply(plugin: 'java-base')


then: then:
assertThatCleanEclipseDependsOn(project, project.cleanEclipseProject) assertThatCleanEclipseDependsOn(project, project.cleanEclipseProject)
Expand All @@ -63,28 +63,31 @@ class EclipsePluginTest extends Specification {
} }


def applyToScalaProject_shouldHaveProjectAndClasspathTaskForScala() { def applyToScalaProject_shouldHaveProjectAndClasspathTaskForScala() {
def scalaIdeContainer = ['org.scala-ide.sdt.launching.SCALA_CONTAINER']

when: when:
project.apply(plugin: 'scala-base')
eclipsePlugin.apply(project) eclipsePlugin.apply(project)
project.apply(plugin: 'scala-base')
project.gradle.buildListenerBroadcaster.projectsEvaluated(project.gradle)


then: then:
assertThatCleanEclipseDependsOn(project, project.cleanEclipseProject) assertThatCleanEclipseDependsOn(project, project.cleanEclipseProject)
assertThatCleanEclipseDependsOn(project, project.cleanEclipseClasspath) assertThatCleanEclipseDependsOn(project, project.cleanEclipseClasspath)
checkEclipseProjectTask([new BuildCommand('org.scala-ide.sdt.core.scalabuilder')], checkEclipseProjectTask([new BuildCommand('org.scala-ide.sdt.core.scalabuilder')],
['org.scala-ide.sdt.core.scalanature', 'org.eclipse.jdt.core.javanature']) ['org.scala-ide.sdt.core.scalanature', 'org.eclipse.jdt.core.javanature'])
checkEclipseClasspath([]) checkEclipseClasspath([], scalaIdeContainer)


when: when:
project.apply(plugin: 'scala') project.apply(plugin: 'scala')


then: then:
checkEclipseClasspath([project.configurations.testRuntime]) checkEclipseClasspath([project.configurations.testRuntime], scalaIdeContainer)
} }


def applyToGroovyProject_shouldHaveProjectAndClasspathTaskForGroovy() { def applyToGroovyProject_shouldHaveProjectAndClasspathTaskForGroovy() {
when: when:
project.apply(plugin: 'groovy-base')
eclipsePlugin.apply(project) eclipsePlugin.apply(project)
project.apply(plugin: 'groovy-base')


then: then:
assertThatCleanEclipseDependsOn(project, project.cleanEclipseProject) assertThatCleanEclipseDependsOn(project, project.cleanEclipseProject)
Expand Down Expand Up @@ -134,14 +137,14 @@ class EclipsePluginTest extends Specification {
assert eclipseProjectTask.outputFile == project.file('.project') assert eclipseProjectTask.outputFile == project.file('.project')
} }


private void checkEclipseClasspath(def configurations) { private void checkEclipseClasspath(def configurations, def additionalContainers = []) {
GenerateEclipseClasspath eclipseClasspath = project.tasks.eclipseClasspath GenerateEclipseClasspath eclipseClasspath = project.tasks.eclipseClasspath
assert eclipseClasspath instanceof GenerateEclipseClasspath assert eclipseClasspath instanceof GenerateEclipseClasspath
assert project.tasks.eclipse.taskDependencies.getDependencies(project.tasks.eclipse).contains(eclipseClasspath) assert project.tasks.eclipse.taskDependencies.getDependencies(project.tasks.eclipse).contains(eclipseClasspath)
assert eclipseClasspath.sourceSets == project.sourceSets assert eclipseClasspath.sourceSets == project.sourceSets
assert eclipseClasspath.plusConfigurations == configurations assert eclipseClasspath.plusConfigurations == configurations
assert eclipseClasspath.minusConfigurations == [] assert eclipseClasspath.minusConfigurations == []
assert eclipseClasspath.containers == ['org.eclipse.jdt.launching.JRE_CONTAINER'] as Set assert eclipseClasspath.containers == ['org.eclipse.jdt.launching.JRE_CONTAINER'] + additionalContainers as Set
assert eclipseClasspath.outputFile == project.file('.classpath') assert eclipseClasspath.outputFile == project.file('.classpath')
assert eclipseClasspath.defaultOutputDir == new File(project.projectDir, 'bin') assert eclipseClasspath.defaultOutputDir == new File(project.projectDir, 'bin')
} }
Expand Down