summaryrefslogtreecommitdiff
path: root/project
diff options
context:
space:
mode:
authorStefan Zeiger <szeiger@novocode.com>2015-10-28 20:28:52 +0100
committerStefan Zeiger <szeiger@novocode.com>2015-10-29 16:46:25 +0100
commit9debc84dcd57c331c184a3cf58b627045db632e0 (patch)
tree7e9fbec53a982fdf98ee09a20a1ed63d3e40cdcf /project
parent5e080eb204dab36dd4ae1e42adc63737fe8a9e6d (diff)
downloadscala-9debc84dcd57c331c184a3cf58b627045db632e0.tar.gz
scala-9debc84dcd57c331c184a3cf58b627045db632e0.tar.bz2
scala-9debc84dcd57c331c184a3cf58b627045db632e0.zip
Create shaded JLine in sbt build
Reusing parts of #4593, this commits adds two additional subprojects to the sbt build: - repl-jline, which is already used by the ant build, builds the part of the REPL that depends on JLine. The actual JLine depenency is moved to this project. - repl-jline-shaded uses JarJar to create a shaded version of repl-jline and jline.jar. Unlike the ant build, this setup does not use any circular dependencies. dist/mkBin puts all of quick/repl, quick/repl-jline and quick/repl-jline-shaded onto the classpath of build-sbt/quick/bin/scala. A future addition to the sbt build for building build-sbt/pack will have to put the generated classfiles into the correct JARs, mirroring the old structure.
Diffstat (limited to 'project')
-rw-r--r--project/JarJar.scala83
-rw-r--r--project/plugins.sbt4
2 files changed, 86 insertions, 1 deletions
diff --git a/project/JarJar.scala b/project/JarJar.scala
new file mode 100644
index 0000000000..64281f23c1
--- /dev/null
+++ b/project/JarJar.scala
@@ -0,0 +1,83 @@
+import org.pantsbuild.jarjar
+import org.pantsbuild.jarjar._
+import org.pantsbuild.jarjar.util._
+import scala.collection.JavaConverters._
+import java.util.jar._
+import java.io._
+import sbt._
+
+object JarJar {
+ sealed abstract class JarJarConfig {
+ def toPatternElement: PatternElement
+ }
+ object JarJarConfig {
+ case class Rule(pattern: String, result: String) extends JarJarConfig {
+ def toPatternElement: PatternElement = {
+ val rule = new jarjar.Rule
+ rule.setPattern(pattern)
+ rule.setResult(result)
+ rule
+ }
+ }
+ case class Keep(pattern: String) extends JarJarConfig {
+ def toPatternElement: PatternElement = {
+ val keep = new jarjar.Keep
+ keep.setPattern(pattern)
+ keep
+ }
+ }
+ }
+
+ sealed abstract class Entry {
+ def name: String
+ def time: Long
+ def data: Array[Byte]
+ }
+
+ case class JarEntryInput(jarFile: JarFile, entry: JarEntry) extends Entry {
+ def name = entry.getName
+ def time = entry.getTime
+ def data = sbt.IO.readBytes(jarFile.getInputStream(entry))
+ }
+ case class FileInput(base: File, file: File) extends Entry {
+ def name = file.relativeTo(base).get.getPath
+ def time = file.lastModified
+ def data = sbt.IO.readBytes(file)
+ }
+
+ private def newMainProcessor(patterns: java.util.List[PatternElement], verbose: Boolean, skipManifest: Boolean): JarProcessor = {
+ val cls = Class.forName("org.pantsbuild.jarjar.MainProcessor")
+ val constructor = cls.getConstructor(classOf[java.util.List[_]], java.lang.Boolean.TYPE, java.lang.Boolean.TYPE)
+ constructor.setAccessible(true)
+ constructor.newInstance(patterns, Boolean.box(verbose), Boolean.box(skipManifest)).asInstanceOf[JarProcessor]
+ }
+
+ def apply(in: Iterator[Entry], outdir: File,
+ config: Seq[JarJarConfig], verbose: Boolean = false): Seq[File] = {
+ val patterns = config.map(_.toPatternElement).asJava
+ val processor: JarProcessor = newMainProcessor(patterns, verbose, false)
+ def process(e: Entry): Option[File] = {
+ val struct = new EntryStruct()
+ struct.name = e.name
+ struct.time = e.time
+ struct.data = e.data
+ if (processor.process(struct)) {
+ if (struct.name.endsWith("/")) None
+ else {
+ val f = outdir / struct.name
+ try {
+ f.getParentFile.mkdirs()
+ sbt.IO.write(f, struct.data)
+ } catch {
+ case ex: Exception =>
+ throw new IOException(s"Failed to write ${e.name} / ${f.getParentFile} / ${f.getParentFile.exists}", ex)
+ }
+ Some(f)
+ }
+ }
+ else None
+ }
+ in.flatMap(entry => process(entry)).toList
+
+ }
+}
diff --git a/project/plugins.sbt b/project/plugins.sbt
index dc266a8db1..862887d57f 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -1 +1,3 @@
-libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.3.2" \ No newline at end of file
+libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.3.2"
+
+libraryDependencies += "org.pantsbuild" % "jarjar" % "1.6.0"