blob: 4e56888707c9238baca0f603c2f164bfb15e646b [file] [log] [blame]
Brian O'Connor1f165982016-04-06 21:36:09 -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':
12 dest = filename
13 else:
14 groupId, artifactId, version = mvnCoords.split(':')
15 groupId = groupId.replace('.', '/')
16 extension = filename.split('.')[-1]
17 if extension == 'jar':
18 filename = '%s-%s.jar' % ( artifactId, version )
Brian O'Connore124f3d2016-04-06 23:54:26 -070019 elif 'features.xml' in filename:
20 filename = '%s-%s-features.xml' % ( artifactId, version )
Brian O'Connor1f165982016-04-06 21:36:09 -070021 dest = 'm2/%s/%s/%s/%s' % ( groupId, artifactId, version, filename )
Brian O'Connor1f165982016-04-06 21:36:09 -070022 zip.write(file, dest)
23
24if __name__ == '__main__':
25 import sys
26
27 if len(sys.argv) < 2:
28 print 'USAGE'
29 sys.exit(1)
30
31 output = sys.argv[1]
32 args = sys.argv[2:]
33
34 if len(args) % 2 != 0:
35 print 'There must be an even number of args: file mvn_coords'
36 sys.exit(2)
37
38 files = zip(*[iter(args)]*2)
39 generateOar(output, files)