diff mxtool/mx.py @ 8457:b27261747964

mx: merge provider configuration files in distribution jars
author Roland Schatz <roland.schatz@oracle.com>
date Mon, 25 Mar 2013 15:39:31 +0100
parents b6b9ab1fde62
children 67f19ede4891
line wrap: on
line diff
--- a/mxtool/mx.py	Fri Mar 22 19:50:51 2013 +0100
+++ b/mxtool/mx.py	Mon Mar 25 15:39:31 2013 +0100
@@ -1658,16 +1658,28 @@
             dname = name[1:]
             d = distribution(dname)
             fd, tmp = tempfile.mkstemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path))
+            services = tempfile.mkdtemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path))
             zf = zipfile.ZipFile(tmp, 'w')
             for p in sorted_deps(d.deps):
                 outputDir = p.output_dir()
                 for root, _, files in os.walk(outputDir):
-                    for f in files:
-                        relpath = root[len(outputDir) + 1:]
-                        arcname = join(relpath, f).replace(os.sep, '/')
-                        zf.write(join(root, f), arcname)
+                    relpath = root[len(outputDir) + 1:]
+                    if relpath == join('META-INF', 'services'):
+                        for f in files:
+                            with open(join(services, f), 'a') as outfile:
+                                with open(join(root, f), 'r') as infile:
+                                    for line in infile:
+                                        outfile.write(line)
+                    else:
+                        for f in files:
+                            arcname = join(relpath, f).replace(os.sep, '/')
+                            zf.write(join(root, f), arcname)
+            for f in os.listdir(services):
+                arcname = join('META-INF', 'services', f).replace(os.sep, '/')
+                zf.write(join(services, f), arcname)
             zf.close()
             os.close(fd)
+            shutil.rmtree(services)
             # Atomic on Unix
             shutil.move(tmp, d.path)
             #print time.time(), 'move:', tmp, '->', d.path