aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-11 18:01:52 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-11 18:30:24 -0500
commitbe9e36b89fd0a266010aa98fa4a3ff9d8572fce9 (patch)
tree81b6288b79501e33ce20ad8faf24f612a2ce7590 /plugins
parentf0a16297ffe7719df9a7ba5dc7f75182d6371852 (diff)
downloadcbt-be9e36b89fd0a266010aa98fa4a3ff9d8572fce9.tar.gz
cbt-be9e36b89fd0a266010aa98fa4a3ff9d8572fce9.tar.bz2
cbt-be9e36b89fd0a266010aa98fa4a3ff9d8572fce9.zip
Google Java Format plugin
Diffstat (limited to 'plugins')
-rw-r--r--plugins/google-java-format/GoogleJavaFormat.scala34
-rw-r--r--plugins/google-java-format/Immutable.java5
-rw-r--r--plugins/google-java-format/build/build.scala9
3 files changed, 48 insertions, 0 deletions
diff --git a/plugins/google-java-format/GoogleJavaFormat.scala b/plugins/google-java-format/GoogleJavaFormat.scala
new file mode 100644
index 0000000..cbccb94
--- /dev/null
+++ b/plugins/google-java-format/GoogleJavaFormat.scala
@@ -0,0 +1,34 @@
+package cbt
+
+import java.io.File
+import java.nio.file.Files._
+import java.nio.file._
+
+import com.google.googlejavaformat.java._
+
+trait GoogleJavaFormat extends BaseBuild {
+ def googleJavaFormat() = GoogleJavaFormat.apply( lib, sourceFiles.filter(_.string endsWith ".java") ).format
+}
+
+object GoogleJavaFormat{
+ case class apply( lib: Lib, files: Seq[File] ){
+ /** @param whiteSpaceInParenthesis more of a hack to make up for missing support in Scalafmt. Does not respect alignment and maxColumn. */
+ def format = {
+ val (successes, errors) = lib.transformFilesOrError( files, in =>
+ try{
+ Right( new Formatter().formatSource(in) )
+ } catch {
+ case e: FormatterException => Left( e )
+ }
+ )
+ if(errors.nonEmpty)
+ throw new RuntimeException(
+ "Google Java Format failed to parse some files:\n" ++ errors.map{
+ case (file, error) => file.string ++ ":" ++ error.toString
+ }.mkString("\n"),
+ errors.head._2
+ )
+ successes
+ }
+ }
+}
diff --git a/plugins/google-java-format/Immutable.java b/plugins/google-java-format/Immutable.java
new file mode 100644
index 0000000..5b3ff44
--- /dev/null
+++ b/plugins/google-java-format/Immutable.java
@@ -0,0 +1,5 @@
+package com.google.errorprone.annotations;
+// to suppress warning
+// "Class com.google.errorprone.annotations.Immutable not found - continuing with a stub."
+// there probably is a better solution
+public class Immutable{}
diff --git a/plugins/google-java-format/build/build.scala b/plugins/google-java-format/build/build.scala
new file mode 100644
index 0000000..50bc423
--- /dev/null
+++ b/plugins/google-java-format/build/build.scala
@@ -0,0 +1,9 @@
+import cbt._
+
+class Build(val context: Context) extends Plugin {
+ override def dependencies =
+ super.dependencies ++
+ Resolver( mavenCentral ).bind(
+ MavenDependency( "com.google.googlejavaformat", "google-java-format", "1.3" )
+ )
+}