Ray Milkey | ad83ef9 | 2018-06-05 11:05:51 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | #FIXME Add license |
| 3 | |
Ray Milkey | 1ccab71 | 2018-06-12 16:30:02 -0700 | [diff] [blame] | 4 | from zipfile import ZipFile, ZipInfo |
| 5 | import os |
Ray Milkey | ad83ef9 | 2018-06-05 11:05:51 -0700 | [diff] [blame] | 6 | |
| 7 | def 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 Milkey | 1ccab71 | 2018-06-12 16:30:02 -0700 | [diff] [blame] | 11 | mvnCoords = mvnCoords.replace("mvn:", "") |
Ray Milkey | ad83ef9 | 2018-06-05 11:05:51 -0700 | [diff] [blame] | 12 | filename = file.split('/')[-1] |
| 13 | if mvnCoords == 'NONE': |
Ray Milkey | 1d52ddd | 2018-06-07 10:37:24 -0700 | [diff] [blame] | 14 | if 'app-xml.xml' in filename: |
| 15 | dest = 'app.xml' |
| 16 | else: |
| 17 | dest = filename |
Ray Milkey | ad83ef9 | 2018-06-05 11:05:51 -0700 | [diff] [blame] | 18 | 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 Milkey | 1d52ddd | 2018-06-07 10:37:24 -0700 | [diff] [blame] | 27 | elif 'feature-xml' in filename: |
Ray Milkey | ad83ef9 | 2018-06-05 11:05:51 -0700 | [diff] [blame] | 28 | filename = '%s-%s-features.xml' % ( artifactId, version ) |
| 29 | dest = 'm2/%s/%s/%s/%s' % ( groupId, artifactId, version, filename ) |
Ray Milkey | 1ccab71 | 2018-06-12 16:30:02 -0700 | [diff] [blame] | 30 | f = open(file, 'rb') |
| 31 | zip.writestr(ZipInfo(dest, date_time=(1980, 1, 1, 0, 0, 0)), f.read()) |
| 32 | f.close() |
Ray Milkey | ad83ef9 | 2018-06-05 11:05:51 -0700 | [diff] [blame] | 33 | |
| 34 | if __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) |