From de99a3344e1a12391417e66f805ff27fe666820e Mon Sep 17 00:00:00 2001 From: Jorge Vicente Cantero Date: Sat, 28 Nov 2020 20:22:57 +0100 Subject: [PATCH] Reformat project --- .scalafmt.conf | 10 ++++- cli/src/main/scala/snailgun/Cli.scala | 20 +++++----- .../scala/snailgun/protocol/Protocol.scala | 40 +++++++++---------- .../scala/snailgun/protocol/Streams.scala | 14 +++---- .../scala/snailgun/SnailgunBaseSuite.scala | 18 ++++----- .../snailgun/logging/RecordingLogger.scala | 8 ++-- .../scala/snailgun/logging/Slf4jAdapter.scala | 16 ++++---- .../scala/snailgun/utils/DiffAssertions.scala | 14 +++---- project/BuildPlugin.scala | 18 ++++----- 9 files changed, 81 insertions(+), 77 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index d1fdcba..04db1c2 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,2 +1,8 @@ -version = "2.0.0-RC4" -maxColumn = 100 \ No newline at end of file +maxColumn = 100 +docstrings = JavaDoc +assumeStandardLibraryStripMargin = true +align.tokens=[] +align.openParenCallSite = false +align.openParenDefnSite = false +binPack.literalArgumentLists = true +version = "2.7.3" diff --git a/cli/src/main/scala/snailgun/Cli.scala b/cli/src/main/scala/snailgun/Cli.scala index eb4b416..1697fb6 100644 --- a/cli/src/main/scala/snailgun/Cli.scala +++ b/cli/src/main/scala/snailgun/Cli.scala @@ -12,14 +12,14 @@ import scopt.OParser import java.net.ConnectException /** - * An implementation of a CLI via case-app. - * - * Unfortunately, GraalVM Native Image doesn't correctly generate a native - * image because of parsing errors and warnings generated by the use of macros - * in case-app via Shapeless. For that reason, this class is left here but it's - * not used by default, preferring a CLI implementation that requires no macros - * and works with GraalVM Native Image. - */ + * An implementation of a CLI via case-app. + * + * Unfortunately, GraalVM Native Image doesn't correctly generate a native + * image because of parsing errors and warnings generated by the use of macros + * in case-app via Shapeless. For that reason, this class is left here but it's + * not used by default, preferring a CLI implementation that requires no macros + * and works with GraalVM Native Image. + */ abstract class Cli(in: InputStream, out: PrintStream, err: PrintStream) { def exit(code: Int): Unit def run(args: Array[String]): Unit = { @@ -101,8 +101,8 @@ abstract class Cli(in: InputStream, out: PrintStream, err: PrintStream) { params.args match { case Nil if params.help => process("help", Array.empty) - case Nil => errorAndExit("Missing command for Nailgun server!") - case cmd :: cmdArgs => process(cmd, cmdArgs.toArray) + case Nil => errorAndExit("Missing command for Nailgun server!") + case cmd :: cmdArgs => process(cmd, cmdArgs.toArray) } } } diff --git a/core/src/main/scala/snailgun/protocol/Protocol.scala b/core/src/main/scala/snailgun/protocol/Protocol.scala index 093a666..11dc94e 100644 --- a/core/src/main/scala/snailgun/protocol/Protocol.scala +++ b/core/src/main/scala/snailgun/protocol/Protocol.scala @@ -30,16 +30,16 @@ import scala.util.Success import scala.util.control.NonFatal /** - * An implementation of the nailgun protocol in Scala. - * - * It follows http://www.martiansoftware.com/nailgun/protocol.html and has - * been slightly inspired in the C and Python clients. The implementation has - * been simplified more than these two and optimized for readability. - * - * The protocol is designed to be used by different instances of - * [[snailgun.Client]] implementing different communication mechanisms (e.g. - * TCP / Unix Domain sockets / Windows Named Pipes). - */ + * An implementation of the nailgun protocol in Scala. + * + * It follows http://www.martiansoftware.com/nailgun/protocol.html and has + * been slightly inspired in the C and Python clients. The implementation has + * been simplified more than these two and optimized for readability. + * + * The protocol is designed to be used by different instances of + * [[snailgun.Client]] implementing different communication mechanisms (e.g. + * TCP / Unix Domain sockets / Windows Named Pipes). + */ class Protocol( streams: Streams, cwd: Path, @@ -91,9 +91,7 @@ class Protocol( logger.debug(s"Sending arguments '${cmdArgs.mkString(" ")}' to Nailgun server") cmdArgs.foreach(sendChunk(ChunkTypes.Argument, _, out)) logger.debug("Sending environment variables to Nailgun server") - allEnvironment.foreach( - kv => sendChunk(ChunkTypes.Environment, s"${kv._1}=${kv._2}", out) - ) + allEnvironment.foreach(kv => sendChunk(ChunkTypes.Environment, s"${kv._1}=${kv._2}", out)) logger.debug(s"Sending working directory $absoluteCwd to Nailgun server") sendChunk(ChunkTypes.Directory, absoluteCwd, out) logger.debug(s"Sending command to $cmd Nailgun server") @@ -119,7 +117,7 @@ class Protocol( printException(error) } case Action.Print(bytes, out) => out.write(bytes) - case Action.SendStdin => sendStdinSemaphore.release() + case Action.SendStdin => sendStdinSemaphore.release() } } } catch { @@ -199,7 +197,7 @@ class Protocol( } readAction match { - case Success(action) => action + case Success(action) => action case Failure(exception) => Action.ExitForcefully(exception) } } @@ -271,12 +269,12 @@ class Protocol( } /** - * Swallows any exception thrown by the closure [[f]] if client exits before - * the timeout of [[Protocol.Time.SendThreadWaitTerminationMillis]]. - * - * Ignoring exceptions in this scenario makes sense (exception could have - * been caught by server finishing connection with client concurrently). - */ + * Swallows any exception thrown by the closure [[f]] if client exits before + * the timeout of [[Protocol.Time.SendThreadWaitTerminationMillis]]. + * + * Ignoring exceptions in this scenario makes sense (exception could have + * been caught by server finishing connection with client concurrently). + */ private def swallowExceptionsIfServerFinished(f: => Unit): Unit = { try f catch { diff --git a/core/src/main/scala/snailgun/protocol/Streams.scala b/core/src/main/scala/snailgun/protocol/Streams.scala index ba39a2f..095fef8 100644 --- a/core/src/main/scala/snailgun/protocol/Streams.scala +++ b/core/src/main/scala/snailgun/protocol/Streams.scala @@ -4,11 +4,11 @@ import java.io.InputStream import java.io.OutputStream /** - * An instance of user-defined streams where the protocol will forward any - * stdout, stdin or stderr coming from the client. - * - * Note that this is decoupled from the logger API, which is mostly used for - * tracing the protocol behaviour and reporting errors. The logger can be - * backed by some of these user-defined streams but it isn't a requirement. - */ + * An instance of user-defined streams where the protocol will forward any + * stdout, stdin or stderr coming from the client. + * + * Note that this is decoupled from the logger API, which is mostly used for + * tracing the protocol behaviour and reporting errors. The logger can be + * backed by some of these user-defined streams but it isn't a requirement. + */ case class Streams(in: InputStream, out: OutputStream, err: OutputStream) diff --git a/core/src/test/scala/snailgun/SnailgunBaseSuite.scala b/core/src/test/scala/snailgun/SnailgunBaseSuite.scala index 2ec9e66..a6dcf13 100644 --- a/core/src/test/scala/snailgun/SnailgunBaseSuite.scala +++ b/core/src/test/scala/snailgun/SnailgunBaseSuite.scala @@ -204,14 +204,14 @@ class SnailgunBaseSuite extends BaseSuite { } /** - * Starts a Nailgun server, creates a snailgun client and executes operations - * with that client. The server is killed when the client exits. - * - * @param streams The user-defined streams. - * @param log The logger instance for the test run. - * @param op A function that will receive the instantiated Client. - * @return The result of executing `op` on the client. - */ + * Starts a Nailgun server, creates a snailgun client and executes operations + * with that client. The server is killed when the client exits. + * + * @param streams The user-defined streams. + * @param log The logger instance for the test run. + * @param op A function that will receive the instantiated Client. + * @return The result of executing `op` on the client. + */ def withRunningServer[T]( streams: Streams, logger: Logger @@ -220,7 +220,7 @@ class SnailgunBaseSuite extends BaseSuite { try Await.result(f, FiniteDuration(5, TimeUnit.SECONDS)) catch { case e: ExecutionException => throw e.getCause() - case t: Throwable => throw t + case t: Throwable => throw t } finally f.cancel() } diff --git a/core/src/test/scala/snailgun/logging/RecordingLogger.scala b/core/src/test/scala/snailgun/logging/RecordingLogger.scala index f3f141f..7cd996a 100644 --- a/core/src/test/scala/snailgun/logging/RecordingLogger.scala +++ b/core/src/test/scala/snailgun/logging/RecordingLogger.scala @@ -27,7 +27,7 @@ class RecordingLogger( val initialMsgs = messages.iterator.asScala val msgs = level match { case Some(level) => initialMsgs.filter(_._1 == level) - case None => initialMsgs + case None => initialMsgs } msgs.map { @@ -40,7 +40,7 @@ class RecordingLogger( if (debug) { debugOut match { case Some(o) => o.println(s"[$key] $value") - case None => println(s"[$key] $value") + case None => println(s"[$key] $value") } } @@ -65,8 +65,8 @@ class RecordingLogger( out.println { s"""Logger contains the following messages: |${getMessages - .map(s => s"[${s._1}] ${s._2}") - .mkString("\n ", "\n ", "\n")} + .map(s => s"[${s._1}] ${s._2}") + .mkString("\n ", "\n ", "\n")} """.stripMargin } } diff --git a/core/src/test/scala/snailgun/logging/Slf4jAdapter.scala b/core/src/test/scala/snailgun/logging/Slf4jAdapter.scala index 8f56e2a..e0726ce 100644 --- a/core/src/test/scala/snailgun/logging/Slf4jAdapter.scala +++ b/core/src/test/scala/snailgun/logging/Slf4jAdapter.scala @@ -3,14 +3,14 @@ package snailgun.logging import org.slf4j.{Marker, Logger => Slf4jLogger} /** - * Defines a slf4j-compliant logger wrapping Bloop logging utils. - * - * This slf4j interface is necessary to be compatible with third-party libraries - * like lsp4s. It only intends to cover the basic functionality and it does not - * support slf4j markers. - * - * @param logger A logger interface. - */ + * Defines a slf4j-compliant logger wrapping Bloop logging utils. + * + * This slf4j interface is necessary to be compatible with third-party libraries + * like lsp4s. It only intends to cover the basic functionality and it does not + * support slf4j markers. + * + * @param logger A logger interface. + */ final class Slf4jAdapter[L <: Logger](logger: L) extends Slf4jLogger { def underlying: L = logger override def getName: String = logger.name diff --git a/core/src/test/scala/snailgun/utils/DiffAssertions.scala b/core/src/test/scala/snailgun/utils/DiffAssertions.scala index 1a7691d..da710ff 100644 --- a/core/src/test/scala/snailgun/utils/DiffAssertions.scala +++ b/core/src/test/scala/snailgun/utils/DiffAssertions.scala @@ -24,8 +24,8 @@ object DiffAssertions { obtainedTitle: String, expectedTitle: String, print: Boolean = true - )( - implicit source: sourcecode.Line + )(implicit + source: sourcecode.Line ): Boolean = { try assertNoDiff(obtained, expected, obtainedTitle, expectedTitle) catch { @@ -89,16 +89,16 @@ object DiffAssertions { if (obtained.length < 1000) { sb.append( s"""#${header("Obtained")} - #${stripTrailingWhitespace(obtained)} - # + #${stripTrailingWhitespace(obtained)} + # #""".stripMargin('#') ) } sb.append( s"""#${header("Diff")} - #${stripTrailingWhitespace( - Diff.unifiedDiff(obtained, expected, obtainedTitle, expectedTitle) - )}""" + #${stripTrailingWhitespace( + Diff.unifiedDiff(obtained, expected, obtainedTitle, expectedTitle) + )}""" .stripMargin('#') ) sb.toString() diff --git a/project/BuildPlugin.scala b/project/BuildPlugin.scala index 8fd34b0..bcaf8c5 100644 --- a/project/BuildPlugin.scala +++ b/project/BuildPlugin.scala @@ -156,9 +156,9 @@ object BuildImplementation { final def reasonableCompileOptions(version: String) = { val base = "-deprecation" :: "-encoding" :: "UTF-8" :: "-feature" :: "-language:existentials" :: "-language:higherKinds" :: "-language:implicitConversions" :: "-unchecked" :: - "-Ywarn-numeric-widen" :: "-Ywarn-value-discard" :: Nil + "-Ywarn-numeric-widen" :: "-Ywarn-value-discard" :: Nil - if(!version.startsWith("2.13")) "-Yno-adapted-args" :: "-Xfuture" :: base else base + if (!version.startsWith("2.13")) "-Yno-adapted-args" :: "-Xfuture" :: base else base } object BuildDefaults { @@ -190,13 +190,13 @@ object BuildImplementation { } /** - * This setting figures out whether the version is a snapshot or not and configures - * the source and doc artifacts that are published by the build. - * - * Snapshot is a term with no clear definition. In this code, a snapshot is a revision - * that is dirty, e.g. has time metadata in its representation. In those cases, the - * build will not publish doc and source artifacts by any of the publishing actions. - */ + * This setting figures out whether the version is a snapshot or not and configures + * the source and doc artifacts that are published by the build. + * + * Snapshot is a term with no clear definition. In this code, a snapshot is a revision + * that is dirty, e.g. has time metadata in its representation. In those cases, the + * build will not publish doc and source artifacts by any of the publishing actions. + */ def publishDocAndSourceArtifact( info: Option[GitDescribeOutput], version: String