1package com.jogamp.gluegen.ant;
41import java.io.IOException;
42import java.util.Iterator;
43import java.util.LinkedList;
46import org.apache.tools.ant.BuildException;
47import org.apache.tools.ant.DirectoryScanner;
48import org.apache.tools.ant.Project;
49import org.apache.tools.ant.Task;
50import org.apache.tools.ant.taskdefs.Execute;
51import org.apache.tools.ant.taskdefs.LogStreamHandler;
52import org.apache.tools.ant.types.AbstractFileSet;
53import org.apache.tools.ant.types.CommandlineJava;
54import org.apache.tools.ant.types.DirSet;
55import org.apache.tools.ant.types.FileSet;
56import org.apache.tools.ant.types.Path;
57import org.apache.tools.ant.types.PatternSet;
58import org.apache.tools.ant.types.Reference;
59import org.apache.tools.ant.util.JavaEnvUtils;
89 private static final String GLUE_GEN =
"com.jogamp.gluegen.GlueGen";
96 private final CommandlineJava gluegenCommandline;
102 private boolean debug=
false;
107 private String logLevel =
null;
112 private boolean dumpCPP=
false;
117 private String outputRootDir;
122 private String emitter;
127 private String configuration;
132 private String sourceFile;
137 private final FileSet includeSet =
new FileSet();
145 private boolean usedIncludeSet =
false;
152 private final List<AbstractFileSet> setOfIncludeSets =
new LinkedList<AbstractFileSet>();
161 private String literalIncludes;
170 gluegenCommandline =
new CommandlineJava();
173 gluegenCommandline.setVm(JavaEnvUtils.getJreExecutable(
"java"));
174 gluegenCommandline.setClassname(GLUE_GEN);
186 log( (
"Setting debug flag: " + debug), Project.MSG_VERBOSE);
195 log( (
"Setting logLevel: " + logLevel), Project.MSG_VERBOSE);
196 this.logLevel=logLevel;
204 log( (
"Setting dumpCPP flag: " + dumpCPP), Project.MSG_VERBOSE);
205 this.dumpCPP=dumpCPP;
215 log( (
"Setting output root dir: " + outputRootDir), Project.MSG_VERBOSE);
216 this.outputRootDir=outputRootDir;
226 log( (
"Setting emitter class name to: " + emitter), Project.MSG_VERBOSE);
227 this.emitter = emitter;
237 log( (
"Setting configuration file name to: " + configuration),
238 Project.MSG_VERBOSE);
239 this.configuration = configuration;
247 public void setSrc(
final String sourceFile)
249 log( (
"Setting source file name to: " + sourceFile), Project.MSG_VERBOSE);
250 this.sourceFile = sourceFile;
261 this.literalIncludes = commaSeparatedIncludes.trim();
272 usedIncludeSet =
true;
273 return includeSet.createInclude();
284 usedIncludeSet =
true;
285 return includeSet.createIncludesFile();
296 usedIncludeSet =
true;
297 includeSet.setIncludes(includes);
308 usedIncludeSet =
true;
309 return includeSet.createExclude();
320 usedIncludeSet =
true;
321 return includeSet.createExcludesFile();
332 usedIncludeSet =
true;
333 includeSet.setExcludes(excludes);
347 final Object referencedObject = reference.getReferencedObject(getProject());
348 if (referencedObject instanceof FileSet) {
349 setOfIncludeSets.add((FileSet)referencedObject);
352 if (referencedObject instanceof DirSet) {
353 setOfIncludeSets.add((DirSet)referencedObject);
357 throw new BuildException(
"Only FileSets or DirSets are allowed as an include refid.");
368 setOfIncludeSets.add(dirset);
379 return gluegenCommandline.createClasspath(project).createPath();
391 throws BuildException
394 validateAttributes();
402 log(gluegenCommandline.describeCommand(), Project.MSG_VERBOSE);
405 final int error =
execute(gluegenCommandline.getCommandline());
407 throw new BuildException( (
"GlueGen returned: " + error), location);
416 private void validateAttributes()
417 throws BuildException
422 if(!isValid(emitter))
423 throw new BuildException(
"Invalid emitter class name: " + emitter);
426 if(!isValid(configuration))
427 throw new BuildException(
"Invalid configuration file name: " + configuration);
430 if(!isValid(sourceFile))
431 throw new BuildException(
"Invalid source file name: " + sourceFile);
444 private boolean isValid(
final String
string)
452 if(
string.trim().length() < 1)
463 private void addAttributes()
464 throws BuildException
471 gluegenCommandline.createArgument().setValue(
"--debug");
475 if(
null != logLevel) {
476 gluegenCommandline.createArgument().setValue(
"--logLevel");
477 gluegenCommandline.createArgument().setValue(logLevel);
482 gluegenCommandline.createArgument().setValue(
"--dumpCPP");
486 if(
null!=outputRootDir && outputRootDir.trim().length()>0) {
487 gluegenCommandline.createArgument().setValue(
"-O" + outputRootDir);
491 gluegenCommandline.createArgument().setValue(
"-E" + emitter);
494 gluegenCommandline.createArgument().setValue(
"-C" + configuration);
503 includeSet.setDir(getProject().getBaseDir());
504 setOfIncludeSets.add(includeSet);
509 final List<String> includedDirectories =
new LinkedList<String>();
510 for (
final Iterator<AbstractFileSet> includes = setOfIncludeSets.iterator(); includes.hasNext();)
514 final AbstractFileSet include = includes.next();
515 final DirectoryScanner directoryScanner = include.getDirectoryScanner(getProject());
516 final String[] directoryDirs = directoryScanner.getIncludedDirectories();
520 for(
int i=0; i<directoryDirs.length; i++)
522 includedDirectories.add(directoryDirs[i]);
528 if( isValid( literalIncludes ) ) {
529 final String[] includes = literalIncludes.split(
",");
530 for(
int i=0; i<includes.length; i++) {
531 final String include = includes[i].trim();
532 if( include.length()>0 ) {
533 includedDirectories.add(include);
539 for(
final Iterator<String> includes=includedDirectories.iterator(); includes.hasNext(); )
541 final String directory = includes.next();
542 gluegenCommandline.createArgument().setValue(
"-I" + directory);
546 gluegenCommandline.createArgument().setValue(sourceFile);
554 private int execute(
final String[] command)
555 throws BuildException
558 final Execute
execute =
new Execute(
new LogStreamHandler(
this, Project.MSG_INFO,
564 execute.setCommandline(command);
565 execute.setWorkingDirectory( project.getBaseDir() );
571 }
catch(
final IOException ioe)
573 throw new BuildException(ioe, location);
void setIncludes(final String includes)
PatternSet.NameEntry createIncludesFile()
void setLiteralInclude(final String commaSeparatedIncludes)
PatternSet.NameEntry createInclude()
PatternSet.NameEntry createExclude()
void setDumpCPP(final boolean dumpCPP)
void setExcludes(final String excludes)
void setOutputRootDir(final String outputRootDir)
void setSrc(final String sourceFile)
void setConfig(final String configuration)
void setEmitter(final String emitter)
void addDirset(final DirSet dirset)
void setLogLevel(final String logLevel)
void setDebug(final boolean debug)
void setIncludeRefid(final Reference reference)
PatternSet.NameEntry createExcludesFile()