Skip to content

Commit

Permalink
twitter-server: Reformat with scalafmt 2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Delmore authored and jenkins committed Mar 26, 2020
1 parent 6d9c877 commit b888ebf
Show file tree
Hide file tree
Showing 23 changed files with 85 additions and 153 deletions.
113 changes: 50 additions & 63 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ val jacksonDatabindVersion = "2.9.10.1"
val jacksonLibs = Seq(
"com.fasterxml.jackson.core" % "jackson-core" % jacksonVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonDatabindVersion,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion exclude("com.google.guava", "guava")
"com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion exclude ("com.google.guava", "guava")
)
val opencensusVersion = "0.19.1"
val slf4jVersion = "1.7.30"

def util(which: String) = "com.twitter" %% ("util-"+which) % releaseVersion
def finagle(which: String) = "com.twitter" %% ("finagle-"+which) % releaseVersion
def util(which: String) = "com.twitter" %% ("util-" + which) % releaseVersion
def finagle(which: String) = "com.twitter" %% ("finagle-" + which) % releaseVersion

lazy val noPublishSettings = Seq(
publish := {},
Expand Down Expand Up @@ -91,42 +91,35 @@ lazy val sharedSettings = Seq(
"com.novocode" % "junit-interface" % "0.11" % "test",
"org.mockito" % "mockito-all" % "1.9.5" % "test"
),

ScoverageKeys.coverageHighlighting := true,

ivyXML :=
<dependencies>
<exclude org="com.sun.jmx" module="jmxri" />
<exclude org="com.sun.jdmk" module="jmxtools" />
<exclude org="javax.jms" module="jms" />
</dependencies>,

scalacOptions ++= Seq(
"-target:jvm-1.8",
"-deprecation",
"-unchecked",
"-feature", "-Xlint",
"-encoding", "utf8"
"-feature",
"-Xlint",
"-encoding",
"utf8"
),
javacOptions ++= Seq("-Xlint:unchecked", "-source", "1.8", "-target", "1.8"),
javacOptions in doc := Seq("-source", "1.8"),

javaOptions ++= Seq(
"-Djava.net.preferIPv4Stack=true",
"-XX:+AggressiveOpts",
"-server"
),

javaOptions ++= gcJavaOptions,

javaOptions in Test ++= travisTestJavaOptions,

// This is bad news for things like com.twitter.util.Time
parallelExecution in Test := false,

// -a: print stack traces for failing asserts
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a"),

// Sonatype publishing
publishArtifact in Test := false,
pomIncludeRepository := { _ => false },
Expand Down Expand Up @@ -158,7 +151,7 @@ lazy val sharedSettings = Seq(
if (version.value.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
)

Expand All @@ -179,10 +172,7 @@ lazy val twitterServer = (project in file("server"))
.enablePlugins(
ScalaUnidocPlugin
)
.settings(
name := "twitter-server",
moduleName := "twitter-server",
sharedSettings)
.settings(name := "twitter-server", moduleName := "twitter-server", sharedSettings)
.settings(
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
Expand All @@ -199,15 +189,16 @@ lazy val twitterServer = (project in file("server"))
util("slf4j-jul-bridge"),
util("tunable")
),
libraryDependencies ++= jacksonLibs)
libraryDependencies ++= jacksonLibs
)

lazy val twitterServerOpenCensus = (project in file("opencensus"))
.enablePlugins(
ScalaUnidocPlugin
)
.settings(
name := "twitter-server-opencensus",
moduleName := "twitter-server-opencensus",
name := "twitter-server-opencensus",
moduleName := "twitter-server-opencensus",
sharedSettings)
.settings(
libraryDependencies ++= Seq(
Expand All @@ -216,54 +207,49 @@ lazy val twitterServerOpenCensus = (project in file("opencensus"))
"io.opencensus" % "opencensus-api" % opencensusVersion,
"io.opencensus" % "opencensus-contrib-zpages" % opencensusVersion
))
.dependsOn(
twitterServer)

.dependsOn(twitterServer)

lazy val twitterServerSlf4jJdk14 = (project in file("slf4j-jdk14"))
.settings(
name := "twitter-server-slf4j-jdk14",
moduleName := "twitter-server-slf4j-jdk14",
name := "twitter-server-slf4j-jdk14",
moduleName := "twitter-server-slf4j-jdk14",
sharedSettings)
.settings(
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.slf4j" % "slf4j-jdk14" % slf4jVersion,
"org.slf4j" % "jcl-over-slf4j" % slf4jVersion,
"org.slf4j" % "log4j-over-slf4j" % slf4jVersion))
.dependsOn(
twitterServer)
.settings(libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.slf4j" % "slf4j-jdk14" % slf4jVersion,
"org.slf4j" % "jcl-over-slf4j" % slf4jVersion,
"org.slf4j" % "log4j-over-slf4j" % slf4jVersion
))
.dependsOn(twitterServer)

