fix project creation prompt and launcher cache

This commit is contained in:
Mark Harrah 2010-01-27 18:22:42 -05:00
parent 5de7a5e3e5
commit 4a566eb581
4 changed files with 31 additions and 10 deletions

View File

@ -54,6 +54,7 @@ class AnalyzingCompiler(val scalaInstance: ScalaInstance, val manager: Component
val bootClasspath = arguments.createBootClasspath
call("xsbt.ConsoleInterface", log) (classOf[String], classOf[String], classOf[String], classOf[xLogger]) (bootClasspath, classpathString, initialCommands, log)
}
def force(log: CompileLogger): Unit = getInterfaceJar(log)
private def call(interfaceClassName: String, log: CompileLogger)(argTypes: Class[_]*)(args: AnyRef*)
{
val interfaceClass = getInterfaceClass(interfaceClassName, log)
@ -64,14 +65,18 @@ class AnalyzingCompiler(val scalaInstance: ScalaInstance, val manager: Component
}
private def getInterfaceClass(name: String, log: CompileLogger) =
{
// this is the instance used to compile the interface component
val componentCompiler = newComponentCompiler(log)
log.debug("Getting " + ComponentCompiler.compilerInterfaceID + " from component compiler for Scala " + scalaInstance.version)
val interfaceJar = componentCompiler(ComponentCompiler.compilerInterfaceID)
val interfaceJar = getInterfaceJar(log)
val dual = createDualLoader(scalaInstance.loader, getClass.getClassLoader) // this goes to scalaLoader for scala classes and sbtLoader for xsbti classes
val interfaceLoader = new URLClassLoader(Array(interfaceJar.toURI.toURL), dual)
Class.forName(name, true, interfaceLoader)
}
private def getInterfaceJar(log: CompileLogger) =
{
// this is the instance used to compile the interface component
val componentCompiler = newComponentCompiler(log)
log.debug("Getting " + ComponentCompiler.compilerInterfaceID + " from component compiler for Scala " + scalaInstance.version)
componentCompiler(ComponentCompiler.compilerInterfaceID)
}
def newComponentCompiler(log: CompileLogger) = new ComponentCompiler(new RawCompiler(scalaInstance, log), manager)
protected def createDualLoader(scalaLoader: ClassLoader, sbtLoader: ClassLoader): ClassLoader =
{

View File

@ -1,20 +1,33 @@
package xsbt.boot
import java.lang.ref.{Reference, SoftReference}
import java.util.HashMap
final class Cache[K,V](create: K => V) extends NotNull
{
private[this] val delegate = new HashMap[K,V]
private[this] val delegate = new HashMap[K,Reference[V]]
def apply(k: K): V =
{
val existing = delegate.get(k)
if(existing == null) newEntry(k) else existing
val existingRef = delegate.get(k)
if(existingRef == null)
newEntry(k)
else
{
val existing = existingRef.get
if(existing == null)
{
println("Cache value for '" + k + "' was garbage collected, recreating it...")
newEntry(k)
}
else
existing
}
}
private[this] def newEntry(k: K): V =
{
val v = create(k)
Pre.assert(v != null, "Value for key " + k + " was null")
delegate.put(k, v)
delegate.put(k, new SoftReference(v))
v
}
}

View File

@ -15,8 +15,11 @@ object Initialize
line.toLowerCase match
{
case "y" | "yes" => process(file, spec, _.create)
case "n" | "no" | "" => declined("")
case "s" => process(file, spec, _.quick)
case "n" | "no" | "" => declined("")
case x =>
System.out.println(" '" + x + "' not understood.")
create(file, promptCreate, enableQuick, spec)
}
}
}

View File

@ -25,7 +25,7 @@ class AggressiveCompiler extends xsbti.AppMain
val launcher = app.scalaProvider.launcher
val sources = Task(cwd ** "*.scala")
val outputDirectory = Task(cwd / "target" / "classes")
val classpath = outputDirectory map { _ ++ (cwd ** "*.jar") }
val classpath = outputDirectory map { _ ++ (cwd * "*.jar") ++(cwd * (-"project")).descendentsExcept( "*.jar", "project" || HiddenFileFilter) }
val cacheDirectory = cwd / "target" / "cache"
val options = Task(args.tail.toSeq)
val log = new ConsoleLogger with CompileLogger with sbt.IvyLogger { def verbose(msg: => String) = debug(msg) }