From 919d7987fad82f59f998a29d79a82116049af1b9 Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Thu, 9 Mar 2017 00:54:45 -0500 Subject: 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 --- libraries/proguard/Proguard.scala | 18 ++++----- libraries/proguard/build/build.scala | 72 +++++++++++------------------------- 2 files changed, 30 insertions(+), 60 deletions(-) (limited to 'libraries') 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 - } } -- cgit v1.2.3