Merge "Buck: Deploy plugin artifacts to Maven Central" into stable-2.9
diff --git a/.gitignore b/.gitignore
index efff6da..e979409 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,4 @@
 /local.properties
 *.pyc
 /gwt-unitCache
+*.asc
diff --git a/Documentation/dev-buck.txt b/Documentation/dev-buck.txt
index 9dfb33b..98cd513 100644
--- a/Documentation/dev-buck.txt
+++ b/Documentation/dev-buck.txt
@@ -142,34 +142,12 @@
   buck build api_install
 ----
 
-Deploy {extension,plugin,gwt}-api to the remote maven repository:
-
-----
-  buck build api_deploy
-----
-
 Install gerrit.war to the local maven repository:
 
 ----
   buck build war_install
 ----
 
-Deploy gerrit.war to the remote maven repository:
-
-----
-  buck build war_deploy
-----
-
-The type of the repo is induced from the Gerrit version name, i.e.
-
-* `2.9-SNAPSHOT`: snapshot repo
-* `2.9`: release repo
-
-Deploying to the remote repository still depends on Maven, and the credentials
-for the repository need to be
-link:dev-release-deploy-config.html#deploy-configuration-settings-xml[
-configured in Maven's settings.xml file].
-
 === Plugins
 
 To build all core plugins:
diff --git a/Documentation/dev-release-deploy-config.txt b/Documentation/dev-release-deploy-config.txt
index 4a4e894..83c28da 100644
--- a/Documentation/dev-release-deploy-config.txt
+++ b/Documentation/dev-release-deploy-config.txt
@@ -1,6 +1,48 @@
 = Deploy Gerrit Artifacts
 
-Gerrit Artifacts are stored on
+[[deploy-configuration-setting-maven-central]]
+== Deploy Configuration settings for Maven Central
+
+Gerrit Extension API Jar and the Gerrit Plugin API artifacts are stored on
+Maven Central.
+
+Prerequisites: Set up the Sonatype account (see link:https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-2.Signup[Sonatype
+Maven Repository Usage Guide]) and put Sonatype user and password in
+~/.m2/settings.xml:
+
+----
+<server>
+  <id>sonatype-nexus-staging</id>
+  <username>USER</username>
+  <password>PASSWORD</password>
+</server>
+----
+
+PGP key must be generated and published, see
+link:https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven[How
+To Generate PGP Signatures With Maven] for details. PGP passphrase can also be
+put in ~/.m2/settings.xml:
+
+----
+<settings>
+  <profiles>
+    <profile>
+      <id>gpg</id>
+      <properties>
+        <gpg.executable>gpg2</gpg.executable>
+        <gpg.passphrase>mypassphrase</gpg.passphrase>
+      </properties>
+    </profile>
+  </profiles>
+  <activeProfiles>
+    <activeProfile>gpg</activeProfile>
+  </activeProfiles>
+</settings>
+----
+
+It can also be included in the key chain on OS X.
+
+Gerrit Subproject Artifacts are stored on
 link:https://developers.google.com/storage/[Google Cloud Storage].
 Via the link:https://code.google.com/apis/console/?noredirect[API Console] the
 Gerrit maintainers have access to the `Gerrit Code Review` project.
diff --git a/Documentation/dev-release.txt b/Documentation/dev-release.txt
index 1af54c7..02f64e6 100644
--- a/Documentation/dev-release.txt
+++ b/Documentation/dev-release.txt
@@ -144,26 +144,34 @@
 link:dev-release-deploy-config.html#deploy-configuration-settings-xml[
 configuration needed for deployment]
 
-* Push the Jars to the storage bucket:
+* Push the Jars to the Maven Central:
 +
 ----
   buck build api_deploy
 ----
 
+* Make sure you have done the
+link:dev-release-deploy-config.html#deploy-configuration-setting-maven-central[
+configuration needed for deployment]
+
+
+* Troubleshooting: to see the commands that are execured in Buck build process
+environment variable VERBOSE can be set:
++
+----
+  VERBOSE=1 buck build api_deploy
+----
 
 [[publish-gerrit-war]]
 ==== Publish the Gerrit WAR (with Core Plugins)
 
