Ensure core plugins are bundled by Maven

Require the core plugins whenever a Gerrit build is run.
These are pulled into the Maven Reactor by being inside
of git submodules. Plugins can be omitted by passing a
-Dgerrit.plugins.skip=true flag on the command line.

Change-Id: I7246389bcae9e98d5f1d46208ff515855eb7c474
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..32483d6
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,11 @@
+[submodule "plugins/replication"]
+	path = plugins/replication
+	url = ../plugins/replication
+
+[submodule "plugins/reviewnotes"]
+	path = plugins/reviewnotes
+	url = ../plugins/reviewnotes
+
+[submodule "plugins/commit-message-length-validator"]
+	path = plugins/commit-message-length-validator
+	url = ../plugins/commit-message-length-validator
diff --git a/Documentation/dev-release.txt b/Documentation/dev-release.txt
index 7f7b489..0bc0b40 100644
--- a/Documentation/dev-release.txt
+++ b/Documentation/dev-release.txt
@@ -131,45 +131,14 @@
 to the released version
 
 
-[[prepare-gerrit]]
-Prepare Gerrit
-~~~~~~~~~~~~~~
+[[build-gerrit]]
+Build Gerrit
+~~~~~~~~~~~~
 
-In all example commands it is assumed that the last release was `2.4`
-and that now the `2.5` release is prepared.
-
-
-[[prepare-war-and-plugin-api]]
-Prepare the Gerrit WAR and the Plugin API Jar
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-* link:dev-readme.html#run-acceptance-tests[Run the acceptance tests]
-
-* Create locally a `stable-2.5` branch for making the new release
-
-* Check in the Gerrit parent `pom.xml` that no `SNAPSHOT` version of a
-Subproject is referenced
-+
-If there is a dependency to a `SNAPSHOT` version,
-link:#subproject[release the subproject] first.
-
-* Create a tag for the Gerrit release
-+
-For an `RC` release:
+* Build the Gerrit WAR
 +
 ====
- git tag -a -m "gerrit 2.5-rc0" v2.5-rc0
-====
-+
-For a final `stable` release:
-+
-====
- git tag -a -m "gerrit 2.5" v2.5
-====
-
-* Build the Gerrit WAR (without plugins) and the Plugin API Jar
-+
-====
+ rm -f ~/.m2/settings.xml
  ./tools/release.sh
 ====
 +
@@ -181,57 +150,6 @@
 ========================================================================
 
 * Sanity check WAR
-
-
-[[prepare-core-plugins]]
-Prepare Core Plugins
-^^^^^^^^^^^^^^^^^^^^
-The core plugins to be prepared are:
-
-* `plugins/replication`
-
-For each core plugin do:
-
-* link:dev-release-subproject.html#make-snapshot[Make a snapshot and test it]
-* link:dev-release-subproject.html#prepare-release[Prepare the Release]
-
-* Update the version of the Core Plugin in
-`gerrit-package-plugins/pom.xml` to the released version
-
-[WARNING]
-========================================================================
-Updating the plugin versions in `gerrit-package-plugins/pom.xml`
-invalidates the Gerrit Release Tag which was created before.
-
-If needed delete the tag and recreate it!
-========================================================================
-
-
-[[prepare-war-with-plugins]]
-Prepare Gerrit WAR with Core Plugins
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-* Ensure that the Core Plugins listed in `gerrit-package-plugins/pom.xml`
-point to the latest release version (no dependency to `SNAPSHOT` versions)
-
-* Ensure that the release tag points to the `HEAD` commit
-
-* Include core plugins into WAR
-+
-====
- $ ./tools/version.sh --release && mvn clean package -f gerrit-package-plugins/pom.xml
- $ ./tools/version.sh --reset
-====
-
-* Find WAR that includes the core plugins at
-`gerrit-package-plugins\target\gerrit-full-v2.5.war`
-
-* Compare `gerrit-package-plugins\target\gerrit-full-v2.5.war` with
-  `gerrit-war\target\gerrit-v2.5.war`
-+
-The only difference should be the core plugins jars under
-`WEB-INF\plugins`.
-
 * Test the new Gerrit version
 
 [[publish-gerrit]]
