Package org.moxie

Examples of org.moxie.MoxieException


   * @throws BuildException
   *             Description of the Exception
   */
  public void setJar(String file) throws MoxieException {
    if (dir != null) {
      throw new MoxieException(
          "GenJar: Can't specify both file and dir in a <library> element");
    }

    File jarFile;
    //
    // try as an absolute path first - if not found
    // then try as a relative path - if still not
    // found then puke
    //
    jarFile = new File(file);
    if (!jarFile.exists()) {
      jarFile = new File(baseDir, file);
      if (!jarFile.exists()) {
        throw new MoxieException(
            "GenJar: specified library jar not found (" + file
                + ")");
      }
    }
    this.jar = jarFile;
View Full Code Here


    // Add the library dir path to the classpath
    // so files can be found with out a classpath being set.
    classpath.setLocation(new File(dir));

    if (jar != null) {
      throw new MoxieException(
          "GenJar: Can't specify both file and dir in a <library> element");
    }
    //
    // if they speced an absolute path then handle it w/o the
    // project baseDir - otherwise we've gotta use the baseDir
    // to make sure we're refering to the right thing
    //
    // the chopPath string is used later to remove part of each file's
    // path so their 'jar names' are relative to the speced dir
    //
    if (dir.charAt(0) == '/' || dir.charAt(0) == '\\'
        || dir.charAt(1) == ':') {
      if (dir.endsWith("/*")) {
        dir = dir.substring(0, dir.length() - 2);
        chopPath = dir;
      } else {
        chopPath = "";
      }
      dirFile = new File(dir);
    } else {
      if (dir.endsWith("/*") || dir.endsWith("\\*")) {
        dir = dir.substring(0, dir.length() - 2);
        File temp = new File(baseDir, dir);
        chopPath = temp.toString();
      } else {
        chopPath = baseDir.toString();
      }
      dirFile = new File(baseDir, dir);
    }
    if (!dirFile.exists()) {
      throw new MoxieException(
          "GenJar: Specified library dir not found (" + jar + ")");
    }
    this.dir = dirFile;
  }
View Full Code Here

        jarEntries.add(je);
      }
      jarFile.close();
    } catch (IOException ioe) {
      throw new MoxieException("Error while reading library jar", ioe);
    }
  }
View Full Code Here

        project.setProperty("_jacoco.agentFile", agentFile.toString());
      }

      return agentFile;
    } catch (final IOException e) {
      throw new MoxieException("Unable to extract agent jar", e);
    }
  }
View Full Code Here

 
  @Override
  public void execute() throws BuildException {
    loadDependencies();
    if (message == null || StringUtils.isEmpty(message.getValue())) {
      throw new MoxieException("The commit must have a message!");
    }
    if (tag != null && StringUtils.isEmpty(tag.getMessage())) {
      // default tag message is the commit message
      tag.createMessage().setValue(message.getValue());
    }   
    if (tag != null && StringUtils.isEmpty(tag.getName())) {
      // default tag name is version
      tag.setName(getProject().getProperty(Toolkit.Key.version.projectId()));
    }

    File dir = getRepositoryDir();
    if (dir == null && !isRequiredGoal()) {
      // do not require git commit
      return;
    }
    File workingDir = dir;
    if (dir.getName().equals(".git")) {
      workingDir = dir.getParentFile();
    }
    titleClass(dir.getAbsolutePath());
   
    // consume path shared by another task
    getPath().add(consumeSharedPaths());

    List<String> files = new ArrayList<String>();
    try {
      int offset = getConsoleOffset();
      setConsoleOffset(0);
      // display log message, fit on 80 column terminal
      getConsole().log(StringUtils.leftPad("", offset, ' ') + StringUtils.trimString(message.getValue(), 67 - offset));
      getConsole().log();
     
      // add all included files relative to the working directory
      for (String file : getPath().list()) {
        String relativePath = FileUtils.getRelativePath(workingDir, new File(file));
        if (relativePath == null) {
          String msg = getConsole().error("Can not add {0} because it is not located relative to {1}",
              file, workingDir.getAbsolutePath());
          throw new MoxieException(msg);
        }
        files.add(relativePath);
        getConsole().log(1, "adding " + relativePath);
      }
      String commitId = JGitUtils.commitFiles(dir, files, message.getValue(),
          tag == null ? null : tag.getName(), tag == null ? null : tag.getMessage());
     
      getConsole().log();
      getConsole().log(1"created commit {0}", commitId);
      if (tag != null) {
        getConsole().log(1"tagged as ''{0}''", tag.getName());
      }
     
      // update the commit id property
      getProject().setProperty(Toolkit.Key.commitId.projectId(), commitId);
    } catch (Exception e) {
      throw new MoxieException(e);
    }
  }
