ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karsten Klohs <>
Subject Re: Extension of the Javah-Task
Date Wed, 20 Apr 2005 12:25:46 GMT
Hash: SHA1

Hi again,

|>>3. I took a brief look at the development of Ant tasks and
|>>implementation of the javah-task. I think that it should be quite
|>>easy (famous last words ;-)) to extend the javah-task, so that it
|>>can take a fileset, transform the filenames internally to classnames
|>>and use the existing functionality to run javah for all classes
|>>corresponding to the given filenames.
| I agree.  Native support for filesets would be the cleanest solution.
|>>I appreciate any comments to this idea.
| All it takes is somebody who does the coding and supplies a patch ;-)

here you are ;-)

Can any Ant developer comment on the code snippet at the end of the mail?

Basically, I have extended the original Javah-task, added a new FileSet
attribute and overwritten the execute method, so that it does the following:

- - Iterate over the the files of the FileSet
- - Transform a file name to a full qualified path name by stripping the ".class"
suffix and replacing all "file.separtor" occurrences with the character "."
- - simulate the insertion of a nested class attribute in the original 
- - finally, call the original execute method.

The good news:

It works, though it is a crude hack ;-)

However, some issues remain on the way to a robust solution:

- - support of more than one FileSet (Consider it as done ;-) )
- - what shall the task do, if the file given file is not a class file i.e. it is
not ending with ".class"? Acutally, it throws a BuildException (yes, I am
paranoid ;-) )
- - The implicit convention, is that the full file name exactly corresponds to
the full class name. How can this restriction be relaxed? One idea is to
investigate the files' contents to find the class names (using BCEL?!) the
other is to at least allow a "class name construction" root relative to the
root of the FileSet.

Can anybody tell me how such issues are usually discussed because I am not sure
that implementation and integration details belong in this user list.

Best regards

Karsten Klohs

- ----------- BEGIN CODE SNIPPET -----------

public class JavahExt
~    extends

~    public void execute()
~    {
~        log("investigating FileSet " + fs);

~        // retrieve the file of the FileList by the DirectoryScanner
~        DirectoryScanner ds = fs.getDirectoryScanner(getProject()); // 3
~        String[] includedFiles = ds.getIncludedFiles();

~        for (int i = 0; i < includedFiles.length; i++) {

~            String filename = includedFiles[i];
~            log("Transforming file name " + filename + " to class name");

~            // transform the file name to a full qualified class name
~            String className = fileName2ClassName(filename);

~            // insert the class as if it was given by a nested class attribute
~            log("Including Class: " + className); // 4

~            ClassArgument newClass = createClass();
~            newClass.setName(className);
~        }

~        // launch the existing implementation
~        log("Launching Javah.execute()");
~        super.execute();
~    }
- ------------ END CODE SNIPPET ------------
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message