Permalink
Browse files

Merge pull request #112 from dragos/issue/separate-runtime-compiletim…

…e-lib-1000729

Correctly identify the Scala library on the class path, and pass it on t...
  • Loading branch information...
dragos committed Jun 4, 2012
2 parents b748d8b + aad11f0 commit 0e901c70668c402a344dc4a31cc4781e1a729de6
@@ -20,6 +20,8 @@ import scala.tools.eclipse.javaelements.ScalaSourceFile
import scala.util.matching.Regex
import testsetup._
import org.eclipse.core.runtime.Path
+import org.eclipse.jdt.core.JavaCore
+import scala.tools.eclipse.buildmanager.sbtintegration._
object SbtBuilderTest extends TestProjectSetup("builder") with CustomAssertion
object depProject extends TestProjectSetup("builder-sub")
@@ -53,7 +55,7 @@ class SbtBuilderTest {
println("building " + depProject)
depProject.project.clean(new NullProgressMonitor())
depProject.project.underlying.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor)
-
+
val targetResource = depProject.project.javaProject.getOutputLocation().append(new Path("resource.txt"))
val file = ScalaPlugin.plugin.workspaceRoot.findMember(targetResource)
Assert.assertNotNull("Resource has been copied to the output directory", file ne null)
@@ -109,7 +111,7 @@ class SbtBuilderTest {
/** Where we look for errors. */
val unitsToWatch = compilationUnits("test/ja/JClassA.java", "test/sc/ClassA.scala", "test/dependency/FooClient.scala").toList
-
+
private def getProblemMarkers(): List[IMarker] = {
unitsToWatch.flatMap(SDTTestUtils.findProblemMarkers)
}
@@ -130,6 +132,43 @@ class SbtBuilderTest {
assertNoErrors(fooClientCU)
}
+ @Test def scalaLibrary_shouldBe_on_BootClasspath() {
+ import SDTTestUtils._
+
+ val Seq(prjClient) = createProjects("client")
+
+ Assert.assertTrue("Found Scala library", prjClient.scalaClasspath.scalaLib.isDefined)
+ val basicConf = new BasicConfiguration(prjClient, ScalaCompilerConf.deployedInstance)
+ val args = basicConf.buildArguments(Seq())
+ Assert.assertTrue("BasicConfiguration bootclasspath " + args, args.mkString(" ").contains("-bootclasspath %s".format(prjClient.scalaClasspath.scalaLib.get.toFile.getAbsolutePath)))
+ deleteProjects(prjClient)
+ }
+
+ @Test def scalaLibrary_in_dependent_project_shouldBe_on_BootClasspath() {
+ import SDTTestUtils._
+
+ val Seq(prjClient, prjLib) = createProjects("client", "library")
+ val Seq(packClient, packLib) = Seq(prjClient, prjLib).map(createSourcePackage("scala"))
+ val baseRawClasspath= prjClient.javaProject.getRawClasspath()
+
+ /* The classpath, with the eclipse scala container removed. */
+ def cleanRawClasspath = for (
+ classpathEntry <- baseRawClasspath if classpathEntry.getPath().toPortableString() != "org.scala-ide.sdt.launching.SCALA_CONTAINER"
+ ) yield classpathEntry
+
+ prjClient.javaProject.setRawClasspath(cleanRawClasspath, null)
+
+ packLib.createCompilationUnit("Predef.scala", "object Predef", true, null)
+ addToClasspath(prjClient, JavaCore.newProjectEntry(prjLib.underlying.getFullPath, true))
+
+ Assert.assertTrue("Found Scala library", prjClient.scalaClasspath.scalaLib.isDefined)
+ Assert.assertEquals("Unexpected Scala lib", new Path("/library/src"), prjClient.scalaClasspath.scalaLib.get)
+ val basicConf = new BasicConfiguration(prjClient, ScalaCompilerConf.deployedInstance)
+ val args = basicConf.buildArguments(Seq())
+ Assert.assertTrue("BasicConfiguration bootclasspath " + args, args.mkString(" ").contains("-bootclasspath /library/src"))
+ deleteProjects(prjClient, prjLib)
+ }
+
/** Returns true if the expected regular expression matches the given error message. */
private def similarErrorMessage(msg: String)(expected: String): Boolean = {
msg.matches(expected)
@@ -32,7 +32,7 @@ import scala.tools.eclipse.logging.HasLogger
*
* The Scala compiler needs these entries to be separated for proper setup.
*/
-class ScalaClasspath(val jdkPaths: Seq[IPath], // JDK classpath
+case class ScalaClasspath(val jdkPaths: Seq[IPath], // JDK classpath
val scalaLib: Option[IPath], // scala library
val userCp: Seq[IPath], // user classpath, excluding the Scala library and JDK
val scalaVersion: Option[String]) {
@@ -137,6 +137,16 @@ trait ClasspathManagement extends HasLogger { self: ScalaProject =>
* this method can't rely on the compiler being present.
*/
def scalaPackageFragments: Seq[(IPackageFragmentRoot, Option[String])] = {
+ val pathToPredef = new Path("scala/Predef.class")
+
+ def isZipFileScalaLib(p: IPath): Boolean = {
+ // catch any JavaModelException and pretend it's not the scala library
+ failAsValue(classOf[JavaModelException], classOf[IOException])(false) {
+ val jarFile = JavaModelManager.getJavaModelManager().getZipFile(p)
+ jarFile.getEntry("scala/Predef.class") ne null
+ }
+ }
+
// look for all package fragment roots containing instances of scala.Predef
val fragmentRoots = new ListBuffer[(IPackageFragmentRoot, Option[String])]
@@ -145,18 +155,18 @@ trait ClasspathManagement extends HasLogger { self: ScalaProject =>
case IPackageFragmentRoot.K_BINARY =>
val resource = fragmentRoot.getUnderlyingResource
- val entry = resource match {
- case folder: IFolder => folder.findMember(new Path("scala/Predef.class"))
- case _ => // it must be a jar file
- // catch any JavaModelException and pretend it's not the scala library
- failAsValue(classOf[JavaModelException])(null) {
- val jarFile = JavaModelManager.getJavaModelManager().getZipFile(fragmentRoot.getPath())
- jarFile.getEntry("scala/Predef.class")
+ val foundIt: Boolean = resource match {
+ case folder: IFolder => folder.findMember(pathToPredef) ne null
+ case file: IFile => isZipFileScalaLib(file.getFullPath)
+ case _ =>
+ val file = fragmentRoot.getPath.toFile
+ file.exists && {
+ if (file.isFile) isZipFileScalaLib(fragmentRoot.getPath)
+ else fragmentRoot.getPath.append(pathToPredef).toFile.exists
}
}
- if (entry ne null)
- fragmentRoots += ((fragmentRoot, getVersionNumber(fragmentRoot)))
+ if (foundIt) fragmentRoots += ((fragmentRoot, getVersionNumber(fragmentRoot)))
case IPackageFragmentRoot.K_SOURCE =>
for {
Oops, something went wrong.

0 comments on commit 0e901c7

Please sign in to comment.