Ejemplo n.º 1
0
  /**
   * Creates the base Options object. This contains both the options specified on the command line
   * and the ones specified in the UMLOptions class, if available. Also create the globally
   * accessible commentOptions object.
   */
  public static Options buildOptions(RootDoc root) {
    commentOptions = new Options();
    commentOptions.setOptions(root.options());
    commentOptions.setOptions(findClass(root, "UMLNoteOptions"));
    commentOptions.shape = new Shape("note");

    Options opt = new Options();
    opt.setOptions(root.options());
    opt.setOptions(findClass(root, "UMLOptions"));
    return opt;
  }
Ejemplo n.º 2
0
 private String[] getOptionValues(String option) {
   for (String[] optionValue : rootDoc.options()) {
     if (option.equals(optionValue[0])) {
       return optionValue;
     }
   }
   return null;
 }
Ejemplo n.º 3
0
 protected static String readOption(String optionName, RootDoc root) {
   String[][] options = root.options();
   for (String[] opt : options) {
     if (opt[0].equals(optionName)) {
       return opt[1];
     }
   }
   return null;
 }
Ejemplo n.º 4
0
 /** @param rootDoc */
 public Generator(final RootDoc rootDoc) {
   documentation = rootDoc;
   setFlags(documentation.options());
 }
Ejemplo n.º 5
0
 /**
  * Set the command line options supported by this configuration.
  *
  * @throws DocletAbortException
  */
 public void setOptions() {
   initPackageArray();
   setOptions(root.options());
   setSpecificDocletOptions(root.options());
 }
