Package org.apache.tools.ant

Examples of org.apache.tools.ant.BuildException


            baseDir = getProject().getBaseDir();
        }
        if (destDir == null )
        {
            String msg = "destdir attribute must be set!";
            throw new BuildException(msg, getLocation());
        }
       
        File templateFile = null;

        if (templateDir == null) {
            if (templateName != null) {
                templateFile = new File(templateName);
                if (!templateFile.isAbsolute()) {
                    templateFile = new File(getProject().getBaseDir(), templateName);
                }
                templateDir = templateFile.getParentFile();
                templateName = templateFile.getName();
            }
            else {
                templateDir = baseDir;
            }
            setTemplateDir(templateDir);
        } else if (templateName != null) {
            if (new File(templateName).isAbsolute()) {
                throw new BuildException("Do not specify an absolute location for the template as well as a templateDir");
            }
            templateFile = new File(templateDir, templateName);
        }
        if (templateFile != null) {
            templateFileLastModified = templateFile.lastModified();
        }

        try {
            if (templateName != null) {
                parsedTemplate = cfg.getTemplate(templateName, templateEncoding);
            }
        }
        catch (IOException ioe) {
            throw new BuildException(ioe.toString());
        }
        // get the last modification of the template
        log("Transforming into: " + destDir.getAbsolutePath(), Project.MSG_INFO);

        // projectFile relative to baseDir
        if (projectAttribute != null && projectAttribute.length() > 0)
        {
            projectFile = new File(baseDir, projectAttribute);
            if (projectFile.isFile())
                projectFileLastModified = projectFile.lastModified();
            else
            {
                log ("Project file is defined, but could not be located: " +
                     projectFile.getAbsolutePath(), Project.MSG_INFO );
                projectFile = null;
            }
        }

        generateModels();
       
        // find the files/directories
        scanner = getDirectoryScanner(baseDir);

        propertiesTemplate = wrapMap(project.getProperties());
        userPropertiesTemplate = wrapMap(project.getUserProperties());

        builderFactory.setValidating(validation);
        try
        {
            builder = builderFactory.newDocumentBuilder();
        }
        catch(ParserConfigurationException e)
        {
            throw new BuildException("Could not create document builder", e, getLocation());
        }

        // get a list of files to work on
        list = scanner.getIncludedFiles();
       
View Full Code Here


                // the result as the outFile.
                Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), encoding));
                try
                {
                    if (parsedTemplate == null) {
                        throw new BuildException("No template file specified in build script or in XML file");
                    }
                    if (prepareModel != null) {
                        Map vars = new HashMap();
                        vars.put("model", root);
                        vars.put("doc", docNode);
                        if (projectNode != null) {
                            vars.put("project", ((NodeModel) projectNode).getNode());
                        }
                        prepareModel.execute(vars);
                    }
                    freemarker.core.Environment env = parsedTemplate.createProcessingEnvironment(root, writer);
                    env.setCurrentVisitorNode(docNodeModel);
                    if (prepareEnvironment != null) {
                        Map vars = new HashMap();
                        vars.put("env", env);
                        vars.put("doc", docNode);
                        if (projectNode != null) {
                            vars.put("project", ((NodeModel) projectNode).getNode());
                        }
                        prepareEnvironment.execute(vars);
                    }
                    env.process();
                    writer.flush();
                }
                finally
                {
                    writer.close();
                }

                log("Output: " + outFile, Project.MSG_INFO );
               
            }
        }
        catch (SAXParseException spe)
        {
            Throwable rootCause = spe;
            if (spe.getException() != null)
                rootCause = spe.getException();
            log("XML parsing error in " + inFile.getAbsolutePath(), Project.MSG_ERR);
            log("Line number " + spe.getLineNumber());
            log("Column number " + spe.getColumnNumber());
            throw new BuildException(rootCause, getLocation());
        }
        catch (Throwable e)
        {
            if (outFile != null ) {
                if(!outFile.delete() && outFile.exists()) {
                    log("Failed to delete " + outFile, Project.MSG_WARN);
                }
            }
            e.printStackTrace();
            throw new BuildException(e, getLocation());
        }
    }
View Full Code Here

            {
                modelsMap.put(name, ClassUtil.forName(clazz).newInstance());
            }
            catch(Exception e)
            {
                throw new BuildException(e);
            }
        }
    }
