示例#1
0
 /**
  * Optional. Sets the window title of the Xref HTML files. Defaults to "${project.name} Xref
  * Documentation".
  *
  * @param windowTitle The window title to set.
  */
 public void setWindowTitle(String windowTitle) {
   this.log("Setting window title to: " + windowTitle, LogLevel.DEBUG.getLevel());
   this.windowTitle = new StringResource(this.getProject(), windowTitle);
 }
示例#2
0
  @Override
  public void execute() throws BuildException {
    this.log("Generating Xref documentation", LogLevel.INFO.getLevel());
    if (this.destDir == null) {
      throw new BuildException("Destination directory not specified.");
    }

    if (this.inputEncoding == null) {
      this.inputEncoding = DEFAULT_ENCODING;
    }
    if (this.outputEncoding == null) {
      this.outputEncoding = DEFAULT_ENCODING;
    }
    if (this.windowTitle == null) {
      this.windowTitle =
          new StringResource(
              this.getProject(), String.format(DEFAULT_WINDOW_TITLE, this.getProject().getName()));
    }
    if (this.docTitle == null) {
      this.docTitle =
          new StringResource(
              this.getProject(), String.format(DEFAULT_DOC_TITLE, this.getProject().getName()));
    }
    if (this.bottom == null) {
      this.bottom = new StringResource(this.getProject(), DEFAULT_BOTTOM);
    }

    List<String> sourcePathStrings = Arrays.asList(this.sourcePaths.list());
    if (sourcePathStrings.isEmpty()) {
      throw new BuildException("No source paths defined.");
    }

    if (this.includesExcludes != null) {
      String[] includePatterns = this.includesExcludes.getIncludePatterns(this.getProject());
      String[] excludePatterns = this.includesExcludes.getExcludePatterns(this.getProject());
      this.jxr.setIncludes(includePatterns);
      this.jxr.setExcludes(excludePatterns);
    }

    String templatePathStr = DEFAULT_TEMPLATE_PATH;
    if (this.templateDir != null && this.templateDir.isDirectory()) {
      templatePathStr = this.templateDir.toString();
    }
    if (this.javadocDir != null && this.javadocDir.isDirectory()) {
      this.log("Setting javadoc directory to " + javadocDir, LogLevel.DEBUG.getLevel());
      this.jxr.setJavadocLinkDir(this.javadocDir.toString());
    }

    this.jxr.setOutputEncoding(this.outputEncoding);
    this.jxr.setInputEncoding(this.inputEncoding);
    this.jxr.setDest(this.destDir.toString());

    try {
      this.jxr.xref(
          sourcePathStrings,
          templatePathStr,
          this.windowTitle.getValue(),
          this.docTitle.getValue(),
          this.bottom.getValue());

      if (this.stylesheet == null) {
        URL defaultStylesheetUrl =
            this.getClass().getResource("/com/mattbertolini/jxr/ant/stylesheet.css");
        this.stylesheet = new URLResource(defaultStylesheetUrl);
      }
      FileResource destStylesheet = new FileResource(this.destDir.getFile(), "stylesheet.css");
      ResourceUtils.copyResource(this.stylesheet, destStylesheet);

    } catch (IOException e) {
      throw new BuildException("Exception while running XJR task. " + e.getMessage(), e);
    } catch (JxrException e) {
      throw new BuildException("Exception running XJR task. " + e.getMessage(), e);
    }
  }
示例#3
0
 /**
  * Optional. Set a custom stylesheet to be used
  *
  * @param stylesheet The custom stylesheet
  */
 public void setStylesheet(FileResource stylesheet) {
   this.log("Setting custom stylesheet " + stylesheet.toString(), LogLevel.DEBUG.getLevel());
   this.stylesheet = stylesheet;
 }
示例#4
0
 /**
  * Optional. Sets the window title of the Xref HTML files. Defaults to "${project.name} Xref
  * Documentation".
  *
  * @param windowTitle The window title to set.
  */
 public void addWindowTitle(StringResource windowTitle) {
   this.log("Setting window title", LogLevel.DEBUG.getLevel());
   this.windowTitle = windowTitle;
 }
示例#5
0
 /**
  * Optional. Sets the file encoding to be used when reading the input files. Defaults to the
  * system file encoding.
  *
  * @param inputEncoding The file encoding.
  */
 public void setInputEncoding(String inputEncoding) {
   this.log("Setting input encoding to " + inputEncoding, LogLevel.DEBUG.getLevel());
   this.inputEncoding = inputEncoding;
 }
示例#6
0
 /**
  * Optional. Set the file encoding of the generated files. Defaults to the system file encoding.
  *
  * @param outputEncoding The encoding to set.
  */
 public void setOutputEncoding(String outputEncoding) {
   this.log("Setting output encoding to " + outputEncoding, LogLevel.DEBUG.getLevel());
   this.outputEncoding = outputEncoding;
 }
