예제 #1
0
 /**
  * Given a PackageDoc, return the source path for that package.
  *
  * @param configuration The Configuration for the current Doclet.
  * @param pkgDoc The package to seach the path for.
  * @return A string representing the path to the given package.
  */
 public static String getPackageSourcePath(Configuration configuration, PackageDoc pkgDoc) {
   try {
     String pkgPath = DirectoryManager.getDirectoryPath(pkgDoc);
     String completePath =
         new SourcePath(configuration.sourcepath).getDirectory(pkgPath)
             + DirectoryManager.URL_FILE_SEPERATOR;
     // Make sure that both paths are using the same seperators.
     completePath =
         Util.replaceText(completePath, File.separator, DirectoryManager.URL_FILE_SEPERATOR);
     pkgPath = Util.replaceText(pkgPath, File.separator, DirectoryManager.URL_FILE_SEPERATOR);
     return completePath.substring(0, completePath.indexOf(pkgPath));
   } catch (Exception e) {
     return "";
   }
 }
예제 #2
0
 /**
  * Create the directory path for the file to be generated, construct FileOutputStream and
  * OutputStreamWriter depending upon docencoding.
  *
  * @param path The directory path to be created for this file.
  * @param filename File Name to which the PrintWriter will do the Output.
  * @param docencoding Encoding to be used for this file.
  * @exception IOException Exception raised by the FileWriter is passed on to next level.
  * @exception UnsupportedEncodingException Exception raised by the OutputStreamWriter is passed on
  *     to next level.
  * @return Writer Writer for the file getting generated.
  * @see java.io.FileOutputStream
  * @see java.io.OutputStreamWriter
  */
 public static Writer genWriter(
     Configuration configuration, String path, String filename, String docencoding)
     throws IOException, UnsupportedEncodingException {
   FileOutputStream fos;
   if (path != null) {
     DirectoryManager.createDirectory(configuration, path);
     fos = new FileOutputStream(((path.length() > 0) ? path + File.separator : "") + filename);
   } else {
     fos = new FileOutputStream(filename);
   }
   if (docencoding == null) {
     return new OutputStreamWriter(fos);
   } else {
     return new OutputStreamWriter(fos, docencoding);
   }
 }
예제 #3
0
 /**
  * Copy the given directory contents from the source package directory to the generated
  * documentation directory. For example for a package java.lang this method find out the source
  * location of the package using {@link SourcePath} and if given directory is found in the source
  * directory structure, copy the entire directory, to the generated documentation hierarchy.
  *
  * @param configuration The configuration of the current doclet.
  * @param path The relative path to the directory to be copied.
  * @param dir The original directory name to copy from.
  * @param overwrite Overwrite files if true.
  */
 public static void copyDocFiles(
     Configuration configuration, String path, String dir, boolean overwrite) {
   if (checkCopyDocFilesErrors(configuration, path, dir)) {
     return;
   }
   String destname = configuration.docFileDestDirName;
   File srcdir = new File(path + dir);
   if (destname.length() > 0 && !destname.endsWith(DirectoryManager.URL_FILE_SEPERATOR)) {
     destname += DirectoryManager.URL_FILE_SEPERATOR;
   }
   String dest = destname + dir;
   try {
     File destdir = new File(dest);
     DirectoryManager.createDirectory(configuration, dest);
     String[] files = srcdir.list();
     for (int i = 0; i < files.length; i++) {
       File srcfile = new File(srcdir, files[i]);
       File destfile = new File(destdir, files[i]);
       if (srcfile.isFile()) {
         if (destfile.exists() && !overwrite) {
           configuration.message.warning(
               (SourcePosition) null,
               "doclet.Copy_Overwrite_warning",
               srcfile.toString(),
               destdir.toString());
         } else {
           configuration.message.notice(
               "doclet.Copying_File_0_To_Dir_1", srcfile.toString(), destdir.toString());
           Util.copyFile(destfile, srcfile);
         }
       } else if (srcfile.isDirectory()) {
         if (configuration.copydocfilesubdirs
             && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
           copyDocFiles(
               configuration,
               path,
               dir + DirectoryManager.URL_FILE_SEPERATOR + srcfile.getName(),
               overwrite);
         }
       }
     }
   } catch (SecurityException exc) {
     throw new DocletAbortException();
   } catch (IOException exc) {
     throw new DocletAbortException();
   }
 }
 /** Copy the doc files for the current ClassDoc if necessary. */
 private void copyDocFiles() {
   PackageDoc containingPackage = annotationTypeDoc.containingPackage();
   if ((configuration.packages == null
           || Arrays.binarySearch(configuration.packages, containingPackage) < 0)
       && !containingPackagesSeen.contains(containingPackage.name())) {
     // Only copy doc files dir if the containing package is not
     // documented AND if we have not documented a class from the same
     // package already. Otherwise, we are making duplicate copies.
     Util.copyDocFiles(
         configuration,
         Util.getPackageSourcePath(configuration, annotationTypeDoc.containingPackage())
             + DirectoryManager.getDirectoryPath(annotationTypeDoc.containingPackage())
             + File.separator,
         DocletConstants.DOC_FILES_DIR_NAME,
         true);
     containingPackagesSeen.add(containingPackage.name());
   }
 }
예제 #5
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();
   }
 }
예제 #6
0
  /**
   * Copy a file in the resources directory to the 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 destination directory and error message
   * @param resourcefile The name of the resource file to copy
   * @param overwrite A flag to indicate whether the file in the destination directory will be
   *     overwritten if it already exists.
   */
  public static void copyResourceFile(
      Configuration configuration, String resourcefile, boolean overwrite) {
    String destdir = configuration.destDirName;
    String destresourcesdir = destdir + "resources";
    DirectoryManager.createDirectory(configuration, destresourcesdir);
    File destfile = new File(destresourcesdir, resourcefile);
    if (destfile.exists() && (!overwrite)) return;
    try {

      InputStream in = Configuration.class.getResourceAsStream("resources/" + resourcefile);

      if (in == null) return;

      OutputStream out = new FileOutputStream(destfile);
      byte[] buf = new byte[2048];
      int n;
      while ((n = in.read(buf)) > 0) out.write(buf, 0, n);

      in.close();
      out.close();
    } catch (Throwable t) {
    }
  }