Index: trunk/build.xml
===================================================================
--- trunk/build.xml	(revision 9749)
+++ trunk/build.xml	(revision 9765)
@@ -9,22 +9,32 @@
 **
 -->
-<project xmlns:as="antlib:org.codehaus.mojo.animal_sniffer" name="josm" default="dist" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
-    <property name="test.dir" location="test"/>
-    <property name="src.dir" location="src"/>
-    <property name="build.dir" location="build"/>
-    <property name="javacc.home" location="tools"/>
-    <property name="mapcss.dir" location="${src.dir}/org/openstreetmap/josm/gui/mappaint/mapcss"/>
-    <property name="epsg.output" location="data/projection/custom-epsg"/>
-    <property name="groovy.jar" location="tools/groovy-all-2.4.6-SNAPSHOT.jar"/>
-    <!-- build parameter: compression level (ant -Dclevel=N)
-             N ranges from 0 (no compression) to 9 (maximum compression)
-             default: 9 -->
-    <condition property="clevel" value="${clevel}" else="9">
-        <isset property="clevel"/>
-    </condition>
-    <!-- For Java9-specific stuff -->
-    <condition property="isJava9">
-        <equals arg1="${ant.java.version}" arg2="1.9" />
-    </condition>
+<project xmlns:as="antlib:org.codehaus.mojo.animal_sniffer" name="josm" default="dist" xmlns:jacoco="antlib:org.jacoco.ant">
+    <target name="init-properties">
+        <!-- Load properties in a target and not at top level, so this build file can be
+        imported from an IDE ant file (Netbeans) without messing up IDE properties.
+        When imported from another file, ${basedir} will point to the parent directory
+        of the importing ant file. Use ${base.dir} instead, which is always the parent
+        directory of this file. -->
+        <dirname property="base.dir" file="${ant.file.josm}"/>
+        <property name="test.dir" location="${base.dir}/test"/>
+        <property name="src.dir" location="${base.dir}/src"/>
+        <property name="build.dir" location="${base.dir}/build"/>
+        <property name="dist.dir" location="${base.dir}/dist"/>
+        <property name="javacc.home" location="${base.dir}/tools"/>
+        <property name="mapcss.dir" location="${src.dir}/org/openstreetmap/josm/gui/mappaint/mapcss"/>
+        <property name="proj-build.dir" location="${base.dir}/build2"/>
+        <property name="epsg.output" location="${base.dir}/data/projection/custom-epsg"/>
+        <property name="groovy.jar" location="${base.dir}/tools/groovy-all-2.4.6-SNAPSHOT.jar"/>
+        <!-- build parameter: compression level (ant -Dclevel=N)
+                 N ranges from 0 (no compression) to 9 (maximum compression)
+                 default: 9 -->
+        <condition property="clevel" value="${clevel}" else="9">
+            <isset property="clevel"/>
+        </condition>
+        <!-- For Java9-specific stuff -->
+        <condition property="isJava9">
+            <equals arg1="${ant.java.version}" arg2="1.9" />
+        </condition>
+    </target>
 
     <!--
@@ -39,6 +49,6 @@
       ** Initializes the REVISION.XML file from SVN information
     -->
-    <target name="init-svn-revision-xml">
-        <exec append="false" output="REVISION.XML" executable="svn" failifexecutionfails="false" resultproperty="svn.info.result">
+    <target name="init-svn-revision-xml" depends="init-properties">
+        <exec append="false" output="${base.dir}/REVISION.XML" executable="svn" dir="${base.dir}" failifexecutionfails="false" resultproperty="svn.info.result">
             <env key="LANG" value="C"/>
             <arg value="info"/>
@@ -53,6 +63,6 @@
       ** Initializes the REVISION.XML file from git information
     -->
-    <target name="init-git-revision-xml" unless="svn.info.success">
-        <exec append="false" output="REVISION.XML" executable="git" failifexecutionfails="false">
+    <target name="init-git-revision-xml" unless="svn.info.success" depends="init-properties">
+        <exec append="false" output="${base.dir}/REVISION.XML" executable="git" dir="${base.dir}" failifexecutionfails="false">
             <arg value="log"/>
             <arg value="-1"/>
@@ -66,5 +76,5 @@
             <arg value="HEAD"/>
         </exec>
