#!/usr/bin/env python """ Copyright 2018-present Open Networking Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ POM_HEADER = '''\ 4.0.0 org.onosproject onos-base 1 ''' POM_FOOTER = '\n' ID_BLOCK = ''' %s %s %s %s ''' DEPENDENCIES_HEADER = ' \n' DEPENDENCIES_FOOTER = ' \n' DEPENDENCY_BLOCK = ''' %s %s %s ''' def write(name, msg): if name is not None: with open(name, "w") as file: file.write(msg) else: print msg def write_pom(output, coords, deps): mvn = coords.split(':') lines = POM_HEADER lines += ID_BLOCK % (mvn[1], mvn[2], mvn[3], mvn[2]) lines += DEPENDENCIES_HEADER for dep in deps: mvn = dep.split(':') lines += DEPENDENCY_BLOCK % (mvn[1], mvn[2], mvn[len(mvn)-1]) lines += DEPENDENCIES_FOOTER lines += POM_FOOTER write(output, lines) if __name__ == '__main__': import sys if len(sys.argv) < 3: print 'usage: pom_generator pom.xml maven_coords dep_coords1 dep_coords2 ...' sys.exit(1) output = sys.argv[1] coords = sys.argv[2] deps = sys.argv[3:] write_pom(output, coords, deps)