blob: 1ad54ec9be51011b6b21ed8e48c7a62c822ea2e5 [file] [log] [blame]
pierventre69db90c2022-05-06 23:06:20 +02001#!/usr/bin/env python3
Thomas Vachuskaac9e5242018-07-19 16:15:39 -07002"""
3 Copyright 2018-present Open Networking Foundation
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16"""
17
18POM_HEADER = '''\
19<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
20<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22 <modelVersion>4.0.0</modelVersion>
23 <parent>
24 <groupId>org.onosproject</groupId>
25 <artifactId>onos-base</artifactId>
26 <version>1</version>
27 </parent>'''
28POM_FOOTER = '</project>\n'
29
30ID_BLOCK = '''
31 <groupId>%s</groupId>
32 <artifactId>%s</artifactId>
33 <version>%s</version>
34 <name>%s</name>
35'''
36
37DEPENDENCIES_HEADER = ' <dependencies>\n'
38DEPENDENCIES_FOOTER = ' </dependencies>\n'
39
40DEPENDENCY_BLOCK = ''' <dependency>
41 <groupId>%s</groupId>
42 <artifactId>%s</artifactId>
43 <version>%s</version>
44 </dependency>
45'''
46
47def write(name, msg):
48 if name is not None:
49 with open(name, "w") as file:
50 file.write(msg)
51 else:
pierventre69db90c2022-05-06 23:06:20 +020052 print(msg)
Thomas Vachuskaac9e5242018-07-19 16:15:39 -070053
54
55def write_pom(output, coords, deps):
56 mvn = coords.split(':')
57 lines = POM_HEADER
58 lines += ID_BLOCK % (mvn[1], mvn[2], mvn[3], mvn[2])
59 lines += DEPENDENCIES_HEADER
60
61 for dep in deps:
62 mvn = dep.split(':')
63 lines += DEPENDENCY_BLOCK % (mvn[1], mvn[2], mvn[len(mvn)-1])
64
65 lines += DEPENDENCIES_FOOTER
66 lines += POM_FOOTER
67 write(output, lines)
68
69if __name__ == '__main__':
70 import sys
71
72 if len(sys.argv) < 3:
pierventre69db90c2022-05-06 23:06:20 +020073 print('usage: pom_generator pom.xml maven_coords dep_coords1 dep_coords2 ...')
Thomas Vachuskaac9e5242018-07-19 16:15:39 -070074 sys.exit(1)
75
76 output = sys.argv[1]
77 coords = sys.argv[2]
78 deps = sys.argv[3:]
79
80 write_pom(output, coords, deps)