<?xml version="1.0" encoding="ISO-8859-1"?>
<!--

    gvSIG. Desktop Geographic Information System.

    Copyright (C) 2007-2013 gvSIG Association.

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 3
    of the License, or (at your option) any later version.

    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.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    MA  02110-1301, USA.

    For any additional information, do not hesitate to contact us
    at info AT gvsig.com, or visit our website www.gvsig.com.

-->
<project name="gvSIG-make-maven-project" default="mkproject-build" basedir=".">

	<!-- Get current file location folder -->
	<dirname property="gvSIG-make-maven-project.basedir" file="${ant.file.gvSIG-make-maven-project}" />

	<!-- Libraries folder in the gvSIG extension -->
	<property name="lib.folder" location="${gvSIG-make-maven-project.basedir}/../lib" />
	<!-- Templates folder in the gvSIG extension -->
	<property name="templates.folder" location="${gvSIG-make-maven-project.basedir}/../templates" />

	<property name="gvsiglogo" location="${basedir}/../gvSIG.png" />

	<!-- Load some ant external utility tasks -->
	<property name="antform.lib" location="${lib.folder}/antform-2.0.jar" />
	<property name="antcontrib.lib" location="${lib.folder}/ant-contrib-1.0b3.jar" />
	<property name="antelope.lib" location="${lib.folder}/antelopetasks-3.2.10.jar" />

	<taskdef resource="net/sf/antcontrib/antlib.xml">
		<classpath>
			<pathelement location="${antcontrib.lib}" />
		</classpath>
	</taskdef>

	<taskdef name="antform" classname="com.sardak.antform.AntForm" classpath="${antform.lib}" />

	<taskdef name="antmenu" classname="com.sardak.antform.AntMenu" classpath="${antform.lib}" />

	<taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" classpath="${antelope.lib}" />

	<target name="mkproject-build-cancelled">
		<antform title="Project creation cancelled" width="${form.width}" image="${gvsiglogo}">
			<textProperty label="" editable="false" columns="40" property="form.title" />
			<label>Creation cancelled.</label>
			<separator />
			<controlbar>
				<button type="cancel" label=" Close " />
			</controlbar>
		</antform>
	</target>

	<target name="mkproject-build">
		<echo>
  Project name: "${project.name}"
  Project name capitalized: "${project.name.capitalized}"
  Project name lowercase: ${project.name.lowercase}"
  Group id: "${project.group.id}"
  ArtifactId: "${project.artifact.id}"
  Project folder: "${project.folder}"
        </echo>

		<echo>Unzipping the basic template project</echo>
		<unzip src="${templates.folder}/landregistryviewer.zip" dest="${project.folder}" />

		<!-- Calculate the project artifact id as PATH -->
		<propertyregex property="project.artifact.id.folder" input="${project.artifact.id}" regexp="([^\.]*).([^\.]*)" replace="\1/\2" />

		<echo>Renaming folder ${project.folder}/org.gvsig.landregistryviewer to 
            ${project.folder}/${project.artifact.id}</echo>

		<move todir="${project.folder}">
			<fileset dir="${project.folder}">
				<include name="org.gvsig.landregistryviewer/**/*.txt" />
				<include name="org.gvsig.landregistryviewer/**/*.java" />
				<include name="org.gvsig.landregistryviewer/**/*.xml" />
				<include name="org.gvsig.landregistryviewer/**/org.gvsig.tools.library.Library" />
				<include name="org.gvsig.landregistryviewer.app/**/org.gvsig.tools.library.Library" />
				<include name="org.gvsig.landregistryviewer.app/**/*.txt" />
				<include name="org.gvsig.landregistryviewer.app/**/*.xml" />
				<include name="org.gvsig.landregistryviewer.app/**/*.java" />
 			</fileset>
			<mapper>
				<filtermapper>
					<replacestring from="org.gvsig.landregistryviewer" to="${project.artifact.id}" />
					<replacestring from="org${file.separator}gvsig${file.separator}landregistryviewer" to="${project.artifact.id.folder}" />
					<replacestring from="LandRegistryViewer" to="${project.name.capitalized}" />
				</filtermapper>
			</mapper>
			<filterchain>
				<tokenfilter>
					<replacestring from="org.gvsig.landregistryviewer" to="${project.artifact.id}" />
				</tokenfilter>
				<tokenfilter>
					<replacestring from="LandRegistryViewer" to="${project.name.capitalized}" />
					<replacestring from="Land Registry Viewer" to="${project.name.capitalized}" />
					<replacestring from="gvsig-landregistryviewer" to="gvsig-${project.name.lowercase}" />
				</tokenfilter>
				<tokenfilter>
					<replacestring from="LandRegistryViewer" to="${project.name.capitalized}" />
					<replacestring from="Land Registry Viewer" to="${project.name.capitalized}" />
					<replacestring from="gvsig-landregistryviewer" to="gvsig-${project.name.lowercase}" />
				</tokenfilter>
			</filterchain>
		</move>
		<move todir="${project.folder}">
			<fileset dir="${project.folder}">
                                <include name="org.gvsig.landregistryviewer/**" />
                                <include name="org.gvsig.landregistryviewer.app/**" />
			</fileset>
			<mapper>
				<filtermapper>
					<replacestring from="org.gvsig.landregistryviewer" to="${project.artifact.id}" />
					<replacestring from="org${file.separator}gvsig${file.separator}landregistryviewer" to="${project.artifact.id.folder}" />
					<replacestring from="LandRegistryViewer" to="${project.name.capitalized}" />
				</filtermapper>
			</mapper>
		</move>
<!--
		<delete dir="${project.folder}/org.gvsig.landregistryviewer"/>
		<delete dir="${project.folder}/org.gvsig.landregistryviewer.app"/>
-->
	</target>


</project>