import java.io.*; import java.util.*; import common.OutputComparator; //import org.aspectj.testing.Tester; public class JavadocCompareClassMode { /** wait a minimum (of 1 second) for processes to complete */ static final int MIN_SECS = 1; /** wait a maximum (of 4 hours) for processes to complete */ static final int MAX_SECS = 4*60*60; static final String INPUT_FILES = "input/applesJava/*.java"; static final String FILE_1 = "Apple.html"; static final String FILE_2 = "AppleCrate.html"; static final String OUTPUT_DIR = "output"; static final String AJDOC_DIR = OUTPUT_DIR + File.separator + "ajdoc"; static final String JAVADOC_DIR = OUTPUT_DIR + File.separator + "javadoc"; static final String AJDOC_CALL = "java org.aspectj.tools.ajdoc.Main -d " + AJDOC_DIR + " " + INPUT_FILES; static final String JAVADOC_CALL = "javadoc -package -d " + JAVADOC_DIR + " " + INPUT_FILES; public static void main(String[] args) { test(System.out); } public static boolean ensureDir(String dirPath, StringBuffer errSink) { boolean result = false; if (dirPath != null) { try { File dir = new File(dirPath); if (!dir.exists()) { dir.mkdir(); } result = (dir.exists() && dir.isDirectory()); } catch (SecurityException e) { if (null != errSink) { errSink.append(e.getClass().getName()); errSink.append(" ensuring directory "); errSink.append(dirPath); errSink.append(": "); errSink.append(e.getMessage()); } } } return result; } // ensureDir /** * This implements a basic three-step test: *
Process.waitFor()
otherwise.
* @throws IllegalArgumentException if any parms are null or invalid
*/
public static int completeProcess(final Process process, int secsToWait,
PrintStream outSink,
PrintStream errSink) {
if (null == process) throw new IllegalArgumentException("null process");
if ((Integer.MAX_VALUE != secsToWait)
&& ((MIN_SECS > secsToWait) || ((MAX_SECS < secsToWait)))) {
throw new IllegalArgumentException("invalid time: " + secsToWait);
}
// setup timeout
TimerTask task = null;
if (Integer.MAX_VALUE != secsToWait) {
Timer t = new Timer(true);
task = new TimerTask() {
public void run() {
process.destroy();
}
};
t.schedule(task, secsToWait*1000l);
}
// try to wait for the process
int status = Integer.MAX_VALUE;
try {
status = process.waitFor();
} catch (InterruptedException ie) {
status = Integer.MIN_VALUE; // ignore
}
finally {
if (null != task) task.cancel();
if (errSink != null) writeStream(process.getErrorStream(), errSink);
// misnamed API: the "input" stream is our input from the process output
if (outSink != null) writeStream(process.getInputStream(), outSink);
}
return status;
} // completeProcess
/**
* Run command, delegating process handling to runProcess.
* @param command the String passed to Runtime.exec
* @return the int returned from process.waitFor();
*/
public static int runCommand(String command) {
int result = -1;
try {
System.out.println("Running " + command);
Process process = Runtime.getRuntime().exec(command);
System.out.println("waiting for Result.." );
final int seconds = 60;
result = completeProcess(process, seconds, System.out, System.err);
System.out.println("Result: " + result + " for " + command);
} catch (Exception e) {
throw new RuntimeException("could not execute: " + command +
", " + e.getMessage() );
}
return result;
}
}