Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Closes #1000566 and #1000565. Unlike SBT, which for compiling Java fi…

…les uses straight java batch compiler, we will use eclipse's java builder (similarly to what we were doing in the past) and then run sbt's classfile analyzer to pick up dependencies correctly. sbt's sources were updated accordingly to allow for multiple output directories.
  • Loading branch information...
commit 306ce8edb30a2e7c485717abdaf0048224134bc2 1 parent 8d08ab4
@hubertp hubertp authored
Showing with 152 additions and 82 deletions.
  1. +1 −2  org.scala-ide.build-toolchain/build-toolchain-2.8.1.final.sh
  2. +1 −2  org.scala-ide.build-toolchain/build-toolchain-2.8.x.sh
  3. +1 −2  org.scala-ide.build-toolchain/build-toolchain-2.9.0-1.sh
  4. +1 −3 org.scala-ide.build-toolchain/build-toolchain-2.9.0.final.sh
  5. +1 −2  org.scala-ide.build-toolchain/build-toolchain-2.9.x.sh
  6. +1 −2  org.scala-ide.build-toolchain/build-toolchain-trunk.sh
  7. +0 −1  org.scala-ide.build-toolchain/env.sh
  8. +1 −1  org.scala-ide.build-toolchain/pom.xml
  9. +0 −1  org.scala-ide.build/pom.xml
  10. +2 −2 org.scala-ide.sbt/pom.xml
  11. +1 −1  org.scala-ide.scala.compiler/pom.xml
  12. +1 −1  org.scala-ide.scala.library/pom.xml
  13. +4 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaBuilder.scala
  14. +0 −2  org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaPlugin.scala
  15. +1 −1  org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaProject.scala
  16. +29 −22 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/AnalysisCompile.scala
  17. +22 −24 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/EclipseSbtBuildManager.scala
  18. +51 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/JavaEclipseCompiler.scala
  19. +13 −9 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/SbtConf.scala
  20. +21 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/ScalaSbtCompiler.scala