-        <replaceregexp file="REVISION.XML" flags="s"
+        <replaceregexp file="${base.dir}/REVISION.XML" flags="s"
                        match=".*git-svn-id: [^@]*@([0-9]+).*(\d{4}-\d{2}-\d{2}.\d{2}\:\d{2}\:\d{2}\s*[+-]\d{2}:?\d{2})\s*$"
                        replace="&lt;info&gt;&lt;entry&gt;&lt;commit revision=&quot;\1&quot;&gt;&lt;date&gt;\2&lt;/date&gt;&lt;/commit&gt;&lt;/entry&gt;&lt;/info&gt;"/>
@@ -73,8 +83,8 @@
       ** Creates the REVISION file to be included in the distribution
     -->
-    <target name="create-revision" depends="init-svn-revision-xml, init-git-revision-xml">
+    <target name="create-revision" depends="init-properties,init-svn-revision-xml,init-git-revision-xml">
         <property name="revision.dir" value="${build.dir}"/>
-        <xmlproperty file="REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
-        <delete file="REVISION.XML"/>
+        <xmlproperty file="${base.dir}/REVISION.XML" prefix="version" keepRoot="false" collapseAttributes="true"/>
+        <delete file="${base.dir}/REVISION.XML"/>
         <tstamp>
             <format property="build.tstamp" pattern="yyyy-MM-dd HH:mm:ss"/>
@@ -94,5 +104,5 @@
       ** Check internal XML files against their XSD
     -->
-    <target name="check-schemas" unless="check-schemas.notRequired">
+    <target name="check-schemas" unless="check-schemas.notRequired" depends="init-properties">
         <schemavalidate file="data/defaultpresets.xml" >
             <schema namespace="http://josm.openstreetmap.de/tagging-preset-1.0" file="data/tagging-preset.xsd" />
@@ -108,6 +118,6 @@
         <copy file="LICENSE" todir="build"/>
         <!-- create josm-custom.jar -->
-        <delete file="dist/josm-custom.jar"/>
-        <jar destfile="dist/josm-custom.jar" basedir="build" level="${clevel}">
+        <delete file="${dist.dir}/josm-custom.jar"/>
+        <jar destfile="${dist.dir}/josm-custom.jar" basedir="${build.dir}" level="${clevel}">
             <!-- add attribute excludes="**/*BZip2*,**/*Bzip2*" to create a non-bzip2 supporting jar -->
             <manifest>
@@ -126,5 +136,5 @@
     </target>
     <!-- Mac OS X target -->
-    <target name="mac">
+    <target name="mac" depends="init-properties">
         <!-- Using https://bitbucket.org/infinitekind/appbundler to create mac application bundle -->
         <taskdef name="bundleapp" classname="com.oracle.appbundler.AppBundlerTask" classpath="tools/appbundler-1.0ea.jar"/>
@@ -156,8 +166,8 @@
             <option value="-Dcom.apple.smallTabs=true"/>
         </bundleapp>
-        
+
         <!-- appbundler lacks the possibility of defining our own keys or using a template, so update the .plist manually -->
         <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="tools/xmltask.jar"/>
-        
+
         <xmltask source="${bundle.outdir}/JOSM.app/Contents/Info.plist" dest="${bundle.outdir}/JOSM.app/Contents/Info.plist" indent="false">
             <!-- remove empty CFBundleDocumentTypes definition -->
@@ -166,5 +176,5 @@
             <insert position="before" path="/plist/dict/key[1]" file="macosx/JOSM.app/Contents/Info.plist_template.xml" />
         </xmltask>
-        
+
         <!-- create ZIP file with MacOS X application bundle -->
         <zip destfile="${bundle.outdir}/josm-custom-macosx.zip" update="true">
@@ -175,6 +185,6 @@
     <target name="distmac" depends="dist">
         <antcall target="mac">
-            <param name="bundle.outdir" value="dist"/>
-            <param name="bundle.jar" value="dist/josm-custom.jar"/>
+            <param name="bundle.outdir" value="${dist.dir}"/>
+            <param name="bundle.jar" value="${dist.dir}/josm-custom.jar"/>
         </antcall>
     </target>
@@ -226,5 +236,5 @@
         </javac>
         <!-- JMapViewer -->
