1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.File;
public class JavadocRecurse {
static PrintWriter writer;
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("First command line argument is the destination file");
System.out.println("where the package names will be stored");
System.out.println("Rest of the arguments are directory paths to the packages");
System.out.println("Example:");
System.out.println(
"java JavadocRecurse packages.txt rootdir1 rootdir2 rootdirN");
return;
}
try {
writer = new PrintWriter(new BufferedWriter(new FileWriter(args[0])));
for (int i=1; i<args.length; i++) {
File root = new File(args[i]);
if (root.isDirectory()) {
writeDirs(root, root);
}
}
writer.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
private static void writeDirs(File root, File dir) {
String files[] = dir.list();
boolean fileFound = true;
for (int i=0; i<files.length; i++) {
File file = new File(dir,files[i]);
if (file.isDirectory()) {
writeDirs(root,file);
} else if (fileFound && (files[i].endsWith(".class")
|| files[i].endsWith(".java"))) {
fileFound = false;
if (root.equals(dir)) {
//writer.println("."); This was incorrect assumption about Javadoc
} else {
writer.println(dir.getPath().substring(root.getPath().length()+1).replace(File.separatorChar,'.'));
}
}
}
}
} |
Partager