lazy val twitterServerSlf4jLog4j12 = (project in file("slf4j-log4j12"))
.settings(
name := "twitter-server-slf4j-log4j12",
moduleName := "twitter-server-slf4j-log4j12",
name := "twitter-server-slf4j-log4j12",
moduleName := "twitter-server-slf4j-log4j12",
sharedSettings)
.settings(
libraryDependencies ++= Seq(
"log4j" % "log4j" % "1.2.17" % "provided",
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.slf4j" % "slf4j-log4j12" % slf4jVersion,
"org.slf4j" % "jcl-over-slf4j" % slf4jVersion,
"org.slf4j" % "jul-to-slf4j" % slf4jVersion))
.dependsOn(
twitterServer)
.settings(libraryDependencies ++= Seq(
"log4j" % "log4j" % "1.2.17" % "provided",
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.slf4j" % "slf4j-log4j12" % slf4jVersion,
"org.slf4j" % "jcl-over-slf4j" % slf4jVersion,
"org.slf4j" % "jul-to-slf4j" % slf4jVersion
))
.dependsOn(twitterServer)

lazy val twitterServerSlf4jLogbackClassic = (project in file("logback-classic"))
.settings(
name := "twitter-server-logback-classic",
moduleName := "twitter-server-logback-classic",
name := "twitter-server-logback-classic",
moduleName := "twitter-server-logback-classic",
sharedSettings)
.settings(
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "1.2.3" % "provided",
"ch.qos.logback" % "logback-core" % "1.2.3" % "provided",
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.slf4j" % "jcl-over-slf4j" % slf4jVersion,
"org.slf4j" % "jul-to-slf4j" % slf4jVersion,
"org.slf4j" % "log4j-over-slf4j" % slf4jVersion))
.dependsOn(
twitterServer)
.settings(libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "1.2.3" % "provided",
"ch.qos.logback" % "logback-core" % "1.2.3" % "provided",
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.slf4j" % "jcl-over-slf4j" % slf4jVersion,
"org.slf4j" % "jul-to-slf4j" % slf4jVersion,
"org.slf4j" % "log4j-over-slf4j" % slf4jVersion
))
.dependsOn(twitterServer)

lazy val twitterServerDoc = (project in file("doc"))
.enablePlugins(
Expand All @@ -275,14 +261,15 @@ lazy val twitterServerDoc = (project in file("doc"))
sharedSettings,
Seq(
scalacOptions in doc ++= Seq("-doc-title", "TwitterServer", "-doc-version", version.value),
includeFilter in Sphinx := ("*.html" | "*.png" | "*.js" | "*.css" | "*.gif" | "*.txt")))
.configs(DocTest).settings(
inConfig(DocTest)(Defaults.testSettings): _*)
includeFilter in Sphinx := ("*.html" | "*.png" | "*.js" | "*.css" | "*.gif" | "*.txt")
)
)
.configs(DocTest).settings(inConfig(DocTest)(Defaults.testSettings): _*)
.settings(
unmanagedSourceDirectories in DocTest += baseDirectory.value / "src/sphinx/code",

// Make the "test" command run both, test and doctest:test
test := Seq(test in Test, test in DocTest).dependOn.value)
test := Seq(test in Test, test in DocTest).dependOn.value
)
.dependsOn(twitterServer)

