summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim van der Riet <kpvdr@apache.org>2006-11-22 16:54:30 +0000
committerKim van der Riet <kpvdr@apache.org>2006-11-22 16:54:30 +0000
commit018723f3889e9a1f63585dddba8eecff1d168501 (patch)
treef947fbef936a6fc33e788ab91914ef743a1a1c17
parentf6b81bf19f1e9c5a6299516f030623bd41a73e56 (diff)
downloadqpid-python-018723f3889e9a1f63585dddba8eecff1d168501.tar.gz
Changes to allow gentools to be used from a makefile
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@478234 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-xgentools/build15
-rw-r--r--gentools/src/org/apache/qpid/gentools/Main.java292
2 files changed, 197 insertions, 110 deletions
diff --git a/gentools/build b/gentools/build
new file mode 100755
index 0000000000..614f600152
--- /dev/null
+++ b/gentools/build
@@ -0,0 +1,15 @@
+#!/bin/bash
+cd src
+echo "--------- Building gentools ----------"
+echo "Clearing out old build files..."
+for f in org/apache/qpid/gentools/*.class; do
+ if [ -e $f ]; then
+ rm $f
+ fi
+done
+echo "Compiling..."
+javac org/apache/qpid/gentools/*.java
+echo "Done. Try it out..."
+java org/apache/qpid/gentools/Main
+echo "--------- Building gentools completed ----------"
+cd ..
diff --git a/gentools/src/org/apache/qpid/gentools/Main.java b/gentools/src/org/apache/qpid/gentools/Main.java
index 5993a556f8..52be82b87e 100644
--- a/gentools/src/org/apache/qpid/gentools/Main.java
+++ b/gentools/src/org/apache/qpid/gentools/Main.java
@@ -23,6 +23,7 @@ package org.apache.qpid.gentools;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -34,17 +35,31 @@ import org.xml.sax.SAXException;
public class Main
{
+ private static final String defaultOutDir = ".." + Utils.fileSeparator + "gen";
+ private static final String defaultCppTemplateDir = ".." + Utils.fileSeparator + "templ.cpp";
+ private static final String defaultJavaTemplateDir = ".." + Utils.fileSeparator + "templ.java";
+
private DocumentBuilder docBuilder;
private AmqpVersionSet versionSet;
private Generator generator;
private AmqpConstantSet constants;
private AmqpDomainMap domainMap;
private AmqpModel model;
+
+ private String outDir;
+ private String tmplDir;
+ private boolean javaFlag;
+ private ArrayList<String> xmlFiles;
+ private File[] modelTemplateFiles;
+ private File[] classTemplateFiles;
+ private File[] methodTemplateFiles;
+ private File[] fieldTemplateFiles;
public Main() throws ParserConfigurationException
{
docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
versionSet = new AmqpVersionSet();
+ xmlFiles = new ArrayList<String>();
}
public void run(String[] args)
@@ -57,117 +72,28 @@ public class Main
IllegalAccessException,
InvocationTargetException
{
- File[] modelTemplateFiles = new File[]{};
- File[] classTemplateFiles = new File[]{};
- File[] methodTemplateFiles = new File[]{};
- File[] fieldTemplateFiles = new File[]{};
- String outDir = "out";
-
- if (args[0].compareToIgnoreCase("-c") == 0)
- {
- // *** C++ generation ***
- System.out.println("C++ generation mode.");
- generator = new CppGenerator(versionSet);
- constants = new AmqpConstantSet(generator);
- domainMap = new AmqpDomainMap(generator);
- model = new AmqpModel(generator);
- modelTemplateFiles = new File[]
- {
- new File("templ.cpp/AMQP_ServerOperations.h.tmpl"),
- new File("templ.cpp/AMQP_ClientOperations.h.tmpl"),
- new File("templ.cpp/AMQP_ServerProxy.h.tmpl"),
- new File("templ.cpp/AMQP_ClientProxy.h.tmpl"),
- new File("templ.cpp/AMQP_ServerProxy.cpp.tmpl"),
- new File("templ.cpp/AMQP_ClientProxy.cpp.tmpl"),
- new File("templ.cpp/AMQP_Constants.h.tmpl"),
- new File("templ.cpp/AMQP_MethodVersionMap.h.tmpl"),
- new File("templ.cpp/AMQP_MethodVersionMap.cpp.tmpl")
- };
- methodTemplateFiles = new File[]
- {
- new File("templ.cpp/MethodBodyClass.h.tmpl")
- };
- outDir += ".cpp";
- }
- else if (args[0].compareToIgnoreCase("-j") == 0)
- {
- // *** Java generation ***
- System.out.println("Java generation mode.");
- generator = new JavaGenerator(versionSet);
- constants = new AmqpConstantSet(generator);
- domainMap = new AmqpDomainMap(generator);
- model = new AmqpModel(generator);
- modelTemplateFiles = new File[]
- {
- new File("templ.java/MethodRegistryClass.tmpl"),
- new File("templ.java/AmqpConstantsClass.tmpl")
- };
- classTemplateFiles = new File[]
- {
- new File("templ.java/PropertyContentHeaderClass.tmpl")
- };
- methodTemplateFiles = new File[]
- {
- new File("templ.java/MethodBodyClass.tmpl")
- };
- outDir += ".java";
- }
- else
- {
- System.err.println("ERROR: Required argument specifying language (C++ [-c] or Java [-j]) missing.");
- usage();
- }
+ modelTemplateFiles = new File[]{};
+ classTemplateFiles = new File[]{};
+ methodTemplateFiles = new File[]{};
+ fieldTemplateFiles = new File[]{};
+
+ // 0. Initialize
+ outDir = defaultOutDir;
+ tmplDir = null;
+ javaFlag = true;
+ xmlFiles.clear();
+ processArgs(args);
+ if (javaFlag)
+ prepareJava();
+ else
+ prepareCpp();
if (modelTemplateFiles.length == 0 && classTemplateFiles.length == 0 &&
methodTemplateFiles.length == 0 && fieldTemplateFiles.length == 0)
System.err.println(" WARNING: No template files.");
-
- // 1. Suck in all the XML spec files provided on the command line.
- System.out.println("Analyzing XML Specification files:");
- for (int i=1; i<args.length; i++)
- {
- File f = new File(args[i]);
- if (f.exists())
- {
- // 1a. Initialize dom
- System.out.print(" \"" + args[i] + "\":");
- Document doc = docBuilder.parse(new File(args[i]));
- Node amqpNode = Utils.findChild(doc, Utils.ELEMENT_AMQP);
-
- // 1b. Extract version (major and minor) from the XML file
- int major = Utils.getNamedIntegerAttribute(amqpNode, Utils.ATTRIBUTE_MAJOR);
- int minor = Utils.getNamedIntegerAttribute(amqpNode, Utils.ATTRIBUTE_MINOR);
- AmqpVersion version = new AmqpVersion(major, minor);
- System.out.println(" Found version " + version.toString() + ".");
- versionSet.add(version);
-
- // 1c. Extract domains
- constants.addFromNode(amqpNode, 0, version);
-
- // 1d. Extract domains
- domainMap.addFromNode(amqpNode, 0, version);
-
- // 1e. Extract class/method/field heirarchy
- model.addFromNode(amqpNode, 0, version);
- }
- else
- System.err.println("ERROR: AMQP XML file \"" + args[i] + "\" not found.");
- }
-// *** DEBUG INFO *** Uncomment bits from this block to see lots of stuff....
-// System.out.println();
-// System.out.println("*** Debug output ***");
-// System.out.println();
-// versionSet.print(System.out, 0, 2);
-// System.out.println();
-// constants.print(System.out, 0, 2);
-// System.out.println();
-// domainMap.print(System.out, 0, 2);
-// System.out.println();
-// model.print(System.out, 0, 2);
-// System.out.println();
-// System.out.println("*** End debug output ***");
-// System.out.println();
+ // 1. Suck in all the XML spec files provided on the command line
+ analyzeXML();
// 2. Load up all templates
generator.initializeTemplates(modelTemplateFiles, classTemplateFiles,
@@ -180,6 +106,148 @@ public class Main
System.out.println("Done.");
}
+ private void processArgs(String[] args)
+ {
+ // Crude but simple...
+ for (int i=0; i<args.length; i++)
+ {
+ String arg = args[i];
+ if (arg.charAt(0) == '-')
+ {
+ switch (arg.charAt(1))
+ {
+ case 'c':
+ case 'C':
+ javaFlag = false;
+ break;
+ case 'j':
+ case 'J':
+ javaFlag = true;
+ break;
+ case 'o':
+ case 'O':
+ if (++i < args.length)
+ {
+ outDir = args[i];
+ }
+ break;
+ case 't':
+ case 'T':
+ if (++i < args.length)
+ {
+ tmplDir = args[i];
+ }
+ break;
+ }
+ }
+ else
+ {
+ xmlFiles.add(args[i]);
+ }
+ }
+ }
+
+ private void prepareJava()
+ {
+ if (tmplDir == null)
+ tmplDir = defaultJavaTemplateDir;
+ System.out.println("Java generation mode.");
+ generator = new JavaGenerator(versionSet);
+ constants = new AmqpConstantSet(generator);
+ domainMap = new AmqpDomainMap(generator);
+ model = new AmqpModel(generator);
+ modelTemplateFiles = new File[]
+ {
+ new File(tmplDir + Utils.fileSeparator + "MethodRegistryClass.tmpl"),
+ new File(tmplDir + Utils.fileSeparator + "AmqpConstantsClass.tmpl")
+ };
+ classTemplateFiles = new File[]
+ {
+ new File(tmplDir + Utils.fileSeparator + "PropertyContentHeaderClass.tmpl")
+ };
+ methodTemplateFiles = new File[]
+ {
+ new File(tmplDir + Utils.fileSeparator + "MethodBodyClass.tmpl")
+ };
+ }
+
+ private void prepareCpp()
+ {
+ if (tmplDir == null)
+ tmplDir = defaultCppTemplateDir;
+ System.out.println("C++ generation mode.");
+ generator = new CppGenerator(versionSet);
+ constants = new AmqpConstantSet(generator);
+ domainMap = new AmqpDomainMap(generator);
+ model = new AmqpModel(generator);
+ modelTemplateFiles = new File[]
+ {
+ new File(tmplDir + Utils.fileSeparator + "AMQP_ServerOperations.h.tmpl"),
+ new File(tmplDir + Utils.fileSeparator + "AMQP_ClientOperations.h.tmpl"),
+ new File(tmplDir + Utils.fileSeparator + "AMQP_ServerProxy.h.tmpl"),
+ new File(tmplDir + Utils.fileSeparator + "AMQP_ClientProxy.h.tmpl"),
+ new File(tmplDir + Utils.fileSeparator + "AMQP_ServerProxy.cpp.tmpl"),
+ new File(tmplDir + Utils.fileSeparator + "AMQP_ClientProxy.cpp.tmpl"),
+ new File(tmplDir + Utils.fileSeparator + "AMQP_Constants.h.tmpl"),
+ new File(tmplDir + Utils.fileSeparator + "AMQP_MethodVersionMap.h.tmpl"),
+ new File(tmplDir + Utils.fileSeparator + "AMQP_MethodVersionMap.cpp.tmpl")
+ };
+ methodTemplateFiles = new File[]
+ {
+ new File(tmplDir + Utils.fileSeparator + "MethodBodyClass.h.tmpl")
+ };
+ }
+
+ private void analyzeXML()
+ throws IOException, SAXException, AmqpParseException, AmqpTypeMappingException
+ {
+ System.out.println("XML files: " + xmlFiles);
+ for (int i=0; i<xmlFiles.size(); i++)
+ {
+ String filename = xmlFiles.get(i);
+ File f = new File(filename);
+ if (f.exists())
+ {
+ // 1a. Initialize dom
+ System.out.print(" \"" + filename + "\":");
+ Document doc = docBuilder.parse(new File(filename));
+ Node amqpNode = Utils.findChild(doc, Utils.ELEMENT_AMQP);
+
+ // 1b. Extract version (major and minor) from the XML file
+ int major = Utils.getNamedIntegerAttribute(amqpNode, Utils.ATTRIBUTE_MAJOR);
+ int minor = Utils.getNamedIntegerAttribute(amqpNode, Utils.ATTRIBUTE_MINOR);
+ AmqpVersion version = new AmqpVersion(major, minor);
+ System.out.println(" Found version " + version.toString() + ".");
+ versionSet.add(version);
+
+ // 1c. Extract domains
+ constants.addFromNode(amqpNode, 0, version);
+
+ // 1d. Extract domains
+ domainMap.addFromNode(amqpNode, 0, version);
+
+ // 1e. Extract class/method/field heirarchy
+ model.addFromNode(amqpNode, 0, version);
+ }
+ else
+ System.err.println("ERROR: AMQP XML file \"" + filename + "\" not found.");
+ }
+// *** DEBUG INFO *** Uncomment bits from this block to see lots of stuff....
+// System.out.println();
+// System.out.println("*** Debug output ***");
+// System.out.println();
+// versionSet.print(System.out, 0, 2);
+// System.out.println();
+// constants.print(System.out, 0, 2);
+// System.out.println();
+// domainMap.print(System.out, 0, 2);
+// System.out.println();
+// model.print(System.out, 0, 2);
+// System.out.println();
+// System.out.println("*** End debug output ***");
+// System.out.println();
+ }
+
public static void main(String[] args)
{
if (args.length < 2)
@@ -199,10 +267,14 @@ public class Main
public static void usage()
{
System.out.println("AMQP XML generator v.0.0");
- System.out.println("Usage: Main -c|-j filename [filename ...]");
- System.out.println(" where -c flags C++ generation.");
- System.out.println(" -j flags Java generation.");
- System.out.println(" filename is a space-separated list of files to be parsed.");
+ System.out.println("Usage: Main -c|-j [-o outDir] [-t tmplDir] XMLfile [XMLfile ...]");
+ System.out.println(" where -c: Generate C++.");
+ System.out.println(" -j: Generate Java.");
+ System.out.println(" -o outDir: Use outDir as the output dir (default=\"" + defaultOutDir + "\").");
+ System.out.println(" -t tmplDir: Find templates in tmplDir.");
+ System.out.println(" Defaults: \"" + defaultCppTemplateDir + "\" for C++;");
+ System.out.println(" \"" + defaultJavaTemplateDir + "\" for java.");
+ System.out.println(" XMLfile is a space-separated list of AMQP XML files to be parsed.");
System.exit(0);
}