blob: 368d2811946fa97b78961c7ee91dba07929907b5 [file] [log] [blame]
Ray Milkeyad83ef92018-06-05 11:05:51 -07001#!/usr/bin/env python
2#FIXME Add license
3
Thomas Vachuskae8f06892018-06-12 15:54:49 -07004from zipfile import ZipFile, ZipInfo
Ray Milkeyad83ef92018-06-05 11:05:51 -07005
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(':')
Thomas Vachuskae8f06892018-06-12 15:54:49 -070015 if len(parts) > 4:
16 parts.insert(3, parts.pop()) # move version to the 3rd position
17 groupId, artifactId, version = parts[1:4]
Ray Milkeyad83ef92018-06-05 11:05:51 -070018 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 )
Thomas Vachuskae8f06892018-06-12 15:54:49 -070025 f = open(file, 'rb')
26 zip.writestr(ZipInfo(dest, date_time=(1980, 1, 1, 0, 0, 0)), f.read())
27 f.close()
Ray Milkeyad83ef92018-06-05 11:05:51 -070028
29if __name__ == '__main__':
30 import sys
31
32 if len(sys.argv) < 2:
33 print 'USAGE'
34 sys.exit(1)
35
36 output = sys.argv[1]
37 args = sys.argv[2:]
38
39 if len(args) % 2 != 0:
40 print 'There must be an even number of args: file mvn_coords'
41 sys.exit(2)
42
43 files = zip(*[iter(args)]*2)
44 generateOar(output, files)