Ejemplo n.º 6
0
  public static boolean start(RootDoc r) {
    String keepListFile = null;
    String proofreadFile = null;
    String todoFile = null;
    String stubsDir = null;
    // Create the dependency graph for the stubs directory
    String apiFile = null;
    HashSet<String> stubPackages = null;
    ArrayList<String> knownTagsFiles = new ArrayList<String>();

    root = r;

    String[][] options = r.options();
    for (String[] a : options) {
      if (a[0].equals("-d")) {
        ClearPage.outputDir = a[1];
      } else if (a[0].equals("-templatedir")) {
        ClearPage.addTemplateDir(a[1]);
      } else if (a[0].equals("-hdf")) {
        mHDFData.add(new String[] {a[1], a[2]});
      } else if (a[0].equals("-markdown")) {
        mMarkdown.add(new String[] {a[1], a[2], a[3]});
      } else if (a[0].equals("-knowntags")) {
        knownTagsFiles.add(a[1]);
      } else if (a[0].equals("-toroot")) {
        ClearPage.toroot = a[1];
      } else if (a[0].equals("-title")) {
        Doclava.title = a[1];
      } else if (a[0].equals("-werror")) {
        Errors.setWarningsAreErrors(true);
      } else if (a[0].equals("-error") || a[0].equals("-warning") || a[0].equals("-hide")) {
        try {
          int level = -1;
          if (a[0].equals("-error")) {
            level = Errors.ERROR;
          } else if (a[0].equals("-warning")) {
            level = Errors.WARNING;
          } else if (a[0].equals("-hide")) {
            level = Errors.HIDDEN;
          }
          Errors.setErrorLevel(Integer.parseInt(a[1]), level);
        } catch (NumberFormatException e) {
          // already printed below
          return false;
        }
      } else if (a[0].equals("-keeplist")) {
        keepListFile = a[1];
      } else if (a[0].equals("-proofread")) {
        proofreadFile = a[1];
      } else if (a[0].equals("-todo")) {
        todoFile = a[1];
      } else if (a[0].equals("-public")) {
        showLevel = SHOW_PUBLIC;
      } else if (a[0].equals("-protected")) {
        showLevel = SHOW_PROTECTED;
      } else if (a[0].equals("-package")) {
        showLevel = SHOW_PACKAGE;
      } else if (a[0].equals("-private")) {
        showLevel = SHOW_PRIVATE;
      } else if (a[0].equals("-hidden")) {
        showLevel = SHOW_HIDDEN;
      } else if (a[0].equals("-stubs")) {
        stubsDir = a[1];
      } else if (a[0].equals("-stubpackages")) {
        stubPackages = new HashSet<String>();
        for (String pkg : a[1].split(":")) {
          stubPackages.add(pkg);
        }
      } else if (a[0].equals("-apixml")) {
        apiFile = a[1];
      } else if (a[0].equals("-nodocs")) {
        generateDocs = false;
      } else if (a[0].equals("-parsecomments")) {
        parseComments = true;
      } else if (a[0].equals("-since")) {
        sinceTagger.addVersion(a[1], a[2]);
      } else if (a[0].equals("-federate")) {
        try {
          String name = a[1];
          URL federationURL = new URL(a[2]);
          federationTagger.addSiteUrl(name, federationURL);
        } catch (MalformedURLException e) {
          System.err.println("Could not parse URL for federation: " + a[1]);
          return false;
        }
      } else if (a[0].equals("-federationxml")) {
        String name = a[1];
        String file = a[2];
        federationTagger.addSiteXml(name, file);
      } else if (a[0].equals("-apiversion")) {
        apiVersion = a[1];
      } else if (a[0].equals("-assetsdir")) {
        assetsOutputDir = a[1];
      } else if (a[0].equals("-generatesources")) {
        generateSources = true;
      }
    }

    if (!readKnownTagsFiles(knownTags, knownTagsFiles)) {
      return false;
    }

    // Set up the data structures
    Converter.makeInfo(r);

    // Stubs and xml
    final File currentApiFile;
    if (!generateDocs && apiFile != null) {
      currentApiFile = new File(apiFile);
    } else if (generateDocs) {
      currentApiFile =
          new File(ensureSlash(ClearPage.outputDir) + javadocDir + FederatedSite.XML_API_PATH);
    } else {
      currentApiFile = null;
    }

    Stubs.writeStubsAndXml(stubsDir, currentApiFile, stubPackages);

    if (generateDocs && apiFile != null) {
      ClearPage.copyFile(currentApiFile, new File(apiFile));
    }

    // Reference documentation
    if (generateDocs) {
      ClearPage.addBundledTemplateDir("assets/customizations");
      ClearPage.addBundledTemplateDir("assets/templates");

      List<ResourceLoader> resourceLoaders = new ArrayList<ResourceLoader>();
      List<String> templates = ClearPage.getTemplateDirs();
      for (String tmpl : templates) {
        resourceLoaders.add(new FileSystemResourceLoader(tmpl));
      }

      templates = ClearPage.getBundledTemplateDirs();
      for (String tmpl : templates) {
        resourceLoaders.add(new ClassResourceLoader(Doclava.class, '/' + tmpl));
      }

      ResourceLoader compositeResourceLoader = new CompositeResourceLoader(resourceLoaders);
      jSilver = new JSilver(compositeResourceLoader);

      if (!Doclava.readTemplateSettings()) {
        return false;
      }

      long startTime = System.nanoTime();

      // Use current version information
      if (apiVersion != null && sinceTagger.hasVersions()) {
        sinceTagger.addVersion(currentApiFile.getAbsolutePath(), apiVersion);
      }

      // Apply @since tags from the XML file
      sinceTagger.tagAll(Converter.rootClasses());

      // Apply details of federated documentation
      federationTagger.tagAll(Converter.rootClasses());

      // Files for proofreading
      if (proofreadFile != null) {
        Proofread.initProofread(proofreadFile);
      }
      if (todoFile != null) {
        TodoFile.writeTodoFile(todoFile);
      }

      writeAssets();

      // Navigation tree
      NavTree.writeNavTree(assetsOutputDir);

      // Write Markdown files
      writeMarkdowns();

      // Mule
      writeModules(muleXmlDir + "modules" + htmlExtension);

      // Packages Pages
      writePackages(javadocDir + "packages" + htmlExtension);

      // Classes
      writeClassLists();
      writeClasses();
      writeHierarchy();
      // writeKeywords();

      // Lists for JavaScript
      writeLists();
      if (keepListFile != null) {
        writeKeepList(keepListFile);
      }

      // Index page
      writeIndex();

      // Installation page
      writeInstall();

      Proofread.finishProofread(proofreadFile);

      long time = System.nanoTime() - startTime;
      System.out.println(
          "Mule DevKit took "
              + (time / 1000000000)
              + " sec. to write docs to "
              + ClearPage.outputDir);
    }

    Errors.printErrors();

    return !Errors.hadError;
  }
