1/*
2 *      Copyright (C) 2005-2013 Team XBMC
3 *      http://xbmc.org
4 *
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.
9 *
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.
14 *
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/>.
18 *
19 */
20
21import groovy.util.Node
22import groovy.text.SimpleTemplateEngine
23import groovy.xml.XmlUtil
24
25import Helper
26
27def usage()
28{
29   println "java/groovy -cp [...] " + getClass().getName() + " [-verbose] moduleSpecFile templateFile outputFile [doxygenoutputdir]";
30   System.exit 1
31}
32
33def verbose = false;
34
35newargs = []
36
37println args
38
39args.each {
40   if (it == '-verbose' || it == '--verbose' || it == '-v')
41      verbose = true
42   else
43      newargs.add(it)
44}
45
46if (newargs.size() != 3 && newargs.size() != 4)
47  usage()
48
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
51if (newargs.size() > 3)
52  Helper.setDoxygenXmlDir(new File(newargs[3]))
53
54File moduleSpec = new File(newargs[0])
55assert moduleSpec.exists() && moduleSpec.isFile(), 'Cannot locate the spec file "' + moduleSpec.getCanonicalPath() + '."'
56
57File templateFile = new File(newargs[1])
58assert templateFile.exists() && templateFile.isFile(), 'Cannot locate the template file "' + templateFile.getCanonicalPath() + '."'
59
60spec = [ 'module' : Helper.transformSwigXml(new XmlParser().parse(moduleSpec)), 'templateFile' : templateFile ]
61
62if (verbose)
63   println XmlUtil.serialize(spec['module'])
64
65te = new SimpleTemplateEngine()
66println 'Processing "' + templateFile + '" using the module specification for module "' + moduleSpec + '"'
67if (verbose) te.setVerbose(true)
68template = te.createTemplate(templateFile).make(spec)
69String output = template.toString()
70if (verbose) println output
71
72println 'writing'
73new File(newargs[2]).write output
74
75