Package org.apache.tools.ant

Examples of org.apache.tools.ant.BuildException


    {
      parser.parse(inFile.toString());
    }
    catch (SAXParseException se)
    {
      throw new BuildException("Exception occurs during parsing file "+inFile+" at line "+
                               se.getLineNumber()+" column "+se.getColumnNumber(), se);
    }
  }
View Full Code Here


  private void ensureDirectoryFor(File targetFile) throws BuildException
  {
    File directory = new File(targetFile.getParent());

    if ((!directory.exists()) && (!directory.mkdirs()))
      throw new BuildException("Unable to create directory: "+directory.getAbsolutePath());
  }
View Full Code Here

        else
          parserFactoryImpl = (SAXParserFactory)Class.forName(parserFactory).newInstance();
      }
      catch (Exception e)
      {
        throw new BuildException("Could not load parser factory", e);
      }
    }

    return parserFactoryImpl;
  }
View Full Code Here

          transformerFactoryImpl =
            (SAXTransformerFactory)Class.forName(transformerFactory).newInstance();
      }
      catch (Exception e)
      {
        throw new BuildException("Could not load transformer factory", e);
      }
    }

    return transformerFactoryImpl;
  }
View Full Code Here

    public void execute() throws BuildException
    {
        if ((file == null && srcDirUrl == null) || (srcDirUrl != null && filesList == null))
        {
            final String message = Messages.getString("vfs.tasks/delete.no-source-files.error");
            throw new BuildException(message);
        }

        try
        {
            if (srcDirUrl != null && filesList != null)
            {
                log("Deleting " + filesList + " in the directory " + srcDirUrl);
                if (!srcDirUrl.endsWith("/"))
                {
                    srcDirUrl += "/";
                }
                StringTokenizer tok = new StringTokenizer(filesList, ", \t\n\r\f", false);
                while (tok.hasMoreTokens())
                {
                    String nextFile = tok.nextToken();
                    final FileObject srcFile = resolveFile(srcDirUrl + nextFile);
                    srcFile.delete(Selectors.SELECT_ALL);
                }
            }
            else
            {
                final FileObject srcFile = resolveFile(file);
                log("Deleting " + srcFile);
                srcFile.delete(Selectors.SELECT_ALL);
            }
        }
        catch (final Exception e)
        {
            throw new BuildException(e);
        }
    }
View Full Code Here

        throws BuildException
    {
        if (srcInfo.file == null)
        {
            final String message = Messages.getString("vfs.tasks/sync.no-source-file.error");
            throw new BuildException(message);
        }
        srcFiles.add(srcInfo);
    }
View Full Code Here

        // Validate
        if (destFileUrl == null && destDirUrl == null)
        {
            final String message =
                Messages.getString("vfs.tasks/sync.no-destination.error");
            throw new BuildException(message);
        }

        if (destFileUrl != null && destDirUrl != null)
        {
            final String message =
                Messages.getString("vfs.tasks/sync.too-many-destinations.error");
            throw new BuildException(message);
        }

        // Add the files of the includes attribute to the list
        if (srcDirUrl != null && !srcDirUrl.equals(destDirUrl) && filesList != null && filesList.length() > 0)
        {
            if (!srcDirUrl.endsWith("/"))
            {
                srcDirUrl += "/";
            }
            StringTokenizer tok = new StringTokenizer(filesList, ", \t\n\r\f", false);
            while (tok.hasMoreTokens())
            {
                String nextFile = tok.nextToken();

                // Basic compatibility with Ant fileset for directories
                if (nextFile.endsWith("/**"))
                {
                    nextFile = nextFile.substring(0, nextFile.length() - 2);
                }

                final SourceInfo src = new SourceInfo();
                src.setFile(srcDirUrl + nextFile);
                addConfiguredSrc(src);
            }
        }

        if (srcFiles.size() == 0)
        {
            final String message = Messages.getString("vfs.tasks/sync.no-source-files.warn");
            log(message, Project.MSG_WARN);
            return;
        }

        // Perform the sync
        try
        {
            if (destFileUrl != null)
            {
                handleSingleFile();
            }
            else
            {
                handleFiles();
            }
        }
        catch (final BuildException e)
        {
            throw e;
        }
        catch (final Exception e)
        {
            throw new BuildException(e.getMessage(), e);
        }
    }
View Full Code Here

        // and is a file.
        if (srcFiles.size() > 1)
        {
            final String message =
                Messages.getString("vfs.tasks/sync.too-many-source-files.error");
            throw new BuildException(message);
        }
        final SourceInfo src = (SourceInfo) srcFiles.get(0);
        final FileObject srcFile = resolveFile(src.file);
        if (srcFile.getType() != FileType.FILE)
        {
            final String message =
                Messages.getString("vfs.tasks/sync.source-not-file.error", srcFile);
            throw new BuildException(message);
        }

        // Locate the destination file
        final FileObject destFile = resolveFile(destFileUrl);
View Full Code Here

   *
   * @since Ant 1.5
   */
  protected void checkParameters() throws BuildException {
    if (destDir != null && !destDir.isDirectory()) {
      throw new BuildException(
        "destination directory \""
          + destDir
          + "\" does not exist "
          + "or is not a directory",
        getLocation());
View Full Code Here

    }
    String[] list = src.list();
    for (int i = 0; i < list.length; i++) {
      File srcDir = getProject().resolveFile(list[i]);
      if (!srcDir.exists()) {
        throw new BuildException(
          "srcdir \"" + srcDir.getPath() + "\" does not exist!",
          getLocation());
      }

      DirectoryScanner ds = this.getDirectoryScanner(srcDir);
      String[] files = ds.getIncludedFiles();
      int j;
      for (j = 0; j < files.length; j++) {
        String one = files[j];

        File source = new File(srcDir, one);     
        File destination = new File(getDestDir(), one);
        if (!destination.getParentFile().exists()) {
          log("Making dir: "+destination.getParentFile(), Project.MSG_VERBOSE);
          destination.getParentFile().mkdirs();
        }
       
   
        if (source.lastModified() <= destination.lastModified()) {
          log(source+" omitted as "+destination+" is up to date", Project.MSG_VERBOSE);
          continue;
        }
        if (one.endsWith(".class")) {
          try {
            log("source: "+source + " to "+destination, Project.MSG_VERBOSE);
            JustLog.speedup(source, destination);
           
            log("Payload: " + 100*(destination.length()-source.length())/source.length()+ "%");
          } catch (ClassFormatException e) {
            throw new BuildException(one + " is not a class file", e);
          } catch (IOException e) {
            throw new BuildException(one + " has an IO problem", e);
          }
        }
        if (one.endsWith(".jar")
          || one.endsWith(".ear")
          || one.endsWith(".zip")
          || one.endsWith(".war")) {
          try {
            JustLog.speedupZip(new FileInputStream(source), new FileOutputStream(destination));
          } catch (FileNotFoundException e) {
            throw new BuildException(one + " is not found", e);
          } catch (IOException e) {
            StackTraceElement[] st=e.getStackTrace();
            StringBuffer sb= new StringBuffer();
            for(int h=0; h<st.length; h++) {
              sb.append(st[h].toString());
              sb.append("\n");
            }
            throw new BuildException(one + " has an IO problem: "+sb.toString(), e);
          }
        }
      }

    }
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.