aboutsummaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-09 00:54:45 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-09 00:54:45 -0500
commit919d7987fad82f59f998a29d79a82116049af1b9 (patch)
treea6a67d4653a5010c401124b7de2978b1f540f23b /libraries
parentc45c8f241d6b2c268fd18341cf80d5467f9b50c6 (diff)
downloadcbt-919d7987fad82f59f998a29d79a82116049af1b9.tar.gz
cbt-919d7987fad82f59f998a29d79a82116049af1b9.tar.bz2
cbt-919d7987fad82f59f998a29d79a82116049af1b9.zip
refactor scalafmt to new plugin style
turn replaceSections into helper function instead of trait method proguard scalafmt build currently suffers from non-deterministic formatting. Try a few times to reproduce commited Proguard.scala
Diffstat (limited to 'libraries')
-rw-r--r--libraries/proguard/Proguard.scala18
-rw-r--r--libraries/proguard/build/build.scala72
2 files changed, 30 insertions, 60 deletions
diff --git a/libraries/proguard/Proguard.scala b/libraries/proguard/Proguard.scala
index e662e0d..7d57a77 100644
--- a/libraries/proguard/Proguard.scala
+++ b/libraries/proguard/Proguard.scala
@@ -22,15 +22,15 @@ object KeepOptionModifier {
object ProGuard {
val artifactId = "proguard-base"
- val groupId = "net.sf.proguard"
- val version = "5.3.2"
- val mainClass = "proguard.ProGuard"
- val `rt.jar` = Seq( new File( System.getProperty( "java.home" ), "lib/rt.jar" ) )
+ val groupId = "net.sf.proguard"
+ val version = "5.3.2"
+ val mainClass = "proguard.ProGuard"
+ val `rt.jar` = Seq( new File( System.getProperty( "java.home" ), "lib/rt.jar" ) )
}
case class ProGuard[T](
main: Seq[String] => Int,
- T: Seq[File] => T,
- log: String => Unit = _ => ()
+ T: Seq[File] => T,
+ log: String => Unit = _ => ()
) {
/**
@@ -160,9 +160,9 @@ case class ProGuard[T](
private object argsFor {
def apply[T: argsFor]( value: T ) = implicitly[argsFor[T]].apply( value )
implicit object SeqFile extends argsFor[Seq[File]]( v => Some( Seq( v.map( _.getPath ).mkString( ":" ) ) ) )
- implicit object File extends argsFor[File]( v => Some( Seq( v.getPath ) ) )
- implicit object String extends argsFor[String]( v => Some( Seq( v ) ) )
- implicit object Int extends argsFor[Int]( i => Some( Seq( i.toString ) ) )
+ implicit object File extends argsFor[File]( v => Some( Seq( v.getPath ) ) )
+ implicit object String extends argsFor[String]( v => Some( Seq( v ) ) )
+ implicit object Int extends argsFor[Int]( i => Some( Seq( i.toString ) ) )
implicit object Boolean
extends argsFor[Boolean]( {
case false => None
diff --git a/libraries/proguard/build/build.scala b/libraries/proguard/build/build.scala
index 9b55ec9..c781ce2 100644
--- a/libraries/proguard/build/build.scala
+++ b/libraries/proguard/build/build.scala
@@ -5,7 +5,27 @@ import java.net._
import java.io._
import scala.xml._
-class Build(val context: Context) extends Scalafmt with GeneratedSections{
+class Build(val context: Context) extends Scalafmt{
+ def description: String = "Type-safe scala wrapper to interfaces with ProGuard.main runner"
+ def inceptionYear = 2017
+
+ def generate = {
+ lib.transformFiles( sourceFiles, replaceSections( _, replacements ) )
+ compile
+ }
+
+ override def scalafmt = super.scalafmt.copy(
+ config = super.scalafmt.lib.cbtRecommendedConfig,
+ whiteSpaceInParenthesis = true
+ )
+
+ override def compile = {
+ // currently suffers from non-deterministic formatting. Try a few times to reproduce commit state.
+ val formatted = scalafmt.apply.map(_.string).mkString("\n")
+ if( formatted.nonEmpty ) System.err.println( "Formatted:\n" ++ formatted ++ "\n---------------" )
+ super.compile
+ }
+
def refcard = projectDirectory / "spec/refcard.html"
/** downloads html proguard parameter specification */
@@ -55,39 +75,6 @@ class Build(val context: Context) extends Scalafmt with GeneratedSections{
XmlNotDownloadingDTD.loadString( w.toString )
}
- override def scalafmtConfig = {
- import org.scalafmt.config._
- ScalafmtConfig.defaultWithAlign.copy(
- maxColumn = 110,
- continuationIndent = super.scalafmtConfig.continuationIndent.copy(
- defnSite = 2
- ),
- align = super.scalafmtConfig.align.copy(
- tokens = AlignToken.default ++ Set(
- AlignToken( ":", "Param" ),
- AlignToken( "=", "Param" )
- ) + AlignToken.caseArrow,
- arrowEnumeratorGenerator = true,
- mixedOwners = true
- ),
- binPack = super.scalafmtConfig.binPack.copy(
- parentConstructors = true
- ),
- spaces = super.scalafmtConfig.spaces.copy(
- inImportCurlyBraces = true
- ),
- lineEndings = LineEndings.unix,
- newlines = super.scalafmtConfig.newlines.copy(
- penalizeSingleSelectMultiArgList = false
- ),
- runner = super.scalafmtConfig.runner.copy(
- optimizer = super.scalafmtConfig.runner.optimizer.copy(
- forceConfigStyleOnOffset = -1
- )
- )
- )
- }
-
/** generates Scala code from parameter specification html */
def replacements = {
val tables = XML.loadFile(refcard) \\ "table"
@@ -143,21 +130,4 @@ class Build(val context: Context) extends Scalafmt with GeneratedSections{
"params" -> params
)
}
-
- override def generate{
- super.generate
- compile
- }
-
- private def whiteSpaceInParenthesis =
- Seq(
- "(\\(+)([^\\s\\)])".r.replaceAllIn(_:String, m => m.group(1).mkString(" ") ++ " " ++ m.group(2) ),
- "([^\\s\\(])(\\)+)".r.replaceAllIn(_:String, m => m.group(1) ++ " " ++ m.group(2).mkString(" ") )
- ).reduce(_ andThen _)
-
- override def compile = {
- scalafmt
- lib.transformFiles( sourceFiles, whiteSpaceInParenthesis )
- super.compile
- }
}