/* Test Configuration for running tests on doc sources */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ private object ZPagesAdminRoutes {
def apply(request: Request): Future[Response] = {
val requestParams =
request
.getParamNames().asScala.map { name =>
name -> request.getParam(name)
}.toMap.asJava
.getParamNames().asScala.map { name => name -> request.getParam(name) }.toMap.asJava

// process in a FuturePool to handle the possibility
// of zpages having blocking code.
Expand Down
3 changes: 2 additions & 1 deletion project/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-feature",
"-encoding", "utf8"
"-encoding",
"utf8"
)
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ trait AdminHttpServer { self: App with Stats =>
muxer.withHandler(route.path, service)
}

val endpoints = allRoutes.map { route =>
s"\t${route.path} => ${route.handler.toString}"
}
val endpoints = allRoutes.map { route => s"\t${route.path} => ${route.handler.toString}" }

log.debug(s"AdminHttpServer Muxer endpoints:\n" + endpoints.mkString("\n"))
adminHttpMuxer.underlying = HttpUtils.combine(Seq(localMuxer, HttpMuxer))
Expand Down
4 changes: 1 addition & 3 deletions server/src/main/scala/com/twitter/server/Hooks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import com.twitter.finagle.util.LoadService
* Mix-in to include service-loaded hooks.
*/
trait Hooks { self: App =>
private val hooks = LoadService[NewHook]().map { newHook =>
newHook(self)
}
private val hooks = LoadService[NewHook]().map { newHook => newHook(self) }

premain {
for (hook <- hooks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ private[handler] object AttachedClientsHandler {
sessionId = clientConnection.sslSessionInfo.sessionId,
cipherSuite = clientConnection.sslSessionInfo.cipherSuite,
peerCertificate = clientConnection.sslSessionInfo.peerCertificates.headOption
.map { peerCertificate =>
PeerCertInfo(peerCertificate.getSubjectDN.getName)
}
.map { peerCertificate => PeerCertInfo(peerCertificate.getSubjectDN.getName) }
))
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ object HistogramQueryHandler {
// For each key return a percentage
private[server] def pdf(counts: Seq[BucketAndCount]): Seq[BucketAndPercentage] = {
val count = countPoints(counts)
counts.map { v =>
BucketAndPercentage(v.lowerLimit, v.upperLimit, v.count.toFloat / count)
}
counts.map { v => BucketAndPercentage(v.lowerLimit, v.upperLimit, v.count.toFloat / count) }
}

// For each key return a cumulative percentage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class IndexHandler(prefix: String = "/", patterns: Seq[String] = HttpMuxer.patte
extends Service[Request, Response] {
def apply(req: Request): Future[Response] = {
val paths = patterns.filter(_.startsWith(prefix))
val links = paths map { p =>
s"<a href='$p'>${escapeHtml(p)}</a>"
}
val links = paths map { p => s"<a href='$p'>${escapeHtml(p)}</a>" }
if (!expectsHtml(req)) newOk(paths.mkString("\n"))
else
newResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ private object LintHandler {
.map {
case (rule, issues) =>
issues
.map { issue =>
failedRow(rule, issue)
}
.map { issue => failedRow(rule, issue) }
.mkString("")
}
.mkString("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,12 @@ class ToggleHandler private[handler] (registeredLibrariesFn: () => Map[String, T
val libraryFilter: String => Boolean = parsedPath.libraryName match {
case Some(name) => _ == name
case None =>
_ =>
true
_ => true
}
val idFilter: String => Boolean = parsedPath.id match {
case Some(name) => _ == name
case None =>
_ =>
true
_ => true
}

val registered = registeredLibrariesFn()
Expand All @@ -317,9 +315,7 @@ class ToggleHandler private[handler] (registeredLibrariesFn: () => Map[String, T

private[this] def toLibraryToggles(toggleMap: ToggleMap): Seq[LibraryToggle] = {
// create a map of id to metadata for faster lookups
val idToMetadata = toggleMap.iterator.map { md =>
md.id -> md
}.toMap
val idToMetadata = toggleMap.iterator.map { md => md.id -> md }.toMap

// create a mapping of id to a seq of its components.
val idToComponents = mutable.Map.empty[String, mutable.ArrayBuffer[Component]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ object DuplicateFlagDefinitions {
if (dupes.isEmpty) {
Nil
} else {
dupes.map { dupe =>
Issue(s"Duplicate flag named: $dupe")
}.toSeq
dupes.map { dupe => Issue(s"Duplicate flag named: $dupe") }.toSeq
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ object DuplicateLoadServiceBindings {
if (dupes.isEmpty) {
Nil
} else {
dupes.map { dupe =>
Issue(s"Duplicate for interface: ${dupe.getName}")
}.toSeq
dupes.map { dupe => Issue(s"Duplicate for interface: ${dupe.getName}") }.toSeq
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ object LoggingRules {

private[lint] def issues(jarPaths: Seq[String]): Seq[Issue] = {
if (jarPaths.length > 1) {
jarPaths.map { jarPath =>
Issue(jarName(jarPath))
}
jarPaths.map { jarPath => Issue(jarName(jarPath)) }
} else {
Nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ private[server] class MetricSchemaSource(
/** Returns all schemas */
def schemaList(): Iterable[MetricSchema] = synchronized {
registry
.foldLeft(IndexedSeq[MetricSchema]()) { (seq, r) =>
seq ++ r.schemas().values
}
.foldLeft(IndexedSeq[MetricSchema]()) { (seq, r) => seq ++ r.schemas().values }
}

/** Returns true if the map contains `key` and false otherwise. */
Expand All @@ -45,8 +43,6 @@ private[server] class MetricSchemaSource(
/** Returns the set of stat keys. */
def keySet: Set[String] = synchronized {
registry
.foldLeft(Set[String]()) { (set, r) =>
set ++ r.schemas().keySet
}
.foldLeft(Set[String]()) { (set, r) => set ++ r.schemas().keySet }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ private[server] object MetricSource {
* which allows for stale StatEntries up to `refreshInterval`.
*/
private[server] class MetricSource(
registry: () => Seq[StatsRegistry] = { () =>
MetricSource.registry
},
registry: () => Seq[StatsRegistry] = { () => MetricSource.registry },
refreshInterval: Duration = 1.second) {
private[this] var lastRefresh = Time.now - refreshInterval
private[this] var underlying: Map[String, StatEntry] = Map.empty

private[this] def refresh(): Unit = {
if (Time.now - lastRefresh > refreshInterval) {
val newStats = registry().foldLeft(Map[String, StatEntry]()) { (map, r) =>
map ++ r()
}
val newStats = registry().foldLeft(Map[String, StatEntry]()) { (map, r) => map ++ r() }
underlying = newStats
lastRefresh = Time.now
}
Expand Down
Loading

0 comments on commit b888ebf

Please sign in to comment.