blob: 4a82b62654cc632ae616bf4c1fb5c53cdc102207 [file] [log] [blame]
Ray Milkeyad83ef92018-06-05 11:05:51 -07001#!/usr/bin/env python
2#FIXME Add license
3
4from zipfile import ZipFile
5
6def generateOar(output, files=[]):
7 # Note this is not a compressed zip
8 with ZipFile(output, 'w') as zip:
9 for file, mvnCoords in files:
10 filename = file.split('/')[-1]
11 if mvnCoords == 'NONE':
Ray Milkey1d52ddd2018-06-07 10:37:24 -070012 if 'app-xml.xml' in filename:
13 dest = 'app.xml'
14 else:
15 dest = filename
Ray Milkeyad83ef92018-06-05 11:05:51 -070016 else:
17 parts = mvnCoords.split(':')
18 if len(parts) > 3:
19 parts.insert(2, parts.pop()) # move version to the 3rd position
20 groupId, artifactId, version = parts[0:3]
21 groupId = groupId.replace('.', '/')
22 extension = filename.split('.')[-1]
23 if extension == 'jar':
24 filename = '%s-%s.jar' % ( artifactId, version )
Ray Milkey1d52ddd2018-06-07 10:37:24 -070025 elif 'feature-xml' in filename:
Ray Milkeyad83ef92018-06-05 11:05:51 -070026 filename = '%s-%s-features.xml' % ( artifactId, version )
27 dest = 'm2/%s/%s/%s/%s' % ( groupId, artifactId, version, filename )
28 zip.write(file, dest)
29
30if __name__ == '__main__':
31 import sys
32
33 if len(sys.argv) < 2:
34 print 'USAGE'
35 sys.exit(1)
36
37 output = sys.argv[1]
38 args = sys.argv[2:]
39
40 if len(args) % 2 != 0:
41 print 'There must be an even number of args: file mvn_coords'
42 sys.exit(2)
43
44 files = zip(*[iter(args)]*2)
45 generateOar(output, files)