diff --git a/gerrit-package-plugins/.gitignore b/gerrit-package-plugins/.gitignore
deleted file mode 100644
index c96b05c..0000000
--- a/gerrit-package-plugins/.gitignore
+++ /dev/null
@@ -1,6 +0,0 @@
-/target
-/.classpath
-/.project
-/.settings/org.maven.ide.eclipse.prefs
-/.settings/org.eclipse.m2e.core.prefs
-/gerrit-package-plugins.iml
diff --git a/gerrit-package-plugins/pom.xml b/gerrit-package-plugins/pom.xml
deleted file mode 100644
index ff403c26..0000000
--- a/gerrit-package-plugins/pom.xml
+++ /dev/null
@@ -1,108 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Copyright (C) 2012 The Android Open Source Project
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-
-  <groupId>com.google.gerrit</groupId>
-  <artifactId>gerrit-package-plugins</artifactId>
-  <packaging>war</packaging>
-  <version>2.7-SNAPSHOT</version>
-
-  <name>Gerrit Code Review - Package Plugins</name>
-  <url>http://code.google.com/p/gerrit/</url>
-
-  <properties>
-    <project.build.sourceEncoding>
-      UTF-8
-    </project.build.sourceEncoding>
-  </properties>
-
-  <dependencies>
-    <dependency>
-      <groupId>com.google.gerrit</groupId>
-      <artifactId>gerrit-war</artifactId>
-      <version>${project.version}</version>
-      <type>war</type>
-    </dependency>
-    <dependency>
-      <groupId>com.googlesource.gerrit.plugins.replication</groupId>
-      <artifactId>replication</artifactId>
-      <version>1.1-rc0</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
-      <groupId>com.googlesource.gerrit.plugins.reviewnotes</groupId>
-      <artifactId>reviewnotes</artifactId>
-      <version>1.0-rc1</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
-      <groupId>com.googlesource.gerrit.plugins.validators</groupId>
-      <artifactId>commit-message-length-validator</artifactId>
-      <version>1.0-rc1</version>
-      <scope>provided</scope>
-    </dependency>
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-dependency-plugin</artifactId>
-        <version>2.1</version>
-        <executions>
-          <execution>
-            <phase>process-resources</phase>
-            <goals>
-              <goal>copy-dependencies</goal>
-            </goals>
-            <configuration>
-              <includeTypes>jar</includeTypes>
-              <stripVersion>true</stripVersion>
-              <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/plugins</outputDirectory>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-war-plugin</artifactId>
-        <version>2.1.1</version>
-        <configuration>
-          <warName>gerrit-full-${project.version}</warName>
-          <archive>
-            <addMavenDescriptor>false</addMavenDescriptor>
-            <manifestEntries>
-              <Main-Class>Main</Main-Class>
-              <Implementation-Title>Gerrit Code Review</Implementation-Title>
-              <Implementation-Version>${project.version}</Implementation-Version>
-            </manifestEntries>
-          </archive>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-  <repositories>
-    <repository>
-      <id>gerrit-plugins</id>
-      <url>https://gerrit-plugins.commondatastorage.googleapis.com</url>
-    </repository>
-  </repositories>
-</project>
diff --git a/gerrit-war/pom.xml b/gerrit-war/pom.xml
index a71d28b..333231a 100644
--- a/gerrit-war/pom.xml
+++ b/gerrit-war/pom.xml
@@ -120,6 +120,38 @@
     </dependency>
   </dependencies>
 
+  <profiles>
+    <profile>
+      <id>plugins</id>
+      <activation>
+        <property>
+          <name>!gerrit.plugins.skip</name>
+        </property>
+      </activation>
+      <dependencies>
+        <!-- CORE PLUGIN LIST -->
+        <dependency>
+          <groupId>com.googlesource.gerrit.plugins.replication</groupId>
+          <artifactId>replication</artifactId>
+          <version>${project.version}</version>
+          <scope>provided</scope>
+        </dependency>
+        <dependency>
+          <groupId>com.googlesource.gerrit.plugins.reviewnotes</groupId>
+          <artifactId>reviewnotes</artifactId>
+          <version>${project.version}</version>
+          <scope>provided</scope>
+        </dependency>
+        <dependency>
+          <groupId>com.googlesource.gerrit.plugins.validators</groupId>
+          <artifactId>commit-message-length-validator</artifactId>
+          <version>${project.version}</version>
+          <scope>provided</scope>
+        </dependency>
+      </dependencies>
+    </profile>
+  </profiles>
+
   <build>
 	<pluginManagement>
 	  <plugins>
