Search in sources :

Example 26 with BuildException

use of org.apache.tools.ant.BuildException in project groovy by apache.

the class Groovyc method makeCompileUnit.

protected CompilationUnit makeCompileUnit() {
    Map<String, Object> options = configuration.getJointCompilationOptions();
    if (options != null) {
        if (keepStubs) {
            options.put("keepStubs", Boolean.TRUE);
        }
        if (stubDir != null) {
            options.put("stubDir", stubDir);
        } else {
            try {
                File tempStubDir = DefaultGroovyStaticMethods.createTempDir(null, "groovy-generated-", "-java-source");
                temporaryFiles.add(tempStubDir);
                options.put("stubDir", tempStubDir);
            } catch (IOException ioe) {
                throw new BuildException(ioe);
            }
        }
        return new JavaAwareCompilationUnit(configuration, buildClassLoaderFor());
    } else {
        return new CompilationUnit(configuration, null, buildClassLoaderFor());
    }
}
Also used : JavaAwareCompilationUnit(org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit) CompilationUnit(org.codehaus.groovy.control.CompilationUnit) JavaAwareCompilationUnit(org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 27 with BuildException

use of org.apache.tools.ant.BuildException in project processing by processing.

the class PAppletMethods method execute.

public void execute() throws BuildException {
    // Do a bunch of checks...
    if (baseDir == null) {
        throw new BuildException("dir parameter must be set!");
    }
    //System.out.println("using basedir " + baseDir);
    File graphicsFile = new File(baseDir, "PGraphics.java");
    File appletFile = new File(baseDir, "PApplet.java");
    File imageFile = new File(baseDir, "PImage.java");
    if (!graphicsFile.exists() || !graphicsFile.canRead()) {
        throw new BuildException("PGraphics file not readable: " + graphicsFile.getAbsolutePath());
    }
    if (!appletFile.exists() || !appletFile.canRead() || !appletFile.canWrite()) {
        throw new BuildException("PApplet file not read/writeable: " + appletFile.getAbsolutePath());
    }
    if (!imageFile.exists() || !imageFile.canRead()) {
        throw new BuildException("PImage file not readable: " + imageFile.getAbsolutePath());
    }
    // Looking good, let's do this!
    //ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
    //PrintStream out = new PrintStream(outBytes, "UTF-8");
    StringBuilder out = new StringBuilder();
    StringBuilder content = new StringBuilder();
    try {
        BufferedReader applet = createReader(appletFile);
        String line;
        while ((line = applet.readLine()) != null) {
            out.append(line);
            // to avoid Windows CRs
            out.append('\n');
            content.append(line);
            // for efficiency
            content.append('\n');
            if (line.indexOf("public functions for processing.core") >= 0) {
                break;
            }
        }
        // read the rest of the file and append it to the
        while ((line = applet.readLine()) != null) {
            content.append(line);
            content.append('\n');
        }
        applet.close();
        process(out, graphicsFile);
        process(out, imageFile);
        out.append('}');
        out.append('\n');
    //} catch (IOException e) {
    //e.printStackTrace();
    } catch (Exception e) {
        //ex.printStackTrace();
        throw new BuildException(e);
    }
    //out.flush();
    String outString = out.toString();
    if (content.toString().equals(outString)) {
        System.out.println("No changes to PApplet API.");
    } else {
        System.out.println("Updating PApplet with API changes " + "from PImage or PGraphics.");
        try {
            PrintStream temp = new PrintStream(appletFile, "UTF-8");
            temp.print(outString);
            temp.flush();
            temp.close();
        } catch (IOException e) {
            //e.printStackTrace();
            throw new BuildException(e);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) BufferedReader(java.io.BufferedReader) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileNotFoundException(java.io.FileNotFoundException)

Example 28 with BuildException

use of org.apache.tools.ant.BuildException in project processing by processing.

the class JavaBuild method buildWindowsLauncher.

/**
   * Run the launch4j build.xml file through ant to create the exe.
   * Most of this code was lifted from Android mode.
   */
protected boolean buildWindowsLauncher(File buildFile, String target) {
    Project p = new Project();
    String path = buildFile.getAbsolutePath().replace('\\', '/');
    p.setUserProperty("ant.file", path);
    // deals with a problem where javac error messages weren't coming through
    p.setUserProperty("build.compiler", "extJavac");
    // too chatty
    /*
    // try to spew something useful to the console
    final DefaultLogger consoleLogger = new DefaultLogger();
    consoleLogger.setErrorPrintStream(System.err);
    consoleLogger.setOutputPrintStream(System.out);
    // WARN, INFO, VERBOSE, DEBUG
    consoleLogger.setMessageOutputLevel(Project.MSG_ERR);
    p.addBuildListener(consoleLogger);
    */
    DefaultLogger errorLogger = new DefaultLogger();
    ByteArrayOutputStream errb = new ByteArrayOutputStream();
    PrintStream errp = new PrintStream(errb);
    errorLogger.setErrorPrintStream(errp);
    ByteArrayOutputStream outb = new ByteArrayOutputStream();
    PrintStream outp = new PrintStream(outb);
    errorLogger.setOutputPrintStream(outp);
    errorLogger.setMessageOutputLevel(Project.MSG_INFO);
    p.addBuildListener(errorLogger);
    try {
        p.fireBuildStarted();
        p.init();
        final ProjectHelper helper = ProjectHelper.getProjectHelper();
        p.addReference("ant.projectHelper", helper);
        helper.parse(p, buildFile);
        p.executeTarget(target);
        return true;
    } catch (final BuildException e) {
        // Send a "build finished" event to the build listeners for this project.
        p.fireBuildFinished(e);
        String out = new String(outb.toByteArray());
        String err = new String(errb.toByteArray());
        System.out.println(out);
        System.err.println(err);
    }
    return false;
}
Also used : Project(org.apache.tools.ant.Project) ProjectHelper(org.apache.tools.ant.ProjectHelper) BuildException(org.apache.tools.ant.BuildException) DefaultLogger(org.apache.tools.ant.DefaultLogger)

Example 29 with BuildException

use of org.apache.tools.ant.BuildException in project felix by apache.

the class SCRDescriptorTask method execute.

@Override
public void execute() throws BuildException {
    // ensure we know the source
    if (getImplicitFileSet().getDir() == null) {
        throw new BuildException("srcdir attribute must be set!", getLocation());
    }
    // while debugging
    final org.apache.felix.scrplugin.Log scrLog = new AntLog(this);
    scrLog.debug("SCRDescriptorTask Configuration");
    scrLog.debug("  implicitFileset: " + getImplicitFileSet());
    scrLog.debug("  outputDirectory: " + destdir);
    scrLog.debug("  classpath: " + classpath);
    scrLog.debug("  generateAccessors: " + generateAccessors);
    scrLog.debug("  strictMode: " + strictMode);
    scrLog.debug("  specVersion: " + specVersion);
    try {
        final Path classPath = createClasspath();
        final org.apache.felix.scrplugin.Project project = new org.apache.felix.scrplugin.Project();
        project.setClassLoader(getClassLoader(this.getClass().getClassLoader()));
        project.setDependencies(getDependencies(classPath));
        project.setSources(getSourceFiles(getImplicitFileSet()));
        project.setClassesDirectory(destdir.getAbsolutePath());
        // create options
        final Options options = new Options();
        options.setOutputDirectory(destdir);
        options.setGenerateAccessors(generateAccessors);
        options.setStrictMode(strictMode);
        options.setProperties(new HashMap<String, String>());
        options.setSpecVersion(SpecVersion.fromName(specVersion));
        if (specVersion != null && options.getSpecVersion() == null) {
            throw new BuildException("Unknown spec version specified: " + specVersion);
        }
        final SCRDescriptorGenerator generator = new SCRDescriptorGenerator(scrLog);
        // setup from plugin configuration
        generator.setOptions(options);
        generator.setProject(project);
        generator.execute();
    } catch (final SCRDescriptorException sde) {
        if (sde.getSourceLocation() != null) {
            final Location loc = new Location(sde.getSourceLocation(), -1, 0);
            throw new BuildException(sde.getMessage(), sde.getCause(), loc);
        }
        throw new BuildException(sde.getMessage(), sde.getCause());
    } catch (SCRDescriptorFailureException sdfe) {
        throw new BuildException(sdfe.getMessage(), sdfe.getCause());
    }
}
Also used : Path(org.apache.tools.ant.types.Path) Options(org.apache.felix.scrplugin.Options) SCRDescriptorFailureException(org.apache.felix.scrplugin.SCRDescriptorFailureException) SCRDescriptorGenerator(org.apache.felix.scrplugin.SCRDescriptorGenerator) Project(org.apache.tools.ant.Project) BuildException(org.apache.tools.ant.BuildException) SCRDescriptorException(org.apache.felix.scrplugin.SCRDescriptorException) Location(org.apache.tools.ant.Location)

Example 30 with BuildException

use of org.apache.tools.ant.BuildException in project chipKIT32-MAX by chipKIT32.

the class PAppletMethods method execute.

public void execute() throws BuildException {
    // Do a bunch of checks...
    if (baseDir == null) {
        throw new BuildException("dir parameter must be set!");
    }
    //System.out.println("using basedir " + baseDir);
    File graphicsFile = new File(baseDir, "PGraphics.java");
    File appletFile = new File(baseDir, "PApplet.java");
    File imageFile = new File(baseDir, "PImage.java");
    if (!graphicsFile.exists() || !graphicsFile.canRead()) {
        throw new BuildException("PGraphics file not readable: " + graphicsFile.getAbsolutePath());
    }
    if (!appletFile.exists() || !appletFile.canRead() || !appletFile.canWrite()) {
        throw new BuildException("PApplet file not read/writeable: " + appletFile.getAbsolutePath());
    }
    if (!imageFile.exists() || !imageFile.canRead()) {
        throw new BuildException("PImage file not readable: " + imageFile.getAbsolutePath());
    }
    // Looking good, let's do this!
    //ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
    //PrintStream out = new PrintStream(outBytes, "UTF-8");
    StringBuffer out = new StringBuffer();
    StringBuffer content = new StringBuffer();
    try {
        BufferedReader applet = createReader(appletFile);
        String line;
        while ((line = applet.readLine()) != null) {
            out.append(line);
            // to avoid Windows CRs
            out.append('\n');
            content.append(line);
            // for efficiency
            content.append('\n');
            if (line.indexOf("public functions for processing.core") >= 0) {
                break;
            }
        }
        // read the rest of the file and append it to the
        while ((line = applet.readLine()) != null) {
            content.append(line);
            content.append('\n');
        }
        applet.close();
        process(out, graphicsFile);
        process(out, imageFile);
        out.append('}');
        out.append('\n');
    //} catch (IOException e) {
    //e.printStackTrace();
    } catch (Exception e) {
        //ex.printStackTrace();
        throw new BuildException(e);
    }
    //out.flush();
    String outString = out.toString();
    if (content.toString().equals(outString)) {
        System.out.println("No changes to PApplet API.");
    } else {
        System.out.println("Updating PApplet with API changes " + "from PImage or PGraphics.");
        try {
            PrintStream temp = new PrintStream(appletFile, "UTF-8");
            temp.print(outString);
            temp.flush();
            temp.close();
        } catch (IOException e) {
            //e.printStackTrace();
            throw new BuildException(e);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) BufferedReader(java.io.BufferedReader) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

BuildException (org.apache.tools.ant.BuildException)930 IOException (java.io.IOException)390 File (java.io.File)365 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)75 ArrayList (java.util.ArrayList)65 InputStream (java.io.InputStream)62 Project (org.apache.tools.ant.Project)61 Resource (org.apache.tools.ant.types.Resource)58 FileSet (org.apache.tools.ant.types.FileSet)52 Path (org.apache.tools.ant.types.Path)52 Commandline (org.apache.tools.ant.types.Commandline)51 Properties (java.util.Properties)50 OutputStream (java.io.OutputStream)44 FileOutputStream (java.io.FileOutputStream)42 FileResource (org.apache.tools.ant.types.resources.FileResource)42 FileInputStream (java.io.FileInputStream)41 URL (java.net.URL)40 BufferedReader (java.io.BufferedReader)37 Writer (java.io.Writer)37 MalformedURLException (java.net.MalformedURLException)37