blob: 30f70f586c05ab50caea1fe9a6047cc5d3a7c93c [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:
Ray Milkey58915da2016-05-17 13:17:07 -070014 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]
Brian O'Connor1f165982016-04-06 21:36:09 -070018 groupId = groupId.replace('.', '/')
19 extension = filename.split('.')[-1]
20 if extension == 'jar':
21 filename = '%s-%s.jar' % ( artifactId, version )
Brian O'Connore124f3d2016-04-06 23:54:26 -070022 elif 'features.xml' in filename:
23 filename = '%s-%s-features.xml' % ( artifactId, version )
Brian O'Connor1f165982016-04-06 21:36:09 -070024 dest = 'm2/%s/%s/%s/%s' % ( groupId, artifactId, version, filename )
Brian O'Connor1f165982016-04-06 21:36:09 -070025 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)