View Full Code Here

   * @param f
   *            The file to be included in the jar as a resource.
   */
  public void setFile(File f) {
    if (filesets.size() > 0) {
      throw new MoxieException("can't add 'file' - fileset already used");
    }
    file = f;
  }
View Full Code Here

   *
   * @return Description of the Return Value
   */
  public FileSet createFileset() {
    if (file != null) {
      throw new MoxieException("can't add Fileset - file already set");
    }
    FileSet set = new FileSet();
    filesets.add(set);
    return set;
  }
View Full Code Here

   *
   * @return Description of the Return Value
   */
  public FileSet createFileset() {
    if (name != null) {
      throw new MoxieException(
          "Unable to add Fileset - class name already set");
    }
    FileSet set = new FileSet();
    filesets.add(set);
    return set;
View Full Code Here

      logger.verbose("Initializing Path Resolvers");
      logger.verbose("Classpath:" + classpath);
      logger.verbose("Librarypath:" + librarypath);
      initPathResolvers();
    } catch (IOException ioe) {
      throw new MoxieException("Unable to process classpath: " + ioe,
          getLocation());
    }

    //
    // run over all the resource and class specifications
    // given in the project file
    // resources are resolved to full path names while
    // class specifications are exploded to dependency
    // graphs - when done, getJarEntries() returns a list
    // of all entries generated by this JarSpec
    //
    List<JarEntrySpec> entries = new ArrayList<JarEntrySpec>();

    for (JarSpec js : jarSpecs) {
      try {
        js.resolve(this);
      } catch (FileNotFoundException ioe) {
        throw new ResolutionFailedException(js.getName(), ioe.getMessage());
      } catch (IOException ioe) {
        throw new MoxieException("Unable to resolve: " + js.getName()
            + "\nMSG=" + ioe.getMessage(), ioe, getLocation());
      }
      //
      // before adding a new jarspec - see if it already exists
      // first entry added to jar always wins
      //
      for (JarEntrySpec spec : js.getJarEntries()) {
        if (!entries.contains(spec)) {
          entries.add(spec);
        } else {
          logger.verbose("Duplicate (ignored): " + spec.getJarName());
        }
      }
    }
    //
    // we have all the entries we're gonna jar - the manifest
    // must be fully built prior to jar generation, so run over
    // each entry and and add it to the manifest
    //
    for (JarEntrySpec jes : entries) {
      if (jes.getSourceFile() == null) {
        try {
          InputStream is = resolveEntry(jes);
          if (is != null) {
            is.close();
          }
        } catch (IOException ioe) {
          throw new MoxieException(
              "Error while generating manifest entry for: "
                  + jes.toString(), ioe, getLocation());
        }
      }
    }

    JarOutputStream jout = null;
    InputStream is = null;
    try {
      jout = new JarOutputStream(new FileOutputStream(destFile), createJarManifest());
      writeJarEntries(jout);
     
      for (JarEntrySpec jes : entries) {
        JarEntry entry = new JarEntry(jes.getJarName());
        is = resolveEntry(jes);

        if (is == null) {
          logger.error("Unable to locate previously resolved resource");
          logger.error("       Jar Name:" + jes.getJarName());
          logger.error("Resolved Source:" + jes.getSourceFile());
          try {
            if (jout != null) {
              jout.close();
            }
          } catch (IOException ioe) {
          }
          throw new MoxieException("Jar component not found: "
              + jes.getJarName(), getLocation());
        }
        jout.putNextEntry(entry);
        byte[] buff = new byte[4096]; // stream copy buffer
        int len;
        while ((len = is.read(buff, 0, buff.length)) != -1) {
          jout.write(buff, 0, len);
        }
        jout.closeEntry();
        is.close();

        logger.verbose("Added: " + jes.getJarName());
      }
    } catch (IOException ioe) {
      throw new MoxieException("Unable to create jar: "
          + destFile.getName(), ioe, getLocation());
    } finally {
      try {
        if (is != null) {
          is.close();
View Full Code Here

      } else if (f.getName().toLowerCase().endsWith(".jar")) {
        resolver = new JarResolver(f, excludeJars, logger);
      } else if (f.getName().toLowerCase().endsWith(".zip")) {
        resolver = new ZipResolver(f, logger);
      } else {
        throw new MoxieException(f.getName()
            + " is not a valid classpath component", getLocation());
      }
      logger.debug("added " + resolver);
      resolvers.add(resolver);
    }
View Full Code Here

TOP

Related Classes of org.moxie.MoxieException

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.