Beispiel #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());
      }
    }
  }
Beispiel #2
0
  /**
   * Concatenates a class path in the order specified by the ${build.sysclasspath} property - using
   * the supplied value if ${build.sysclasspath} has not been set.
   */
  private Path concatSpecialPath(String defValue, Path p) {
    Path result = new Path(getProject());

    String order = defValue;
    String o =
        getProject() != null
            ? getProject().getProperty(MagicNames.BUILD_SYSCLASSPATH)
            : System.getProperty(MagicNames.BUILD_SYSCLASSPATH);
    if (o != null) {
      order = o;
    }
    if (order.equals("only")) {
      // only: the developer knows what (s)he is doing
      result.addExisting(p, true);

    } else if (order.equals("first")) {
      // first: developer could use a little help
      result.addExisting(p, true);
      result.addExisting(this);

    } else if (order.equals("ignore")) {
      // ignore: don't trust anyone
      result.addExisting(this);

    } else {
      // last: don't trust the developer
      if (!order.equals("last")) {
        log("invalid value for " + MagicNames.BUILD_SYSCLASSPATH + ": " + order, Project.MSG_WARN);
      }
      result.addExisting(this);
      result.addExisting(p, true);
    }
    return result;
  }
Beispiel #3
0
  private void doForkCommandLineList(
      List<String> commandLineList, Path classpath, String separator) {
    if (!fork) return;

    if (includeAntRuntime) {
      classpath.addExisting((new Path(getProject())).concatSystemClasspath("last"));
    }
    if (includeJavaRuntime) {
      classpath.addJavaRuntime();
    }

    if (forkedExecutable != null && !forkedExecutable.equals("")) {
      commandLineList.add(forkedExecutable);
    } else {
      String javaHome;
      if (forkJavaHome != null) {
        javaHome = forkJavaHome.getPath();
      } else {
        javaHome = System.getProperty("java.home");
      }
      commandLineList.add(javaHome + separator + "bin" + separator + "java");
    }
    commandLineList.add("-classpath");
    commandLineList.add(classpath.toString());

    final String fileEncodingProp = System.getProperty("file.encoding");
    if ((fileEncodingProp != null) && !fileEncodingProp.equals("")) {
      commandLineList.add("-Dfile.encoding=" + fileEncodingProp);
    }
    if (targetBytecode != null) {
      commandLineList.add("-Dgroovy.target.bytecode=" + targetBytecode);
    }

    if ((memoryInitialSize != null) && !memoryInitialSize.equals("")) {
      commandLineList.add("-Xms" + memoryInitialSize);
    }
    if ((memoryMaximumSize != null) && !memoryMaximumSize.equals("")) {
      commandLineList.add("-Xmx" + memoryMaximumSize);
    }
    if (!"*.groovy".equals(getScriptExtension())) {
      String tmpExtension = getScriptExtension();
      if (tmpExtension.startsWith("*.")) tmpExtension = tmpExtension.substring(1);
      commandLineList.add("-Dgroovy.default.scriptExtension=" + tmpExtension);
    }
    commandLineList.add(FileSystemCompilerFacade.class.getName());
    if (forceLookupUnnamedFiles) {
      commandLineList.add("--forceLookupUnnamedFiles");
    }
  }
Beispiel #4
0
  /** Add the Java Runtime classes to this Path instance. */
  public void addJavaRuntime() {
    if (JavaEnvUtils.isKaffe()) {
      // newer versions of Kaffe (1.1.1+) won't have this,
      // but this will be sorted by FileSet anyway.
      File kaffeShare =
          new File(
              System.getProperty("java.home")
                  + File.separator
                  + "share"
                  + File.separator
                  + "kaffe");
      if (kaffeShare.isDirectory()) {
        FileSet kaffeJarFiles = new FileSet();
        kaffeJarFiles.setDir(kaffeShare);
        kaffeJarFiles.setIncludes("*.jar");
        addFileset(kaffeJarFiles);
      }
    } else if ("GNU libgcj".equals(System.getProperty("java.vm.name"))) {
      addExisting(systemBootClasspath);
    }

    if (System.getProperty("java.vendor").toLowerCase(Locale.ENGLISH).indexOf("microsoft") >= 0) {
      // TODO is this code still necessary? is there any 1.2+ port?
      // Pull in *.zip from packages directory
      FileSet msZipFiles = new FileSet();
      msZipFiles.setDir(new File(System.getProperty("java.home") + File.separator + "Packages"));
      msZipFiles.setIncludes("*.ZIP");
      addFileset(msZipFiles);
    } else {
      // JDK 1.2+ seems to set java.home to the JRE directory.
      addExisting(
          new Path(
              null,
              System.getProperty("java.home")
                  + File.separator
                  + "lib"
                  + File.separator
                  + "rt.jar"));
      // Just keep the old version as well and let addExisting
      // sort it out.
      addExisting(
          new Path(
              null,
              System.getProperty("java.home")
                  + File.separator
                  + "jre"
                  + File.separator
                  + "lib"
                  + File.separator
                  + "rt.jar"));

      // Sun's and Apple's 1.4 have JCE and JSSE in separate jars.
      String[] secJars = {"jce", "jsse"};
      for (int i = 0; i < secJars.length; i++) {
        addExisting(
            new Path(
                null,
                System.getProperty("java.home")
                    + File.separator
                    + "lib"
                    + File.separator
                    + secJars[i]
                    + ".jar"));
        addExisting(
            new Path(
                null,
                System.getProperty("java.home")
                    + File.separator
                    + ".."
                    + File.separator
                    + "Classes"
                    + File.separator
                    + secJars[i]
                    + ".jar"));
      }

      // IBM's 1.4 has rt.jar split into 4 smaller jars and a combined
      // JCE/JSSE in security.jar.
      String[] ibmJars = {"core", "graphics", "security", "server", "xml"};
      for (int i = 0; i < ibmJars.length; i++) {
        addExisting(
            new Path(
                null,
                System.getProperty("java.home")
                    + File.separator
                    + "lib"
                    + File.separator
                    + ibmJars[i]
                    + ".jar"));
      }

      // Added for MacOS X
      addExisting(
          new Path(
              null,
              System.getProperty("java.home")
                  + File.separator
                  + ".."
                  + File.separator
                  + "Classes"
                  + File.separator
                  + "classes.jar"));
      addExisting(
          new Path(
              null,
              System.getProperty("java.home")
                  + File.separator
                  + ".."
                  + File.separator
                  + "Classes"
                  + File.separator
                  + "ui.jar"));
    }
  }
Beispiel #5
0
 /**
  * Adds the components on the given path which exist to this Path. Components that don't exist
  * aren't added.
  *
  * @param source - source path whose components are examined for existence
  */
 public void addExisting(Path source) {
   addExisting(source, false);
 }