blob: cbccb94bb67d9e21849a39b1bb59beb4957dd3dc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
}
}
}
|