Ejemplo n.º 1
0
  public void execute() throws BuildException {
    List<String> packagesToDoc = new ArrayList<String>();
    Path sourceDirs = new Path(getProject());
    Properties properties = new Properties();
    properties.setProperty("windowTitle", windowTitle);
    properties.setProperty("docTitle", docTitle);
    properties.setProperty("footer", footer);
    properties.setProperty("header", header);
    checkScopeProperties(properties);
    properties.setProperty("publicScope", publicScope.toString());
    properties.setProperty("protectedScope", protectedScope.toString());
    properties.setProperty("packageScope", packageScope.toString());
    properties.setProperty("privateScope", privateScope.toString());
    properties.setProperty("author", author.toString());
    properties.setProperty("processScripts", processScripts.toString());
    properties.setProperty("includeMainForScripts", includeMainForScripts.toString());
    properties.setProperty(
        "overviewFile", overviewFile != null ? overviewFile.getAbsolutePath() : "");
    properties.setProperty("charset", charset != null ? charset : "");
    properties.setProperty("fileEncoding", fileEncoding != null ? fileEncoding : "");

    if (sourcePath != null) {
      sourceDirs.addExisting(sourcePath);
    }
    parsePackages(packagesToDoc, sourceDirs);

    GroovyDocTool htmlTool =
        new GroovyDocTool(
            new ClasspathResourceManager(), // we're gonna get the default templates out of the dist
                                            // jar file
            sourcePath.list(),
            getDocTemplates(),
            getPackageTemplates(),
            getClassTemplates(),
            links,
            properties);

    try {
      htmlTool.add(sourceFilesToDoc);
      FileOutputTool output = new FileOutputTool();
      htmlTool.renderToOutput(
          output, destDir.getCanonicalPath()); // TODO push destDir through APIs?
    } catch (Exception e) {
      e.printStackTrace();
    }
    // try to override the default stylesheet with custom specified one if needed
    if (styleSheetFile != null) {
      try {
        String css = ResourceGroovyMethods.getText(styleSheetFile);
        File outfile = new File(destDir, "stylesheet.css");
        ResourceGroovyMethods.setText(outfile, css);
      } catch (IOException e) {
        System.out.println(
            "Warning: Unable to copy specified stylesheet '"
                + styleSheetFile.getAbsolutePath()
                + "'. Using default stylesheet instead. Due to: "
                + e.getMessage());
      }
    }
  }
Ejemplo n.º 2
0
 public String getText(String urlOrFilename) throws IOException {
   if (isScriptUrl(urlOrFilename)) {
     try {
       return ResourceGroovyMethods.getText(new URL(urlOrFilename));
     } catch (Exception e) {
       throw new GroovyRuntimeException("Unable to get script from URL: ", e);
     }
   }
   return ResourceGroovyMethods.getText(huntForTheScriptFile(urlOrFilename));
 }
Ejemplo n.º 3
0
 private Object parseURL(URL url, Map params, String charset) {
   Reader reader = null;
   try {
     if (params == null || params.isEmpty()) {
       reader = ResourceGroovyMethods.newReader(url, charset);
     } else {
       reader = ResourceGroovyMethods.newReader(url, params, charset);
     }
     return parse(reader);
   } catch (IOException ioe) {
     throw new JsonException("Unable to process url: " + url.toString(), ioe);
   } finally {
     if (reader != null) {
       DefaultGroovyMethodsSupport.closeWithWarning(reader);
     }
   }
 }
Ejemplo n.º 4
0
 private Object parseFile(File file, String charset) {
   Reader reader = null;
   try {
     if (charset == null || charset.length() == 0) {
       reader = ResourceGroovyMethods.newReader(file);
     } else {
       reader = ResourceGroovyMethods.newReader(file, charset);
     }
     return parse(reader);
   } catch (IOException ioe) {
     throw new JsonException("Unable to process file: " + file.getPath(), ioe);
   } finally {
     if (reader != null) {
       DefaultGroovyMethodsSupport.closeWithWarning(reader);
     }
   }
 }