001: /*
002: * $Id: SunReferenceEnhancer.java,v 1.6 2003/10/20 05:59:26 jackknifebarber Exp $
003: */
004:
005: package com.triactive.jdo.enhance;
006:
007: import java.io.File;
008: import java.util.Arrays;
009: import java.util.ArrayList;
010: import java.util.Collection;
011: import java.util.List;
012:
013: /**
014: * This is an implementation of the Enhancer that wraps Sun's JDO Reference
015: * Implementation class endhancer.
016: *
017: * @version $Revision: 1.6 $
018: */
019: public class SunReferenceEnhancer extends Enhancer {
020: private final Collection jdoFiles;
021: private final String destDir;
022: private final boolean verbose;
023:
024: private SunReferenceEnhancer(String destDir, boolean verbose,
025: Collection jdoFiles) {
026: super ();
027:
028: this .destDir = destDir;
029: this .verbose = verbose;
030: this .jdoFiles = jdoFiles;
031: }
032:
033: /**
034: * This method accepts a list of jdo files that should be enhanced by
035: * the Sun Reference Implementation enhancer.
036: *
037: * @param classNames The list of class names to be enhanced
038: */
039: protected int callExternalEnhancer(String[] classNames)
040: throws Exception {
041: int returnCode = 0;
042:
043: if (classNames.length > 0) {
044: ArrayList args = new ArrayList();
045:
046: args.add("-f"); // Force writing of .class files.
047: args.add("-d");
048: args.add(destDir);
049:
050: if (verbose)
051: args.add("-v");
052:
053: args.addAll(jdoFiles);
054:
055: for (int i = 0; i < classNames.length; ++i) {
056: String name = classNames[i];
057: System.out.println("Enhancing class " + name);
058:
059: args.add(new File(destDir, name.replace('.', '/')
060: + ".class").toString());
061: }
062:
063: com.sun.jdori.enhancer.Main main = new com.sun.jdori.enhancer.Main();
064: returnCode = main.process((String[]) args
065: .toArray(new String[args.size()]));
066: }
067:
068: return returnCode;
069: }
070:
071: /**
072: * Called when the class is invoked from the command line.
073: *
074: * @param args
075: * A list of JDO metadata files (*.jdo files). The list may optionally
076: * be prefixed by a -l flag followed by the name of a file to which
077: * the list of enhanced classes will be written to. The -d argument
078: * is also accepted to specify the destination directory to write the
079: * class files to. The -v flag makes the enhancer run with verbose
080: * output.
081: */
082: public static void main(String[] args) throws Exception {
083: String classListFile = null;
084: String destDir = ".";
085: boolean verbose = false;
086: ArrayList jdoFiles = new ArrayList();
087:
088: for (int i = 0; i < args.length; i++) {
089: if (args[i].equals("-l")) {
090: classListFile = args[++i];
091: } else if (args[i].equals("-d")) {
092: destDir = args[++i];
093: } else if (args[i].equals("-v")) {
094: verbose = true;
095: } else {
096: jdoFiles.add(args[i]);
097: }
098: }
099:
100: List classNames = getOrderedClassNames((String[]) jdoFiles
101: .toArray(new String[jdoFiles.size()]));
102:
103: if (classListFile != null)
104: writeClassListFile(classListFile, classNames);
105:
106: System
107: .exit(new SunReferenceEnhancer(destDir, verbose,
108: jdoFiles).enhance(classNames));
109: }
110: }
|