blob: e5915f89af47daebad516a1116a60756d600b10e [file] [log] [blame]
Ray Milkeyad83ef92018-06-05 11:05:51 -07001#!/usr/bin/env python
2#FIXME Add license
3
Ray Milkey1ccab712018-06-12 16:30:02 -07004from zipfile import ZipFile, ZipInfo
5import os
Ray Milkeyad83ef92018-06-05 11:05:51 -07006
7def generateOar(output, files=[]):
8 # Note this is not a compressed zip
9 with ZipFile(output, 'w') as zip:
10 for file, mvnCoords in files:
Ray Milkey1ccab712018-06-12 16:30:02 -070011 mvnCoords = mvnCoords.replace("mvn:", "")
Ray Milkeyad83ef92018-06-05 11:05:51 -070012 filename = file.split('/')[-1]
13 if mvnCoords == 'NONE':
Ray Milkey1d52ddd2018-06-07 10:37:24 -070014 if 'app-xml.xml' in filename:
15 dest = 'app.xml'
16 else:
17 dest = filename
Ray Milkeyad83ef92018-06-05 11:05:51 -070018 else:
19 parts = mvnCoords.split(':')
20 if len(parts) > 3:
21 parts.insert(2, parts.pop()) # move version to the 3rd position
22 groupId, artifactId, version = parts[0:3]
23 groupId = groupId.replace('.', '/')
24 extension = filename.split('.')[-1]
25 if extension == 'jar':
26 filename = '%s-%s.jar' % ( artifactId, version )
Ray Milkey1d52ddd2018-06-07 10:37:24 -070027 elif 'feature-xml' in filename:
Ray Milkeyad83ef92018-06-05 11:05:51 -070028 filename = '%s-%s-features.xml' % ( artifactId, version )
29 dest = 'm2/%s/%s/%s/%s' % ( groupId, artifactId, version, filename )
Ray Milkey1ccab712018-06-12 16:30:02 -070030 f = open(file, 'rb')
31 zip.writestr(ZipInfo(dest, date_time=(1980, 1, 1, 0, 0, 0)), f.read())
32 f.close()
Ray Milkeyad83ef92018-06-05 11:05:51 -070033
34if __name__ == '__main__':
35 import sys
36
37 if len(sys.argv) < 2:
38 print 'USAGE'
39 sys.exit(1)
40
41 output = sys.argv[1]
42 args = sys.argv[2:]
43
44 if len(args) % 2 != 0:
45 print 'There must be an even number of args: file mvn_coords'
46 sys.exit(2)
47
48 files = zip(*[iter(args)]*2)
49 generateOar(output, files)