diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-04 03:02:04 +0000 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-04 20:43:25 -0500 |
commit | c6fd3f43a9d2b2f38442602769e920803a7d43ba (patch) | |
tree | e1561087d27c603075b89877213818603c3787d3 /stage2/plugins | |
parent | 4bd0255f0a39d87652c032533ce45eb65e8f3b1e (diff) | |
download | cbt-c6fd3f43a9d2b2f38442602769e920803a7d43ba.tar.gz cbt-c6fd3f43a9d2b2f38442602769e920803a7d43ba.tar.bz2 cbt-c6fd3f43a9d2b2f38442602769e920803a7d43ba.zip |
separate type-safe proguard wrapper into self-contained library
also make logic to maintain auto-generated sections re-usable
Diffstat (limited to 'stage2/plugins')
-rw-r--r-- | stage2/plugins/GeneratedSections.scala | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/stage2/plugins/GeneratedSections.scala b/stage2/plugins/GeneratedSections.scala new file mode 100644 index 0000000..417278c --- /dev/null +++ b/stage2/plugins/GeneratedSections.scala @@ -0,0 +1,40 @@ +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 = sourceFiles.flatMap{ file => + val template = file.readAsString + val replaced = replaceSections( template, replacements ) + if( template != replaced ) { + write( file.toPath, replaced.getBytes ) + Some(file) + } else None + } + + logger.log("generated-sections","Updated:" + updated.map(_ ++ "\n").mkString) + } +} |