-        <javac sourcepath="" srcdir="${src.dir}" excludes="com/**,oauth/**,org/apache/commons/**,org/glassfish/**,org/openstreetmap/gui/jmapviewer/Demo.java,org/openstreetmap/josm/**,JOSM.java,gnu/**" 
+        <javac sourcepath="" srcdir="${src.dir}" excludes="com/**,oauth/**,org/apache/commons/**,org/glassfish/**,org/openstreetmap/gui/jmapviewer/Demo.java,org/openstreetmap/josm/**,JOSM.java,gnu/**"
             destdir="build" target="1.7" source="1.7" debug="on" includeantruntime="false" createMissingPackageInfoClass="false" encoding="UTF-8">
             <compilerarg value="-Xlint:cast"/>
@@ -243,5 +253,5 @@
         </javac>
         <!-- JOSM -->
-        <javac sourcepath="" srcdir="${src.dir}" excludes="com/**,oauth/**,org/apache/commons/**,org/glassfish/**,org/openstreetmap/gui/jmapviewer/Demo.java" 
+        <javac sourcepath="" srcdir="${src.dir}" excludes="com/**,oauth/**,org/apache/commons/**,org/glassfish/**,org/openstreetmap/gui/jmapviewer/Demo.java"
             destdir="build" target="1.7" source="1.7" debug="on" includeantruntime="false" createMissingPackageInfoClass="false" encoding="UTF-8">
             <compilerarg value="-Xlint:cast"/>
@@ -264,15 +274,15 @@
         </copy>
     </target>
-    <target name="init">
+    <target name="init" depends="init-properties">
         <uptodate property="javacc.notRequired" targetfile="${mapcss.dir}/parsergen/MapCSSParser.java" >
             <srcfiles dir="${mapcss.dir}" includes="MapCSSParser.jj"/>
         </uptodate>
-        <mkdir dir="build"/>
-        <mkdir dir="dist"/>
-    </target>
-    <target name="javadoc">
-        <javadoc destdir="javadoc" 
+        <mkdir dir="${build.dir}"/>
+        <mkdir dir="${dist.dir}"/>
+    </target>
+    <target name="javadoc" depends="init-properties">
+        <javadoc destdir="javadoc"
                 sourcepath="${src.dir}"
-                encoding="UTF-8"    
+                encoding="UTF-8"
                 packagenames="org.openstreetmap.josm.*,org.openstreetmap.gui.jmapviewer.*"
                 excludepackagenames="org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.*"
@@ -287,8 +297,8 @@
         </javadoc>
     </target>
-    <target name="clean">
-        <delete dir="build"/>
-        <delete dir="build2"/>
-        <delete dir="dist"/>
+    <target name="clean" depends="init-properties">
+        <delete dir="${build.dir}"/>
+        <delete dir="${proj-build.dir}"/>
+        <delete dir="${dist.dir}"/>
         <delete dir="${mapcss.dir}/parsergen"/>
         <delete file="${src.dir}/org/w3/_2001/xmlschema/Adapter1.java"/>
@@ -300,5 +310,5 @@
             <include name="**/*.jar"/>
         </fileset>
-        <pathelement path="dist/josm-custom.jar"/>
+        <pathelement path="${dist.dir}/josm-custom.jar"/>
         <pathelement path="${groovy.jar}"/>
         <pathelement path="tools/findbugs/annotations.jar"/>
@@ -312,5 +322,5 @@
         </sequential>
     </macrodef>
-    <target name="test-init">
+    <target name="test-init" depends="init-properties">
         <mkdir dir="${test.dir}/build"/>
         <mkdir dir="${test.dir}/build/unit"/>
@@ -323,5 +333,5 @@
         <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpath="tools/jacocoant.jar" />
     </target>
-    <target name="test-clean">
+    <target name="test-clean" depends="init-properties">
         <delete dir="${test.dir}/build"/>
         <delete dir="${test.dir}/report"/>
@@ -527,5 +537,5 @@
                 <tokenfilter>
                     <replaceregex pattern="\|$" replace="" flags="gi"/>
-                </tokenfilter>    
+                </tokenfilter>
             </filterchain>
         </loadresource>
@@ -547,5 +557,5 @@
         <as:build-signatures destfile="${dir}/api.sig">
             <path>
-                <fileset file="dist/josm-custom-optimized.jar"/>
+                <fileset file="${dist.dir}/josm-custom-optimized.jar"/>
                 <fileset file="${java.home}/lib/rt.jar"/>
                 <fileset file="${java.home}/lib/jce.jar"/>
@@ -594,5 +604,5 @@
         <sequential>
             <echo message="Generating Taginfo for type @{type} to @{output}"/>
