filter detected binary plugins by classpath now that plugin class loader is shared. fixes #412

This commit is contained in:
Mark Harrah 2012-03-31 21:51:01 -04:00
parent 89678735e1
commit 6fb1934efa
5 changed files with 40 additions and 10 deletions

View File

@ -4,7 +4,7 @@
package sbt
import java.io.File
import java.net.URI
import java.net.{URI,URL}
import compiler.{Eval,EvalImports}
import xsbt.api.{Discovered,Discovery}
import classpath.ClasspathUtilities
@ -519,13 +519,17 @@ object Load
new LoadedPlugins(dir, classpath, loader, plugins, pluginNames)
}
def getPluginNames(classpath: Seq[Attributed[File]], loader: ClassLoader): Seq[String] =
( binaryPlugins(loader) ++ (analyzed(classpath) flatMap findPlugins) ).distinct
( binaryPlugins(Build.data(classpath), loader) ++ (analyzed(classpath) flatMap findPlugins) ).distinct
def binaryPlugins(loader: ClassLoader): Seq[String] =
def binaryPlugins(classpath: Seq[File], loader: ClassLoader): Seq[String] =
{
import collection.JavaConversions._
loader.getResources("sbt/sbt.plugins").toSeq flatMap { u => IO.readLinesURL(u) map { _.trim } filter { !_.isEmpty } };
loader.getResources("sbt/sbt.plugins").toSeq.filter(onClasspath(classpath)) flatMap { u =>
IO.readLinesURL(u).map( _.trim).filter(!_.isEmpty)
}
}
def onClasspath(classpath: Seq[File])(url: URL): Boolean =
IO.urlAsFile(url) exists (classpath.contains _)
def loadPlugins(loader: ClassLoader, pluginNames: Seq[String]): Seq[Plugin] =
pluginNames.map(pluginName => loadPlugin(pluginName, loader))

View File

@ -0,0 +1,7 @@
name := "source-plugins"
organization := "org.example"
ProguardPlugin.proguardSettings
useJGit

View File

@ -0,0 +1,7 @@
import sbt._
object PluginDef extends Build {
override def projects = Seq(root)
lazy val root = Project("plugins", file(".")) dependsOn(proguard, git)
lazy val proguard = uri("git://github.com/jsuereth/xsbt-proguard-plugin.git")
lazy val git = uri("git://github.com/sbt/sbt-git-plugin.git#scala-build")
}

View File

@ -0,0 +1,2 @@
# just need to verify it loads
> help

View File

@ -7,6 +7,7 @@ import Using._
import ErrorHandling.translate
import java.io.{BufferedReader, ByteArrayOutputStream, BufferedWriter, File, FileInputStream, InputStream, OutputStream, PrintWriter}
import java.io.{ObjectInputStream, ObjectStreamClass}
import java.net.{URI, URISyntaxException, URL}
import java.nio.charset.Charset
import java.util.Properties
@ -65,18 +66,18 @@ object IO
catch { case _: URISyntaxException => new File(url.getPath) }
/** Converts the given URL to a File. If the URL is for an entry in a jar, the File for the jar is returned. */
def asFile(url: URL): File =
{
def asFile(url: URL): File = urlAsFile(url) getOrElse error("URL is not a file: " + url)
def urlAsFile(url: URL): Option[File] =
url.getProtocol match
{
case "file" => toFile(url)
case "file" => Some(toFile(url))
case "jar" =>
val path = url.getPath
val end = path.indexOf('!')
new File(new URI(if(end == -1) path else path.substring(0, end)))
case _ => error("Invalid protocol " + url.getProtocol)
Some(new File(new URI(if(end == -1) path else path.substring(0, end))))
case _ => None
}
}
def assertDirectory(file: File) { assert(file.isDirectory, (if(file.exists) "Not a directory: " else "Directory not found: ") + file) }
def assertDirectories(file: File*) { file.foreach(assertDirectory) }
@ -704,4 +705,13 @@ object IO
def assertAbsolute(uri: URI) = assert(uri.isAbsolute, "Not absolute: " + uri)
def parseClasspath(s: String): Seq[File] = IO.pathSplit(s).map(new File(_)).toSeq
def objectInputStream(wrapped: InputStream, loader: ClassLoader): ObjectInputStream = new ObjectInputStream(wrapped)
{
override def resolveClass(osc: ObjectStreamClass): Class[_] =
{
val c = Class.forName(osc.getName, false, loader)
if(c eq null) super.resolveClass(osc) else c
}
}
}