Scala formatter setup
Setup Scalafmt and run the first code formatting.
Formatting will automatically triggered on compilation.
Change-Id: I38e587192324a593588cd6e912db553ac9a67794
diff --git a/.scalafmt.conf b/.scalafmt.conf
new file mode 100644
index 0000000..30a9298
--- /dev/null
+++ b/.scalafmt.conf
@@ -0,0 +1,2 @@
+align = true
+maxColumn = 100
diff --git a/build.sbt b/build.sbt
index eaeef1a..f382090 100644
--- a/build.sbt
+++ b/build.sbt
@@ -1,24 +1,26 @@
enablePlugins(GitVersioning)
val gerritApiVersion = "2.16-rc0"
-val pluginName = "analytics-wizard"
+val pluginName = "analytics-wizard"
git.useGitDescribe := true
+scalafmtOnCompile in ThisBuild := true
+
lazy val root = (project in file("."))
.settings(
name := pluginName,
resolvers += Resolver.mavenLocal,
scalaVersion := "2.11.8",
libraryDependencies ++= Seq(
- "com.google.inject" % "guice" % "3.0" % Provided,
+ "com.google.inject" % "guice" % "3.0" % Provided,
"com.google.gerrit" % "gerrit-plugin-api" % gerritApiVersion % Provided withSources (),
- "com.spotify" % "docker-client" % "8.14.1",
- "org.scalatest" %% "scalatest" % "3.0.4" % Test,
- "net.codingwell" %% "scala-guice" % "4.1.0" % Test),
-
+ "com.spotify" % "docker-client" % "8.14.1",
+ "org.scalatest" %% "scalatest" % "3.0.4" % Test,
+ "net.codingwell" %% "scala-guice" % "4.1.0" % Test
+ ),
assemblyJarName in assembly := s"$pluginName.jar",
- packageOptions in(Compile, packageBin) += Package.ManifestAttributes(
+ packageOptions in (Compile, packageBin) += Package.ManifestAttributes(
("Gerrit-ApiType", "plugin"),
("Gerrit-PluginName", pluginName),
("Gerrit-Module", "com.googlesource.gerrit.plugins.analytics.wizard.Module"),
@@ -26,4 +28,3 @@
("Implementation-Title", "Analytics plugin wizard")
)
)
-
diff --git a/project/plugins.sbt b/project/plugins.sbt
index 45f9d0f..081bd4a 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -2,3 +2,4 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3")
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4")
+addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15")
diff --git a/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/AnalyticsWizardActions.scala b/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/AnalyticsWizardActions.scala
index baf08fb..5a73f68 100644
--- a/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/AnalyticsWizardActions.scala
+++ b/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/AnalyticsWizardActions.scala
@@ -19,7 +19,12 @@
import com.google.common.io.ByteStreams
import com.google.gerrit.extensions.annotations.PluginData
-import com.google.gerrit.extensions.restapi.{Response, RestApiException, RestModifyView, RestReadView}
+import com.google.gerrit.extensions.restapi.{
+ Response,
+ RestApiException,
+ RestModifyView,
+ RestReadView
+}
import com.google.gerrit.server.config.GerritServerConfig
import com.google.gerrit.server.project.ProjectResource
import com.google.inject.{ImplementedBy, Inject}
@@ -33,7 +38,8 @@
class Input(var dashboardName: String)
-class PutAnalyticsStack @Inject()(@PluginData val dataPath: Path, @GerritServerConfig gerritConfig: Config)
+class PutAnalyticsStack @Inject()(@PluginData val dataPath: Path,
+ @GerritServerConfig gerritConfig: Config)
extends RestModifyView[ProjectResource, Input] {
override def apply(resource: ProjectResource, input: Input): Response[String] = {
@@ -46,21 +52,24 @@
configHelper.getGerritLocalAddress match {
case Success(gerritLocalUrl) =>
AnalyticDashboardSetup(
- projectName, dataPath.resolve(s"docker-compose.$encodedName.yaml"), gerritLocalUrl
+ projectName,
+ dataPath.resolve(s"docker-compose.$encodedName.yaml"),
+ gerritLocalUrl
).createDashboardSetupFile()
Response.created(s"Dashboard configuration created for $encodedName!")
case Failure(exception) =>
- Response.withStatusCode(500, s"Cannot create dashboard configuration - '${exception.getMessage}'")
+ Response.withStatusCode(
+ 500,
+ s"Cannot create dashboard configuration - '${exception.getMessage}'")
}
}
}
class DockerComposeCommand(var action: String)
class PostAnalyticsStack @Inject()(@PluginData val dataPath: Path)
-extends RestModifyView[ProjectResource, DockerComposeCommand] {
- override def apply(resource: ProjectResource,
- input: DockerComposeCommand): Response[String] = {
+ extends RestModifyView[ProjectResource, DockerComposeCommand] {
+ override def apply(resource: ProjectResource, input: DockerComposeCommand): Response[String] = {
val projectName = resource.getName
val encodedName = AnalyticsWizardActions
@@ -82,20 +91,17 @@
ps.exitValue match {
case 0 => Response.created(output)
case _ =>
- throw new RestApiException(
- s"Failed with exit code: ${ps.exitValue} - $output")
+ throw new RestApiException(s"Failed with exit code: ${ps.exitValue} - $output")
}
}
}
-class GetAnalyticsStackStatus @Inject()(
- @PluginData val dataPath: Path,
- val dockerClientProvider: DockerClientProvider)
+class GetAnalyticsStackStatus @Inject()(@PluginData val dataPath: Path,
+ val dockerClientProvider: DockerClientProvider)
extends RestReadView[ProjectResource] {
override def apply(resource: ProjectResource): Response[String] = {
val containerName = "analytics-wizard_spark-gerrit-analytics-etl_1"
- responseFromContainerInfo(
- dockerClientProvider.client.inspectContainer(containerName))
+ responseFromContainerInfo(dockerClientProvider.client.inspectContainer(containerName))
}
private def responseFromContainerInfo(containerInfo: ContainerInfo) = {
diff --git a/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/XAuthFilter.scala b/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/XAuthFilter.scala
index d940da7..8a7814e 100644
--- a/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/XAuthFilter.scala
+++ b/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/XAuthFilter.scala
@@ -25,8 +25,9 @@
import org.slf4j.{Logger, LoggerFactory}
@Singleton
-class XAuthFilter @Inject()(val webSession: DynamicItem[WebSession], @PluginName pluginName: String) extends AllRequestFilter {
- implicit val log: Logger = LoggerFactory.getLogger(classOf[XAuthFilter])
+class XAuthFilter @Inject()(val webSession: DynamicItem[WebSession], @PluginName pluginName: String)
+ extends AllRequestFilter {
+ implicit val log: Logger = LoggerFactory.getLogger(classOf[XAuthFilter])
val authenticatedPluginURIs = (s".*/a/.*$pluginName.*").r
override def init(filterConfig: FilterConfig) {}
@@ -45,4 +46,4 @@
chain.doFilter(req, resp)
}
-}
\ No newline at end of file
+}
diff --git a/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/utils/GerritConfigHelper.scala b/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/utils/GerritConfigHelper.scala
index cd7e946..bbf295c 100644
--- a/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/utils/GerritConfigHelper.scala
+++ b/src/main/scala/com/googlesource/gerrit/plugins/analytics/wizard/utils/GerritConfigHelper.scala
@@ -8,12 +8,13 @@
class GerritConfigHelper(gerritConfig: Config) { self: LocalAddressGetter =>
- def getGerritLocalAddress: Try[URL] = for {
- listenUrl <- Try { new URL(gerritConfig.getString("httpd", null, "listenUrl")) }
- localAddress <- Try { getLocalAddress }
- } yield new URL(s"${listenUrl.getProtocol}://$localAddress:${listenUrl.getPort}")
+ def getGerritLocalAddress: Try[URL] =
+ for {
+ listenUrl <- Try { new URL(gerritConfig.getString("httpd", null, "listenUrl")) }
+ localAddress <- Try { getLocalAddress }
+ } yield new URL(s"${listenUrl.getProtocol}://$localAddress:${listenUrl.getPort}")
}
trait LocalAddressGetter {
def getLocalAddress = InetAddress.getLocalHost.getHostAddress
-}
\ No newline at end of file
+}
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/AnalyticDashboardSetupSpec.scala b/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/AnalyticDashboardSetupSpec.scala
index d539469..0f91888 100644
--- a/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/AnalyticDashboardSetupSpec.scala
+++ b/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/AnalyticDashboardSetupSpec.scala
@@ -19,7 +19,9 @@
implicit val writer = new MockWriter()
val composeYamlFile = File.createTempFile(getClass.getName, ".yaml").toPath
- val ads = AnalyticDashboardSetup("aProject", composeYamlFile, new URL("http://gerrit_local_ip_address:8080"))
+ val ads = AnalyticDashboardSetup("aProject",
+ composeYamlFile,
+ new URL("http://gerrit_local_ip_address:8080"))
ads.createDashboardSetupFile()
gotFilename shouldBe Some(composeYamlFile)
}
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/fixtures/TestFixtures.scala b/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/fixtures/TestFixtures.scala
index 9ccfcdd..c0f254c 100644
--- a/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/fixtures/TestFixtures.scala
+++ b/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/fixtures/TestFixtures.scala
@@ -6,8 +6,7 @@
def gerritConfig(httpProtocol: String, httpPort: Int): Config = {
val gerritConfig = new Config()
- gerritConfig.fromText(
- s"""
+ gerritConfig.fromText(s"""
|[httpd]
| listenUrl = $httpProtocol://*:$httpPort/
""".stripMargin)
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/utils/GerritConfigHelperSpec.scala b/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/utils/GerritConfigHelperSpec.scala
index 264400e..86700a7 100644
--- a/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/utils/GerritConfigHelperSpec.scala
+++ b/src/test/scala/com/googlesource/gerrit/plugins/analytics/wizard/utils/GerritConfigHelperSpec.scala
@@ -12,10 +12,12 @@
it should "retrieve a URL successfully when the right configuration is set" in {
val httpProtocol = "http"
- val httpPort = 8080
- val helper = new GerritConfigHelper(gerritConfig(httpProtocol, httpPort)) with TestLocalAddressGetter
+ val httpPort = 8080
+ val helper = new GerritConfigHelper(gerritConfig(httpProtocol, httpPort))
+ with TestLocalAddressGetter
- helper.getGerritLocalAddress.success.value shouldBe new URL(s"$httpProtocol://${helper.getLocalAddress}:$httpPort")
+ helper.getGerritLocalAddress.success.value shouldBe new URL(
+ s"$httpProtocol://${helper.getLocalAddress}:$httpPort")
}
@@ -38,4 +40,4 @@
trait FailingLocalAddressGetter extends LocalAddressGetter {
override def getLocalAddress: String = throw new Exception("Cannot get local address")
-}
\ No newline at end of file
+}