Search in sources :

Example 46 with BuildException

use of org.apache.tools.ant.BuildException in project mkgmap by openstreetmap.

the class MKGMapTask method execute.

public void execute() {
    List<String> args = new ArrayList<String>();
    try {
        CommandArgsReader argsReader = new CommandArgsReader(new Main());
        if (configFile != null)
            args.add("--read-config=" + configFile);
        for (Path path : paths) {
            String[] includedFiles = path.list();
            for (String filename : includedFiles) {
                log("processing " + filename);
                args.add("--input-file=" + filename);
            }
        }
        argsReader.readArgs(args.toArray(new String[args.size()]));
    } catch (Exception ex) {
        // log(ex, 1);
        throw new BuildException(ex);
    }
}
Also used : Path(org.apache.tools.ant.types.Path) CommandArgsReader(uk.me.parabola.mkgmap.CommandArgsReader) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException) Main(uk.me.parabola.mkgmap.main.Main) BuildException(org.apache.tools.ant.BuildException)

Example 47 with BuildException

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

the class TruncateTask method execute.

public void execute() throws BuildException {
    if (null == file)
        throw new BuildException("file not set.");
    if (0 >= size)
        throw new BuildException("size not set to a value greater than 0.");
    if (file.length() < size) {
        return;
    }
    try {
        final RandomAccessFile random = new RandomAccessFile(file, "rw");
        random.setLength(size);
        random.close();
    } catch (IOException e) {
        throw new BuildException("Error truncating file " + file, e);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException)

Example 48 with BuildException

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

the class GenerateBootImageSizeSummary method computeTotalImageSizes.

private SortedMap<String, String> computeTotalImageSizes() {
    SortedMap<String, String> imageNameToTotalImageSize = new TreeMap<String, String>();
    File[] subDirectories = imageDir.listFiles();
    if (subDirectories == null) {
        throw new BuildException("Image directory " + imageDir + " doesn't exist!");
    }
    for (File dir : subDirectories) {
        if (!dir.isDirectory()) {
            continue;
        } else {
            log("Found (potential) boot image directory: " + dir.getAbsolutePath(), VERBOSE);
            long totalSize = 0;
            for (File imageFile : dir.listFiles(IMAGE_NAMES_FILTER)) {
                log("Found image file: " + imageFile.getAbsolutePath(), VERBOSE);
                totalSize += imageFile.length();
            }
            if (totalSize > 0) {
                imageNameToTotalImageSize.put(dir.getName(), Long.toString(totalSize));
                log("Total image size for " + dir + " was: " + totalSize, VERBOSE);
            } else {
                log("Directory " + dir + " didn't contain valid image files.", VERBOSE);
            }
        }
    }
    return imageNameToTotalImageSize;
}
Also used : BuildException(org.apache.tools.ant.BuildException) TreeMap(java.util.TreeMap) File(java.io.File)

Example 49 with BuildException

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

the class GenerateBootImageSizeSummary method verifyTaskAttributes.

private void verifyTaskAttributes() {
    if (summaryFile == null) {
        throw new BuildException("summaryFile not set. " + "It must be set to the name of a not yet existing file.");
    } else if (summaryFile.isDirectory()) {
        throw new BuildException("Expected summaryFile (" + summaryFile + ") to be a file but it's a directory.");
    }
    log("Summary file set to " + summaryFile, VERBOSE);
    if (imageDir == null) {
        throw new BuildException("imageDir not set. " + "It must be set to the directory containing the boot image directories " + "(e.g. dist by default).");
    } else if (imageDir.isFile()) {
        throw new BuildException("Expected imageDir (" + imageDir + ") to be a directory but it's a file.");
    }
    log("Image directory set to " + imageDir, VERBOSE);
}
Also used : BuildException(org.apache.tools.ant.BuildException)

Example 50 with BuildException

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

the class SelectRegexTask method matchFile.

private String matchFile() {
    BufferedReader input = null;
    try {
        final Regexp regexp = this.pattern.getRegexp(getProject());
        input = new BufferedReader(new FileReader(file));
        String[] lines = new String[patternLines];
        String sep = System.getProperty("line.separator");
        for (int i = 0; i < lines.length; i++) {
            lines[i] = "";
        }
        int nextLine = 0;
        while ((lines[nextLine] = input.readLine()) != null) {
            StringBuilder sb = new StringBuilder();
            for (int i = nextLine + 1; i <= nextLine + lines.length; i++) {
                String line = lines[i % lines.length];
                sb.append(line);
                sb.append(sep);
            }
            String result = performMatching(sb.toString());
            if (result != null) {
                return result;
            }
            nextLine = (nextLine + 1) % lines.length;
        }
        return null;
    } catch (IOException ioe) {
        throw new BuildException("Error loading file " + file, ioe, getLocation());
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (final IOException ioe) {
            // ignore
            }
        }
    }
}
Also used : Regexp(org.apache.tools.ant.util.regexp.Regexp) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

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