View
3  org.scala-ide.build-toolchain/build-toolchain-2.8.1.final.sh
@@ -4,11 +4,10 @@
SCALA_VERSION=2.8.1
SCALA_PRECOMPILED=2_8_1
-SBT_VERSION=0.10.1-SNAPSHOT
SBT_SCALA_VERSION=2.8.1
SBINARY_VERSION=0.4.0
-set_version ${SCALA_VERSION} ${SBT_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
+set_version ${SCALA_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
PROFILE="-P sbt-2.8"
View
3  org.scala-ide.build-toolchain/build-toolchain-2.8.x.sh
@@ -6,10 +6,9 @@ SCALA_VERSION=2.8.2-SNAPSHOT
#THIS NEEDS TO BE UPDATED ONCE WE HAVE SNAPSHOTS
SCALA_PRECOMPILED=2_8_2-SNAPSHOT
SBT_SCALA_VERSION=2.8.1
-SBT_VERSION=0.10.1-SNAPSHOT
SBINARY_VERSION=0.4.0
-set_version ${SCALA_VERSION} ${SBT_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
+set_version ${SCALA_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
PROFILE="-P sbt-2.8,default"
View
3  org.scala-ide.build-toolchain/build-toolchain-2.9.0-1.sh
@@ -4,11 +4,10 @@
SCALA_VERSION=2.9.0-1
SCALA_PRECOMPILED=2_9_0-1
-SBT_VERSION=0.10.1-SNAPSHOT
SBT_SCALA_VERSION=2.9.0-1
SBINARY_VERSION=0.4.0
-set_version ${SCALA_VERSION} ${SBT_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
+set_version ${SCALA_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
PROFILE="-P sbt-2.9,default"
View
4 org.scala-ide.build-toolchain/build-toolchain-2.9.0.final.sh
@@ -2,14 +2,12 @@
. $(dirname $0)/env.sh
-
SCALA_VERSION=2.9.0
SCALA_PRECOMPILED=2_9_0
-SBT_VERSION=0.10.1-SNAPSHOT
SBT_SCALA_VERSION=2.9.0
SBINARY_VERSION=0.4.0
-set_version ${SCALA_VERSION} ${SBT_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
+set_version ${SCALA_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
PROFILE="-P sbt-2.9,default"
View
3  org.scala-ide.build-toolchain/build-toolchain-2.9.x.sh
@@ -6,10 +6,9 @@ SCALA_VERSION=2.9.1-SNAPSHOT
#THIS NEEDS TO BE UPDATED ONCE WE HAVE SNAPSHOTS
SCALA_PRECOMPILED=2_9_1-SNAPSHOT
SBT_SCALA_VERSION=2.9.0-1
-SBT_VERSION=0.10.1-SNAPSHOT
SBINARY_VERSION=0.4.0
-set_version ${SCALA_VERSION} ${SBT_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
+set_version ${SCALA_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
PROFILE="-P sbt-2.9,default"
View
3  org.scala-ide.build-toolchain/build-toolchain-trunk.sh
@@ -3,12 +3,11 @@
. $(dirname $0)/env.sh
SCALA_VERSION=2.10.0-SNAPSHOT
-SBT_VERSION=0.10.1-SNAPSHOT
SBT_SCALA_VERSION=2.10.0-SNAPSHOT
SBINARY_VERSION=0.4.0
SCALA_PRECOMPILED=2_10_0-SNAPSHOT
-set_version ${SCALA_VERSION} ${SBT_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
+set_version ${SCALA_VERSION} ${SBINARY_VERSION} ${SCALA_PRECOMPILED} ${SBT_SCALA_VERSION}
PROFILE="-P sbt-2.10,default"
View
1  org.scala-ide.build-toolchain/env.sh
@@ -25,7 +25,6 @@ build()
-U \
$PROFILE \
-Dscala.version=${SCALA_VERSION} \
- -Dsbt.version=${SBT_VERSION} \
-Dsbt.scala.version=${SBT_SCALA_VERSION} \
-Dsbinary.version=${SBINARY_VERSION} \
-Dscala.precompiled.version=${SCALA_PRECOMPILED} \
View
2  org.scala-ide.build-toolchain/pom.xml
@@ -10,7 +10,7 @@
<properties>
<scala.version>2.8.0</scala.version>
- <sbt.version>0.10.1-SNAPSHOT</sbt.version>
+ <sbt.version>0.10.2-SNAPSHOT</sbt.version>
<patch.level>p0002</patch.level>
<encoding>UTF-8</encoding>
</properties>
View
1  org.scala-ide.build/pom.xml
@@ -13,7 +13,6 @@
<version.tag>nightly</version.tag>
<version.suffix>210</version.suffix>
<tycho.version>0.11.1</tycho.version>
- <sbt.version>0.10.1-SNAPSHOT</sbt.version>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
<encoding>UTF-8</encoding>
View
4 org.scala-ide.sbt/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.scala-ide</groupId>
<artifactId>scala-toolchain-for-eclipse</artifactId>
- <version>2.9.1-SNAPSHOT</version>
+ <version>2.10.0-SNAPSHOT</version>
<relativePath>../org.scala-ide.build-toolchain/pom.xml</relativePath>
</parent>
<artifactId>org.scala-ide.sbt.full.library</artifactId>
@@ -407,7 +407,7 @@
<artifactItem>
<groupId>org.scala-tools.sbt</groupId>
<artifactId>precompiled-${sbt.compiled.version}-${scala.precompiled.version}</artifactId>
- <version>0.10.1-SNAPSHOT</version>
+ <version>${sbt.version}</version>
<type>jar</type>
<destFileName>scala-${scala.major.minor.version}/lib/compiler-interface.jar</destFileName>
</artifactItem>
View
2  org.scala-ide.scala.compiler/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.scala-ide</groupId>
<artifactId>scala-toolchain-for-eclipse</artifactId>
- <version>2.9.1-SNAPSHOT</version>
+ <version>2.10.0-SNAPSHOT</version>
<relativePath>../org.scala-ide.build-toolchain/pom.xml</relativePath>
</parent>
<artifactId>org.scala-ide.scala.compiler</artifactId>
View
2  org.scala-ide.scala.library/pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.scala-ide</groupId>
<artifactId>scala-toolchain-for-eclipse</artifactId>
- <version>2.9.1-SNAPSHOT</version>
+ <version>2.10.0-SNAPSHOT</version>
<relativePath>../org.scala-ide.build-toolchain/pom.xml</relativePath>
</parent>
<artifactId>org.scala-ide.scala.library</artifactId>
View
6 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaBuilder.scala
@@ -34,6 +34,7 @@ class ScalaBuilder extends IncrementalProjectBuilder {
override def build(kind : Int, ignored : ju.Map[_, _], monitor : IProgressMonitor) : Array[IProject] = {
import IncrementalProjectBuilder._
+ import buildmanager.sbtintegration.EclipseSbtBuildManager
val project = plugin.getScalaProject(getProject)
@@ -65,7 +66,7 @@ class ScalaBuilder extends IncrementalProjectBuilder {
})
// Only for sbt which is able to track external dependencies properly
project.buildManager match {
- case _: buildmanager.sbtintegration.EclipseSbtBuildManager =>
+ case _: EclipseSbtBuildManager =>
if (project.externalDepends.exists(
x => { val delta = getDelta(x); delta == null || delta.getKind != IResourceDelta.NO_CHANGE})) {
// in theory need to be able to identify the exact dependencies
@@ -88,7 +89,8 @@ class ScalaBuilder extends IncrementalProjectBuilder {
project.build(addedOrUpdated, removed, subMonitor)
val depends = project.externalDepends.toList.toArray
- if (allSourceFiles.exists(FileUtils.hasBuildErrors(_)))
+ // SBT build manager already calls java builder internally
+ if (allSourceFiles.exists(FileUtils.hasBuildErrors(_)) || project.buildManager.isInstanceOf[EclipseSbtBuildManager])
depends
else {
ensureProject
View
2  org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaPlugin.scala
@@ -82,8 +82,6 @@ class ScalaPlugin extends AbstractUIPlugin with IResourceChangeListener with IEl
val scalaFileExtn = ".scala"
val javaFileExtn = ".java"
val jarFileExtn = ".jar"
-
- val sbtVersion = "0.10.1-SNAPSHOT"
private def cutVersion(version: String): String = {
val pattern = "(\\d)\\.(\\d+)\\..*".r
View
2  org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaProject.scala
@@ -482,7 +482,7 @@ class ScalaProject(val underlying: IProject) {
println("BM: Refined Build Manager")
buildManager0 = new buildmanager.refined.EclipseRefinedBuildManager(this, settings)
case "sbt" =>
- println("BM: SBT 0.10.1 enhanced Build Manager for " + ScalaPlugin.plugin.scalaVer + " Scala library")
+ println("BM: SBT enhanced Build Manager for " + ScalaPlugin.plugin.scalaVer + " Scala library")
buildManager0 = new buildmanager.sbtintegration.EclipseSbtBuildManager(this, settings)
case _ =>
println("Invalid build manager choice '" + choice + "'. Setting to (default) refined build manager")
View
51 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/AnalysisCompile.scala
@@ -1,4 +1,6 @@
-package scala.tools.eclipse.buildmanager.sbtintegration
+package scala.tools.eclipse
+package buildmanager
+package sbtintegration
import sbt.{Logger, IO, CompileSetup, CompileOptions,
ClasspathOptions, CompileOrder}
@@ -18,38 +20,42 @@ import sbinary.DefaultProtocol.{ immutableMapFormat, immutableSetFormat, StringF
import scala.collection.Seq
import scala.tools.nsc.io.AbstractFile
+import scala.tools.nsc.Settings
import scala.tools.eclipse.util.EclipseResource
import java.io.File
-class CompilerArgsConstr {
- def apply(sources: Seq[File], out: File, classpath: Seq[File]): Seq[String] = {
- param("-d", abs(out).toString) ++ debugSbt ++ param("-classpath", classpath.map(_.toString).mkString(":")) ++ abs(sources)
- }
-
- private def debugSbt: Seq[String] = Seq("-Dxsbt.inc.debug=true")
- private def param(name: String, value: String): Seq[String] = Seq(name, value)
-
- private def abs(files: Seq[File]) = files.map(_.getAbsolutePath).sortWith(_ < _)
- private def abs(file: File) = file.getAbsolutePath
-}
class AnalysisCompile (conf: BasicConfiguration, bm: EclipseSbtBuildManager, contr: Controller) {
import AnalysisFormats._
- private lazy val store = AnalysisStore.sync(AnalysisStore.cached(FileBasedStore(conf.cacheDirectory)))
+ private lazy val store = AnalysisStore.sync(AnalysisStore.cached(FileBasedStore(EclipseResource(conf.cacheLocation).file)))
private def withBootclasspath(args: CompilerArguments, classpath: Seq[File]): Seq[File] =
args.bootClasspath ++ args.finishClasspath(classpath)
implicit def toAbstractFile(files: Seq[File]): Set[AbstractFile] =
files.flatMap(f => EclipseResource.fromString(f.getPath)).toSet
+
+ def removeSbtOutputDirs(args: List[String]) = {
+ val outputOpt = "-d"
+ val left = args.takeWhile(_ != outputOpt)
+ val right = args.dropWhile(_ != outputOpt)
+ right match {
+ case d::out::rest =>
+ (left:::rest).toSeq
+ case _ =>
+ // something is wrong
+ assert(false, "Incorrect configuration for compiler arguments: " + args)
+ args.toSeq
+ }
+ }
- def doCompile(scalac: ScalaSbtCompiler, javac: JavaCompiler,
- sources: Seq[File], reporter: Reporter,
+ def doCompile(scalac: ScalaSbtCompiler, javac: JavaEclipseCompiler,
+ sources: Seq[File], reporter: Reporter, settings: Settings,
compOptions: Seq[String] = Nil, javaSrcBases: Seq[File] = Nil,
javacOptions: Seq[String] = Nil, compOrder: CompileOrder.Value = Mixed,
analysisMap: Map[File, Analysis] = Map.empty, maxErrors: Int = 100)(implicit log: EclipseLogger): Analysis = {
-
+
val currentSetup = new CompileSetup(conf.outputDirectory, new CompileOptions(compOptions, javacOptions),
scalac.scalaInstance.actualVersion, Mixed)
import currentSetup._
@@ -67,7 +73,7 @@ class AnalysisCompile (conf: BasicConfiguration, bm: EclipseSbtBuildManager, con
val (previousAnalysis, previousSetup) = extract(store.get)
val compile0 = (include: Set[File], callback: AnalysisCallback) => {
- IO.createDirectory(conf.outputDirectory)
+ conf.outputDirectories.foreach(IO.createDirectory)
val incSrc = sources.filter(include)
println("Compiling:\n\t" + incSrc.mkString("\n\t"))
bm.buildingFiles(toAbstractFile(incSrc))
@@ -85,9 +91,9 @@ class AnalysisCompile (conf: BasicConfiguration, bm: EclipseSbtBuildManager, con
def compileScala() =
if(!scalaSrcs.isEmpty) {
val sources0 = if(order == Mixed) incSrc else scalaSrcs
- val arguments = compArgs(sources0, conf.classpath, conf.outputDirectory, options.options)
+ val arguments = removeSbtOutputDirs(compArgs(sources0, conf.classpath, conf.outputDirectory, options.options).toList)
try {
- scalac.compile(arguments, callback, maxErrors, log, contr)
+ scalac.compile(arguments, callback, maxErrors, log, contr, settings)
} catch {
case err: xsbti.CompileFailed =>
scalaError = Some(err)
@@ -99,15 +105,15 @@ class AnalysisCompile (conf: BasicConfiguration, bm: EclipseSbtBuildManager, con
val loader = ClasspathUtilities.toLoader(conf.classpath, scalac.scalaInstance.loader)
def readAPI(source: File, classes: Seq[Class[_]]) { callback.api(source, sbt.ClassToAPI(classes)) }
- sbt.classfile.Analyze(conf.outputDirectory, javaSrcs, log)(callback, loader, readAPI) {
- javac(javaSrcs, conf.classpath, conf.outputDirectory, options.javacOptions)
+ sbt.classfile.Analyze(conf.outputDirectories, javaSrcs, log)(callback, loader, readAPI) {
+ javac.build(org.eclipse.core.resources.IncrementalProjectBuilder.INCREMENTAL_BUILD)
log.flush()
}
}
if(order == JavaThenScala) {
compileJava(); compileScala()
- throwLater()
+ throwLater()
} else {
compileScala(); compileJava()
// if we reached here, then it might be that compiling scala files failed but java succeded
@@ -125,6 +131,7 @@ class AnalysisCompile (conf: BasicConfiguration, bm: EclipseSbtBuildManager, con
case _ => Incremental.prune(sources.toSet, previousAnalysis)
}
+ // Seems ok to just provide conf.outputDirectory
val (modified, result) : (Boolean, Analysis) =
IncrementalCompile(sources.toSet, entry, compile0, analysis, getAnalysis, conf.outputDirectory, log)
View
46 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/EclipseSbtBuildManager.scala
@@ -208,20 +208,6 @@ class SbtBuildLogger(underlying: BuildReporter) extends EclipseLogger {
}
}
-object SettingsUnParser {
- def apply(s: Settings): Seq[String] = {
- val disallowed = Set(s.d, s.Ybuildmanagerdebug, s.Ybuilderdebug, s.sourcepath, s.sourcedir,
- s.YpresentationDebug, s.YpresentationDelay, s.YpresentationLog,
- s.YpresentationReplay, s.YpresentationVerbose,
- s.classpath)
-
- val set = s.userSetSettings -- disallowed
-
- set.toList flatMap (_.unparse)
- }
-}
-
-
class EclipseSbtBuildManager(project: ScalaProject, settings0: Settings)
extends EclipseBuildManager {
@@ -271,9 +257,9 @@ class EclipseSbtBuildManager(project: ScalaProject, settings0: Settings)
lazy val reporter: xsbti.Reporter = new SbtBuildReporter(_buildReporter)
val pendingSources = new mutable.HashSet[IFile]
- private def filterOutScalaJars(l: Seq[IPath]): Seq[IPath] = {
+ private def filterOutScalaJars(l: Seq[IPath]): (Seq[IPath], Option[IPath]) = {
val jars = l.partition(p => p.lastSegment() == ScalaCompilerConf.LIBRARY_SUFFIX || p.lastSegment() == ScalaCompilerConf.COMPILER_SUFFIX)
- jars._2
+ (jars._2, jars._1.find(p => p.lastSegment() == ScalaCompilerConf.LIBRARY_SUFFIX))
}
lazy val scalaVersion = {
@@ -281,13 +267,14 @@ class EclipseSbtBuildManager(project: ScalaProject, settings0: Settings)
ScalaPlugin.plugin.scalaVer
}
- def compilers(settings: Settings, libJar: File, compJar:File, compInterfaceJar: File): (ScalaSbtCompiler, JavaCompiler) = {
+ def compilers(settings: Settings, libJar: File, compJar:File, compInterfaceJar: File): (ScalaSbtCompiler, JavaEclipseCompiler) = {
val scalacInstance = ScalaCompilerConf(scalaVersion, libJar, compJar, compInterfaceJar)
val scalac = new ScalaSbtCompiler(settings,
scalacInstance,
ClasspathOptions.auto,
reporter)
- val javac = JavaCompiler.directOrFork(scalac.cp, scalac.scalaInstance)( (args: Seq[String], log: sbt.Logger) => Process("javac", args) ! log )
+ //val javac = JavaCompiler.directOrFork(scalac.cp, scalac.scalaInstance)( (args: Seq[String], log: sbt.Logger) => Process("javac", args) ! log )
+ val javac = new JavaEclipseCompiler(project.underlying, monitor)
(scalac, javac)
}
@@ -327,23 +314,30 @@ class EclipseSbtBuildManager(project: ScalaProject, settings0: Settings)
private def runCompiler(sources: Seq[File]) {
// setup the settings
- val restJars = filterOutScalaJars(project.classpath)
+ val allJarsAndLibrary = filterOutScalaJars(project.classpath)
// Fixed 2.9 for now
- val libJar = ScalaPlugin.plugin.sbtScalaLib
+ val libJar = allJarsAndLibrary match {
+ case (_, Some(lib)) =>
+ lib.toFile()
+ case (_, None) =>
+ println("Cannot find Scala library on the classpath. Verify your build path! Using default library corresponding to the compiler")
+ // TODO remove once we no longer pack scala-library with it
+ ScalaPlugin.plugin.sbtScalaLib.get.toFile
+ }
val compJar = ScalaPlugin.plugin.sbtScalaCompiler
// TODO pull the actual version from properties and select the correct one
val compInterfaceJar = ScalaPlugin.plugin.sbtCompilerInterface
- val (scalac, javac) = compilers(settings0, libJar.get.toFile, compJar.get.toFile, compInterfaceJar.get.toFile)
+ val (scalac, javac) = compilers(settings0, libJar, compJar.get.toFile, compInterfaceJar.get.toFile)
// read settings properly
//val cp = disintegrateClasspath(settings.classpath.value)
- val cp = restJars.map(_.toFile)
+ val cp = allJarsAndLibrary._1.map(_.toFile)
val conf = new BasicConfiguration(
project, Seq(scalac.scalaInstance.libraryJar, compInterfaceJar.get.toFile) ++ cp)
val analysisComp = new AnalysisCompile(conf, this, new SbtProgress())
val result = analysisComp.doCompile(
- scalac, javac, sources, reporter, SettingsUnParser(settings0))
+ scalac, javac, sources, reporter, settings0)
}
/** Not supported */
@@ -352,7 +346,11 @@ class EclipseSbtBuildManager(project: ScalaProject, settings0: Settings)
/** Not supported */
def saveTo(file: AbstractFile, fromFile: AbstractFile => String) {}
- def clean(implicit monitor: IProgressMonitor) {} // Should remove .cache and output directory
+ def clean(implicit monitor: IProgressMonitor) {
+ val dummy = new BasicConfiguration(project, Seq())
+ dummy.cacheLocation.delete(true, false, monitor)
+ // refresh explorer
+ }
def invalidateAfterLoad: Boolean = true
View
51 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/JavaEclipseCompiler.scala
@@ -0,0 +1,51 @@
+package scala.tools.eclipse
+package buildmanager
+package sbtintegration
+
+import org.eclipse.core.runtime.SubMonitor
+import org.eclipse.core.resources.{ IncrementalProjectBuilder, IProject}
+import scala.tools.eclipse.javaelements.JDTUtils
+import scala.tools.eclipse.util.FileUtils
+
+import org.eclipse.jdt.internal.core.JavaModelManager
+import org.eclipse.jdt.internal.core.builder.{ JavaBuilder, NameEnvironment, State }
+
+
+class JavaEclipseCompiler(project: IProject, monitor: SubMonitor) {
+ private val scalaJavaBuilder = new GeneralScalaJavaBuilder
+
+ def plugin = ScalaPlugin.plugin
+ def getProject = project
+
+ def build(kind: Int): Array[IProject] = {
+
+
+ val project = plugin.getScalaProject(getProject)
+
+ val allSourceFiles = project.allSourceFiles()
+ val depends = project.externalDepends.toList.toArray
+ if (allSourceFiles.exists(FileUtils.hasBuildErrors(_)))
+ depends
+ else {
+ ensureProject
+ val javaDepends = scalaJavaBuilder.build(kind,new java.util.HashMap(), monitor)
+ val modelManager = JavaModelManager.getJavaModelManager
+ val state = modelManager.getLastBuiltState(getProject, null).asInstanceOf[State]
+ val newState = if (state ne null) state
+ else {
+ ScalaJavaBuilderUtils.initializeBuilder(scalaJavaBuilder, 0, false)
+ StateUtils.newState(scalaJavaBuilder)
+ }
+ StateUtils.tagAsStructurallyChanged(newState)
+ StateUtils.resetStructurallyChangedTypes(newState)
+ modelManager.setLastBuiltState(getProject, newState)
+ JDTUtils.refreshPackageExplorer
+ (Set.empty ++ depends ++ javaDepends).toArray
+ }
+ }
+
+ def ensureProject = {
+ if (scalaJavaBuilder.getProject == null)
+ scalaJavaBuilder.setProject0(getProject)
+ }
+}
View
22 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/SbtConf.scala
@@ -53,22 +53,26 @@ class BasicConfiguration(
private final val cacheSuffix = ".cache"
private final val outSuffix = "target"
- def cacheDirectory: File = {
- outputDirectory / cacheSuffix
- }
- def outputDirectory: File = {
+ def cacheLocation = project.underlying.getFile(cacheSuffix)
+
+ def outputDirectories: List[File] = {
val outDirs = project.outputFolders.toList
outDirs match {
- case List(out) =>
+ case Nil =>
+ println("[Warning] No output directory specified")
+ List(project.underlying.getLocation().toFile / "default-bin")
+ case dirs =>
val root = ResourcesPlugin.getWorkspace().getRoot()
- val ifolder = root.getFolder(out)
- ifolder.getLocation().toFile
- case _ =>
- project.underlying.getLocation().toFile / "default-bin"
+ dirs.map(dir => root.getFolder(dir).getLocation().toFile())
}
}
+ def outputDirectory: File =
+ // use projects directory. It doesn't really matter because this configuration
+ // contains only a dummy value for sbt (though it needs to be real directory)
+ project.underlying.getLocation().toFile
+
def classesDirectory: File = {
outputDirectory
}
View
23 org.scala-ide.sdt.core/src/scala/tools/eclipse/buildmanager/sbtintegration/ScalaSbtCompiler.scala
@@ -4,6 +4,24 @@ import scala.tools.nsc.Settings
import sbt.{ScalaInstance, LoggerReporter, ClasspathOptions}
import xsbti.{AnalysisCallback, Reporter, Logger, Controller}
+import xsbt.Log
+
+
+object SettingsCleanup {
+ def apply(s: Settings, log: Logger): Settings = {
+ val toDefault = Set(s.d, s.Ybuildmanagerdebug, s.Ybuilderdebug, s.sourcepath, s.sourcedir,
+ s.YpresentationDebug, s.YpresentationDelay, s.YpresentationLog,
+ s.YpresentationReplay, s.YpresentationVerbose,
+ s.classpath)
+ val s1 = new Settings(Log.settingsError(log))
+ val xs = (s.userSetSettings -- toDefault) flatMap (_.unparse)
+
+ s1.processArguments(xs.toList, true)
+ // Needs to preserve output directories
+ s.outputDirs.outputs.foreach(v => s1.outputDirs.add(v._1, v._2))
+ s1
+ }
+}
/*
* In comparison to sbt.compile.AnalyzingCompiler we only need a single version of the scala compiler to support ATM.
@@ -14,8 +32,9 @@ class ScalaSbtCompiler(val settings: Settings,
val scalaInstance: ScalaInstance,
val cp: ClasspathOptions,
reporter: Reporter) {
- def compile(args: Seq[String], callback: AnalysisCallback, maxErrors:Int, log: Logger, contr: Controller) {
+ def compile(args: Seq[String], callback: AnalysisCallback, maxErrors:Int, log: Logger, contr: Controller, s: Settings) {
val cInterface = new xsbt.CompilerInterface
- cInterface.run(args.toArray[String], callback, log, reporter, contr)
+ val properSettingsWithErrorReporting = SettingsCleanup(s, log)
+ cInterface.run(args.toArray[String], callback, log, reporter, contr, properSettingsWithErrorReporting)
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.