diff --git a/main/Load.scala b/main/Load.scala index 6f4fb83b3..73dc0bb38 100755 --- a/main/Load.scala +++ b/main/Load.scala @@ -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)) diff --git a/sbt/src/sbt-test/project/source-plugins/build.sbt b/sbt/src/sbt-test/project/source-plugins/build.sbt new file mode 100644 index 000000000..500e7835b --- /dev/null +++ b/sbt/src/sbt-test/project/source-plugins/build.sbt @@ -0,0 +1,7 @@ +name := "source-plugins" + +organization := "org.example" + +ProguardPlugin.proguardSettings + +useJGit \ No newline at end of file diff --git a/sbt/src/sbt-test/project/source-plugins/project/project/Build.scala b/sbt/src/sbt-test/project/source-plugins/project/project/Build.scala new file mode 100644 index 000000000..74665f0e1 --- /dev/null +++ b/sbt/src/sbt-test/project/source-plugins/project/project/Build.scala @@ -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") +} \ No newline at end of file diff --git a/sbt/src/sbt-test/project/source-plugins/test b/sbt/src/sbt-test/project/source-plugins/test new file mode 100644 index 000000000..08a542bb3 --- /dev/null +++ b/sbt/src/sbt-test/project/source-plugins/test @@ -0,0 +1,2 @@ +# just need to verify it loads +> help \ No newline at end of file diff --git a/util/io/IO.scala b/util/io/IO.scala index d3ff939af..d4afd1dc6 100644 --- a/util/io/IO.scala +++ b/util/io/IO.scala @@ -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 + } + } }