Skip to content

Commit

Permalink
Update to the latest Scalafmt that doesn't use coursier-small (#50)
Browse files Browse the repository at this point in the history
The coursier/interface module requires OutputStreamWriter instead of
PrintWriter, causing the large diff.
  • Loading branch information
olafurpg authored and poslegm committed Sep 26, 2019
1 parent cc82025 commit 8e3019a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inThisBuild(
url("https://github.com/tanishiking/")
)
),
resolvers += Resolver.sonatypeRepo("releases"),
resolvers += Resolver.sonatypeRepo("public"),
scalaVersion := "2.12.8",
publishArtifact in packageDoc := sys.env.contains("CI"),
publishArtifact in packageSrc := sys.env.contains("CI")
Expand All @@ -39,7 +39,7 @@ lazy val plugin = project
.settings(
moduleName := "sbt-scalafmt",
libraryDependencies ++= List(
"org.scalameta" %% "scalafmt-dynamic" % "2.0.0"
"org.scalameta" %% "scalafmt-dynamic" % "2.1.0-RC2"
),
scriptedBufferLog := false,
scriptedLaunchOpts += s"-Dplugin.version=${version.value}"
Expand Down
29 changes: 16 additions & 13 deletions plugin/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.scalafmt.sbt

import java.io.PrintWriter
import java.io.OutputStreamWriter
import java.nio.file.Path

import sbt.Keys._
Expand Down Expand Up @@ -94,7 +94,7 @@ object ScalafmtPlugin extends AutoPlugin {
sources: Seq[File],
config: Path,
log: Logger,
writer: PrintWriter
writer: OutputStreamWriter
)(
onFormat: (File, Input, Output) => T
): Seq[Option[T]] = {
Expand All @@ -118,7 +118,7 @@ object ScalafmtPlugin extends AutoPlugin {
sources: Seq[File],
config: Path,
log: Logger,
writer: PrintWriter
writer: OutputStreamWriter
): Unit = {
trackSourcesAndConfig(cacheStoreFactory, sources, config) {
(outDiff, configChanged, prev) =>
Expand All @@ -143,7 +143,7 @@ object ScalafmtPlugin extends AutoPlugin {
sources: Set[File],
config: Path,
log: Logger,
writer: PrintWriter
writer: OutputStreamWriter
): Unit = {
val cnt = withFormattedSources(sources.toSeq, config, log, writer)(
(file, input, output) => {
Expand All @@ -167,7 +167,7 @@ object ScalafmtPlugin extends AutoPlugin {
sources: Seq[File],
config: Path,
log: Logger,
writer: PrintWriter
writer: OutputStreamWriter
): ScalafmtAnalysis = {
trackSourcesAndConfig(cacheStoreFactory, sources, config) {
(outDiff, configChanged, prev) =>
Expand Down Expand Up @@ -205,7 +205,7 @@ object ScalafmtPlugin extends AutoPlugin {
sources: Seq[File],
config: Path,
log: Logger,
writer: PrintWriter
writer: OutputStreamWriter
): ScalafmtAnalysis = {
if (sources.nonEmpty) {
log.info(s"Checking ${sources.size} Scala sources...")
Expand Down Expand Up @@ -282,7 +282,7 @@ object ScalafmtPlugin extends AutoPlugin {
(unmanagedSources in scalafmt).value,
scalaConfig.value,
streams.value.log,
streams.value.text()
outputStreamWriter(streams.value)
)
},
scalafmtIncremental := scalafmt.value,
Expand All @@ -291,13 +291,13 @@ object ScalafmtPlugin extends AutoPlugin {
sbtSources.value.toSet,
sbtConfig.value,
streams.value.log,
streams.value.text()
outputStreamWriter(streams.value)
)
formatSources(
metabuildSources.value.toSet,
scalaConfig.value,
streams.value.log,
streams.value.text()
outputStreamWriter(streams.value)
)
},
scalafmtCheck := {
Expand All @@ -306,7 +306,7 @@ object ScalafmtPlugin extends AutoPlugin {
(unmanagedSources in scalafmt).value,
scalaConfig.value,
streams.value.log,
streams.value.text()
outputStreamWriter(streams.value)
)
trueOrBoom(analysis)
},
Expand All @@ -316,15 +316,15 @@ object ScalafmtPlugin extends AutoPlugin {
sbtSources.value,
sbtConfig.value,
streams.value.log,
streams.value.text()
outputStreamWriter(streams.value)
)
)
trueOrBoom(
checkSources(
metabuildSources.value,
scalaConfig.value,
streams.value.log,
streams.value.text()
outputStreamWriter(streams.value)
)
)
},
Expand Down Expand Up @@ -354,11 +354,14 @@ object ScalafmtPlugin extends AutoPlugin {
absFiles.toSet,
scalaConfig.value,
streams.value.log,
streams.value.text()
outputStreamWriter(streams.value)
)
}
)

private def outputStreamWriter(streams: TaskStreams): OutputStreamWriter =
new OutputStreamWriter(streams.binary())

private val anyConfigsInThisProject = ScopeFilter(
configurations = inAnyConfiguration
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.scalafmt.sbt

import java.io.PrintWriter
import java.io.OutputStreamWriter
import java.nio.file.Path

import org.scalafmt.interfaces.ScalafmtReporter
Expand All @@ -9,7 +10,7 @@ import sbt.util.Logger

import scala.util.control.NoStackTrace

class ScalafmtSbtReporter(log: Logger, writer: PrintWriter)
class ScalafmtSbtReporter(log: Logger, out: OutputStreamWriter)
extends ScalafmtReporter {
override def error(file: Path, message: String): Unit = {
throw new MessageOnlyException(s"$message: $file")
Expand All @@ -29,7 +30,8 @@ class ScalafmtSbtReporter(log: Logger, writer: PrintWriter)
override def parsedConfig(config: Path, scalafmtVersion: String): Unit =
log.debug(s"parsed config (v$scalafmtVersion): $config")

override def downloadWriter(): PrintWriter = writer
override def downloadWriter(): PrintWriter = new PrintWriter(out)
override def downloadOutputStreamWriter(): OutputStreamWriter = out

private class FailedToFormat(filename: String, cause: Throwable)
extends Exception(filename, cause)
Expand Down

0 comments on commit 8e3019a

Please sign in to comment.