blob: 731ce712b0255b331e77643cafef0d20ce62b014 [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':
12 dest = filename
13 else:
14 parts = mvnCoords.split(':')
15 if len(parts) > 3:
16 parts.insert(2, parts.pop()) # move version to the 3rd position
17 groupId, artifactId, version = parts[0:3]
18 groupId = groupId.replace('.', '/')
19 extension = filename.split('.')[-1]
20 if extension == 'jar':
21 filename = '%s-%s.jar' % ( artifactId, version )
22 elif 'features.xml' in filename:
23 filename = '%s-%s-features.xml' % ( artifactId, version )
24 dest = '%s/%s/%s/%s' % ( groupId, artifactId, version, filename )
25 zip.write(file, dest)
26
27if __name__ == '__main__':
28 import sys
29
30 if len(sys.argv) < 2:
31 print 'USAGE'
32 sys.exit(1)
33
34 output = sys.argv[1]
35 args = sys.argv[2:]
36
37 if len(args) % 2 != 0:
38 print 'There must be an even number of args: file mvn_coords'
39 sys.exit(2)
40
41 files = zip(*[iter(args)]*2)
42 generateOar(output, files)