Permalink
Browse files

Cherrypicked fix for #1000406.

Reverting the revert (that's sounds weird btw): "Revert "Fixes #1000406. Also don't add compiler to the classpath automatically"" and fixed the underlying problem. Also added a bunch of tests for sbt builder for other bugs. Not sure how to force jdk change easily for this bug, so I am leaving the test case open

Cherry-picked from d98125e without ImplicitsHighlighting test.

Added files necessary to initialize workspace for the tests
(cherry picked from commit a9a3f72)

Finally fixed tests, which revealed problem with the build manager in testSimpleJavaDep test in ScalaJavaDepTest. We seem to still remove java classes and sbt assumes that they are still there.
(cherry picked from commit 31bb845)

Ignore failing test for now (it is not related to this ticket anyway, but to builder in general. Made smaller jar for compiler testing
(cherry picked from commit 0c9bb34)

Typo
(cherry picked from commit 0e60fea)

I was overzealous with my changes. Incorported fix pointed out in the review
(cherry picked from commit 77472e6)
  • Loading branch information...
1 parent ecc4453 commit ce49e0a3a82f0e5ebc93221424ee47bd9036246e @hubertp hubertp committed Oct 31, 2011
Showing with 386 additions and 33 deletions.
  1. +5 −1 org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/TestsSuite.java
  2. +58 −0 org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/sbtbuilder/ScalaCompilerClasspathTest.scala
  3. +108 −0 org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/sbtbuilder/ScalaJavaDepTest.scala
  4. +0 −3 org.scala-ide.sdt.core.tests/src/scala/tools/eclipse/testsetup/TestProjectSetup.scala
  5. +7 −0 org.scala-ide.sdt.core.tests/test-workspace/builder-compiler-classpath/.classpath
  6. +18 −0 org.scala-ide.sdt.core.tests/test-workspace/builder-compiler-classpath/.project
  7. +12 −0 ...ide.sdt.core.tests/test-workspace/builder-compiler-classpath/.settings/org.eclipse.jdt.core.prefs
  8. +34 −0 ...e.sdt.core.tests/test-workspace/builder-compiler-classpath/.settings/org.scala-ide.sdt.core.prefs
  9. BIN org.scala-ide.sdt.core.tests/test-workspace/builder-compiler-classpath/lib/2.10.x/scala-compiler.jar
  10. +7 −0 org.scala-ide.sdt.core.tests/test-workspace/builder-compiler-classpath/src/test/CompilerDep.scala
  11. +7 −0 org.scala-ide.sdt.core.tests/test-workspace/scalajavadep/.classpath
  12. +18 −0 org.scala-ide.sdt.core.tests/test-workspace/scalajavadep/.project
  13. +12 −0 org.scala-ide.sdt.core.tests/test-workspace/scalajavadep/.settings/org.eclipse.jdt.core.prefs
  14. +34 −0 org.scala-ide.sdt.core.tests/test-workspace/scalajavadep/.settings/org.scala-ide.sdt.core.prefs
  15. +10 −0 org.scala-ide.sdt.core.tests/test-workspace/scalajavadep/src/test/J.java
  16. +5 −0 org.scala-ide.sdt.core.tests/test-workspace/scalajavadep/src/test/S.scala
  17. +43 −14 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/AnalysisCompile.scala
  18. +6 −10 ...ala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/EclipseSbtBuildManager.scala
  19. +2 −5 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/ScalaSbtCompiler.scala
@@ -11,6 +11,8 @@
import scala.tools.eclipse.sbtbuilder.OutputFoldersTest;
import scala.tools.eclipse.sbtbuilder.SbtBuilderTest;
import scala.tools.eclipse.sbtbuilder.TodoBuilderTest;
+import scala.tools.eclipse.sbtbuilder.ScalaCompilerClasspathTest;
+import scala.tools.eclipse.sbtbuilder.ScalaJavaDepTest;
import scala.tools.eclipse.structurebuilder.StructureBuilderTest;
import scala.tools.eclipse.pc.PresentationCompilerTest;
import scala.tools.eclipse.wizards.*;
@@ -36,9 +38,11 @@
CompletionTests.class,
AbstractMethodVerifierTest.class,
SbtBuilderTest.class,
- PresentationCompilerTest.class,
OutputFoldersTest.class,
+ ScalaCompilerClasspathTest.class,
+ PresentationCompilerTest.class,
ClasspathTests.class,
TodoBuilderTest.class,
+ ScalaJavaDepTest.class,
})
class TestsSuite { }
@@ -0,0 +1,58 @@
+package scala.tools.eclipse
+package sbtbuilder
+
+import org.junit.Test
+import org.eclipse.core.runtime.NullProgressMonitor
+import org.eclipse.core.resources.IncrementalProjectBuilder
+import org.eclipse.jdt.core.IJavaModelMarker
+import org.eclipse.jdt.core.JavaCore
+import org.eclipse.jdt.core.IProblemRequestor
+import org.eclipse.jdt.core.WorkingCopyOwner
+import org.eclipse.core.runtime.Path
+import org.eclipse.core.resources.IResource
+import org.junit.Assert
+import org.eclipse.core.resources.IMarker
+
+import scala.tools.eclipse.testsetup.SDTTestUtils
+import org.eclipse.core.resources.IFile
+import org.junit.{Ignore, Before, After}
+
+object ScalaCompilerClasspathTest extends testsetup.TestProjectSetup("builder-compiler-classpath")
+
+class ScalaCompilerClasspathTest {
+
+ import ScalaCompilerClasspathTest._
+
+ val baseRawClasspath= project.javaProject.getRawClasspath()
+
+ @Before
+ def setupWorkspace {
+ SDTTestUtils.enableAutoBuild(false)
+ }
+
+ @Test def testWithoutCompilerOnClasspath() {
+ println("building " + project)
+ project.clean(new NullProgressMonitor())
+ project.underlying.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor)
+
+ val unit = compilationUnit("test/CompilerDep.scala")
+ val errors = unit.getUnderlyingResource().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE)
+ println("problem: %s: %s".format(unit, errors.toList))
+ Assert.assertTrue("Single compiler error expected", errors.length == 1)
+ }
+
+ @Test def testWithCompilerOnClasspath() {
+ println("building " + project)
+ project.clean(new NullProgressMonitor())
+ val p = new Path(project.underlying.getLocation().toOSString()).append("/lib/2.10.x/scala-compiler.jar")
+ Assert.assertTrue("scala compiler exists in the test framework", p.toFile().exists())
+ val newRawClasspath = baseRawClasspath :+ JavaCore.newLibraryEntry(p, null, null)
+ project.javaProject.setRawClasspath(newRawClasspath, new NullProgressMonitor)
+ project.underlying.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor)
+
+ val unit = compilationUnit("test/CompilerDep.scala")
+ val errors = unit.getUnderlyingResource().findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE)
+ println("problem: %s: %s".format(unit, errors.toList))
+ Assert.assertTrue("Build errors found", errors.isEmpty)
+ }
+}
@@ -0,0 +1,108 @@
+package scala.tools.eclipse
+package sbtbuilder
+
+
+import org.junit.Test
+import org.eclipse.core.runtime.NullProgressMonitor
+import org.eclipse.core.resources.IncrementalProjectBuilder
+import org.eclipse.jdt.core.IJavaModelMarker
+import org.eclipse.core.resources.IResource
+
+import org.junit.Assert
+import org.eclipse.core.resources.IMarker
+
+import scala.tools.eclipse.testsetup.SDTTestUtils
+import org.eclipse.core.resources.IFile
+import org.junit.Ignore
+import org.junit.Before
+
+object ScalaJavaDepTest extends testsetup.TestProjectSetup("scalajavadep")
+
+class ScalaJavaDepTest {
+
+ import ScalaJavaDepTest._
+
+ @Before
+ def setupWorkspace {
+ SDTTestUtils.enableAutoBuild(true)
+ }
+
+ @Test def testSimpleScalaDep() {
+ println("building " + project)
+ project.clean(new NullProgressMonitor())
+ rebuild(project)
+
+ val problems0 = getProblemMarkers
+ Assert.assertTrue("Build errors found: " + userFriendlyMarkers(problems0), problems0.isEmpty)
+
+ val JJavaCU = compilationUnit("test/J.java")
+ val originalJJava = SDTTestUtils.slurpAndClose(project.underlying.getFile("src/test/J.java").getContents)
+ SDTTestUtils.changeContentOfFile(project.underlying, JJavaCU.getResource().getAdapter(classOf[IFile]).asInstanceOf[IFile], changedJJava)
+ rebuild(project)
+ val problems1 = getProblemMarkers()
+ Assert.assertTrue("One build error expected, got: " + userFriendlyMarkers(problems1), problems1.length == 1) // do more precise matching later
+
+ val JJavaCU2 = compilationUnit("test/J.java")
+ SDTTestUtils.changeContentOfFile(project.underlying, JJavaCU2.getResource().getAdapter(classOf[IFile]).asInstanceOf[IFile], originalJJava)
+ rebuild(project)
+ val problems2 = getProblemMarkers()
+ Assert.assertTrue("Build errors found: " + userFriendlyMarkers(problems2), problems2.isEmpty)
+ }
+
+ @Ignore
+ @Test def testSimpleJavaDep() {
+ println("building " + project)
+ project.clean(new NullProgressMonitor())
+ rebuild(project)
+
+ val problems0 = getProblemMarkers()
+ Assert.assertTrue("Build errors found: " + userFriendlyMarkers(problems0), problems0.isEmpty)
+
+ val SScalaCU = compilationUnit("test/S.scala")
+ val originalSScala = SDTTestUtils.slurpAndClose(project.underlying.getFile("src/test/S.scala").getContents)
+ SDTTestUtils.changeContentOfFile(project.underlying, SScalaCU.getResource().getAdapter(classOf[IFile]).asInstanceOf[IFile], changedSScala)
+ rebuild(project)
+ val problems1 = getProblemMarkers()
+ Assert.assertTrue("One build error expected: " + userFriendlyMarkers(problems1), problems1.length == 1) // do more precise matching later
+
+ val SScalaCU2 = compilationUnit("test/S.scala")
+ SDTTestUtils.changeContentOfFile(project.underlying, SScalaCU2.getResource().getAdapter(classOf[IFile]).asInstanceOf[IFile], originalSScala)
+ rebuild(project)
+ val problems2 = getProblemMarkers()
+ Assert.assertTrue("Build errors found: " + userFriendlyMarkers(problems2), problems2.isEmpty)
+ }
+
+ def rebuild(prj: ScalaProject): List[IMarker] = {
+ println("building " + prj)
+ prj.underlying.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor)
+ getProblemMarkers()
+ }
+
+ def getProblemMarkers(): List[IMarker] = {
+ val units = compilationUnits("test/J.java", "test/S.scala").toList
+ units.flatMap(SDTTestUtils.findProblemMarkers)
+ }
+
+ def userFriendlyMarkers(markers: List[IMarker]) = markers.map(_.getAttribute(IMarker.MESSAGE))
+
+ lazy val changedJJava = """
+package test;
+
+public class J {
+ public static void main(String[] args) {
+ new S().foo("ahoy");
+ }
+ public String bar1(String s) {
+ return s + s;
+ }
+}
+"""
+
+ lazy val changedSScala = """
+package test
+
+class S {
+ def foo1(s:String) { println(new J().bar(s)) }
+}
+"""
+}
@@ -8,11 +8,8 @@ import scala.tools.eclipse.ScalaProject
import org.eclipse.jdt.core.ICompilationUnit
import scala.tools.eclipse.javaelements.ScalaSourceFile
import scala.tools.eclipse.javaelements.ScalaCompilationUnit
-import org.eclipse.jdt.core.ICompilationUnit
import org.eclipse.jdt.core.IProblemRequestor
import org.eclipse.jdt.core.WorkingCopyOwner
-import scala.tools.eclipse.javaelements.ScalaCompilationUnit
-import scala.tools.eclipse.javaelements.ScalaSourceFile
import org.eclipse.core.runtime.NullProgressMonitor
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>builder-compiler-classpath</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.scala-ide.sdt.core.scalabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.scala-ide.sdt.core.scalanature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,12 @@
+#Tue Sep 20 15:12:59 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
@@ -0,0 +1,34 @@
+#Tue Sep 20 15:24:27 CEST 2011
+Xcheck-null=false
+Xcheckinit=false
+Xdisable-assertions=false
+Xelide-below=-2147483648
+Xexperimental=false
+Xfatal-warnings=false
+Xfuture=false
+Xlog-implicits=false
+Xmigration=false
+Xno-uescape=false
+Xpluginsdir=misc/scala-devel/plugins
+Ybuild-manager-debug=false
+Yno-generic-signatures=false
+Yno-imports=false
+Ypresentation-debug=false
+Ypresentation-delay=0
+Ypresentation-verbose=false
+Yrecursion=0
+Yself-in-annots=false
+Ystruct-dispatch=poly-cache
+Ywarn-dead-code=false
+buildmanager=sbt
+deprecation=false
+eclipse.preferences.version=1
+explaintypes=false
+g=vars
+no-specialization=false
+nowarn=false
+optimise=false
+scala.compiler.useProjectSettings=true
+target=jvm-1.5
+unchecked=false
+verbose=false
@@ -0,0 +1,7 @@
+package test
+
+class CompilerDep {
+ def foo {
+ println(scala.tools.nsc.Main.prompt)
+ }
+}
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>scalajavadep</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.scala-ide.sdt.core.scalabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.scala-ide.sdt.core.scalanature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,12 @@
+#Tue Sep 20 15:12:59 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
@@ -0,0 +1,34 @@
+#Tue Sep 20 15:24:27 CEST 2011
+Xcheck-null=false
+Xcheckinit=false
+Xdisable-assertions=false
+Xelide-below=-2147483648
+Xexperimental=false
+Xfatal-warnings=false
+Xfuture=false
+Xlog-implicits=false
+Xmigration=false
+Xno-uescape=false
+Xpluginsdir=misc/scala-devel/plugins
+Ybuild-manager-debug=false
+Yno-generic-signatures=false
+Yno-imports=false
+Ypresentation-debug=false
+Ypresentation-delay=0
+Ypresentation-verbose=false
+Yrecursion=0
+Yself-in-annots=false
+Ystruct-dispatch=poly-cache
+Ywarn-dead-code=false
+buildmanager=sbt
+deprecation=false
+eclipse.preferences.version=1
+explaintypes=false
+g=vars
+no-specialization=false
+nowarn=false
+optimise=false
+scala.compiler.useProjectSettings=true
+target=jvm-1.5
+unchecked=false
+verbose=false
@@ -0,0 +1,10 @@
+package test;
+
+public class J {
+ public static void main(String[] args) {
+ new S().foo("ahoy");
+ }
+ public String bar(String s) {
+ return s + s;
+ }
+}
@@ -0,0 +1,5 @@
+package test
+
+class S {
+ def foo(s:String) { println(new J().bar(s)) }
+}
Oops, something went wrong.

0 comments on commit ce49e0a

Please sign in to comment.