Bug 560492 - Build should validate that P2 repositories contain source bundles

Add a python script to releng that verifies that all bundles in a
repository, with exception of an exclusions list, also have their
corresponding source bundle. If the verification fails, the build fails
and bundles with missing source are printed to the build log.

Change-Id: I2beb68bc1c25a1eaba39bd4786e4fcdf0d79f4f3
Signed-off-by: Lucas Koehler <lkoehler@eclipsesource.com>
diff --git a/releng/org.eclipse.emf.ecp.releng/scripts/verify-sources-exceptions b/releng/org.eclipse.emf.ecp.releng/scripts/verify-sources-exceptions
new file mode 100644
index 0000000..bbd4b27
--- /dev/null
+++ b/releng/org.eclipse.emf.ecp.releng/scripts/verify-sources-exceptions
@@ -0,0 +1,54 @@
+# Source Exceptions
+
+## Plugins
+org.eclipse.emfforms.coffee.model.viewmodel
+org.eclipse.emfforms.setup.base
+org.eclipse.emf.ecp.common.ui.nl
+org.eclipse.emf.ecp.core.nl
+org.eclipse.emf.ecp.diffmerge.model.edit.nl
+org.eclipse.emf.ecp.diffmerge.swt.nl
+org.eclipse.emf.ecp.edit.nl
+org.eclipse.emf.ecp.edit.swt.nl
+org.eclipse.emf.ecp.emfstore.ui.e4
+org.eclipse.emf.ecp.ide.editor.view.nl
+org.eclipse.emf.ecp.makeithappen.model.edit.nl
+org.eclipse.emf.ecp.makeithappen.wizards.nl
+org.eclipse.emf.ecp.ui.e3.nl
+org.eclipse.emf.ecp.ui.e4
+org.eclipse.emf.ecp.ui.nl
+org.eclipse.emf.ecp.ui.validation.nl
+org.eclipse.emf.ecp.ui.view.editor.controls.nl
+org.eclipse.emf.ecp.validation.nl
+org.eclipse.emf.ecp.view.categorization.model.edit.nl
+org.eclipse.emf.ecp.view.core.swt.nl
+org.eclipse.emf.ecp.view.custom.model.edit.nl
+org.eclipse.emf.ecp.view.custom.model.nl
+org.eclipse.emf.ecp.view.dynamictree.model.edit.nl
+org.eclipse.emf.ecp.view.group.model.edit.nl
+org.eclipse.emf.ecp.view.groupedgrid.model.edit.nl
+org.eclipse.emf.ecp.view.horizontal.model.edit.nl
+org.eclipse.emf.ecp.view.label.model.edit.nl
+org.eclipse.emf.ecp.view.model.edit.nl
+org.eclipse.emf.ecp.view.model.editor.nl
+org.eclipse.emf.ecp.view.model.nl
+org.eclipse.emf.ecp.view.rule.model.edit.nl
+org.eclipse.emf.ecp.view.stack.viewmodel
+org.eclipse.emf.ecp.view.table.model.edit.nl
+org.eclipse.emf.ecp.view.table.model.nl
+org.eclipse.emf.ecp.view.table.ui.nebula.grid.nl
+org.eclipse.emf.ecp.view.table.ui.swt.nl
+org.eclipse.emf.ecp.view.table.validation
+org.eclipse.emf.ecp.view.template.model.edit.nl
+org.eclipse.emf.ecp.view.treemasterdetail.model.edit.nl
+org.eclipse.emf.ecp.view.vertical.model.edit.nl
+
+## Features
+org.eclipse.emf.ecp.demo.e4.feature
+org.eclipse.emf.ecp.e4.feature
+org.eclipse.emf.ecp.emfforms.sdk.feature
+org.eclipse.emf.ecp.i18n.feature
+org.eclipse.emf.ecp.license.feature
+org.eclipse.emf.ecp.rap.sdk.feature
+org.eclipse.emf.ecp.sdk.e4.feature
+org.eclipse.emf.ecp.sdk.feature
+org.eclipse.emfforms.i18n.feature
\ No newline at end of file
diff --git a/releng/org.eclipse.emf.ecp.releng/scripts/verify-sources.py b/releng/org.eclipse.emf.ecp.releng/scripts/verify-sources.py
new file mode 100644
index 0000000..6a37cb6
--- /dev/null
+++ b/releng/org.eclipse.emf.ecp.releng/scripts/verify-sources.py
@@ -0,0 +1,61 @@
+#!python
+import os
+import sys
+
+SOURCE_POSTFIX = '.source'
+
+def get_missing_source_bundles(root_dir = '.', exceptions = []):
+  missing_source = []
+  source_jars = []
+  jars = []
+  for root, dirs, files in os.walk(root_dir):
+    for file in files:
+      # get rid of the version identifier and file extension. only the bundle name is relevant
+      stripped_name = file.split('_')[0]
+      if stripped_name.endswith(SOURCE_POSTFIX):
+        source_jars.append(stripped_name[:len(stripped_name) - len(SOURCE_POSTFIX)])
+      else:
+        jars.append(stripped_name)
+
+  for jar in jars:
+    if (jar not in source_jars) and (jar not in exceptions):
+      missing_source.append(jar)
+
+  return missing_source
+
+# Assumes that the scripts workding dir is the repository bundle's project base dir.
+# arguments
+# argv[0] - path to exceptions
+def main(argv):
+  print("Verify source bundles have been exported...")
+  with open(argv[0], mode="rt") as exceptions_file:
+    exceptions = [ex.strip() for ex in exceptions_file if ex.strip() and not ex.strip().startswith('#')]
+
+  plugins_missing_src = get_missing_source_bundles('./target/repository/plugins', exceptions)
+  features_missing_src = get_missing_source_bundles('./target/repository/features', exceptions)
+
+  if plugins_missing_src:
+    print('----------------------------------')
+    print('Plugins with missing source jars:')
+    print('----------------------------------')
+    plugins_missing_src.sort()
+    for b in plugins_missing_src:
+      print(b)
+    print('----------------------------------')
+
+  if features_missing_src:
+    print('----------------------------------')
+    print('Features with missing source jars:')
+    print('----------------------------------')
+    features_missing_src.sort()
+    for b in features_missing_src:
+      print(b)
+    print('----------------------------------')
+
+  if plugins_missing_src or features_missing_src:
+    print("There are missing source bundles! See output above.")
+    sys.exit(2)
+  print("...verification successful.")
+
+if __name__ == "__main__":
+  main(sys.argv[1:])
\ No newline at end of file
diff --git a/releng/org.eclipse.emf.ecp.repository.target/pom.xml b/releng/org.eclipse.emf.ecp.repository.target/pom.xml
index 934b853..49058c6 100644
--- a/releng/org.eclipse.emf.ecp.repository.target/pom.xml
+++ b/releng/org.eclipse.emf.ecp.repository.target/pom.xml
@@ -26,6 +26,28 @@
 					<xzCompress>false</xzCompress>
 				</configuration>
 			</plugin>
