Skip to content

Commit

Permalink
sbt 1.0 support (#19)
Browse files Browse the repository at this point in the history
* replaced deprecated operators

* now compiles only to sbt 1.0.0

* fixed binaryDeps

* moved proguardOptions and proguardMerge into autoimport and added scripted plugin

* fixed bintrayReleaseOnPublish = false

* sbt 0.13.16 and 1.0.0 cross compilation

* bintrayReleaseOnPublish fix

* revert last commit

* fixed scala-sbt-1.0 package directory structure

* fixed configuration doesn't exist error and stack overflow

* added akka test back

* testing

* all tests pass

* change version back to 0.2.4-SNAPSHOT

* make travis use jdk8 for scala 2.12

* make travis use jdk8 for scala 2.12

* applied the requested changes and fixed readme
  • Loading branch information
LolHens authored and pvlugter committed Aug 31, 2017
1 parent d4974f7 commit a2ca4f4
Show file tree
Hide file tree
Showing 23 changed files with 329 additions and 247 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
project/project/
target/
.idea/*
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
language: scala

jdk: oraclejdk8

script: sbt "^ publish-local" "^ scripted"
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sbt-proguard
============

[sbt] plugin for running [ProGuard]. This plugin requires sbt 0.12 or 0.13.
[sbt] plugin for running [ProGuard]. This plugin requires sbt 0.13 or 1.0.

[![Build Status](https://travis-ci.org/sbt/sbt-proguard.png?branch=master)](https://travis-ci.org/sbt/sbt-proguard)

Expand All @@ -22,11 +22,11 @@ Example
A simple `build.sbt` with settings to configure sbt-proguard:

```scala
proguardSettings
enablePlugins(SbtProguard)

ProguardKeys.options in Proguard ++= Seq("-dontnote", "-dontwarn", "-ignorewarnings")
proguardOptions in Proguard ++= Seq("-dontnote", "-dontwarn", "-ignorewarnings")

ProguardKeys.options in Proguard += ProguardOptions.keepMain("some.MainClass")
proguardOptions in Proguard += ProguardOptions.keepMain("some.MainClass")
```

Run proguard at the sbt shell with:
Expand All @@ -46,7 +46,7 @@ files.
For example, to add a `!META-INF/**` filter to just the scala-library jar:

```scala
ProguardKeys.inputFilter in Proguard := { file =>
proguardInputFilter in Proguard := { file =>
file.name match {
case "scala-library.jar" => Some("!META-INF/**")
case _ => None
Expand All @@ -60,11 +60,11 @@ which will create the following proguard configuration:
-injars "/path/to/scala-library.jar"(!META-INF/**)
```

There are corresponding settings for libraries and outputs: `libraryFilter` and
`outputFilter`.
There are corresponding settings for libraries and outputs: `proguardLibraryFilter` and
`proguardOutputFilter`.

For more advanced usage the `filteredInputs`, `filteredLibraries`, and
`filteredOutputs` settings can be set directly.
For more advanced usage the `proguardFilteredInputs`, `proguardFilteredLibraries`, and
`proguardFilteredOutputs` settings can be set directly.


Merging
Expand All @@ -79,7 +79,7 @@ The sbt-proguard plugin supports pre-merging inputs, similar to creating an
assembly jar first. To enable this merging use:

```scala
ProguardKeys.merge in Proguard := true
proguardMerge in Proguard := true
```

Conflicting paths that are not identical will now fail at the merge stage. These
Expand All @@ -102,25 +102,25 @@ The default strategy is to only discard `META-INF/MANIFEST.MF`. This same
strategy could be added with:

```scala
ProguardKeys.mergeStrategies in Proguard += ProguardMerge.discard("META-INF/MANIFEST.MF")
proguardMergeStrategies in Proguard += ProguardMerge.discard("META-INF/MANIFEST.MF")
```

Or all `META-INF` contents could be discarded with a regular expression:

```scala
ProguardKeys.mergeStrategies in Proguard += ProguardMerge.discard("META-INF/.*".r)
proguardMergeStrategies in Proguard += ProguardMerge.discard("META-INF/.*".r)
```

To concatenate all `reference.conf` files together use:

```scala
ProguardKeys.mergeStrategies in Proguard += ProguardMerge.append("reference.conf")
proguardMergeStrategies in Proguard += ProguardMerge.append("reference.conf")
```

To discard all `.html` and `.txt` files you may use two strategies together:

```scala
ProguardKeys.mergeStrategies in Proguard ++= Seq(
proguardMergeStrategies in Proguard ++= Seq(
ProguardMerge.discard("\\.html$".r),
ProguardMerge.discard("\\.txt$".r)
)
Expand Down
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ publishMavenStyle := false
bintrayOrganization := Some("sbt")
bintrayRepository := "sbt-plugin-releases"
bintrayPackage := name.value
bintrayReleaseOnPublish := false
bintrayReleaseOnPublish in ThisBuild := false

crossBuildingSettings
CrossBuilding.crossSbtVersions := Seq("0.12", "0.13")
CrossBuilding.scriptedSettings
crossSbtVersions := Seq("0.13.16", "1.0.0")

ScriptedPlugin.scriptedSettings
scriptedLaunchOpts := Seq("-Xms512m", "-Xmx512m", "-XX:MaxPermSize=256m", s"-Dproject.version=${version.value}")
//scriptedBufferLog := false
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.9
sbt.version=0.13.16
5 changes: 3 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")
addSbtPlugin("net.virtual-void" % "sbt-cross-building" % "0.8.1")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.1")

libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.typesafe.sbt.proguard

import sbt.Keys.compile
import sbt.{File, _}

object Sbt10Compat {

implicit class RichSbtFile(file: File) {
def allPaths: PathFinder = file.***
}

implicit def toProcessLogger(logger: Logger): scala.sys.process.ProcessLogger =
new scala.sys.process.ProcessLogger {
override def out(s: => String): Unit = (logger: sbt.ProcessLogger).info(s)
override def err(s: => String): Unit = (logger: sbt.ProcessLogger).error(s)
override def buffer[T](f: => T): T = (logger: sbt.ProcessLogger).buffer(f)
}

val getAllBinaryDeps: Def.Initialize[Task[Seq[java.io.File]]] = Def.task {
(compile in Compile).value.relations.allBinaryDeps.toSeq
}

val ClasspathUtilities = sbt.classpath.ClasspathUtilities

object DummyPath

val SbtIoPath = DummyPath
}
18 changes: 18 additions & 0 deletions src/main/scala-sbt-1.0/com/typesafe/sbt/proguard/Sbt10Compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.typesafe.sbt.proguard

import sbt.{Def, Task, _}
import sbt.internal.inc.Analysis
import sbt.Keys.compile

object Sbt10Compat {
val getAllBinaryDeps: Def.Initialize[Task[Seq[java.io.File]]] = Def.task {
((compile in Compile).value match {
case analysis: Analysis =>
analysis.relations.allLibraryDeps.toSeq
})
}

val ClasspathUtilities = sbt.internal.inc.classpath.ClasspathUtilities

val SbtIoPath = sbt.io.Path
}
86 changes: 86 additions & 0 deletions src/main/scala/com/typesafe/sbt/ProguardKeys.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.typesafe.sbt

import com.typesafe.sbt.SbtProguard.autoImport.ProguardOptions.Filtered
import com.typesafe.sbt.proguard.Merge
import com.typesafe.sbt.proguard.Merge.Strategy
import sbt.{File, SettingKey, _}

trait ProguardKeys {
val proguardVersion = settingKey[String]("proguard version")
val proguardDirectory = settingKey[File]("proguard directory")
val proguardConfiguration = settingKey[File]("proguard configuration")
val proguardBinaryDeps = taskKey[Seq[File]]("proguard binary dependencies")
val proguardInputs = taskKey[Seq[File]]("proguard inputs")
val proguardLibraries = taskKey[Seq[File]]("proguard libraries")
val proguardOutputs = taskKey[Seq[File]]("proguard outputs")
val proguardDefaultInputFilter = taskKey[Option[String]]("proguard default input filter")
val proguardInputFilter = taskKey[File => Option[String]]("proguard input filter")
val proguardLibraryFilter = taskKey[File => Option[String]]("proguard library filter")
val proguardOutputFilter = taskKey[File => Option[String]]("proguard output filter")
val proguardFilteredInputs = taskKey[Seq[Filtered]]("proguard filtered inputs")
val proguardFilteredLibraries = taskKey[Seq[Filtered]]("proguard filtered libraries")
val proguardFilteredOutputs = taskKey[Seq[Filtered]]("proguard filtered outputs")
val proguardMerge = taskKey[Boolean]("proguard merge")
val proguardMergeDirectory = settingKey[File]("proguard merge directory")
val proguardMergeStrategies = taskKey[Seq[Strategy]]("proguard merge strategies")
val proguardMergedInputs = taskKey[Seq[Filtered]]("proguard merged inputs")
val proguardOptions = taskKey[Seq[String]]("proguard options")
val proguard = taskKey[Seq[File]]("proguard")

object ProguardOptions {

case class Filtered(file: File, filter: Option[String])

def noFilter(jar: File): Seq[Filtered] = Seq(Filtered(jar, None))

def noFilter(jars: Seq[File]): Seq[Filtered] = filtered(jars, None)

def filtered(jars: Seq[File], filter: File => Option[String]): Seq[Filtered] = {
jars map { jar => Filtered(jar, filter(jar)) }
}

def filtered(jars: Seq[File], filter: Option[String]): Seq[Filtered] = {
jars map { jar => Filtered(jar, filter) }
}

def filterString(filter: Option[String]): String = {
filter map {
"(" + _ + ")"
} getOrElse ""
}

def jarOptions(option: String, jars: Seq[Filtered]): Seq[String] = {
jars map { jar => "%s \"%s\"%s" format(option, jar.file.getCanonicalPath, filterString(jar.filter)) }
}

def keepMain(name: String): String = {
"""-keep public class %s {
| public static void main(java.lang.String[]);
|}""".stripMargin.format(name)
}
}

object ProguardMerge {

import Merge.Strategy.{matchingRegex, matchingString}

import scala.util.matching.Regex

def defaultStrategies = Seq(
discard("META-INF/MANIFEST.MF")
)

def discard(exactly: String) = matchingString(exactly, Merge.discard)
def first(exactly: String) = matchingString(exactly, Merge.first)
def last(exactly: String) = matchingString(exactly, Merge.last)
def rename(exactly: String) = matchingString(exactly, Merge.rename)
def append(exactly: String) = matchingString(exactly, Merge.append)

def discard(pattern: Regex) = matchingRegex(pattern, Merge.discard)
def first(pattern: Regex) = matchingRegex(pattern, Merge.first)
def last(pattern: Regex) = matchingRegex(pattern, Merge.last)
def rename(pattern: Regex) = matchingRegex(pattern, Merge.rename)
def append(pattern: Regex) = matchingRegex(pattern, Merge.append)
}

}
Loading

0 comments on commit a2ca4f4

Please sign in to comment.