summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2008-03-03 14:56:50 -0800
committerMark Spruiell <mes@zeroc.com>2008-03-03 14:56:50 -0800
commit52ad04cf152145a1ba62f1816233e307bd05e1ba (patch)
tree0975ef8476c22e74c0414a229dac7aeaad5b9ae5 /java/src
parentNew icestormmigrate exe (diff)
downloadice-52ad04cf152145a1ba62f1816233e307bd05e1ba.tar.bz2
ice-52ad04cf152145a1ba62f1816233e307bd05e1ba.tar.xz
ice-52ad04cf152145a1ba62f1816233e307bd05e1ba.zip
bug 2724, 2725, 2744 - Java fixes
Diffstat (limited to 'java/src')
-rw-r--r--java/src/ant/Slice2FreezeJTask.java663
-rw-r--r--java/src/ant/Slice2JavaTask.java387
-rw-r--r--java/src/ant/SliceDefine.java40
-rw-r--r--java/src/ant/SliceMeta.java25
-rw-r--r--java/src/ant/SliceTask.java513
5 files changed, 1628 insertions, 0 deletions
diff --git a/java/src/ant/Slice2FreezeJTask.java b/java/src/ant/Slice2FreezeJTask.java
new file mode 100644
index 00000000000..92509e79814
--- /dev/null
+++ b/java/src/ant/Slice2FreezeJTask.java
@@ -0,0 +1,663 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+//package Ice.Ant;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.taskdefs.ExecTask;
+import org.apache.tools.ant.types.Commandline.Argument;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+/**
+ * An ant task for slice2freezej. This task extends the abstract
+ * SliceTask class which takes care of attributes common to all slice
+ * translators (see SliceTask.java for details on these attributes).
+ *
+ * Attributes:
+ *
+ * Nested elements:
+ *
+ * define - defines a preprocessor symbol
+ * dict - contains the NAME, KEY TYPE, and VALUE TYPE of a Freeze map.
+ * index - contains the NAME, CLASS TYPE, MEMBER NAME and optional
+ * case sensitivity of a Freeze Evictor index.
+ * dictindex - contains the NAME and optional member name and case
+ * sensitivity of a Freeze Map index.
+ *
+ * Example:
+ *
+ * <project ...>
+ * <taskdef name="slice2freezej" classname="Slice2FreezeJTask" />
+ * <property name="slice.dir" value="../include/slice"/>
+ * <target name="generate">
+ * <mkdir dir="tags" />
+ * <slice2freezej tagdir="tags" outputdir="out" output="CharIntMap">
+ * <define name="SYMBOL" value="VALUE"/>
+ * <includepath>
+ * <pathelement path="${slice.dir}" />
+ * </includepath>
+ * <fileset dir="${slice.dir}">
+ * <include name="*.ice" />
+ * </fileset>
+ * <dict name="CharIntMap" key="char" value="int"/>
+ * <index name="NameIndex" type="Foo" member="name" casesensitive="false"/>
+ * </slice2freezej>
+ * </target>
+ * </project>
+ *
+ * The <taskdef> element installs the slice2freezej task.
+ */
+public class Slice2FreezeJTask extends SliceTask
+{
+ public
+ Slice2FreezeJTask()
+ {
+ }
+
+ public void
+ setTranslator(File prog)
+ {
+ _translator = prog;
+ }
+
+ public Dict
+ createDict()
+ {
+ Dict d = new Dict();
+ _dicts.add(d);
+ return d;
+ }
+
+ public Index
+ createIndex()
+ {
+ Index i = new Index();
+ _indices.add(i);
+ return i;
+ }
+
+ public Dictindex
+ createDictindex()
+ {
+ Dictindex i = new Dictindex();
+ _dictIndices.add(i);
+ return i;
+ }
+
+ public void
+ execute()
+ throws BuildException
+ {
+ if(_dicts.isEmpty() && _indices.isEmpty())
+ {
+ throw new BuildException("No dictionary or index specified");
+ }
+
+ //
+ // Read the set of dependencies for this task.
+ //
+ java.util.HashMap dependencies = readDependencies();
+
+ //
+ // Check if the set of slice files changed. If it changed we
+ // need to rebuild all the dictionnaries and indices.
+ //
+ boolean build = false;
+ java.util.List sliceFiles = new java.util.LinkedList();
+
+ java.util.Iterator p = _fileSets.iterator();
+ while(p.hasNext())
+ {
+ FileSet fileset = (FileSet)p.next();
+
+ DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
+ String[] files = scanner.getIncludedFiles();
+
+ for(int i = 0; i < files.length; i++)
+ {
+ File slice = new File(fileset.getDir(getProject()), files[i]);
+ sliceFiles.add(slice);
+
+ if(!build)
+ {
+ //
+ // The dictionnaries need to be re-created since
+ // on dependency changed.
+ //
+ SliceDependency depend = (SliceDependency)dependencies.get(getSliceTargetKey(slice.toString()));
+ if(depend == null || !depend.isUpToDate())
+ {
+ build = true;
+ }
+ }
+ }
+ }
+
+ if(!build)
+ {
+ //
+ // Check that each dictionary has been built at least
+ // once.
+ //
+ p = _dicts.iterator();
+ while(p.hasNext())
+ {
+ SliceDependency depend = (SliceDependency)dependencies.get(getDictTargetKey((Dict)p.next()));
+ if(depend == null)
+ {
+ build = true;
+ break;
+ }
+ }
+
+ //
+ // Likewise for indices
+ //
+ p = _indices.iterator();
+ while(p.hasNext())
+ {
+ SliceDependency depend = (SliceDependency)dependencies.get(getIndexTargetKey((Index)p.next()));
+ if(depend == null)
+ {
+ build = true;
+ break;
+ }
+ }
+ }
+
+ //
+ // Add the --dict options.
+ //
+ p = _dicts.iterator();
+ StringBuffer dictString = new StringBuffer();
+ while(p.hasNext())
+ {
+ Dict d = (Dict)p.next();
+
+ dictString.append(" --dict ");
+ dictString.append(d.getName() + "," + d.getKey() + "," + d.getValue());
+ }
+
+ //
+ // Add the --dict-index options.
+ //
+ p = _dictIndices.iterator();
+ StringBuffer dictIndexString = new StringBuffer();
+ while(p.hasNext())
+ {
+ Dictindex d = (Dictindex)p.next();
+
+ dictIndexString.append(" --dict-index ");
+ dictIndexString.append(d.getName());
+ if(d.getMember() != null)
+ {
+ dictIndexString.append("," + d.getMember());
+ }
+ if(d.getCasesensitive() == false)
+ {
+ dictIndexString.append("," + "case-insensitive");
+ }
+ }
+
+ //
+ // Add the --index options.
+ //
+ p = _indices.iterator();
+ StringBuffer indexString = new StringBuffer();
+ while(p.hasNext())
+ {
+ Index i = (Index)p.next();
+
+ indexString.append(" --index ");
+ indexString.append(i.getName() + "," + i.getType() + "," + i.getMember());
+ if(i.getCasesensitive() == false)
+ {
+ indexString.append("," + "case-insensitive");
+ }
+ }
+
+ if(!build)
+ {
+ log("skipping" + dictString + indexString);
+ return;
+ }
+
+ //
+ // Run the translator
+ //
+ StringBuffer cmd = new StringBuffer();
+
+ //
+ // Add --ice
+ //
+ if(_ice)
+ {
+ cmd.append(" --ice");
+ }
+
+ //
+ // Add --output-dir
+ //
+ if(_outputDir != null)
+ {
+ cmd.append(" --output-dir ");
+ cmd.append(_outputDirString);
+ }
+
+ //
+ // Add --case-sensitive
+ //
+ if(_caseSensitive)
+ {
+ cmd.append(" --case-sensitive");
+ }
+
+ //
+ // Add include directives
+ //
+ if(_includePath != null)
+ {
+ String[] dirs = _includePath.list();
+ for(int i = 0; i < dirs.length; i++)
+ {
+ cmd.append(" -I");
+ if(dirs[i].indexOf(' ') != -1)
+ {
+ cmd.append('"' + dirs[i] + '"');
+ }
+ else
+ {
+ cmd.append(dirs[i]);
+ }
+ }
+ }
+
+ //
+ // Add defines
+ //
+ if(!_defines.isEmpty())
+ {
+ java.util.Iterator i = _defines.iterator();
+ while(i.hasNext())
+ {
+ SliceDefine define = (SliceDefine)i.next();
+ cmd.append(" -D");
+ cmd.append(define.getName());
+ String value = define.getValue();
+ if(value != null)
+ {
+ cmd.append("=");
+ cmd.append(value);
+ }
+ }
+ }
+
+ //
+ // Add the --dict options.
+ //
+ cmd.append(dictString);
+
+ //
+ // Add the --dict-index options.
+ //
+ cmd.append(dictIndexString);
+
+ //
+ // Add the --index options.
+ //
+ cmd.append(indexString);
+
+ //
+ // Add the --meta options.
+ //
+ if(!_meta.isEmpty())
+ {
+ java.util.Iterator i = _meta.iterator();
+ while(i.hasNext())
+ {
+ SliceMeta m = (SliceMeta)i.next();
+ cmd.append(" --meta " + m.getValue());
+ }
+ }
+
+ //
+ // Add the slice files.
+ //
+ p = sliceFiles.iterator();
+ while(p.hasNext())
+ {
+ File f = (File)p.next();
+ cmd.append(" ");
+ String s = f.toString();
+ if(s.indexOf(' ') != -1)
+ {
+ cmd.append('"' + s + '"');
+ }
+ else
+ {
+ cmd.append(s);
+ }
+ }
+
+ String translator;
+ if(_translator == null)
+ {
+ translator = getDefaultTranslator("slice2freezej");
+ }
+ else
+ {
+ translator = _translator.toString();
+ }
+
+ //
+ // Execute.
+ //
+ log(translator + " " + cmd);
+ ExecTask task = (ExecTask)getProject().createTask("exec");
+ addLdLibraryPath(task);
+ task.setFailonerror(true);
+ Argument arg = task.createArg();
+ arg.setLine(cmd.toString());
+ task.setExecutable(translator);
+ task.execute();
+
+ //
+ // Update the dependencies.
+ //
+ if(!sliceFiles.isEmpty())
+ {
+ cmd = new StringBuffer("--depend");
+
+ //
+ // Add include directives
+ //
+ if(_includePath != null)
+ {
+ String[] dirs = _includePath.list();
+ for(int i = 0; i < dirs.length; i++)
+ {
+ cmd.append(" -I");
+ if(dirs[i].indexOf(' ') != -1)
+ {
+ cmd.append('"' + dirs[i] + '"');
+ }
+ else
+ {
+ cmd.append(dirs[i]);
+ }
+ }
+ }
+
+ //
+ // Add the --dict options.
+ //
+ cmd.append(dictString);
+
+ //
+ // Add the --dict-index options.
+ //
+ cmd.append(dictIndexString);
+
+ //
+ // Add the --index options.
+ //
+ cmd.append(indexString);
+
+ //
+ // Add the slice files.
+ //
+ p = sliceFiles.iterator();
+ while(p.hasNext())
+ {
+ File f = (File)p.next();
+ cmd.append(" ");
+ String s = f.toString();
+ if(s.indexOf(' ') != -1)
+ {
+ cmd.append('"' + s + '"');
+ }
+ else
+ {
+ cmd.append(s);
+ }
+ }
+
+
+ //
+ // It's not possible anymore to re-use the same output property since Ant 1.5.x. so we use a
+ // unique property name here. Perhaps we should output the dependencies to a file instead.
+ //
+ final String outputProperty = "slice2freezej.depend." + System.currentTimeMillis();
+
+ task = (ExecTask)getProject().createTask("exec");
+ addLdLibraryPath(task);
+ task.setFailonerror(true);
+ arg = task.createArg();
+ arg.setLine(cmd.toString());
+ task.setExecutable(translator);
+ task.setOutputproperty(outputProperty);
+ task.execute();
+
+ //
+ // Update dependency file.
+ //
+ java.util.List newDependencies = parseDependencies(getProject().getProperty(outputProperty));
+ p = newDependencies.iterator();
+ while(p.hasNext())
+ {
+ SliceDependency dep = (SliceDependency)p.next();
+ dependencies.put(getSliceTargetKey(dep._dependencies[0]), dep);
+ }
+ }
+
+ p = _dicts.iterator();
+ while(p.hasNext())
+ {
+ dependencies.put(getDictTargetKey((Dict)p.next()), new SliceDependency());
+ }
+
+ p = _indices.iterator();
+ while(p.hasNext())
+ {
+ dependencies.put(getIndexTargetKey((Index)p.next()), new SliceDependency());
+ }
+
+ writeDependencies(dependencies);
+ }
+
+ private String
+ getSliceTargetKey(String slice)
+ {
+ //
+ // Since the dependency file can be shared by several slice
+ // tasks we need to make sure that each dependency has a
+ // unique key. We use the name of the task, the output
+ // directory, the first dictionary or index name and the name of the
+ // slice file to be compiled.
+ //
+ String name;
+ if(_dicts.size() > 0)
+ {
+ name = ((Dict)_dicts.get(0)).getName();
+ }
+ else
+ {
+ name = ((Index)_indices.get(0)).getName();
+ }
+ return "slice2freezej " + _outputDir.toString() + name + slice;
+ }
+
+ private String
+ getDictTargetKey(Dict d)
+ {
+ return "slice2freezej " + _outputDir.toString() + d.getName();
+ }
+
+ private String
+ getIndexTargetKey(Index i)
+ {
+ return "slice2freezej " + _outputDir.toString() + i.getName();
+ }
+
+ private File _translator = null;
+
+ public class Dict
+ {
+ private String _name;
+ private String _key;
+ private String _value;
+
+ public void
+ setName(String name)
+ {
+ _name = name;
+ }
+
+ public String
+ getName()
+ {
+ return _name;
+ }
+
+ public void
+ setKey(String key)
+ {
+ _key = key;
+ }
+
+ public String
+ getKey()
+ {
+ return _key;
+ }
+
+ public void
+ setValue(String value)
+ {
+ _value = value;
+ }
+
+ public String
+ getValue()
+ {
+ return _value;
+ }
+ }
+
+ public class Dictindex
+ {
+ private String _name;
+ private String _member;
+ private boolean _caseSensitive = true;
+
+ public void
+ setName(String name)
+ {
+ _name = name;
+ }
+
+ public String
+ getName()
+ {
+ return _name;
+ }
+
+ public void
+ setMember(String member)
+ {
+ _member = member;
+ }
+
+ public String
+ getMember()
+ {
+ return _member;
+ }
+
+ public void
+ setCasesensitive(boolean caseSensitive)
+ {
+ _caseSensitive = caseSensitive;
+ }
+
+ public boolean
+ getCasesensitive()
+ {
+ return _caseSensitive;
+ }
+ }
+
+
+ public class Index
+ {
+ private String _name;
+ private String _type;
+ private String _member;
+ private boolean _caseSensitive = true;
+
+ public void
+ setName(String name)
+ {
+ _name = name;
+ }
+
+ public String
+ getName()
+ {
+ return _name;
+ }
+
+ public void
+ setType(String type)
+ {
+ _type = type;
+ }
+
+ public String
+ getType()
+ {
+ return _type;
+ }
+
+ public void
+ setMember(String member)
+ {
+ _member = member;
+ }
+
+ public String
+ getMember()
+ {
+ return _member;
+ }
+
+ public void
+ setCasesensitive(boolean caseSensitive)
+ {
+ _caseSensitive = caseSensitive;
+ }
+
+ public boolean
+ getCasesensitive()
+ {
+ return _caseSensitive;
+ }
+ }
+
+ private java.util.List _dicts = new java.util.LinkedList();
+ private java.util.List _dictIndices = new java.util.LinkedList();
+ private java.util.List _indices = new java.util.LinkedList();
+}
diff --git a/java/src/ant/Slice2JavaTask.java b/java/src/ant/Slice2JavaTask.java
new file mode 100644
index 00000000000..34dc7e4ca8a
--- /dev/null
+++ b/java/src/ant/Slice2JavaTask.java
@@ -0,0 +1,387 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+//package Ice.Ant;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.taskdefs.ExecTask;
+import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.taskdefs.PumpStreamHandler;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.Commandline.Argument;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.StringReader;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+
+/**
+ * An ant task for slice2java. This task extends the abstract
+ * SliceTask class which takes care of attributes common to all slice
+ * translators (see SliceTask.java for details on these attributes).
+ *
+ * Attributes specific to slice2java:
+ *
+ * translator - The pathname of the translator (default: "slice2java").
+ * tie - The value for the --tie translator option.
+ * checksum - The value for the --checksum translator option.
+ * stream - The value for the --stream translator option.
+ *
+ * Example:
+ *
+ * <project ...>
+ * <taskdef name="slice2java" classname="Slice2JavaTask" />
+ * <property name="slice.dir" value="../include/slice"/>
+ * <target name="generate">
+ * <mkdir dir="tags" />
+ * <slice2java tagdir="tags" outputdir="out">
+ * <define name="SYMBOL" value="VALUE"/>
+ * <includepath>
+ * <pathelement path="${slice.dir}" />
+ * </includepath>
+ * <fileset dir="${slice.dir}">
+ * <include name="*.ice" />
+ * </fileset>
+ * </slice2java>
+ * </target>
+ * </project>
+ *
+ * The <taskdef> element installs the slice2java task.
+ */
+public class Slice2JavaTask extends SliceTask
+{
+ public
+ Slice2JavaTask()
+ {
+ _translator = null;
+ _tie = false;
+ _checksum = null;
+ }
+
+ public void
+ setTranslator(File prog)
+ {
+ _translator = prog;
+ }
+
+ public void
+ setTie(boolean tie)
+ {
+ _tie = tie;
+ }
+
+ public void
+ setChecksum(String checksum)
+ {
+ _checksum = checksum;
+ }
+
+ public void
+ setStream(boolean stream)
+ {
+ _stream = stream;
+ }
+
+ public void
+ execute()
+ throws BuildException
+ {
+ if(_fileSets.isEmpty())
+ {
+ throw new BuildException("No fileset specified");
+ }
+
+ //
+ // Read the set of dependencies for this task.
+ //
+ java.util.HashMap dependencies = readDependencies();
+
+ //
+ // Compose a list of the files that need to be translated. A
+ // file needs to translated if we can't find a dependency in
+ // the dependency table or if its dependency is not up-to-date
+ // anymore (the slice file changed since the dependency was
+ // last updated or a slice file it depends on changed).
+ //
+ java.util.Vector buildList = new java.util.Vector();
+ java.util.Iterator p = _fileSets.iterator();
+ while(p.hasNext())
+ {
+ FileSet fileset = (FileSet)p.next();
+
+ DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
+ scanner.scan();
+ String[] files = scanner.getIncludedFiles();
+ for(int i = 0; i < files.length; i++)
+ {
+ File slice = new File(fileset.getDir(getProject()), files[i]);
+
+ SliceDependency depend = (SliceDependency)dependencies.get(getTargetKey(slice.toString()));
+ if(depend == null || !depend.isUpToDate())
+ {
+ buildList.addElement(slice);
+ }
+ else
+ {
+ log("skipping " + files[i]);
+ }
+ }
+ }
+
+ //
+ // Run the translator
+ //
+ if(!buildList.isEmpty())
+ {
+ String translator;
+ if(_translator == null)
+ {
+ translator = getDefaultTranslator("slice2java");
+ }
+ else
+ {
+ translator = _translator.toString();
+ }
+
+ StringBuffer cmd = new StringBuffer();
+
+ //
+ // Add --output-dir
+ //
+ if(_outputDir != null)
+ {
+ cmd.append(" --output-dir ");
+ cmd.append(_outputDirString);
+ }
+
+ //
+ // Add include directives
+ //
+ if(_includePath != null)
+ {
+ String[] dirs = _includePath.list();
+ for(int i = 0; i < dirs.length; i++)
+ {
+ cmd.append(" -I");
+ if(dirs[i].indexOf(' ') != -1)
+ {
+ cmd.append('"' + dirs[i] + '"');
+ }
+ else
+ {
+ cmd.append(dirs[i]);
+ }
+ }
+ }
+
+ //
+ // Add defines
+ //
+ if(!_defines.isEmpty())
+ {
+ java.util.Iterator i = _defines.iterator();
+ while(i.hasNext())
+ {
+ SliceDefine define = (SliceDefine)i.next();
+ cmd.append(" -D");
+ cmd.append(define.getName());
+ String value = define.getValue();
+ if(value != null)
+ {
+ cmd.append("=");
+ cmd.append(value);
+ }
+ }
+ }
+
+ //
+ // Add --tie
+ //
+ if(_tie)
+ {
+ cmd.append(" --tie");
+ }
+
+ //
+ // Add --checksum
+ //
+ if(_checksum != null && _checksum.length() > 0)
+ {
+ cmd.append(" --checksum " + _checksum);
+ }
+
+ //
+ // Add --stream
+ //
+ if(_stream)
+ {
+ cmd.append(" --stream");
+ }
+
+ //
+ // Add --meta
+ //
+ if(!_meta.isEmpty())
+ {
+ java.util.Iterator i = _meta.iterator();
+ while(i.hasNext())
+ {
+ SliceMeta m = (SliceMeta)i.next();
+ cmd.append(" --meta " + m.getValue());
+ }
+ }
+
+ //
+ // Add --ice
+ //
+ if(_ice)
+ {
+ cmd.append(" --ice");
+ }
+
+ //
+ // Add --case-sensitive
+ //
+ if(_caseSensitive)
+ {
+ cmd.append(" --case-sensitive");
+ }
+
+ //
+ // Add files to be translated
+ //
+ for(int i = 0; i < buildList.size(); i++)
+ {
+ File f = (File)buildList.elementAt(i);
+ cmd.append(" ");
+ String s = f.toString();
+ if(s.indexOf(' ') != -1)
+ {
+ cmd.append('"' + s + '"');
+ }
+ else
+ {
+ cmd.append(s);
+ }
+ }
+
+ //
+ // Execute
+ //
+ log(translator + " " + cmd);
+ ExecTask task = (ExecTask)getProject().createTask("exec");
+ addLdLibraryPath(task);
+ task.setFailonerror(true);
+ Argument arg = task.createArg();
+ arg.setLine(cmd.toString());
+ task.setExecutable(translator);
+ task.execute();
+
+ //
+ // Update the dependencies.
+ //
+ cmd = new StringBuffer("--depend");
+
+ //
+ // Add include directives
+ //
+ if(_includePath != null)
+ {
+ String[] dirs = _includePath.list();
+ for(int i = 0; i < dirs.length; i++)
+ {
+ cmd.append(" -I");
+ if(dirs[i].indexOf(' ') != -1)
+ {
+ cmd.append('"' + dirs[i] + '"');
+ }
+ else
+ {
+ cmd.append(dirs[i]);
+ }
+ }
+ }
+
+ //
+ // Add files for which we need to check dependencies.
+ //
+ for(int i = 0; i < buildList.size(); i++)
+ {
+ File f = (File)buildList.elementAt(i);
+ cmd.append(" ");
+ String s = f.toString();
+ if(s.indexOf(' ') != -1)
+ {
+ cmd.append('"' + s + '"');
+ }
+ else
+ {
+ cmd.append(s);
+ }
+ }
+
+ //
+ // It's not possible anymore to re-use the same output property since Ant 1.5.x. so we use a
+ // unique property name here. Perhaps we should output the dependencies to a file instead.
+ //
+ final String outputProperty = "slice2java.depend." + System.currentTimeMillis();
+
+ task = (ExecTask)getProject().createTask("exec");
+ addLdLibraryPath(task);
+ task.setFailonerror(true);
+ arg = task.createArg();
+ arg.setLine(cmd.toString());
+ task.setExecutable(translator);
+ task.setOutputproperty(outputProperty);
+ task.execute();
+
+ //
+ // Update dependency file.
+ //
+ java.util.List newDependencies = parseDependencies(getProject().getProperty(outputProperty));
+ p = newDependencies.iterator();
+ while(p.hasNext())
+ {
+ SliceDependency dep = (SliceDependency)p.next();
+ dependencies.put(getTargetKey(dep._dependencies[0]), dep);
+ }
+
+ writeDependencies(dependencies);
+ }
+ }
+
+ private String
+ getTargetKey(String slice)
+ {
+ //
+ // Since the dependency file can be shared by several slice
+ // tasks we need to make sure that each dependency has a
+ // unique key. We use the name of the task, the output
+ // directory and the name of the slice file to be compiled.
+ //
+ // If there's two slice2java tasks using the same dependency
+ // file, with the same output dir and which compiles the same
+ // slice file they'll use the same dependency.
+ //
+ return "slice2java " + _outputDir.toString() + " " + slice;
+ }
+
+ private File _translator;
+ private boolean _tie;
+ private String _checksum;
+ private boolean _stream;
+}
diff --git a/java/src/ant/SliceDefine.java b/java/src/ant/SliceDefine.java
new file mode 100644
index 00000000000..e9e423da46a
--- /dev/null
+++ b/java/src/ant/SliceDefine.java
@@ -0,0 +1,40 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+//package Ice.Ant;
+
+public class SliceDefine
+{
+ public void
+ setName(String name)
+ {
+ _name = name;
+ }
+
+ public String
+ getName()
+ {
+ return _name;
+ }
+
+ public void
+ setValue(String value)
+ {
+ _value = value;
+ }
+
+ public String
+ getValue()
+ {
+ return _value;
+ }
+
+ private String _name;
+ private String _value;
+}
diff --git a/java/src/ant/SliceMeta.java b/java/src/ant/SliceMeta.java
new file mode 100644
index 00000000000..878dad75218
--- /dev/null
+++ b/java/src/ant/SliceMeta.java
@@ -0,0 +1,25 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+public class SliceMeta
+{
+ public void
+ setValue(String value)
+ {
+ _value = value;
+ }
+
+ public String
+ getValue()
+ {
+ return _value;
+ }
+
+ private String _value;
+}
diff --git a/java/src/ant/SliceTask.java b/java/src/ant/SliceTask.java
new file mode 100644
index 00000000000..48da90adc7b
--- /dev/null
+++ b/java/src/ant/SliceTask.java
@@ -0,0 +1,513 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+//package Ice.Ant;
+
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.taskdefs.ExecTask;
+import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.taskdefs.PumpStreamHandler;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.Environment;
+import org.apache.tools.ant.types.Commandline.Argument;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.StringReader;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+
+/**
+ * An abstract ant task for slice translators. The task minimizes
+ * regeneration by checking the dependencies between slice files.
+ *
+ * Attributes:
+ *
+ * dependencyfile - The file in which dependencies are stored (default: ".depend").
+ * outputdir - The value for the --output-dir translator option.
+ * casesensitive - Enables the --case-sensitive translator option.
+ * ice - Enables the --ice translator option.
+ *
+ * Nested elements:
+ *
+ * includepath - The directories in which to search for Slice files.
+ * These are converted into -I directives for the translator.
+ * define - Defines a preprocessor symbol. The "name" attribute
+ * specifies the symbol name, and the optional "value" attribute
+ * specifies the symbol's value.
+ * fileset - The set of Slice files which contain relevent types.
+ *
+ */
+public class SliceTask extends org.apache.tools.ant.Task
+{
+ public
+ SliceTask()
+ {
+ _dependencyFile = null;
+ _outputDir = null;
+ _outputDirString = null;
+ _caseSensitive = false;
+ _ice = false;
+ _includePath = null;
+ }
+
+ public void
+ setDependencyFile(File file)
+ {
+ _dependencyFile = file;
+ }
+
+ public void
+ setOutputdir(File dir)
+ {
+ _outputDir = dir;
+ _outputDirString = _outputDir.toString();
+ if(_outputDirString.indexOf(' ') != -1)
+ {
+ _outputDirString = '"' + _outputDirString + '"';
+ }
+ }
+
+ public void
+ setCaseSensitive(boolean c)
+ {
+ _caseSensitive = c;
+ }
+
+ public void
+ setIce(boolean ice)
+ {
+ _ice = ice;
+ }
+
+ public Path
+ createIncludePath()
+ {
+ if(_includePath == null)
+ {
+ _includePath = new Path(getProject());
+ }
+ return _includePath.createPath();
+ }
+
+ public void
+ setIncludePathRef(Reference ref)
+ {
+ createIncludePath().setRefid(ref);
+ }
+
+ public void
+ setIncludePath(Path includePath)
+ {
+ if(_includePath == null)
+ {
+ _includePath = includePath;
+ }
+ else
+ {
+ _includePath.append(includePath);
+ }
+ }
+
+ public FileSet
+ createFileset()
+ {
+ FileSet fileset = new FileSet();
+ _fileSets.add(fileset);
+
+ return fileset;
+ }
+
+ public void
+ addConfiguredDefine(SliceDefine define)
+ throws BuildException
+ {
+ if(define.getName() == null)
+ {
+ throw new BuildException("The name attribute must be supplied in a <define> element");
+ }
+
+ _defines.add(define);
+ }
+
+ public void
+ addConfiguredMeta(SliceMeta meta)
+ {
+ if(meta.getValue().length() > 0)
+ {
+ _meta.add(meta);
+ }
+ }
+
+ //
+ // Read the dependency file.
+ //
+ protected java.util.HashMap
+ readDependencies()
+ {
+ if(_dependencyFile == null)
+ {
+ if(_outputDir != null)
+ {
+ _dependencyFile = new File(_outputDir, ".depend");
+ }
+ else
+ {
+ _dependencyFile = new File(".depend");
+ }
+ }
+
+ try
+ {
+ java.io.ObjectInputStream in = new java.io.ObjectInputStream(new java.io.FileInputStream(_dependencyFile));
+ java.util.HashMap dependencies = (java.util.HashMap)in.readObject();
+ in.close();
+ return dependencies;
+ }
+ catch(java.io.IOException ex)
+ {
+ }
+ catch(java.lang.ClassNotFoundException ex)
+ {
+ }
+
+ return new java.util.HashMap();
+ }
+
+ protected void
+ writeDependencies(java.util.HashMap dependencies)
+ {
+ try
+ {
+ java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(new FileOutputStream(_dependencyFile));
+ out.writeObject(dependencies);
+ out.close();
+ }
+ catch(java.io.IOException ex)
+ {
+ throw new BuildException("Unable to write dependencies in file " + _dependencyFile.getPath() + ": " + ex);
+ }
+ }
+
+ //
+ // Parse dependencies returned by the slice translator (Makefile
+ // dependencies).
+ //
+ protected java.util.List
+ parseDependencies(String allDependencies)
+ {
+ java.util.List dependencies = new java.util.LinkedList();
+ try
+ {
+ BufferedReader in = new BufferedReader(new StringReader(allDependencies));
+ StringBuffer depline = new StringBuffer();
+ String line;
+
+ while((line = in.readLine()) != null)
+ {
+ if(line.length() == 0)
+ {
+ continue;
+ }
+ else if(line.endsWith("\\"))
+ {
+ depline.append(line.substring(0, line.length() - 1));
+ }
+ else
+ {
+ depline.append(line);
+
+ //
+ // It's easier to split up the filenames if we first convert Windows
+ // path separators into Unix path separators.
+ //
+ char[] chars = depline.toString().toCharArray();
+ int pos = 0;
+ while(pos < chars.length)
+ {
+ if(chars[pos] == '\\')
+ {
+ if(pos + 1 < chars.length)
+ {
+ //
+ // Only convert the backslash if it's not an escape.
+ //
+ if(chars[pos + 1] != ' ' && chars[pos + 1] != ':' && chars[pos + 1] != '\r' &&
+ chars[pos + 1] != '\n')
+ {
+ chars[pos] = '/';
+ }
+ }
+ }
+ ++pos;
+ }
+
+ //
+ // Split the dependencies up into filenames. Note that filenames containing
+ // spaces are escaped and the initial file may have escaped colons
+ // (e.g., "C\:/Program\ Files/...").
+ //
+ java.util.ArrayList l = new java.util.ArrayList();
+ StringBuffer file = new StringBuffer();
+ pos = 0;
+ while(pos < chars.length)
+ {
+ if(Character.isWhitespace(chars[pos]))
+ {
+ if(file.length() > 0)
+ {
+ l.add(file.toString());
+ file = new StringBuffer();
+ }
+ }
+ else if(chars[pos] != '\\') // Skip backslash of an escaped character.
+ {
+ file.append(chars[pos]);
+ }
+ ++pos;
+ }
+ if(file.length() > 0)
+ {
+ l.add(file.toString());
+ }
+
+ //
+ // Create SliceDependency. We need to remove the trailing colon from the first file.
+ // We also normalize the pathname for this platform.
+ //
+ SliceDependency depend = new SliceDependency();
+ depend._dependencies = new String[l.size()];
+ l.toArray(depend._dependencies);
+ depend._timeStamp = new java.util.Date().getTime();
+ pos = depend._dependencies[0].lastIndexOf(':');
+ assert(pos == depend._dependencies[0].length() - 1);
+ depend._dependencies[0] = depend._dependencies[0].substring(0, pos);
+ for(int i = 0; i < depend._dependencies.length; ++i)
+ {
+ depend._dependencies[i] = new File(depend._dependencies[i]).toString();
+ }
+ dependencies.add(depend);
+
+ depline = new StringBuffer();
+ }
+ }
+ }
+ catch(java.io.IOException ex)
+ {
+ throw new BuildException("Unable to read dependencies from slice translator: " + ex);
+ }
+
+ return dependencies;
+
+ }
+
+ protected String
+ getDefaultTranslator(String name)
+ {
+ String iceInstall = getIceHome();
+ if(iceInstall != null)
+ {
+ return new File(iceInstall + File.separator + "bin" + File.separator + name).toString();
+ }
+ else
+ {
+ //
+ // If the location of the Ice install is not known, we
+ // rely on a path search to find the translator.
+ //
+ return name;
+ }
+ }
+
+ protected void
+ addLdLibraryPath(ExecTask task)
+ {
+ String iceInstall = getIceHome();
+ if(iceInstall != null)
+ {
+ String ldLibPathEnv = null;
+ String ldLib64PathEnv = null;
+ String libPath = new File(iceInstall + File.separator + "lib").toString();
+ String lib64Path = null;
+
+ String os = System.getProperty("os.name");
+ if(os.equals("Mac OS X"))
+ {
+ ldLibPathEnv = "DYLD_LIBRARY_PATH";
+ }
+ else if(os.equals("AIX"))
+ {
+ ldLibPathEnv = "LIBPATH";
+ }
+ else if(os.equals("HP-UX"))
+ {
+ ldLibPathEnv = "SHLIB_PATH";
+ ldLib64PathEnv = "LD_LIBRARY_PATH";
+ lib64Path = new File(iceInstall + File.separator + "lib" + File.separator + "pa20_64").toString();
+ }
+ else if(os.startsWith("Windows"))
+ {
+ //
+ // No need to change the PATH environment variable on Windows, the DLLs should be found
+ // in the translator local directory.
+ //
+ //ldLibPathEnv = "PATH";
+ }
+ else if(os.equals("SunOS"))
+ {
+ ldLibPathEnv = "LD_LIBRARY_PATH";
+ ldLib64PathEnv = "LD_LIBRARY_PATH_64";
+ lib64Path = new File(iceInstall + File.separator + "lib" + File.separator + "sparcv9").toString();
+ }
+ else
+ {
+ ldLibPathEnv = "LD_LIBRARY_PATH";
+ ldLib64PathEnv = "LD_LIBRARY_PATH_64";
+ lib64Path = new File(iceInstall + File.separator + "lib64").toString();
+ }
+
+ if(ldLibPathEnv != null)
+ {
+ String envLibPath = getEnvironment(ldLibPathEnv);
+ if(envLibPath != null)
+ {
+ libPath = libPath + File.pathSeparator + envLibPath;
+ }
+
+ Environment.Variable v = new Environment.Variable();
+ v.setKey(ldLibPathEnv);
+ v.setValue(libPath);
+ task.addEnv(v);
+ }
+
+ if(ldLib64PathEnv != null)
+ {
+ String envLib64Path = getEnvironment(ldLib64PathEnv);
+ if(envLib64Path != null)
+ {
+ lib64Path = lib64Path + File.pathSeparator + envLib64Path;
+ }
+
+ Environment.Variable v = new Environment.Variable();
+ v.setKey(ldLib64PathEnv);
+ v.setValue(lib64Path);
+ task.addEnv(v);
+ }
+ }
+ }
+
+ //
+ // Query for the location of the Ice install. The Ice install
+ // location may be indicated in one of two ways:
+ //
+ // 1. Through the ice.home property
+ // 2. Through the ICE_HOME environment variable.
+ //
+ // If both the property and environment variable is specified, the
+ // property takes precedence. If neither is available, getIceHome()
+ // returns null.
+ //
+ protected String
+ getIceHome()
+ {
+ if(_iceHome == null)
+ {
+ if(getProject().getProperties().containsKey("ice.home"))
+ {
+ _iceHome = (String)getProject().getProperties().get("ice.home");
+ }
+ else
+ {
+ _iceHome = getEnvironment("ICE_HOME");
+ }
+ }
+ return _iceHome;
+ }
+
+ //
+ // A slice dependency.
+ //
+ // * the _timeStamp attribute contains the last time the slice
+ // file was compiled.
+ //
+ // * the _dependencies attribute contains an array with all the
+ // files this slice file depends on.
+ //
+ // This dependency represents the dependencies for the slice file
+ // _dependencies[0].
+ //
+ protected class SliceDependency implements java.io.Serializable
+ {
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws java.io.IOException
+ {
+ out.writeObject(_dependencies);
+ out.writeLong(_timeStamp);
+ }
+
+ private void readObject(java.io.ObjectInputStream in)
+ throws java.io.IOException, java.lang.ClassNotFoundException
+ {
+ _dependencies = (String[])in.readObject();
+ _timeStamp = in.readLong();
+ }
+
+ public boolean
+ isUpToDate()
+ {
+ for(int i = 0; i < _dependencies.length; ++i)
+ {
+ File dep = new File(_dependencies[i]);
+ if(!dep.exists() || _timeStamp < dep.lastModified())
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public String[] _dependencies;
+ public long _timeStamp;
+ }
+
+ private String
+ getEnvironment(String key)
+ {
+ java.util.Vector env = Execute.getProcEnvironment();
+ java.util.Enumeration e = env.elements();
+ while(e.hasMoreElements())
+ {
+ String entry = (String)e.nextElement();
+ if(entry.startsWith(key + "="))
+ {
+ return entry.substring(entry.indexOf('=') + 1);
+ }
+ }
+ return null;
+ }
+
+ protected File _dependencyFile;
+ protected File _outputDir;
+ protected String _outputDirString;
+ protected boolean _caseSensitive;
+ protected boolean _ice;
+ protected Path _includePath;
+ protected java.util.List _fileSets = new java.util.LinkedList();
+ protected java.util.List _defines = new java.util.LinkedList();
+ protected java.util.List _meta = new java.util.LinkedList();
+ private String _iceHome;
+}