@@ -194,6 +226,19 @@
               <goal>copy-dependencies</goal>
             </goals>
           </execution>
+          <execution>
+            <id>copy-plugins</id>
+            <configuration>
+              <!-- CORE PLUGIN LIST -->
+              <includeArtifactIds>commit-message-length-validator,replication,reviewnotes</includeArtifactIds>
+              <includeTypes>jar</includeTypes>
+              <stripVersion>true</stripVersion>
+              <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/plugins</outputDirectory>
+            </configuration>
+            <goals>
+              <goal>copy-dependencies</goal>
+            </goals>
+          </execution>
         </executions>
       </plugin>
 
diff --git a/plugins/README b/plugins/README
new file mode 100644
index 0000000..00df3c5
--- /dev/null
+++ b/plugins/README
@@ -0,0 +1,11 @@
+If you are adding a directory here:
+
+- Search all pom.xml files for "CORE PLUGIN LIST".
+- Add the new plugin to that location.
+- (optional) Thank the Maven developers for making this easy.
+
+- Ensure the plugin's pom.xml <version> is the same as Gerrit's
+  own pom.xml(s). Gerrit will only embed a plugin that has the
+  same version as itself.
+
+- Register the plugin as a submodule with git submodule.
diff --git a/plugins/commit-message-length-validator b/plugins/commit-message-length-validator
new file mode 160000
index 0000000..2793491
--- /dev/null
+++ b/plugins/commit-message-length-validator
@@ -0,0 +1 @@
+Subproject commit 2793491aefda6da23e94f87d910f3f92096cfb63
diff --git a/plugins/replication b/plugins/replication
new file mode 160000
index 0000000..0812161
--- /dev/null
+++ b/plugins/replication
@@ -0,0 +1 @@
+Subproject commit 0812161cf90458fd0a6412ba7fb457a73f769be2
diff --git a/plugins/reviewnotes b/plugins/reviewnotes
new file mode 160000
index 0000000..2f24a14
--- /dev/null
+++ b/plugins/reviewnotes
@@ -0,0 +1 @@
+Subproject commit 2f24a1454eb23437408adfa9ed6cb4f008f3dc84
diff --git a/pom.xml b/pom.xml
index 1dfd199..74753de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -98,6 +98,23 @@
     <module>gerrit-plugin-gwt-archetype</module>
   </modules>
 
+  <profiles>
+    <profile>
+      <id>plugins</id>
+      <activation>
+        <property>
+          <name>!gerrit.plugins.skip</name>
+        </property>
+      </activation>
+      <modules>
+        <!-- CORE PLUGIN LIST -->
+        <module>plugins/commit-message-length-validator</module>
+        <module>plugins/replication</module>
+        <module>plugins/reviewnotes</module>
+      </modules>
+    </profile>
+  </profiles>
+
   <licenses>
     <license>
       <name>Apache License, 2.0</name>
diff --git a/tools/release.sh b/tools/release.sh
index 466490e..a63a7a1 100755
--- a/tools/release.sh
+++ b/tools/release.sh
@@ -9,8 +9,12 @@
 		flags="$flags -Dgerrit.documentation.skip=true"
 		shift
 		;;
+	--no-plugins|--without-plugins)
+		flags="$flags -Dgerrit.plugins.skip=true"
+		shift
+		;;
 	*)
-		echo >&2 "usage: $0 [--without-documentation]"
+		echo >&2 "usage: $0 [--no-documentation] [--no-plugins]"
 		exit 1
 	esac
 done
@@ -25,7 +29,7 @@
 fi
 
 ./tools/version.sh --release &&
-mvn clean install $flags
+mvn clean package $flags
 rc=$?
 ./tools/version.sh --reset