diff mxtool/mx.py @ 21043:5ea65fe64368

Check distributions overlap in gate
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Mon, 20 Apr 2015 18:27:46 +0200
parents b99da6d86cfe
children 53b2d64f8ad1
line wrap: on
line diff
--- a/mxtool/mx.py	Mon Apr 20 14:40:48 2015 +0200
+++ b/mxtool/mx.py	Mon Apr 20 18:27:46 2015 +0200
@@ -101,7 +101,7 @@
 A distribution is a jar or zip file containing the output from one or more Java projects.
 """
 class Distribution:
-    def __init__(self, suite, name, path, sourcesPath, deps, mainClass, excludedDependencies, distDependencies, javaCompliance):
+    def __init__(self, suite, name, path, sourcesPath, deps, mainClass, excludedDependencies, distDependencies, javaCompliance, isProcessorDistribution=False):
         self.suite = suite
         self.name = name
         self.path = path.replace('/', os.sep)
@@ -113,6 +113,7 @@
         self.excludedDependencies = excludedDependencies
         self.distDependencies = distDependencies
         self.javaCompliance = JavaCompliance(javaCompliance) if javaCompliance else None
+        self.isProcessorDistribution = isProcessorDistribution
 
     def sorted_deps(self, includeLibs=False, transitive=False):
         deps = []
@@ -1090,7 +1091,7 @@
                 exclDeps = []
                 distDeps = []
                 javaCompliance = None
-                d = Distribution(self, dname, path, sourcesPath, deps, mainClass, exclDeps, distDeps, javaCompliance)
+                d = Distribution(self, dname, path, sourcesPath, deps, mainClass, exclDeps, distDeps, javaCompliance, True)
                 d.subDir = os.path.relpath(os.path.dirname(p.dir), self.dir)
                 self.dists.append(d)
                 p.definedAnnotationProcessors = annotationProcessors
@@ -2563,6 +2564,7 @@
     parser.add_argument('-p', action='store_true', dest='parallelize', help='parallelizes Java compilation if possible')
     parser.add_argument('--source', dest='compliance', help='Java compliance level for projects without an explicit one')
     parser.add_argument('--Wapi', action='store_true', dest='warnAPI', help='show warnings about using internal APIs')
+    parser.add_argument('--check-distributions', action='store_true', dest='check_distributions', help='check built distributions for overlap')
     parser.add_argument('--projects', action='store', help='comma separated projects to build (omit to build all projects)')
     parser.add_argument('--only', action='store', help='comma separated projects to build, without checking their dependencies (omit to build all projects)')
     parser.add_argument('--no-java', action='store_false', dest='java', help='do not build Java projects')
@@ -2790,9 +2792,16 @@
             abort('{0} Java compilation tasks failed'.format(len(failed)))
 
     if args.java:
+        files = []
         for dist in sorted_dists():
             if dist not in updatedAnnotationProcessorDists:
                 archive(['@' + dist.name])
+            if args.check_distributions and not dist.isProcessorDistribution:
+                with zipfile.ZipFile(dist.path, 'r') as zf:
+                    files.extend([member for member in zf.namelist() if not member.startswith('META-INF/services')])
+        dups = set([x for x in files if files.count(x) > 1])
+        if len(dups) > 0:
+            abort('Distributions overlap! duplicates: ' + str(dups))
 
     if suppliedParser:
         return args