ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivan Ivanov <rambiusparkisan...@yahoo.com>
Subject Basedir of imported file replaced with basedir of importing file
Date Thu, 24 Jun 2004 06:48:46 GMT
Dear Colleagues,

I am having some issues when using <import> task and I
would be very grateful if you help me to resolve them.
The scenario is the following:

I created an ant build xml called jalopy.xml[1] which
<taskdef> jalopy task (Jalopy is a source code
formatter). The paths to the jalopy distribution and
jalopy lib  are moved to an external properties file
called jalopy.properties[2]. Both jalopy.xml and
jalopy.properties are in one dir. I also created a
macrodef that uses <jalopy> task.

I tried to designed jalopy.xml script to be applicable
to all our projects. What one needs to do to use is
simply to checkout the script and properties from CVS
anywhere she wants on her file system, change the
properties in jalopy.properties, <import> jalopy.xml
and start using the macrodef. For example, this is a
sample use of it for the project MyProj:

<project name="MyProject" basedir="." default="usage">
    <target name="usage"/>
    <import file="${jalopy.commons.dir}/jalopy.xml"
optional="true"/>

    <target name="format-src"
depends="compile,-jalopy.init" description="Formats
the project's java sources">
   	<path id="project.classpath">
   	    <path refid="classpath"/>
   	    <path location="${project.classes}"/>
   	</path>
	<fileset dir="${project.src}" id="project.src.java">
            <include name="**/*.java" />
      	</fileset>
        <format-jalopy 
classpathref="project.classpath"
srcref="project.src.java"/>
</project>

The problem with this is that when I call 
<property file="${basedir}/jalopy.properties"> in
jalopy.xml, ${basedir} property is resolved against
MyProject, and not against jalopy.xml. So
jalopy.properties is not found and the build failed

Of course, I workarounded it but it is not beautifull
any more. This is only because the basedir of the
imported file is replaced with basedir of the
importing file. Is it a bug or it is done by design
and intention? And is it possible to implement my idea
in this way?

[1] jalopy.xml
<project name="SourceFormatter" default="usage"
basedir=".">
    <target name="usage"/>
    <target name="-jalopy.init"
description="Initializes the needed properties and
tasks">

<import file="${jalopy.dir}/jalopy.xml"
optional="true"/>
        <!-- Import Jalopy Settings -->
        <property file="${basedir}/jalopy.properties">
	<taskdef name="jalopy"	     
classname="de.hunsicker.jalopy.plugin.ant.AntPlugin">
	    <classpath>
	    	<fileset dir="${jalopy.dir.lib}">
	      	    <include name="*.jar" />
	    	</fileset>
	    </classpath>
	</taskdef>

   	<macrodef name="format-jalopy"
description="Formats java sources with jalopy">
   	    <attribute name="classpathref" default=""
description="Reference to classpath, used for
formatting"/>
   	    <attribute name="srcref"
description="Reference to a fileset, describing the
sources to format"/>
   	    <sequential>
                <jalopy
convention="${basedir}/mycc.xml" force="yes"
		        classpathref="@{classpathref}">
		    <fileset refid="@{srcref}"/>
		</jalopy>
   	    </sequential>
   	</macrodef>

    </target>
</project>

and mycc.xml is the xml represantation of my code
conventions against which the code will be formatted.

[2]jalopy.properties
# Jalopy root directory
jalopy.dir.install=/usr/java/jalopy
# Jalopy library directory
jalopy.dir.lib=${jalopy.dir.install}/lib



		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message