diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/essentials/build/build.scala | 2 | ||||
-rw-r--r-- | plugins/sbt_layout/SbtLayout.scala | 2 | ||||
-rw-r--r-- | plugins/scalafmt/Scalafmt.scala | 64 | ||||
-rw-r--r-- | plugins/scalafmt/build/build.scala | 3 | ||||
-rw-r--r-- | plugins/scalajs/ScalaJsBuild.scala | 13 | ||||
-rw-r--r-- | plugins/scalajs/ScalaJsLib.scala | 19 | ||||
-rw-r--r-- | plugins/sonatype-release/src/SonatypeRelease.scala | 1 | ||||
-rw-r--r-- | plugins/uber-jar/src/UberJar.scala | 2 |
8 files changed, 39 insertions, 67 deletions
diff --git a/plugins/essentials/build/build.scala b/plugins/essentials/build/build.scala index 91c3a0f..eef4921 100644 --- a/plugins/essentials/build/build.scala +++ b/plugins/essentials/build/build.scala @@ -1,4 +1,6 @@ import cbt._ +// TODO: maybe move this back into stage2 to avoid having to call zinc separately for this as a plugin +// and to avoid the special casing "BuildBuildWithoutEssentials" class Build(val context: Context) extends BaseBuild{ override def dependencies = ( super.dependencies diff --git a/plugins/sbt_layout/SbtLayout.scala b/plugins/sbt_layout/SbtLayout.scala index 5cd7a03..3e8706d 100644 --- a/plugins/sbt_layout/SbtLayout.scala +++ b/plugins/sbt_layout/SbtLayout.scala @@ -1,5 +1,5 @@ package cbt - +// TODO: move this into stage2 to avoid having to call zinc separately for this as a plugin trait SbtLayoutTest extends BaseBuild{ override def sources = Seq(projectDirectory ++ "/src/test/scala") override def compileTarget = super.compileTarget.getParentFile ++ "/test-classes" diff --git a/plugins/scalafmt/Scalafmt.scala b/plugins/scalafmt/Scalafmt.scala index 1f8bf2d..e3c3c3e 100644 --- a/plugins/scalafmt/Scalafmt.scala +++ b/plugins/scalafmt/Scalafmt.scala @@ -6,7 +6,7 @@ import org.scalafmt.cli.StyleCache import org.scalafmt.config.ScalafmtConfig import java.io.File import java.nio.file.Files._ -import java.nio.file.{ FileSystems, Path, Paths } +import java.nio.file._ /** * This plugin provides scalafmt support for cbt. @@ -18,10 +18,7 @@ trait Scalafmt extends BaseBuild { * * @return always returns `ExitCode.Success` */ - final def scalafmt: ExitCode = { - Scalafmt.format(sourceFiles, scalafmtConfig) - ExitCode.Success - } + final def scalafmt: ExitCode = Scalafmt.format(sourceFiles, scalafmtConfig) /** * Scalafmt formatting config. @@ -54,46 +51,31 @@ object Scalafmt { customStyle.getOrElse(ScalafmtConfig.default) } - def format(files: Seq[File], style: ScalafmtConfig): Unit = { - var reformattedCount: Int = 0 - scalaSourceFiles(files) foreach { path => - handleFormatted(path, style) { case (original, result) => - result match { - case Formatted.Success(formatted) => - if (original != formatted) { - write(path, formatted.getBytes) - reformattedCount += 1 - } - case Formatted.Failure(e: Incomplete) => - System.err.println(s"Couldn't complete file reformat: $path") - case Formatted.Failure(e) => - System.err.println(s"Failed to format file: $path, cause: ${e}") - } + def format(files: Seq[File], style: ScalafmtConfig): ExitCode = { + val results = files.filter(_.string endsWith ".scala").map(_.toPath).map{ path => + val original = new String(readAllBytes(path)) + org.scalafmt.Scalafmt.format(original, style) match { + case Formatted.Success(formatted) => + if (original != formatted) { + val tmpPath = Paths.get(path.toString ++ ".scalafmt-tmp") + write(tmpPath, formatted.getBytes) + move(tmpPath, path, StandardCopyOption.REPLACE_EXISTING) + Some(1) + } + Some(0) + case Formatted.Failure(e) => + System.err.println(s"Scalafmt failed for $path\nCause: $e\n") + None } } - if (reformattedCount > 0) System.err.println(s"Formatted $reformattedCount Scala sources") - } - - private val scalaFileMatcher = FileSystems.getDefault.getPathMatcher("glob:**.scala") - - private def scalaSourceFiles(files: Seq[File]): Seq[Path] = { - files collect { - case f if f.exists - && scalaFileMatcher.matches(f.toPath) => f.toPath - } - } - - private def handleFormatted[T](path: Path, style: ScalafmtConfig)(handler: (String, Formatted) => T): T = { - val original = new String(readAllBytes(path)) - val result = org.scalafmt.Scalafmt.format(original, style) - handler(original, result) + if(results.forall(_.nonEmpty)){ + System.err.println(s"Formatted ${results.flatten.sum} Scala sources") + ExitCode.Success + } else ExitCode.Failure } private def getConfigPath(base: Path): Option[Path] = { - val location = base.resolve(".scalafmt.conf").toFile - Option(location.exists && location.isFile) collect { - case true => location.toPath.toAbsolutePath - } + Some( base.resolve(".scalafmt.conf").toFile ) + .collect{ case f if f.exists && f.isFile => f.toPath.toAbsolutePath } } - } diff --git a/plugins/scalafmt/build/build.scala b/plugins/scalafmt/build/build.scala index 2631908..b37d769 100644 --- a/plugins/scalafmt/build/build.scala +++ b/plugins/scalafmt/build/build.scala @@ -1,12 +1,11 @@ import cbt._ class Build(val context: Context) extends Plugin { - private val ScalafmtVersion = "0.4.2" + private val ScalafmtVersion = "0.5.7" override def dependencies = super.dependencies ++ Resolver( mavenCentral ).bind( - ScalaDependency("com.geirsson", "scalafmt", ScalafmtVersion), ScalaDependency("com.geirsson", "scalafmt-cli", ScalafmtVersion) ) } diff --git a/plugins/scalajs/ScalaJsBuild.scala b/plugins/scalajs/ScalaJsBuild.scala index 0c7222c..b6df9e9 100644 --- a/plugins/scalajs/ScalaJsBuild.scala +++ b/plugins/scalajs/ScalaJsBuild.scala @@ -2,6 +2,7 @@ package cbt import java.io.File import java.net.URL +// TODO: maybe move this into stage2 to avoid having to call zinc separately for this as a plugin trait ScalaJsBuild extends DynamicOverrides{ final protected val scalaJsLib = ScalaJsLib( scalaJsVersion, scalaVersion, context.cbtLastModified, context.paths.mavenCache @@ -23,17 +24,17 @@ trait ScalaJsBuild extends DynamicOverrides{ } override def compile = { - super.compile - scalaJsLib.link( - scalaJsTargetFile, scalaJsOptions, target +: dependencies.collect{case d: BoundMavenDependency => d.jar} - ) - None // FIXME: we need to rethink the concept of a "compile" task I think. There is no time to return here. + val res = super.compile + scalaJsLib.link( scalaJsTargetFile, scalaJsOptions, target +: dependencyClasspath.files ) + res + // FIXME: we need to rethink the concept of a "compile" task I think. + // An exit code would probably be more appropriate here. } def scalaJsOptions: Seq[String] = Seq() /** Where to put the generated js file */ - def scalaJsTargetFile: File + def scalaJsTargetFile: File = target / "app.js" override def cleanFiles = super.cleanFiles :+ scalaJsTargetFile :+ (scalaJsTargetFile ++ ".map") diff --git a/plugins/scalajs/ScalaJsLib.scala b/plugins/scalajs/ScalaJsLib.scala index ae37bde..7886478 100644 --- a/plugins/scalajs/ScalaJsLib.scala +++ b/plugins/scalajs/ScalaJsLib.scala @@ -4,28 +4,15 @@ import java.io.File case class ScalaJsLib( scalaJsVersion: String, scalaVersion: String, cbtLastModified: Long, mavenCache: File )(implicit logger: Logger, transientCache: java.util.Map[AnyRef,AnyRef], classLoaderCache: ClassLoaderCache){ - sealed trait ScalaJsOutputMode { - def option: String - def fileSuffix: String - } - case object FastOptJS extends ScalaJsOutputMode{ - override val option = "--fastOpt" - override val fileSuffix = "fastopt" - } - case object FullOptJS extends ScalaJsOutputMode{ - override val option = "--fullOpt" - override val fileSuffix = "fullopt" - } - val lib = new Lib(logger) def dep(artifactId: String) = MavenResolver( cbtLastModified, mavenCache, mavenCentral ).bindOne( MavenDependency("org.scala-js", artifactId, scalaJsVersion) ) def link( - outputPath: File, - scalaJsOptions: Seq[String], entriesToLink: Seq[File] - ) = { + outputPath: File, scalaJsOptions: Seq[String], entriesToLink: Seq[File] + ): ExitCode = { + outputPath.getParentFile.mkdirs val scalaJsCliDep = dep( "scalajs-cli_"++lib.libMajorVersion(scalaVersion) ) outputPath.getParentFile.mkdirs lib.runMain( diff --git a/plugins/sonatype-release/src/SonatypeRelease.scala b/plugins/sonatype-release/src/SonatypeRelease.scala index 32303ad..cc2932a 100644 --- a/plugins/sonatype-release/src/SonatypeRelease.scala +++ b/plugins/sonatype-release/src/SonatypeRelease.scala @@ -1,4 +1,5 @@ package cbt +// TODO: maybe move this into stage2 to avoid having to call zinc separately for this as a plugin import cbt.sonatype.SonatypeLib diff --git a/plugins/uber-jar/src/UberJar.scala b/plugins/uber-jar/src/UberJar.scala index 3783367..79b87a1 100644 --- a/plugins/uber-jar/src/UberJar.scala +++ b/plugins/uber-jar/src/UberJar.scala @@ -15,7 +15,7 @@ trait UberJar extends BaseBuild { def uberJarMainClass: Option[String] = runClass - def uberJarName: String = projectName + ".jar" + def uberJarName: String = name + ".jar" } |