Package org.apache.tools.ant

Examples of org.apache.tools.ant.BuildException


        line = br.readLine();
      }
    } catch (Throwable t) {
      final String msg = "Failed to get version from '" +res.toString()
        +"'; " +t.getMessage();
      throw new BuildException(msg, t);
    }
    return null;
  }
View Full Code Here


                   +newVersion +" based on data from '" +pkgInfoPath +"'.",
                   Project.MSG_VERBOSE);
        } else if (!newVersion.equals(curVersion)) {
          // May happen when the classes of a package are in two
          // different directories on the class path.
          throw new BuildException("Conflicting versions for '"
                                   +pkgName +"' previous  '"
                                   +curVersion +"' from '"
                                   +curPkgInfoPath +"', new '"
                                   +newVersion +"' in '"
                                   +pkgInfoPath +"'.");
View Full Code Here

  }

  public void addConfiguredHtmlFragment(HtmlFragment fragment) {
    final String name = fragment.getName();
    if (name == null) {
      throw new BuildException("Nested HTML-fragments must have a name");
    }
    if (null==fragment.getFromFile()) {
      throw new BuildException("Nested HTML-fragments must have a from file");
    }
    fragments.put(name, fragment);
  }
View Full Code Here

  public void execute() {
    Project proj = getProject();
    this.projectName = proj.getName();

    if (template == null) throw new BuildException("template must be set");
    if (title == null) title = "";
    if (description == null) description = "";

    if (filesets.isEmpty() && fromFile == null && toFile == null) {
      throw new BuildException("Need to specify tofile and fromfile or give a fileset");
    }

    if (filesets.isEmpty()) {
      // log("Project base is: " + getProject().getBaseDir());
      // log("Attempting to transform: " + fromFile);
      if (!FileUtils.isAbsolutePath(fromFile)) {
        fromFile = getProject().getBaseDir() + File.separator + fromFile;
      }
      transform(fromFile, toFile.toString());
    } else {
      if (fromFile != null)
        throw new BuildException("Can not specify fromfile when using filesets");
      if (toFile != null)
        throw new BuildException("Can not specify tofile when using filesets");

      for (Iterator iter = filesets.iterator(); iter.hasNext(); ) {
        FileSet fs = (FileSet) iter.next();
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        String[] files = ds.getIncludedFiles();
View Full Code Here

      }
    }
  }

  private void transform(String fromFile, String toFile) {
    if (fromFile == null) throw new BuildException("fromfile must be set");
    if (toFile == null) throw new BuildException("tofile must be set");

    try {
      Project proj = getProject();
      File tmp = new File(outdir, toFile).getParentFile();

      if (!tmp.exists()) {
        if (tmp.exists() || !tmp.mkdirs()) {
          throw new IOException("Could not create " + tmp);
        }
      }

      tmp = new File(toFile);
      String pathToRoot = ".";

      while ((tmp = tmp.getParentFile()) != null) {
        pathToRoot = pathToRoot + "/..";
      }

      // Compute the relative path from directory holding the toFile
      // to the javadoc direcotry.
      String pathToOutDir = "";
      tmp = new File(outdir, toFile).getParentFile();
      while ((tmp = tmp.getParentFile()) != null && tmp.equals(outdir)) {
        pathToOutDir = pathToOutDir + "../";
      }
      final String pathToJavadocDir = pathToOutDir + javadocRelPath;

      String content = Util.loadFile(template.toString());
      content = Util.replace(content, "$(LINKS)", links());
      content = Util.replace(content, "$(MAIN)", Util.loadFile(fromFile));
      for (Iterator it = fragments.keySet().iterator(); it.hasNext(); ) {
        final String key = (String) it.next();
        final HtmlFragment frag = (HtmlFragment) fragments.get(key);
        final String linkText = frag.getLinkText();
        if (null!=linkText && 0<linkText.length()) {
          String fragLink = "<a href=\"#" +key +"\">" +linkText +"</a>";
          content = Util.replace(content, "$("+key +"_LINK)", fragLink);
        }
        String fragCont = Util.loadFile(frag.getFromFile().getPath());
        if (null!=fragCont && 0<fragCont.length()) {
          fragCont = "<a name=\"" +key +"\"></a>\n" + fragCont;
        }
        content = Util.replace(content, "$("+key +")", fragCont);
      }
      content = Util.replace(content, "$(TITLE)", title);
      content = Util.replace(content, "$(DESC)", description);
      content = Util.replace(content, "$(TSTAMP)", TIMESTAMP);
      content = Util.replace(content, "$(YEAR)", YEAR);
      content = Util.replace(content, "$(USER)",
                             System.getProperty("user.name"));
      content = Util.replace(content, "$(VERSION)",
                             proj.getProperty("version"));
      content = Util.replace(content, "$(BASE_VERSION)",
                             proj.getProperty("base_version"));
      content = Util.replace(content, "$(DISTNAME)",
                             proj.getProperty("distname"));
      content = Util.replace(content, "$(DISTRIB_NAME)",
                             proj.getProperty("distrib.name"));
      content = Util.replace(content, "$(RELEASE_NAME)",
                             proj.getProperty("release.name"));
      content = Util.replace(content, "$(MESSAGE)",
                             proj.getProperty("release"));
      content = Util.replace(content, "$(BUNDLE_LIST)", bundleList);
      content = Util.replace(content, "$(ROOT)", pathToRoot);
      content = Util.replace(content, "$(JAVADOC)",
                             proj.getProperty("JAVADOC"));
      content = Util.replace(content, "$(CLASS_NAVIGATION)",
                             proj.getProperty("css_navigation_enabled"));
      content = Util.replace(content, "$(SVN_REPO_URL)",
                             proj.getProperty("svn.repo.url"));
      content = Util.replace(content, "$(SVN_TAG)",proj.getProperty("svn.tag"));
      content = Util.replace(content, "$(JAVADOCPATH)", pathToJavadocDir);
      content = Util.replace(content, "$(JAVADOCLINK)",
                             pathToJavadocDir + "/index.html?");

      // Used for bundle_doc generation
      if (do_manpage) {
        content = Util.replace(content, "$(BUNDLE_NAME)", this.projectName);
        content = Util.replace(content, "$(BUNDLE_VERSION)",
                               proj.getProperty("bmfa.Bundle-Version"));

        final BundleArchives bas = getBundleArchives();

        // Create links to jardoc for bundles built from this project
        content = Util.replace(content, "$(BUNDLE_JARDOCS)", basToString(bas));

        content = Util.replace(content, "$(BUNDLE_EXPORT_PACKAGE)",
                               getExportPkgs(bas, pathToJavadocDir));

        // Replce H1-H3 headers to man page style, if manpage style
        content = Util.replace(content, "<h1", "<h1 class=\"man\"");
        content = Util.replace(content, "<H1", "<h1 class=\"man\"");
        content = Util.replace(content, "<h2", "<h2 class=\"man\"");
        content = Util.replace(content, "<H2", "<h2 class=\"man\"");
        content = Util.replace(content, "<h3", "<h3 class=\"man\"");
        content = Util.replace(content, "<H3", "<h3 class=\"man\"");
      }

      String s = proj.getProperty("navigation_pages");
      String navEnabled = proj.getProperty("css_navigation_enabled");
      String navDisabled = proj.getProperty("css_navigation_disabled");
      // System.out.println("Navigation pages: " + s);
      if (s != null) {
        String[] navPages = Util.splitwords(s);
        for (int i = 0; i < navPages.length; i++) {
          // System.out.println("Checking: " + navPages[i]);
          if (disable != null && disable.equals(navPages[i])) {
            content = Util.replace(content,
                                   "$(CLASS_NAVIGATION_" + navPages[i] + ")",
                                   navDisabled);
          }
          else {
            content = Util.replace(content,
                                   "$(CLASS_NAVIGATION_" + navPages[i] + ")",
                                   navEnabled);
          }
        }
      }

      Util.writeStringToFile(new File(outdir, toFile), content);
      log("Created: " + new File(outdir, toFile));
    } catch (IOException e) {
      e.printStackTrace();
      throw new BuildException(e);
    } catch (Exception e) {
      e.printStackTrace();
      throw new BuildException(e);
    }
  }
