/**
  * Implementation of ResourceSelector.isSelected().
  *
  * @param resource The resource to check
  * @return whether the resource is selected
  * @see ResourceSelector#isSelected(Resource)
  */
 public boolean isSelected(Resource resource) {
   if (resource.isFilesystemOnly()) {
     // We have a 'resourced' file, so reconvert it and use
     // the 'old' implementation.
     FileResource fileResource = (FileResource) resource;
     File file = fileResource.getFile();
     String filename = fileResource.getName();
     File basedir = fileResource.getBaseDir();
     return isSelected(basedir, filename, file);
   } else {
     try {
       // How to handle non-file-Resources? I copy temporarily the
       // resource to a file and use the file-implementation.
       FileUtils fu = FileUtils.getFileUtils();
       File tmpFile = fu.createTempFile("modified-", ".tmp", null, true, false);
       Resource tmpResource = new FileResource(tmpFile);
       ResourceUtils.copyResource(resource, tmpResource);
       boolean isSelected =
           isSelected(tmpFile.getParentFile(), tmpFile.getName(), resource.toLongString());
       tmpFile.delete();
       return isSelected;
     } catch (UnsupportedOperationException uoe) {
       log(
           "The resource '"
               + resource.getName()
               + "' does not provide an InputStream, so it is not checked. "
               + "Akkording to 'selres' attribute value it is "
               + ((selectResourcesWithoutInputStream) ? "" : " not")
               + "selected.",
           Project.MSG_INFO);
       return selectResourcesWithoutInputStream;
     } catch (Exception e) {
       throw new BuildException(e);
     }
   }
 }
Exemple #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);
    }
  }
Exemple #3
0
 /**
  * Convenience method to copy content from one Resource to another. No filtering is performed.
  *
  * @param source the Resource to copy from. Must not be <code>null</code>.
  * @param dest the Resource to copy to. Must not be <code>null</code>.
  * @param project the project instance.
  * @throws IOException if the copying fails.
  * @since Ant 1.7
  */
 public static void copyResource(Resource source, Resource dest, Project project)
     throws IOException {
   copyResource(source, dest, null, null, false, false, null, null, project);
 }
Exemple #4
0
 /**
  * Convenience method to copy content from one Resource to another. No filtering is performed.
  *
  * @param source the Resource to copy from. Must not be <code>null</code>.
  * @param dest the Resource to copy to. Must not be <code>null</code>.
  * @throws IOException if the copying fails.
  * @since Ant 1.7
  */
 public static void copyResource(Resource source, Resource dest) throws IOException {
   copyResource(source, dest, null);
 }