View Full Code Here

        File directory = new File( targetFile.getParent() );
        if (!directory.exists())
        {
            if (!directory.mkdirs())
            {
                throw new BuildException("Unable to create directory: "
                                         + directory.getAbsolutePath(), getLocation());
            }
        }
    }
View Full Code Here

         }
         catch (Exception e)
         {
            e.printStackTrace();
            throw new BuildException("Could not register property editors: " + e);
         } // end of try-catch

         try
         {
            HashMap env = new HashMap();
            if (username != null && password != null)
            {
               if (verbose )
               {
                  log("will connect with username=" + username);
               }
               String[] creds = new String[2];
               creds[0] = username;
               creds[1] = password;
               env.put(JMXConnector.CREDENTIALS, creds);
            }
           
            JMXServiceURL url = new JMXServiceURL(serverURL);

            if (verbose )
            {
               log("will connect with JMXServiceURL = "+url);
            }

            JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
            MBeanServerConnection server = jmxc.getMBeanServerConnection();
            if(verbose)
            {
               log("connected to server");
            }

            for (int i = 0; i < ops.size(); i++)
            {
               Operation op = ops.get(i);
               if(verbose)
               {
                  log("execute operation " + op.getLogInformation());
               }
               Object result = op.execute(server, this);
               if( verbose && result != null)
               {
                  log(result.toString());
               }
            } // end of for ()

         }
         catch (Exception e)
         {
            e.printStackTrace();
            throw new BuildException("problem: " + e);
         } // end of try-catch
      }
      finally
      {
         Thread.currentThread().setContextClassLoader(origCL);
View Full Code Here

  {
    if (baseDir==null)
      baseDir = project.resolveFile(".");

    if (grammarFile==null)
      throw new BuildException("No grammar file is specified", location);

    if (!grammarFile.exists())
      throw new BuildException("Grammar file doesn't exists:"+grammarFile.getAbsolutePath(),
                               location);

    if (destDir==null)
      throw new BuildException("No destdir specified!", location);

    log = new AntLog(getProject(), msgLevel);

    buildAutomata(grammarFile);
View Full Code Here

   * @throws BuildException
   */
  public Mapper createMapper() throws BuildException
  {
    if (mapper!=null)
      throw new BuildException("Cannot define more than one mapper", location);

    mapper = new Mapper(project);
    return mapper;
  }
View Full Code Here

  private void process(File inFile, File outFile) throws BuildException
  {
    try
    {
      if (!inFile.exists())
        throw new BuildException("File "+inFile+" doesn't exists", location);

      if (inFile.lastModified()>outFile.lastModified())
      {
        ensureDirectoryFor(outFile);
        log("Parsing file "+inFile+" to "+outFile, Project.MSG_INFO);

        Properties format = new Properties();

        format.put(OutputKeys.ENCODING, encoding);
        if (indent)
          format.put(OutputKeys.INDENT, "yes");

        format.put(OutputKeys.METHOD, "xml");

        SAXTransformerFactory factory = getTransformerFactory();

        TransformerHandler serializer = factory.newTransformerHandler();
        serializer.getTransformer().setOutputProperties(format);
        serializer.setResult(new StreamResult(outFile));

        this.parser = new ExtendedDirectParserProcessor();
        this.parser.setLog(log);
        this.parser.setFlatten(this.flatten);

        this.parser.setExtendedGrammar(this.grammar);
        this.parser.setContentHandler(serializer);

        if (!inputtype.equalsIgnoreCase("xml"))
          pushTextFile(inFile);
        else
          pushXMLFile(inFile);
      }
    }
    catch (Exception ex)
    {
      if (outFile!=null)
        outFile.delete();

      if (ex instanceof BuildException)
        throw (BuildException)ex;

      throw new BuildException("Failed to process "+inFile+" : "+ex.getMessage(), ex);
    }
  }
View Full Code Here

    catch (Exception ex)
    {
      if (ex instanceof BuildException)
        throw (BuildException)ex;

      throw new BuildException(ex);
    }
  }
View Full Code Here

      this.parser.endElement("http://chaperon.sourceforge.net/schema/text/1.0", "text", "text");
      this.parser.endDocument();
    }
    catch (SAXParseException se)
    {
      throw new BuildException("Exception occurs during parsing file "+inFile+" at line "+
                               se.getLineNumber()+" column "+se.getColumnNumber(), se);
    }
  }
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.