-* The WAR file to upload is `buck-out/gen/release.war`
-* Upload WAR to the storage bucket via `https://cloud.google.com/console` (manual via web browser)
-* Push the WAR file to the Maven storage bucket:
+* Push the WAR to the Maven Central:
 +
 ----
   buck build war_deploy
 ----
 
 
-
 [[push-stable]]
 ==== Push the Stable Branch
 
diff --git a/gerrit-war/pom.xml b/gerrit-war/pom.xml
new file mode 100644
index 0000000..e8031ef
--- /dev/null
+++ b/gerrit-war/pom.xml
@@ -0,0 +1,59 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.google.gerrit</groupId>
+  <artifactId>gerrit-war</artifactId>
+  <version>2.9-SNAPSHOT</version>
+  <packaging>war</packaging>
+  <name>Gerrit Code Review - WAR</name>
+  <description>Gerrit WAR</description>
+  <url>http://code.google.com/p/gerrit/</url>
+
+  <licenses>
+    <license>
+      <name>The Apache Software License, Version 2.0</name>
+      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+      <distribution>repo</distribution>
+    </license>
+  </licenses>
+
+  <scm>
+    <url>https://gerrit.googlesource.com/gerrit</url>
+    <connection>https://gerrit.googlesource.com/gerrit</connection>
+  </scm>
+
+  <developers>
+    <developer>
+      <name>Dave Borowitz</name>
+    </developer>
+    <developer>
+      <name>David Pursehouse</name>
+    </developer>
+    <developer>
+      <name>Edwin Kempin</name>
+    </developer>
+    <developer>
+      <name>Martin Fick</name>
+    </developer>
+    <developer>
+      <name>Saša Živkov</name>
+    </developer>
+    <developer>
+      <name>Shawn Pearce</name>
+    </developer>
+  </developers>
+
+  <mailingLists>
+    <mailingList>
+      <name>Repo and Gerrit Discussion</name>
+      <post>repo-discuss@googlegroups.com</post>
+      <subscribe>https://groups.google.com/forum/#!forum/repo-discuss</subscribe>
+      <unsubscribe>https://groups.google.com/forum/#!forum/repo-discuss</unsubscribe>
+      <archive>https://groups.google.com/forum/#!forum/repo-discuss</archive>
+    </mailingList>
+  </mailingLists>
+
+  <issueManagement>
+    <url>http://code.google.com/p/gerrit/issues/list</url>
+    <system>Google Code Issue Tracker</system>
+  </issueManagement>
+</project>
diff --git a/tools/maven/BUCK b/tools/maven/BUCK
index b6b501e..4d53783 100644
--- a/tools/maven/BUCK
+++ b/tools/maven/BUCK
@@ -1,11 +1,13 @@
 include_defs('//VERSION')
 include_defs('//tools/maven/package.defs')
 
