diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-09 00:54:45 -0500 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-09 00:54:45 -0500 |
commit | 919d7987fad82f59f998a29d79a82116049af1b9 (patch) | |
tree | a6a67d4653a5010c401124b7de2978b1f540f23b /stage2 | |
parent | c45c8f241d6b2c268fd18341cf80d5467f9b50c6 (diff) | |
download | cbt-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 'stage2')
-rw-r--r-- | stage2/plugins/GeneratedSections.scala | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/stage2/plugins/GeneratedSections.scala b/stage2/plugins/GeneratedSections.scala index dc065cf..aedcaff 100644 --- a/stage2/plugins/GeneratedSections.scala +++ b/stage2/plugins/GeneratedSections.scala @@ -1,33 +1,27 @@ package cbt import java.nio.file.Files._ -trait GeneratedSections extends BaseBuild{ - def generatedSectionStartMarker( name: String ) = s"AUTO GENERATED SECTION BEGIN: $name " - def generatedSectionEndMarker( name: String ) = s"AUTO GENERATED SECTION END: $name " - assert( - generatedSectionStartMarker("foo").endsWith(" "), - "generatedSectionStartMarker needs to end with a space character" - ) - assert( - generatedSectionEndMarker("foo").endsWith(" "), - "generatedSectionEndMarker needs to end with a space character" - ) - - def replacements: Seq[(String, String)] - - def generate = { - def replaceSections(subject: String, sections: Seq[(String, String)]): String = { - sections.headOption.map{ - case (name, replacement) => - replaceSections( - s"(?s)(\n[^\n]*AUTO GENERATED SECTION BEGIN: $name [^\n]*\n).*(\n[^\n]*AUTO GENERATED SECTION END: $name [^\n]*\n)" - .r.replaceAllIn( subject, m => m.group(1) ++ replacement ++ m.group(2) ), - sections.tail - ) - }.getOrElse(subject) - } - - val updated = lib.transformFiles( sourceFiles, replaceSections( _, replacements ) ) - - logger.log("generated-sections","Updated:" + updated.map(_ ++ "\n").mkString) +object replaceSections{ + def apply( + subject: String, + sections: Seq[(String, String)], + generatedSectionBeginMarker: String => String = name => s"AUTO GENERATED SECTION BEGIN: $name ", + generatedSectionEndMarker: String => String = name => s"AUTO GENERATED SECTION END: $name " + ): String = { + assert( + generatedSectionBeginMarker("foo").endsWith(" "), + "generatedSectionStartMarker needs to end with a space character" + ) + assert( + generatedSectionEndMarker("foo").endsWith(" "), + "generatedSectionEndMarker needs to end with a space character" + ) + sections.headOption.map{ + case (name, replacement) => + replaceSections( + s"(?s)(\n[^\n]*AUTO GENERATED SECTION BEGIN: $name [^\n]*\n).*(\n[^\n]*AUTO GENERATED SECTION END: $name [^\n]*\n)" + .r.replaceAllIn( subject, m => m.group(1) ++ replacement ++ m.group(2) ), + sections.tail + ) + }.getOrElse(subject) } } |