Ejemplo n.º 7
0
 private static void init(RootDoc root) {
   outDir = readOptions(root.options());
 }
Ejemplo n.º 8
0
 /**
  * Add at least the first sentence from a doc block for a package to the API. This is used by the
  * report generator if no comment is provided. The default source tree may not include the
  * package.html files, so this may be unavailable in many cases. Need to make sure that HTML tags
  * are not confused with XML tags. This could be done by stuffing the &lt; character to another
  * string or by handling HTML in the parser. This second option is neater. Note that XML expects
  * all element tags to have either a closing "/>" or a matching end element tag. Due to the
  * difficulties of converting incorrect HTML to XHTML, the first option is used.
  */
 public void addPkgDocumentation(RootDoc root, PackageDoc pd, int indent) {
   String rct = null;
   String filename = pd.name();
   try {
     // See if the source path was specified as part of the
     // options and prepend it if it was.
     String srcLocation = null;
     String[][] options = root.options();
     for (int opt = 0; opt < options.length; opt++) {
       if ((options[opt][0]).compareTo("-sourcepath") == 0) {
         srcLocation = options[opt][1];
         break;
       }
     }
     filename = filename.replace('.', JDiff.DIR_SEP.charAt(0));
     if (srcLocation != null) {
       // Make a relative location absolute
       if (srcLocation.startsWith("..")) {
         String curDir = System.getProperty("user.dir");
         while (srcLocation.startsWith("..")) {
           srcLocation = srcLocation.substring(3);
           int idx = curDir.lastIndexOf(JDiff.DIR_SEP);
           curDir = curDir.substring(0, idx + 1);
         }
         srcLocation = curDir + srcLocation;
       }
       filename = srcLocation + JDiff.DIR_SEP + filename;
     }
     // Try both ".htm" and ".html"
     filename += JDiff.DIR_SEP + "package.htm";
     File f2 = new File(filename);
     if (!f2.exists()) {
       filename += "l";
     }
     FileInputStream f = new FileInputStream(filename);
     BufferedReader d = new BufferedReader(new InputStreamReader(f));
     String str = d.readLine();
     // Ignore everything except the lines between <body> elements
     boolean inBody = false;
     while (str != null) {
       if (!inBody) {
         if (str.toLowerCase().trim().startsWith("<body")) {
           inBody = true;
         }
         str = d.readLine(); // Get the next line
         continue; // Ignore the line
       } else {
         if (str.toLowerCase().trim().startsWith("</body")) {
           inBody = false;
           continue; // Ignore the line
         }
       }
       if (rct == null) rct = str + "\n";
       else rct += str + "\n";
       str = d.readLine();
     }
   } catch (java.io.FileNotFoundException e) {
     // If it doesn't exist, that's fine
     if (trace) System.out.println("No package level documentation file at '" + filename + "'");
   } catch (java.io.IOException e) {
     System.out.println("Error reading file \"" + filename + "\": " + e.getMessage());
     System.exit(5);
   }
   if (rct != null) {
     rct = stripNonPrintingChars(rct, (Doc) pd);
     rct = rct.trim();
     if (rct.compareTo("") != 0
         && rct.indexOf(Comments.placeHolderText) == -1
         && rct.indexOf("InsertOtherCommentsHere") == -1) {
       int idx = endOfFirstSentence(rct);
       if (idx == 0) return;
       for (int i = 0; i < indent; i++) outputFile.print(" ");
       outputFile.println("<doc>");
       for (int i = 0; i < indent; i++) outputFile.print(" ");
       String firstSentence = null;
       if (idx == -1) firstSentence = rct;
       else firstSentence = rct.substring(0, idx + 1);
       String firstSentenceNoTags = API.stuffHTMLTags(firstSentence);
       outputFile.println(firstSentenceNoTags);
       for (int i = 0; i < indent; i++) outputFile.print(" ");
       outputFile.println("</doc>");
     }
   }
 }