示例#7
0
 /**
  * Optional. Sets the title of the main page of Xref HTML pages. Defaults to "${project.name} Xref
  * Documentation".
  *
  * @param docTitle The doc title.
  */
 public void setDocTitle(String docTitle) {
   this.log("Setting doc title to: " + docTitle, LogLevel.DEBUG.getLevel());
   this.docTitle = new StringResource(this.getProject(), docTitle);
 }
示例#8
0
 /**
  * Optional. Sets the title of the main page of Xref HTML pages. Defaults to "${project.name} Xref
  * Documentation".
  *
  * @param docTitle The doc title
  */
 public void addDocTitle(StringResource docTitle) {
   this.log("Setting doc title", LogLevel.DEBUG.getLevel());
   this.docTitle = docTitle;
 }
示例#9
0
 /**
  * Optional.
  *
  * @param bottom The footer text.
  */
 public void setBottom(String bottom) {
   this.log("Setting bottom text", LogLevel.DEBUG.getLevel());
   this.bottom = new StringResource(this.getProject(), bottom);
 }
示例#10
0
 /**
  * Optional.
  *
  * @param bottom The footer text.
  */
 public void addBottom(StringResource bottom) {
   this.log("Setting bottom text", LogLevel.DEBUG.getLevel());
   this.bottom = bottom;
 }
示例#11
0
 public void execute() {
   if (repoDir == null) {
     log("repoDir attribute is empty !", LogLevel.ERR.getLevel());
     throw new RuntimeException("Bad attributes for apt-repo task");
   }
   log("repo dir: " + repoDir);
   File repoFolder = new File(repoDir);
   if (!repoFolder.exists()) {
     repoFolder.mkdirs();
   }
   File[] files =
       repoFolder.listFiles(
           new FileFilter() {
             public boolean accept(File pathname) {
               if (pathname.getName().endsWith(FILE_DEB_EXT)) {
                 return true;
               }
               return false;
             }
           });
   Packages packages = new Packages();
   for (int i = 0; i < files.length; i++) {
     File file = files[i];
     PackageEntry packageEntry = new PackageEntry();
     packageEntry.setSize(file.length());
     packageEntry.setSha1(Utils.getDigest("SHA-1", file));
     packageEntry.setSha256(Utils.getDigest("SHA-256", file));
     packageEntry.setMd5sum(Utils.getDigest("MD5", file));
     String fileName = file.getName();
     packageEntry.setFilename(fileName);
     log("found deb: " + fileName);
     try {
       ArchiveInputStream control_tgz;
       ArArchiveEntry entry;
       TarArchiveEntry control_entry;
       ArchiveInputStream debStream =
           new ArchiveStreamFactory().createArchiveInputStream("ar", new FileInputStream(file));
       while ((entry = (ArArchiveEntry) debStream.getNextEntry()) != null) {
         if (entry.getName().equals("control.tar.gz")) {
           ControlHandler controlHandler = new ControlHandler();
           GZIPInputStream gzipInputStream = new GZIPInputStream(debStream);
           control_tgz =
               new ArchiveStreamFactory().createArchiveInputStream("tar", gzipInputStream);
           while ((control_entry = (TarArchiveEntry) control_tgz.getNextEntry()) != null) {
             log("control entry: " + control_entry.getName(), LogLevel.DEBUG.getLevel());
             if (control_entry.getName().trim().equals(CONTROL_FILE_NAME)) {
               ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
               IOUtils.copy(control_tgz, outputStream);
               String content_string = outputStream.toString("UTF-8");
               outputStream.close();
               controlHandler.setControlContent(content_string);
               log("control cont: " + outputStream.toString("utf-8"), LogLevel.DEBUG.getLevel());
               break;
             }
           }
           control_tgz.close();
           if (controlHandler.hasControlContent()) {
             controlHandler.handle(packageEntry);
           } else {
             throw new RuntimeException("no control content found for: " + file.getName());
           }
           break;
         }
       }
       debStream.close();
       packages.addPackageEntry(packageEntry);
     } catch (Exception e) {
       String msg = FAILED_TO_CREATE_APT_REPO + " " + file.getName();
       log(msg, e, LogLevel.ERR.getLevel());
       throw new RuntimeException(msg, e);
     }
   }
   try {
     File packagesFile = new File(repoDir, PACKAGES_GZ);
     packagesWriter =
         new BufferedWriter(
             new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(packagesFile))));
     packagesWriter.write(packages.toString());
     DefaultHashes hashes = Utils.getDefaultDigests(packagesFile);
     ReleaseInfo pinfo = new ReleaseInfo(PACKAGES_GZ, packagesFile.length(), hashes);
     Release release = new Release();
     release.addInfo(pinfo);
     final File releaseFile = new File(repoDir, RELEASE);
     FileUtils.fileWrite(releaseFile, release.toString());
   } catch (IOException e) {
     throw new RuntimeException("writing files failed", e);
   } finally {
     if (packagesWriter != null) {
       try {
         packagesWriter.close();
       } catch (IOException e) {
         throw new RuntimeException("writing files failed", e);
       }
     }
   }
 }