Merge pull request #25820 from hribz/master
[xbmc.git] / tools / codegenerator / Generator.groovy
blob79cfe4f5fbfa5f2f70b6666c4dd666b7618a7f11
1 /*
2 * Copyright (C) 2005-2013 Team XBMC
3 * http://xbmc.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 import groovy.text.SimpleTemplateEngine
22 import groovy.xml.XmlParser
23 import groovy.xml.XmlUtil
25 import Helper
27 def usage()
29 println "java/groovy -cp [...] " + getClass().getName() + " [-verbose] moduleSpecFile templateFile outputFile [doxygenoutputdir]";
30 System.exit 1
33 def verbose = false;
35 newargs = []
37 println args
39 args.each {
40 if (it == '-verbose' || it == '--verbose' || it == '-v')
41 verbose = true
42 else
43 newargs.add(it)
46 if (newargs.size() != 3 && newargs.size() != 4)
47 usage()
49 // set the doxygen xml directory on the Helper assuming the output file will be placed
50 // in the same place the doxygen subdirectory is placed
51 if (newargs.size() > 3)
52 Helper.setDoxygenXmlDir(new File(newargs[3]))
54 File moduleSpec = new File(newargs[0])
55 assert moduleSpec.exists() && moduleSpec.isFile(), 'Cannot locate the spec file "' + moduleSpec.getCanonicalPath() + '."'
57 File templateFile = new File(newargs[1])
58 assert templateFile.exists() && templateFile.isFile(), 'Cannot locate the template file "' + templateFile.getCanonicalPath() + '."'
60 spec = [ 'module' : Helper.transformSwigXml(new XmlParser().parse(moduleSpec)), 'templateFile' : templateFile ]
62 if (verbose)
63 println XmlUtil.serialize(spec['module'])
65 te = new SimpleTemplateEngine()
66 println 'Processing "' + templateFile + '" using the module specification for module "' + moduleSpec + '"'
67 if (verbose) te.setVerbose(true)
68 template = te.createTemplate(templateFile).make(spec)
69 String output = template.toString()
70 if (verbose) println output
72 println 'writing'
73 new File(newargs[2]).write output