-TYPE = 'snapshot' if GERRIT_VERSION.endswith('-SNAPSHOT') else 'release'
+URL = 'https://oss.sonatype.org/content/repositories/snapshots' \
+      if GERRIT_VERSION.endswith('-SNAPSHOT') else \
+        'https://oss.sonatype.org/service/local/staging/deploy/maven2'
 
 maven_package(
-  repository = 'gerrit-api-repository',
-  url = 'gs://gerrit-api/%s' % TYPE,
+  repository = 'sonatype-nexus-staging',
+  url = URL,
   version = GERRIT_VERSION,
   jar = {
     'gerrit-extension-api': '//gerrit-extension-api:extension-api',
diff --git a/tools/maven/fake_pom_deploy.xml b/tools/maven/fake_pom_deploy.xml
deleted file mode 100644
index a531200..0000000
--- a/tools/maven/fake_pom_deploy.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0">
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>com.google.gerrit</groupId>
-  <artifactId>Gerrit-Code-Review-Maven</artifactId>
-  <version>1</version>
-  <distributionManagement>
-    <repository>
-      <id>gerrit-api-repository</id>
-      <name>Gerrit API Repository</name>
-      <url>gs://gerrit-api</url>
-      <uniqueVersion>true</uniqueVersion>
-    </repository>
-  </distributionManagement>
-  <build>
-    <extensions>
-      <extension>
-        <groupId>com.googlesource.gerrit</groupId>
-        <artifactId>gs-maven-wagon</artifactId>
-        <version>3.3</version>
-      </extension>
-    </extensions>
-  </build>
-  <pluginRepositories>
-    <pluginRepository>
-      <id>gerrit-maven-repository</id>
-      <url>https://gerrit-maven.storage.googleapis.com/</url>
-    </pluginRepository>
-  </pluginRepositories>
-</project>
diff --git a/tools/maven/fake_pom_install.xml b/tools/maven/fake_pom_install.xml
deleted file mode 100644
index d066a4a..0000000
--- a/tools/maven/fake_pom_install.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0">
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>com.google.gerrit</groupId>
-  <artifactId>Gerrit-Code-Review-Maven</artifactId>
-  <version>1</version>
-</project>
diff --git a/tools/maven/mvn.py b/tools/maven/mvn.py
index a4aaa5a..9e36b48 100644
--- a/tools/maven/mvn.py
+++ b/tools/maven/mvn.py
@@ -15,14 +15,11 @@
 
 from __future__ import print_function
 from optparse import OptionParser
-from os import path
+from os import path, environ
 
 from sys import stderr
 from tools.util import check_output
 
-def mvn(action):
-  return ['mvn', '--file', path.join(self, 'fake_pom_%s.xml' % action)]
-
 opts = OptionParser()
 opts.add_option('--repository', help='maven repository id')
 opts.add_option('--url', help='maven repository url')
@@ -36,33 +33,38 @@
   print('version is empty', file=stderr)
   exit(1)
 
-common = [
-  '-DgroupId=com.google.gerrit',
-  '-Dversion=%s' % args.v,
-]
-
-self = path.dirname(path.abspath(__file__))
+root = path.abspath(__file__)
+for _ in range(0, 3):
+  root = path.dirname(root)
 
 if 'install' == args.a:
-  cmd = mvn(args.a) + ['install:install-file'] + common
+  cmd = [
+    'mvn',
+    'install:install-file',
+    '-Dversion=%s' % args.v,
+  ]
 elif 'deploy' == args.a:
-  cmd = mvn(args.a) + [
-    'deploy:deploy-file',
+  cmd = [
+    'mvn',
+    'gpg:sign-and-deploy-file',
     '-DrepositoryId=%s' % args.repository,
     '-Durl=%s' % args.url,
-  ] + common
+  ]
 else:
   print("unknown action -a %s" % args.a, file=stderr)
   exit(1)
 
 for spec in args.s:
   artifact, packaging_type, src = spec.split(':')
+  exe = cmd + [
+    '-DpomFile=%s' % path.join(root, '%s/pom.xml' % artifact),
+    '-Dpackaging=%s' % packaging_type,
+    '-Dfile=%s' % src,
+  ]
   try:
-    check_output(cmd + [
-      '-DartifactId=%s' % artifact,
-      '-Dpackaging=%s' % packaging_type,
-      '-Dfile=%s' % src,
-    ])
+    if environ.get('VERBOSE'):
+      print(' '.join(exe), file=stderr)
+    check_output(exe)
   except Exception as e:
     print('%s command failed: %s' % (args.a, e), file=stderr)
     exit(1)
diff --git a/tools/version.py b/tools/version.py
index 92143ba..a994bd8 100755
--- a/tools/version.py
+++ b/tools/version.py
@@ -32,7 +32,8 @@
 
 for project in ['gerrit-extension-api', 'gerrit-plugin-api',
                 'gerrit-plugin-archetype', 'gerrit-plugin-gwt-archetype',
-                'gerrit-plugin-gwtui', 'gerrit-plugin-js-archetype']:
+                'gerrit-plugin-gwtui', 'gerrit-plugin-js-archetype',
+                'gerrit-war']:
   pom = os.path.join(project, 'pom.xml')
   try:
     outxml = ""