scala-ide/scala-ide — pull request #262 by rkrzewski (2012-12-14 11:02:31+00:00)
Title: Ignore non-existent source classpath entries

I'm using scala-ide together with [scala-maven-plugin](https://github.com/davidB/scala-maven-plugin) and [m2eclipse-scala](https://github.com/sonatype/m2eclipse-scala).

m2e projects configurators routinely add all source directories defined in POM: (src/main/java, src/main/scala, src/test/java, src/test/scala in case of m2eclipse-scala). All entries are marked as optional, and when the directories are not physically present, JDT ignores them. Unfortunately SBT chokes on such non-existent directories: project compilation aborts and two error markers are added per project:

```
Error in Scala compiler: /home/rafal/workspaces/scala/scalate-scala-2.10/scalate/scalate-guice/src/main/java does not exist or is not a directory
```
```
SBT builder crashed while compiling. The error message is /home/rafal/workspaces/scala/scalate-scala-2.10/scalate/scalate-guice/src/main/java'. Check Error Log for details.
```
Log entry:
```
scala.reflect.internal.FatalError: /home/rafal/workspaces/scala/scalate-scala-2.10/scalate/scalate-guice/src/main/java does not exist or is not a directory
at scala.tools.nsc.settings.MutableSettings$OutputDirs.checkDir(MutableSettings.scala:262)
at scala.tools.nsc.settings.MutableSettings$OutputDirs.add(MutableSettings.scala:251)
at xsbt.CachedCompiler0$$anonfun$2.apply(CompilerInterface.scala:67)
at xsbt.CachedCompiler0$$anonfun$2.apply(CompilerInterface.scala:66)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:105)
at xsbt.CachedCompiler0.(CompilerInterface.scala:66)
at xsbt.CompilerInterface.newCompiler(CompilerInterface.scala:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:74)
at sbt.compiler.AnalyzingCompiler.newCachedCompiler(AnalyzingCompiler.scala:45)
at sbt.compiler.AnalyzingCompiler.newCachedCompiler(AnalyzingCompiler.scala:40)
at sbt.compiler.CompilerCache$$anon$2.apply(CompilerCache.scala:50)
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:28)
at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply$mcV$sp(AggressiveCompile.scala:72)
at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:72)
at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:72)
at sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:129)
at sbt.compiler.AggressiveCompile$$anonfun$3.compileScala$1(AggressiveCompile.scala:71)
at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:112)
at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:60)
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:24)
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:22)
at sbt.inc.Incremental$.cycle(Incremental.scala:40)
at sbt.inc.Incremental$.compile(Incremental.scala:25)
at sbt.inc.IncrementalCompile$.apply(Compile.scala:20)
at sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:120)
at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:44)
at sbt.compiler.AggressiveCompile.apply(AggressiveCompile.scala:31)
at sbt.compiler.IC$.compile(IncrementalCompiler.scala:20)
at scala.tools.eclipse.buildmanager.sbtintegration.EclipseSbtBuildManager.runCompiler(EclipseSbtBuildManager.scala:129)
at scala.tools.eclipse.buildmanager.sbtintegration.EclipseSbtBuildManager.update(EclipseSbtBuildManager.scala:119)
at scala.tools.eclipse.buildmanager.sbtintegration.EclipseSbtBuildManager.build(EclipseSbtBuildManager.scala:174)
at scala.tools.eclipse.ScalaProject.build(ScalaProject.scala:608)
at scala.tools.eclipse.ScalaBuilder.build(ScalaBuilder.scala:114)
```
This problem can be fixed temporarily by manually deleting the faulty classpath entries and rebuilding the project. Unfortunately as soon as m2e updates project configuration the classpath entries are created back again. This gets irritating rather quickly, especially if there are a few dozen projects in the workspace :)

Fixing this problem on m2e side is probably not feasible - there are many m2e connectors out there for various code generator plugins and they all use the optional classpath entry convention because of shared base class from m2e.core (org.eclipse.m2e.jdt.AbstractJavaProjectConfigurator).

I was able to track down two places where scala-ide handles the source classpath entries and patch them up to ignore the non-existent ones. This fixed the problem for me.