+			<plugin>
+				<groupId>org.codehaus.mojo</groupId>
+				<artifactId>exec-maven-plugin</artifactId>
+				<version>1.2.1</version>
+				<executions>
+					<execution>
+						<id>verify-source-bundles</id>
+						<phase>verify</phase>
+						<goals>
+							<goal>exec</goal>
+						</goals>
+					</execution>
+				</executions>
+				<configuration>
+					<executable>python</executable>
+					<workingDirectory>${project.basedir}</workingDirectory>
+					<arguments>
+						<argument>${project.basedir}/../org.eclipse.emf.ecp.releng/scripts/verify-sources.py</argument>
+						<argument>${project.basedir}/../org.eclipse.emf.ecp.releng/scripts/verify-sources-exceptions</argument>
+					</arguments>
+				</configuration>
+			</plugin>
 		</plugins>
 	</build>
 	
diff --git a/releng/org.eclipse.emf.ecp.repository/pom.xml b/releng/org.eclipse.emf.ecp.repository/pom.xml
index 08d2d44..2c08054 100644
--- a/releng/org.eclipse.emf.ecp.repository/pom.xml
+++ b/releng/org.eclipse.emf.ecp.repository/pom.xml
@@ -26,6 +26,28 @@
 					<xzCompress>false</xzCompress>
 				</configuration>
 			</plugin>
+			<plugin>
+				<groupId>org.codehaus.mojo</groupId>
+				<artifactId>exec-maven-plugin</artifactId>
+				<version>1.2.1</version>
+				<executions>
+					<execution>
+						<id>verify-source-bundles</id>
+						<phase>verify</phase>
+						<goals>
+							<goal>exec</goal>
+						</goals>
+					</execution>
+				</executions>
+				<configuration>
+					<executable>python</executable>
+					<workingDirectory>${project.basedir}</workingDirectory>
+					<arguments>
+						<argument>${project.basedir}/../org.eclipse.emf.ecp.releng/scripts/verify-sources.py</argument>
+						<argument>${project.basedir}/../org.eclipse.emf.ecp.releng/scripts/verify-sources-exceptions</argument>
+					</arguments>
+				</configuration>
+			</plugin>
 		</plugins>
 	</build>