View Full Code Here

        break;
      }

      String type = proj.getProperty(LINK_TYPE + i);
      if (type == null) {
        throw new BuildException("must set htdocs.link.type." + i);
      }

      if (type.equals("separator")) {
        buf.append("<p></p>");

      } else if (type.equals("link")) {

        String name = proj.getProperty(LINK_NAME + i);
        String url  = proj.getProperty(LINK_URL + i);
        if (name == null) {
          throw new BuildException("Name not set for htdocs.link.url." + i);
        }

        String cssClass = null;

        if (disable != null && disable.equals(id)) {
          cssClass = getProject().getProperty(CSS_CLASS_DISABLED);
        } else {
          cssClass = getProject().getProperty(CSS_CLASS_ENABLED);
        }

        buf.append("<a class=\"" + cssClass + "\" href=\"" + url
                   + "\">" + name + "</a><br/>\n");
      } else {
        throw new BuildException("Do not recognize type " + type);
      }
    }

    return buf.toString();
  }
View Full Code Here

  private void validateHelpdoc(Helpdoc helpdoc) throws BuildException {
    if (helpdoc.getTemplateitem() != null) {
      File template = new File(helpdoc.getTemplateitem());

      if (template.exists() && template.isDirectory()) {
        throw new BuildException(getMsg(I18N_HELPDOC_TEMPLATE_ITEM_FILE_NOT_A_FILE, helpdoc.getTemplateitem()));
      }
    }

    if (helpdoc.getTemplateheader() != null) {
      File template = new File(helpdoc.getTemplateheader());

      if (template.exists() && template.isDirectory()) {
        throw new BuildException(getMsg(I18N_HELPDOC_TEMPLATE_HEADER_FILE_NOT_A_FILE, helpdoc.getTemplateheader()));
      }
    }

    if (helpdoc.getTemplatefooter() != null) {
      File template = new File(helpdoc.getTemplatefooter());

      if (template.exists() && template.isDirectory()) {
        throw new BuildException(getMsg(I18N_HELPDOC_TEMPLATE_FOOTER_FILE_NOT_A_FILE, helpdoc.getTemplatefooter()));
      }
    }

    if (helpdoc.getOutputdir() == null) {
      throw new BuildException(getMsg(I18N_HELPDOC_OUTPUT_DIR_IS_NULL));
    }

    File output = new File(helpdoc.getOutputdir());

    if (output.exists()) {
      if (!output.isDirectory()) {
        throw new BuildException(getMsg(I18N_HELPDOC_OUTPUT_DIR_NOT_A_DIR, helpdoc.getOutputdir()));
      }
    }
    else {
      output.mkdirs();

      if (!output.isDirectory()) {
        throw new BuildException(getMsg(I18N_HELPDOC_CANNOT_CREATE_OUTPUT_DIR, helpdoc.getOutputdir()));
      }
    }

    return;
  }
View Full Code Here

      }

      to_stream.flush();
    }
    catch (Exception e) {
      throw new BuildException(getMsg(FAILED_TO_COPY_BUNDLE, from_file, to_file, e.getMessage()), e);
    }
    finally {
      try {
        if (to_stream != null) {
          to_stream.close();
View Full Code Here

   *
   * @throws BuildException if the task configuration was invalid in some way
   */
  private void validateTaskConfiguration() throws BuildException {
    if (message == null) {
      throw new BuildException(Msg.createMsg(BUNDLE_BASE_NAME, I18NMSG_MISSING_MESSAGE).toString());
    }

    return;
  }
View Full Code Here

   *
   * @throws BuildException if the helpdoc element was specified more than once
   */
  public void addConfiguredHelpdoc(Helpdoc helpdoc) throws BuildException {
    if (m_helpdoc != null) {
      throw new BuildException(getMsg(I18N_HELPDOC_ALREADY_SPECIFIED));
    }

    m_helpdoc = helpdoc;

    return;
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.BuildException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.