Search in sources :

Example 1 with CommandArgsReader

use of uk.me.parabola.mkgmap.CommandArgsReader 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 2 with CommandArgsReader

use of uk.me.parabola.mkgmap.CommandArgsReader in project mkgmap by openstreetmap.

the class Main method mainStart.

/**
 * The main program to make or combine maps.  We now use a two pass process,
 * first going through the arguments and make any maps and collect names
 * to be used for creating summary files like the TDB and gmapsupp.
 *
 * @param args The command line arguments.
 */
private static int mainStart(String... args) {
    Instant start = Instant.now();
    System.out.println("Time started: " + new Date());
    // We need at least one argument.
    if (args.length < 1) {
        printUsage();
        printHelp(System.err, getLang(), "options");
        return 0;
    }
    Main mm = new Main();
    int numExitExceptions = 0;
    try {
        // Read the command line arguments and process each filename found.
        CommandArgsReader commandArgs = new CommandArgsReader(mm);
        commandArgs.setValidOptions(getValidOptions(System.err));
        commandArgs.readArgs(args);
    } catch (OutOfMemoryError e) {
        ++numExitExceptions;
        System.err.println(e);
        if (mm.maxJobs > 1)
            System.err.println("Try using the mkgmap --max-jobs option with a value less than " + mm.maxJobs + " to reduce the memory requirement, or use the Java -Xmx option to increase the available heap memory.");
        else
            System.err.println("Try using the Java -Xmx option to increase the available heap memory.");
    } catch (MapFailedException e) {
        // one of the combiners failed
        e.printStackTrace();
        ++numExitExceptions;
    } catch (ExitException e) {
        ++numExitExceptions;
        String message = e.getMessage();
        Throwable cause = e.getCause();
        while (cause != null) {
            message += "\r\n" + cause.toString();
            cause = cause.getCause();
        }
        System.err.println(message);
    }
    System.out.println("Number of ExitExceptions: " + numExitExceptions);
    System.out.println("Time finished: " + new Date());
    Duration duration = Duration.between(start, Instant.now());
    long seconds = duration.getSeconds();
    if (seconds > 0) {
        long hours = seconds / 3600;
        seconds -= hours * 3600;
        long minutes = seconds / 60;
        seconds -= minutes * 60;
        System.out.println("Total time taken: " + (hours > 0 ? hours + (hours > 1 ? " hours " : " hour ") : "") + (minutes > 0 ? minutes + (minutes > 1 ? " minutes " : " minute ") : "") + (seconds > 0 ? seconds + (seconds > 1 ? " seconds" : " second") : ""));
    } else
        System.out.println("Total time taken: " + duration.getNano() / 1000000 + " ms");
    if (numExitExceptions > 0 || mm.getProgramRC() != 0) {
        return 1;
    }
    return 0;
}
Also used : CommandArgsReader(uk.me.parabola.mkgmap.CommandArgsReader) MapFailedException(uk.me.parabola.imgfmt.MapFailedException) Instant(java.time.Instant) Duration(java.time.Duration) ExitException(uk.me.parabola.imgfmt.ExitException) Date(java.util.Date) OutOfMemoryError(java.lang.OutOfMemoryError)

Aggregations

CommandArgsReader (uk.me.parabola.mkgmap.CommandArgsReader)2 OutOfMemoryError (java.lang.OutOfMemoryError)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 BuildException (org.apache.tools.ant.BuildException)1 Path (org.apache.tools.ant.types.Path)1 ExitException (uk.me.parabola.imgfmt.ExitException)1 MapFailedException (uk.me.parabola.imgfmt.MapFailedException)1 Main (uk.me.parabola.mkgmap.main.Main)1