-            <groovy src="${taginfoextract}" classpath="dist/josm-custom.jar">
+            <groovy src="${taginfoextract}" classpath="${dist.dir}/josm-custom.jar">
                 <arg value="-t"/>
                 <arg value="@{type}"/>
@@ -616,8 +626,8 @@
     </target>
 
-    <target name="imageryindex">
+    <target name="imageryindex" depends="init-properties">
         <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpath="${groovy.jar};tools/commons-cli-1.3.1.jar"/>
         <echo message="Checking editor imagery difference"/>
-        <groovy src="scripts/sync_editor_imagery_index.groovy" classpath="dist/josm-custom.jar">
+        <groovy src="scripts/sync_editor_imagery_index.groovy" classpath="${dist.dir}/josm-custom.jar">
             <arg value="-nomissingeii"/>
         </groovy>
@@ -640,11 +650,11 @@
     </target>
 
-    <target name="checkstyle">
-        <taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties" 
+    <target name="checkstyle" depends="init-properties">
+        <taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties"
              classpath="tools/checkstyle/checkstyle-6.15-all.jar"/>
         <checkstyle config="tools/checkstyle/josm_checks.xml">
-            <fileset dir="${basedir}/src/org/openstreetmap/josm" includes="**/*.java" 
+            <fileset dir="${base.dir}/src/org/openstreetmap/josm" includes="**/*.java"
                 excludes="gui/mappaint/mapcss/parsergen/*.java"/>
-            <fileset dir="${basedir}/test" includes="**/*.java"/>
+            <fileset dir="${base.dir}/test" includes="**/*.java"/>
             <formatter type="xml" toFile="checkstyle-josm.xml"/>
         </checkstyle>
@@ -654,5 +664,5 @@
         <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpath="tools/findbugs/findbugs-ant.jar"/>
         <path id="findbugs-classpath">
-            <fileset dir="tools/findbugs/">
+            <fileset dir="${base.dir}/tools/findbugs/">
                 <include name="*.jar"/>
             </fileset>
@@ -666,10 +676,10 @@
                 effort="max"
                 >
-            <sourcePath path="${basedir}/src" />
-            <class location="${basedir}/dist/josm-custom.jar" />
+            <sourcePath path="${base.dir}/src" />
+            <class location="${dist.dir}/josm-custom.jar" />
         </findbugs>
     </target>
     <target name="run" depends="dist">
-        <java jar="dist/josm-custom.jar" fork="true">
+        <java jar="${dist.dir}/josm-custom.jar" fork="true">
             <arg value="--set=expert=true"/>
             <arg value="--set=remotecontrol.enabled=true"/>
@@ -678,12 +688,19 @@
         </java>
     </target>
-    <!-- compile build script for generating projection list -->
-    <target name="epsg-compile" depends="compile">
-        <mkdir dir="build2"/>
-        <javac sourcepath="" srcdir="scripts" failonerror="true"
-            destdir="build2" target="1.7" source="1.7" debug="on" includeantruntime="false" createMissingPackageInfoClass="false" encoding="UTF-8" classpath="build">
+    <!--
+      ** Compile build script for generating projection list.
+    -->
+    <target name="epsg-compile">
+        <property name="proj-classpath" location="${build.dir}"/>
+        <mkdir dir="${proj-build.dir}"/>
+        <javac sourcepath="" srcdir="${base.dir}/scripts" failonerror="true"
+            destdir="${proj-build.dir}" target="1.7" source="1.7" debug="on"
+            includeantruntime="false" createMissingPackageInfoClass="false"
+            encoding="UTF-8" classpath="${proj-classpath}">
         </javac>
     </target>
-    <!-- generate projection list -->
+    <!--
+      ** generate projection list.
+    -->
     <target name="epsg" depends="epsg-compile">
         <touch file="${epsg.output}"/>
@@ -691,9 +708,9 @@
             <sysproperty key="java.awt.headless" value="true"/>
             <classpath>
-                <pathelement path="."/>
-                <pathelement path="build"/>
-                <pathelement path="build2"/>
+                <pathelement path="${base.dir}"/>
+                <pathelement path="${proj-classpath}"/>
+                <pathelement path="${proj-build.dir}"/>
             </classpath>
-            <arg value="${basedir}"/>
+            <arg value="${base.dir}"/>
         </java>
     </target>
