[patch] Ant-Task for mkgmap

Hi, I've written an ant task for mkgmap which can be used like this: <target name="mkgmap"> <taskdef name="mkgmap" classname="uk.me.parabola.mkgmap.ant.MKGMapTask" classpath="/home/cgawron/mkgmap/dist/mkgmap.jar:."/> <mkgmap options="mkgmap.cfg"> <path> <fileset dir="." includes="input_sauerland.osm" /> </path> </mkgmap> </target> The task supports an options file and nested filesets with osm files. Since it reuses most of mkgmap's argument processing, I had to make some protected methods of Option.java and CommandArgsReader.java public (see attached patch). Best wishes Christian /* * Copyright (C) 2009 Christian Gawron * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * Author: Christian Gawron * Create date: 19-Jun-2009 */ package uk.me.parabola.mkgmap.ant; import org.apache.tools.ant.Task; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.types.Path; import java.io.*; import java.util.*; import uk.me.parabola.mkgmap.main.Main; import uk.me.parabola.mkgmap.ArgumentProcessor; import uk.me.parabola.mkgmap.CommandArgs; import uk.me.parabola.mkgmap.CommandArgsReader; /** * This class provides an ant task for mkgmap */ public class MKGMapTask extends Task { private ArgumentProcessor proc = null; CommandArgsReader argsReader = null; private Vector<Path> paths = new Vector<Path>(); public void init() { proc = new Main(); argsReader = new CommandArgsReader(proc); } public void addPath(Path path) { paths.add(path); } public void setOptions(String configFile) { argsReader.readConfigFile(configFile); } public void execute() { try { proc.startOptions(); for (Path path : paths) { String[] includedFiles = path.list(); for (int i=0; i<includedFiles.length; i++) { String filename = includedFiles[i]; log("processing " + filename); argsReader.addOption("input-file", filename); } } for (CommandArgsReader.ArgType a : argsReader.getArgList()) { a.processArg(); } proc.endOptions(new CommandArgs(argsReader.getArgs())); } catch (Exception ex) { log(ex, 1); ex.printStackTrace(); throw new BuildException(ex); } } } Index: src/uk/me/parabola/mkgmap/Option.java =================================================================== --- src/uk/me/parabola/mkgmap/Option.java (Revision 1067) +++ src/uk/me/parabola/mkgmap/Option.java (Arbeitskopie) @@ -34,7 +34,7 @@ } } - protected Option(String option, String value) { + public Option(String option, String value) { this.option = option; this.value = value; } Index: src/uk/me/parabola/mkgmap/CommandArgsReader.java =================================================================== --- src/uk/me/parabola/mkgmap/CommandArgsReader.java (Revision 1067) +++ src/uk/me/parabola/mkgmap/CommandArgsReader.java (Arbeitskopie) @@ -129,7 +129,7 @@ * @param option The option name. * @param value Its value. */ - private void addOption(String option, String value) { + public void addOption(String option, String value) { CommandOption opt = new CommandOption(option, value); addOption(opt); } @@ -181,13 +181,21 @@ return arglist.iterator(); } + public ArgList getArgList() { + return arglist; + } + + public EnhancedProperties getArgs() { + return args; + } + /** * Read a config file that contains more options. When the number of * options becomes large it is more convenient to place them in a file. * * @param filename The filename to obtain options from. */ - private void readConfigFile(String filename) { + public void readConfigFile(String filename) { Options opts = new Options(new OptionProcessor() { public void processOption(Option opt) { log.debug("incoming opt", opt.getOption(), opt.getValue()); @@ -206,14 +214,14 @@ * the argument to be processed in order. Options can be intersperced with * filenames. The options take effect where they appear. */ - interface ArgType { + public interface ArgType { public abstract void processArg(); } /** * A filename. */ - class Filename implements ArgType { + public class Filename implements ArgType { private final String name; private boolean useFilenameAsMapname = true; @@ -270,7 +278,7 @@ /** * An option argument. A key value pair. */ - class CommandOption implements ArgType { + public class CommandOption implements ArgType { private final Option option; private CommandOption(Option option) { @@ -297,7 +305,7 @@ /** * The arguments are held in this list. */ - class ArgList implements Iterable<CommandArgsReader.ArgType> { + public class ArgList implements Iterable<CommandArgsReader.ArgType> { private final List<ArgType> alist; private int filenameCount;
participants (1)
-
Christian Gawron