001: package tide.javadocgen;
002:
003: import snow.utils.storage.FileUtils;
004: import tide.project.ProjectUtils;
005: import tide.editor.MainEditorFrame;
006: import java.io.*;
007: import java.util.*;
008: import tide.utils.*;
009:
010: /** Remark: incremental doc is not possible (=> must be generated from time to time...)
011: * (in background).
012: */
013: public class JavaDocCreation {
014: // can be retrieved to initialize a progressbar for example
015: public static int guessedNumberOfJavaFiles = 0;
016:
017: /** C:\Java\jdk1.6.0_05\bin\javadoc -d JavaDoc -sourcepath ..\src -subpackages snow:script
018: */
019: public static Process javaDocCreation(File javaDocExecutor,
020: File sourcesFolder, File destination, List<File> classPath,
021: String includedPackages, String options) throws Exception {
022: if (!javaDocExecutor.exists())
023: throw new Exception("JavaDoc tool no found: "
024: + javaDocExecutor);
025:
026: List<String> execCommand = new ArrayList<String>();
027: execCommand.add(javaDocExecutor.getAbsolutePath());
028: execCommand.add("-J-Duser.language=en");
029:
030: // options
031: if (options != null && options.trim().length() > 0) {
032: execCommand.addAll(ProjectUtils.splitArgs(options, false));
033: }
034:
035: execCommand.add("-d");
036: execCommand.add(destination.getAbsolutePath());
037:
038: if (classPath != null && classPath.size() > 0) {
039: execCommand.add("-classpath");
040: StringBuilder cp = new StringBuilder();
041: for (int i = 0; i < classPath.size(); i++) {
042: cp.append(classPath.get(i).getAbsolutePath());
043: if (i < classPath.size() - 1)
044: cp.append(";");
045: }
046: execCommand.add(cp.toString());
047: }
048:
049: execCommand.add("-sourcepath");
050: execCommand.add(sourcesFolder.getAbsolutePath());
051:
052: guessedNumberOfJavaFiles = 0;
053: if (includedPackages.trim().length() == 0) {
054: List<String> packNames = MainEditorFrame.instance.sourcesTreePanel
055: .getTreeModel().getFirstLevelPackages();
056:
057: if (packNames.isEmpty()) {
058: // [Nov2007]
059: throw new Exception(
060: "Javadoc cannot ONLY process sources that are in packages.");
061: }
062:
063: StringBuilder dirList = new StringBuilder();
064: for (int i = 0; i < packNames.size(); i++) {
065: dirList.append(packNames.get(i)); // Basic names: no points
066: if (i < packNames.size() - 1) {
067: dirList.append(":");
068: }
069:
070: // count java files in this directory
071: List<File> allJavaFiles = new ArrayList<File>();
072: //FileUtilities.getAllFilesRecurse_withNameEndingWith(allJavaFiles, new File( sourcesFolder.getAbsolutePath()+"/"+packNames.get(i)), ".java");
073:
074: FileUtils.getAllJavaFilesRecurse(new File(sourcesFolder
075: .getAbsolutePath()
076: + "/" + packNames.get(i)), allJavaFiles, false,
077: true);
078:
079: guessedNumberOfJavaFiles += allJavaFiles.size();
080:
081: }
082:
083: if (dirList.length() > 0) {
084: execCommand.add("-subpackages");
085: execCommand.add(dirList.toString());
086: }
087: } else {
088: execCommand.add("-subpackages");
089: StringTokenizer st = new StringTokenizer(includedPackages,
090: " \r\n\t:,;", false);
091: StringBuilder dirList = new StringBuilder();
092: while (st.hasMoreElements()) {
093: String name = st.nextToken(); // maybe with points "snow.utils"
094: dirList.append(name);
095: if (st.hasMoreElements())
096: dirList.append(":");
097:
098: // count java files in this directory
099: File dir = new File(sourcesFolder, name.replace('.',
100: '/'));
101: List<File> allJavaFiles = new ArrayList<File>();
102: FileUtils.getAllJavaFilesRecurse(dir, allJavaFiles,
103: false, true);
104: //FileUtilities.getAllFilesRecurse_withNameEndingWith(allJavaFiles, dir, ".java");
105: guessedNumberOfJavaFiles += allJavaFiles.size();
106: }
107: execCommand.add(dirList.toString());
108: }
109:
110: MainEditorFrame.debugOut("JavaDoc creation command= "
111: + execCommand);
112:
113: ProcessBuilder pb = new ProcessBuilder(execCommand);
114: pb.directory(sourcesFolder);
115: return pb.start();
116: }
117:
118: }
|