Introduce SBT build to replace BUCK/Bazel

Buck has been discontinued and the Analytics plugin is going to evolve
into a server-side data extractor and aggregator engine.

This is the perfect time to transform it into a SBT based
project and start then introducing a Scala-based core data
processing engine.

Additionally, allows a standalone build with full support for downloaded
source code lookup from Maven.

Change-Id: I0e7479f8ddb7412509791d336b6d859b091d933c
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f81b8e9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+.idea
+.project
+.classpath
+.settings/
+target/
+/bin/
diff --git a/BUILD b/BUILD
deleted file mode 100644
index 1f0f6ae..0000000
--- a/BUILD
+++ /dev/null
@@ -1,32 +0,0 @@
-load("//tools/bzl:junit.bzl", "junit_tests")
-load(
-    "//tools/bzl:plugin.bzl",
-    "gerrit_plugin",
-    "PLUGIN_DEPS",
-    "PLUGIN_TEST_DEPS",
-)
-
-gerrit_plugin(
-    name = "analytics",
-    srcs = glob(["src/main/java/**/*.java"]),
-    resources = glob(["src/main/resources/**/*"]),
-    manifest_entries = [
-        "Gerrit-PluginName: analytics",
-        "Gerrit-Module: com.googlesource.gerrit.plugins.analytics.Module",
-        "Gerrit-SshModule: com.googlesource.gerrit.plugins.analytics.SshModule",
-        "Implementation-Title: Analytics plugin",
-        "Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/analytics",
-    ],
-    deps = [
-        "@gitective-core//jar",
-    ],
-)
-
-junit_tests(
-    name = "analytics_tests",
-    srcs = glob(["src/test/java/**/*.java"]),
-    tags = ["analytics"],
-    deps = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [
-        ":analytics__plugin",
-    ],
-)
diff --git a/README.md b/README.md
index d79db9c..f360e7b 100644
--- a/README.md
+++ b/README.md
@@ -5,22 +5,24 @@
 
 ## How to build
 
-Clone the analytics plugin into an existing Gerrit source tree under /plugins/analytics
-and then execute buck build.
+To build the analytics plugin you need to have SBT 0.13.x or later installed.
+If you have a Linux operating system, see the
+[Installing SBT on Linux instructions](http://www.scala-sbt.org/0.13/docs/Installing-sbt-on-Linux.html)
+
+Clone the analytics plugin and execute ```sbt assembly```.
 
 Example:
 
 ```
-   $ git clone https://gerrit.googlesource.com/gerrit
-   $ git clone https://gerrit.googlesource.com/plugins/analytics gerrit/plugins/analytics
-   $ cd gerrit
-   $ buck build plugins/analytics
+   $ git clone https://gerrit.googlesource.com/plugins/analytics
+   $ cd analytics && sbt assembly
 ```
 
+The plugin jar file is created under ```target/scala-2.11/analytics.jar```
+
 ## How to install
 
-Copy the analytics.jar generated under /buck-out/gen/plugins/analytics/analytics.jar
-onto Gerrit's /plugins directory.
+Copy the analytics.jar generated onto the Gerrit's /plugins directory.
 
 ## How to configure
 
@@ -28,23 +30,25 @@
 
 ## How to use
 
-Adds new REST API and SSH commands to allow the extraction of repository statistics
-from Gerrit repositories and changes.
+Adds new REST API and SSH commands to allow the extraction of repository
+statistics from Gerrit repositories and changes.
 
 ## API
 
-All the API share the same syntax and behaviour. Differently from the standard Gerrit REST
-API, the JSON collections are returned as individual lines and streamed over the socket
-I/O. The choice is driven by the fact that the typical consumer of these API is a BigData
-batch process, typically external to Gerrit and hosted on a separate computing cluster.
+All the API share the same syntax and behaviour. Differently from the standard
+Gerrit REST API, the JSON collections are returned as individual lines and
+streamed over the socket I/O. The choice is driven by the fact that the typical
+consumer of these API is a BigData batch process, typically external to Gerrit
+and hosted on a separate computing cluster.
 
-A large volume of data can be potentially generated: splitting the output file into separate
-lines helps the BigData processing in the splitting, shuffling and sorting phase.
+A large volume of data can be potentially generated: splitting the output file
+into separate lines helps the BigData processing in the splitting, shuffling and
+sorting phase.
 
 ### Contributors
 
-Extract a unordered list of project contributors statistics, including the commits data
-relevant for statistics purposes, such as timestamp and merge flag.
+Extract a unordered list of project contributors statistics, including the
+commits data relevant for statistics purposes, such as timestamp and merge flag.
 
 *REST*
 
diff --git a/build.sbt b/build.sbt
new file mode 100644
index 0000000..1bcb710
--- /dev/null
+++ b/build.sbt
@@ -0,0 +1,42 @@
+import sbt.Keys._
+
+val gerritApiVersion = "2.13.7"
+
+val pluginName = "analytics"
+
+lazy val root = (project in file("."))
+  .settings(
+    name := pluginName,
+
+    version := "1.0-SNAPSHOT",
+
+    scalaVersion := "2.11.8",
+
+    libraryDependencies ++= Seq(
+      "io.fabric8" % "gitective-core" % "0.9.19"
+        exclude ("org.eclipse.jgit", "org.eclipse.jgit"),
+
+      "com.google.inject" % "guice" % "3.0" % Provided,
+      "com.google.gerrit" % "gerrit-plugin-api" % gerritApiVersion % Provided withSources(),
+      "com.google.code.gson" % "gson" % "2.7" % Provided,
+      "joda-time" % "joda-time" % "2.9.4" % Provided,
+
+      "org.scalatest" %% "scalatest" % "3.0.1" % Test,
+      "net.codingwell" %% "scala-guice" % "4.1.0" % Test),
+
+    assemblyJarName in assembly := s"$pluginName.jar",
+
+    packageOptions in(Compile, packageBin) += Package.ManifestAttributes(
+      ("Gerrit-ApiType", "plugin"),
+      ("Gerrit-PluginName", pluginName),
+      ("Gerrit-Module", "com.googlesource.gerrit.plugins.analytics.Module"),
+      ("Gerrit-SshModule", "com.googlesource.gerrit.plugins.analytics.SshModule"),
+      ("Implementation-Title", "Analytics plugin"),
+      ("Implementation-URL", "https://gerrit.googlesource.com/plugins/analytics")
+    )
+  )
+
+
+
+
+
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
deleted file mode 100644
index 7a5dcb2..0000000
--- a/external_plugin_deps.bzl
+++ /dev/null
@@ -1,8 +0,0 @@
-load("//tools/bzl:maven_jar.bzl", "maven_jar")
-
-def external_plugin_deps():
-  maven_jar(
-      name = 'gitective-core',
-      artifact = 'io.fabric8:gitective-core:0.9.18',
-      sha1 = 'e9e3cd5c83da434ad64eadd08efd02a1e33fb3fb',
-  )
diff --git a/project/plugins.sbt b/project/plugins.sbt
new file mode 100644
index 0000000..e43b477
--- /dev/null
+++ b/project/plugins.sbt
@@ -0,0 +1,4 @@
+logLevel := Level.Warn
+addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.4")
+addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.1.0")
+