• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with creating sub directories using File I/O and Sun's Doclet API  RSS feed

 
Michael K. Wilson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

I am using Sun's Doclet API to parse source code and write newly created Java source files (which don't contain any private members).

Wrote a program which reads in Java source files (using the JVM's javadoc command line utility through an Ant target) and creates new Java source files (using Sun's Doclet API located inside tools.jar).

My problem is that it doesn't seem to create the fully qualified package directory structure (meaning that inside the destination directory, I want it to place the correct package sub directory like this: /destination/com/sourcetool).

My doclet does parse the Java source files correctly but just places the newly created Java source files inside the destination directory with out the top level directories.

Here's the breakdown of my code:

(1) Have a top-level project directory which is specified as:

C:\Projects\SourceTool\

(2) My actual file exists inside:

C:\Projects\SourceTool\src\com\sourcetool\MyDoclet.java

(3) The destination where I want the subdirectories is located here:

C:\Projects\SourceTool\destination

The reason for I am using File I/O is because I read that if one is trying to invoke a Java Doclet with the -d (the destination flag for the javadoc command line utility) with a -doclet flag that the JVM becomes fails to located the doclet (which is MyDoclet.java) location.

Here's my code:



Ant target:


Build.properties:



I believe my problem is more so based on the fact that I am improperly using Java's File I/O API than anything else.

Would really be happy if someone could assist me...

Thanks again,

Mike
[ July 20, 2008: Message edited by: Michael K. Wilson ]
 
Taariq San
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're right.

Here's your fileName based on...
String fileName = DEST_DIR + cd.simpleTypeName() + ".java";

C:\Projects\SourceTool\destination.MyDoclet.java

Then you create a new FileOutputStream with that path.
sourceFile = new FileOutputStream(fileName);

What you really want is to create the directory first, based on your destination plus any additional subdirectories, then use that File object to create your source file.

Like so...


It's important to use mkdirs instead of mkdir, as packages typically include multiple.
[ July 21, 2008: Message edited by: Taariq San ]
 
Michael K. Wilson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Taariq,

Thank you for your suggestion...

Basically, this is what's happening (please take a look at my altered code):



Now, when I run this file from my Ant target, this is what I see in the Eclipse console:



So, basically, I want inside the destination directory to have these sub directories (derived from the package names):



It only places the newly created source file underneath my destination folder:

ServletController.java (the file that I created using MyDoclet.java)

Happy coding,

-Mike
[ July 21, 2008: Message edited by: Michael K. Wilson ]
 
Michael K. Wilson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it working!

The solution consisted of prepending the filePath value inside the fileName variable...



The only thing it does now (which might be a problem) is that it creates directories for the inner classes and then places the inner classes inside those folders.

But this is pretty good enough!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!