Exemplo n.º 1
0
  /**
   * Write the XML representation of the API to a file.
   *
   * @param root the RootDoc object passed by Javadoc
   * @return true if no problems encountered
   */
  public static boolean writeXML(RootDoc root) {
    String tempFileName = outputFileName;
    if (outputDirectory != null) {
      tempFileName = outputDirectory;
      if (!tempFileName.endsWith(JDiff.DIR_SEP)) tempFileName += JDiff.DIR_SEP;
      tempFileName += outputFileName;
    }

    try {
      FileOutputStream fos = new FileOutputStream(tempFileName);
      outputFile = new PrintWriter(fos);
      System.out.println("JDiff: writing the API to file '" + tempFileName + "'...");
      if (root.specifiedPackages().length != 0 || root.specifiedClasses().length != 0) {
        RootDocToXML apiWriter = new RootDocToXML();
        apiWriter.emitXMLHeader();
        apiWriter.logOptions();
        apiWriter.processPackages(root);
        apiWriter.emitXMLFooter();
      }
      outputFile.close();
    } catch (IOException e) {
      System.out.println("IO Error while attempting to create " + tempFileName);
      System.out.println("Error: " + e.getMessage());
      System.exit(1);
    }
    // If validation is desired, write out the appropriate api.xsd file
    // in the same directory as the XML file.
    if (XMLToAPI.validateXML) {
      writeXSD();
    }
    return true;
  }
Exemplo n.º 2
0
 /**
  * Create a TreeWriter object and use it to generate the "overview-tree.html" file.
  *
  * @param classtree the class tree being documented.
  * @throws DocletAbortException
  */
 public static void generate(ConfigurationImpl configuration, ClassTree classtree) {
   TreeWriter treegen;
   String filename = "overview-tree.html";
   try {
     treegen = new TreeWriter(configuration, filename, classtree);
     treegen.generateTreeFile();
     treegen.close();
   } catch (IOException exc) {
     configuration.standardmessage.error("doclet.exception_encountered", exc.toString(), filename);
     throw new DocletAbortException();
   }
 }
 /**
  * Generate a class page.
  *
  * @param configuration the current configuration of the doclet.
  * @param mapper the mapping of the class usage.
  * @param pkgdoc the package doc being documented.
  */
 public static void generate(
     ConfigurationImpl configuration, ClassUseMapper mapper, PackageDoc pkgdoc) {
   PackageUseWriter pkgusegen;
   DocPath filename = DocPaths.PACKAGE_USE;
   try {
     pkgusegen = new PackageUseWriter(configuration, mapper, filename, pkgdoc);
     pkgusegen.generatePackageUseFile();
     pkgusegen.close();
   } catch (IOException exc) {
     configuration.standardmessage.error("doclet.exception_encountered", exc.toString(), filename);
     throw new DocletAbortException(exc);
   }
 }
