Skip to content

Commit

Permalink
Reformat project
Browse files Browse the repository at this point in the history
  • Loading branch information
jvican committed Nov 28, 2020
1 parent e122cdb commit de99a33
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 77 deletions.
10 changes: 8 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
version = "2.0.0-RC4"
maxColumn = 100
maxColumn = 100
docstrings = JavaDoc
assumeStandardLibraryStripMargin = true
align.tokens=[]
align.openParenCallSite = false
align.openParenDefnSite = false
binPack.literalArgumentLists = true
version = "2.7.3"
20 changes: 10 additions & 10 deletions cli/src/main/scala/snailgun/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
40 changes: 19 additions & 21 deletions core/src/main/scala/snailgun/protocol/Protocol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand Down Expand Up @@ -199,7 +197,7 @@ class Protocol(
}

readAction match {
case Success(action) => action
case Success(action) => action
case Failure(exception) => Action.ExitForcefully(exception)
}
}
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/scala/snailgun/protocol/Streams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
18 changes: 9 additions & 9 deletions core/src/test/scala/snailgun/SnailgunBaseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/test/scala/snailgun/logging/RecordingLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
}

Expand All @@ -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
}
}
Expand Down
16 changes: 8 additions & 8 deletions core/src/test/scala/snailgun/logging/Slf4jAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions core/src/test/scala/snailgun/utils/DiffAssertions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions project/BuildPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit de99a33

Please sign in to comment.