Exemplo n.º 4
0
 /**
  * Copy a file from a source directory to a destination directory (if it is not there already). If
  * <code>overwrite</code> is true and the destination file already exists, overwrite it.
  *
  * @param configuration Holds the error message
  * @param file The name of the file to copy
  * @param source The source directory
  * @param destination The destination directory where the file needs to be copied
  * @param overwrite A flag to indicate whether the file in the destination directory will be
  *     overwritten if it already exists.
  * @param replaceNewLine true if the newline needs to be replaced with platform- specific newline.
  */
 public static void copyFile(
     Configuration configuration,
     String file,
     String source,
     String destination,
     boolean overwrite,
     boolean replaceNewLine) {
   DirectoryManager.createDirectory(configuration, destination);
   File destfile = new File(destination, file);
   if (destfile.exists() && (!overwrite)) return;
   try {
     InputStream in =
         Configuration.class.getResourceAsStream(
             source + DirectoryManager.URL_FILE_SEPARATOR + file);
     if (in == null) return;
     OutputStream out = new FileOutputStream(destfile);
     try {
       if (!replaceNewLine) {
         byte[] buf = new byte[2048];
         int n;
         while ((n = in.read(buf)) > 0) out.write(buf, 0, n);
       } else {
         BufferedReader reader = new BufferedReader(new InputStreamReader(in));
         BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
         try {
           String line;
           while ((line = reader.readLine()) != null) {
             writer.write(line);
             writer.write(DocletConstants.NL);
           }
         } finally {
           reader.close();
           writer.close();
         }
       }
     } finally {
       in.close();
       out.close();
     }
   } catch (IOException ie) {
     ie.printStackTrace(System.err);
     throw new DocletAbortException();
   }
 }
 /**
  * Convert the given Class to an HTML.
  *
  * @param cd the class to convert.
  * @param outputdir the name of the directory to output to.
  */
 public void convertClass(ClassDoc cd, DocPath outputdir) {
   if (cd == null) {
     return;
   }
   try {
     SourcePosition sp = cd.position();
     if (sp == null) return;
     Reader r;
     // temp hack until we can update SourcePosition API.
     if (sp instanceof SourcePositionImpl) {
       FileObject fo = ((SourcePositionImpl) sp).fileObject();
       if (fo == null) return;
       r = fo.openReader(true);
     } else {
       File file = sp.file();
       if (file == null) return;
       r = new FileReader(file);
     }
     int lineno = 1;
     String line;
     relativePath = DocPaths.SOURCE_OUTPUT.resolve(DocPath.forPackage(cd)).invert();
     Content body = getHeader();
     Content pre = new HtmlTree(HtmlTag.PRE);
     try (LineNumberReader reader = new LineNumberReader(r)) {
       while ((line = reader.readLine()) != null) {
         addLineNo(pre, lineno);
         addLine(pre, line, lineno);
         lineno++;
       }
     }
     addBlankLines(pre);
     Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
     body.addContent((configuration.allowTag(HtmlTag.MAIN)) ? HtmlTree.MAIN(div) : div);
     writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 6
0
 /** Write the XML Schema file used for validation. */
 public static void writeXSD() {
   String xsdFileName = outputFileName;
   if (outputDirectory == null) {
     int idx = xsdFileName.lastIndexOf('\\');
     int idx2 = xsdFileName.lastIndexOf('/');
     if (idx == -1 && idx2 == -1) {
       xsdFileName = "";
     } else if (idx == -1 && idx2 != -1) {
       xsdFileName = xsdFileName.substring(0, idx2);
     } else if (idx != -1 && idx2 == -1) {
       xsdFileName = xsdFileName.substring(0, idx);
     } else if (idx != -1 && idx2 != -1) {
       int max = idx2 > idx ? idx2 : idx;
       xsdFileName = xsdFileName.substring(0, max);
     }
   } else {
     xsdFileName = outputDirectory;
     if (!xsdFileName.endsWith(JDiff.DIR_SEP)) xsdFileName += JDiff.DIR_SEP;
   }
   xsdFileName += "api.xsd";
   try {
     FileOutputStream fos = new FileOutputStream(xsdFileName);
     PrintWriter xsdFile = new PrintWriter(fos);
     // The contents of the api.xsd file
     xsdFile.println("<?xml version=\"1.0\" encoding=\"iso-8859-1\" standalone=\"no\"?>");
     xsdFile.println("<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
     xsdFile.println("");
     xsdFile.println("<xsd:annotation>");
     xsdFile.println("  <xsd:documentation>");
     xsdFile.println("  Schema for JDiff API representation.");
     xsdFile.println("  </xsd:documentation>");
     xsdFile.println("</xsd:annotation>");
     xsdFile.println();
     xsdFile.println("<xsd:element name=\"api\" type=\"apiType\"/>");
     xsdFile.println("");
     xsdFile.println("<xsd:complexType name=\"apiType\">");
     xsdFile.println("  <xsd:sequence>");
     xsdFile.println(
         "    <xsd:element name=\"package\" type=\"packageType\" minOccurs='1' maxOccurs='unbounded'/>");
     xsdFile.println("  </xsd:sequence>");
     xsdFile.println("  <xsd:attribute name=\"name\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"jdversion\" type=\"xsd:string\"/>");
     xsdFile.println("</xsd:complexType>");
     xsdFile.println();
     xsdFile.println("<xsd:complexType name=\"packageType\">");
     xsdFile.println("  <xsd:sequence>");
     xsdFile.println("    <xsd:choice maxOccurs='unbounded'>");
     xsdFile.println("      <xsd:element name=\"class\" type=\"classType\"/>");
     xsdFile.println("      <xsd:element name=\"interface\" type=\"classType\"/>");
     xsdFile.println("    </xsd:choice>");
     xsdFile.println(
         "    <xsd:element name=\"doc\" type=\"xsd:string\" minOccurs='0' maxOccurs='1'/>");
     xsdFile.println("  </xsd:sequence>");
     xsdFile.println("  <xsd:attribute name=\"name\" type=\"xsd:string\"/>");
     xsdFile.println("</xsd:complexType>");
     xsdFile.println();
     xsdFile.println("<xsd:complexType name=\"classType\">");
     xsdFile.println("  <xsd:sequence>");
     xsdFile.println(
         "    <xsd:element name=\"implements\" type=\"interfaceTypeName\" minOccurs='0' maxOccurs='unbounded'/>");
     xsdFile.println(
         "    <xsd:element name=\"constructor\" type=\"constructorType\" minOccurs='0' maxOccurs='unbounded'/>");
     xsdFile.println(
         "    <xsd:element name=\"method\" type=\"methodType\" minOccurs='0' maxOccurs='unbounded'/>");
     xsdFile.println(
         "    <xsd:element name=\"field\" type=\"fieldType\" minOccurs='0' maxOccurs='unbounded'/>");
     xsdFile.println(
         "    <xsd:element name=\"doc\" type=\"xsd:string\" minOccurs='0' maxOccurs='1'/>");
     xsdFile.println("  </xsd:sequence>");
     xsdFile.println("  <xsd:attribute name=\"name\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"extends\" type=\"xsd:string\" use='optional'/>");
     xsdFile.println("  <xsd:attribute name=\"abstract\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"src\" type=\"xsd:string\" use='optional'/>");
     xsdFile.println("  <xsd:attribute name=\"static\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"final\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"deprecated\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"visibility\" type=\"xsd:string\"/>");
     xsdFile.println("</xsd:complexType>");
     xsdFile.println();
     xsdFile.println("<xsd:complexType name=\"interfaceTypeName\">");
     xsdFile.println("  <xsd:attribute name=\"name\" type=\"xsd:string\"/>");
     xsdFile.println("</xsd:complexType>");
     xsdFile.println();
     xsdFile.println("<xsd:complexType name=\"constructorType\">");
     xsdFile.println("  <xsd:sequence>");
     xsdFile.println(
         "    <xsd:element name=\"exception\" type=\"exceptionType\" minOccurs='0' maxOccurs='unbounded'/>");
     xsdFile.println(
         "    <xsd:element name=\"doc\" type=\"xsd:string\" minOccurs='0' maxOccurs='1'/>");
     xsdFile.println("  </xsd:sequence>");
     xsdFile.println("  <xsd:attribute name=\"name\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"type\" type=\"xsd:string\" use='optional'/>");
     xsdFile.println("  <xsd:attribute name=\"src\" type=\"xsd:string\" use='optional'/>");
     xsdFile.println("  <xsd:attribute name=\"static\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"final\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"deprecated\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"visibility\" type=\"xsd:string\"/>");
     xsdFile.println("</xsd:complexType>");
     xsdFile.println();
     xsdFile.println("<xsd:complexType name=\"paramsType\">");
     xsdFile.println("  <xsd:attribute name=\"name\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"type\" type=\"xsd:string\"/>");
     xsdFile.println("</xsd:complexType>");
     xsdFile.println();
     xsdFile.println("<xsd:complexType name=\"exceptionType\">");
     xsdFile.println("  <xsd:attribute name=\"name\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"type\" type=\"xsd:string\"/>");
     xsdFile.println("</xsd:complexType>");
     xsdFile.println();
     xsdFile.println("<xsd:complexType name=\"methodType\">");
     xsdFile.println("  <xsd:sequence>");
     xsdFile.println(
         "    <xsd:element name=\"param\" type=\"paramsType\" minOccurs='0' maxOccurs='unbounded'/>");
     xsdFile.println(
         "    <xsd:element name=\"exception\" type=\"exceptionType\" minOccurs='0' maxOccurs='unbounded'/>");
     xsdFile.println(
         "    <xsd:element name=\"doc\" type=\"xsd:string\" minOccurs='0' maxOccurs='1'/>");
     xsdFile.println("  </xsd:sequence>");
     xsdFile.println("  <xsd:attribute name=\"name\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"return\" type=\"xsd:string\" use='optional'/>");
     xsdFile.println("  <xsd:attribute name=\"abstract\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"native\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"synchronized\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"src\" type=\"xsd:string\" use='optional'/>");
     xsdFile.println("  <xsd:attribute name=\"static\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"final\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"deprecated\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"visibility\" type=\"xsd:string\"/>");
     xsdFile.println("</xsd:complexType>");
     xsdFile.println();
     xsdFile.println("<xsd:complexType name=\"fieldType\">");
     xsdFile.println("  <xsd:sequence>");
     xsdFile.println(
         "    <xsd:element name=\"doc\" type=\"xsd:string\" minOccurs='0' maxOccurs='1'/>");
     xsdFile.println("  </xsd:sequence>");
     xsdFile.println("  <xsd:attribute name=\"name\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"type\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"transient\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"volatile\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"value\" type=\"xsd:string\" use='optional'/>");
     xsdFile.println("  <xsd:attribute name=\"src\" type=\"xsd:string\" use='optional'/>");
     xsdFile.println("  <xsd:attribute name=\"static\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"final\" type=\"xsd:boolean\"/>");
     xsdFile.println("  <xsd:attribute name=\"deprecated\" type=\"xsd:string\"/>");
     xsdFile.println("  <xsd:attribute name=\"visibility\" type=\"xsd:string\"/>");
     xsdFile.println("</xsd:complexType>");
     xsdFile.println();
     xsdFile.println("</xsd:schema>");
     xsdFile.close();
   } catch (IOException e) {
     System.out.println("IO Error while attempting to create " + xsdFileName);
     System.out.println("Error: " + e.getMessage());
     System.exit(1);
   }
 }