You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jason Rogers <ja...@tumbleweed.com> on 2001/09/19 21:16:40 UTC

RE: Checking if properties is set

<target name="preinit" if="property.one, property.two, property.three,
property.four">
    <property name="all.okay" value="yes"/>
</target>
All of the other targets have <...if="all.okay"...> set.
-Jason

    > -----Original Message-----
    > From: Ylan Segal [mailto:ylan@digiworks.tv]
    > Sent: Wednesday, September 19, 2001 4:04 PM
    > To: ant-user@jakarta.apache.org
    > Subject: Checking if properties is set
    > 
    > 
    > Hi,
    > 
    > 
    > I am trying to write a target that checks if all needed 
    > properties are set
    > before it actually does anything else.
    > Why? because there are several developers working on a 
    > project and since the
    > build.xml is being checked into cvs, the specific 
    > properties (like src.home,
    > javadoc.home, etc) are particular to each developer and set in a
    > build.properties that is NOT checked-in to cvs.
    > However, I have managed to check with the condition task if the
    > build.properties is present, but that does not garantee 
    > that all the
    > properties needed are set, for example, if javadoc.home 
    > is not set, then I
    > end up having a directory created with the name ${javadoc.home}.
    > I want the build to fail if not all required properties are set.
    > 
    > Does anyone have an idea on how to do this? What I want 
    > really, is for the
    > condition task to be able to check for a specific property.
    > 
    > All help greatly appreciated.
    > 
    > Ylan Segal.
    > 
    > 
    > 


Re: Any way to test if on unix/linux, mac, windows, etc?

Posted by Diane Holt <ho...@yahoo.com>.
--- Kevin Duffey <ke...@home.com> wrote:
> I am wondering if there is a way to conditionally check and/or set the
> path based on the platform it is being run on?

There's the ${os.name} system property.

Diane



=====
(holtdl@yahoo.com)



__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

Any way to test if on unix/linux, mac, windows, etc?

Posted by Kevin Duffey <ke...@home.com>.
Hi,

I have built scripts for windows only, and now I need a "cross-platform" 
script. Almost everything in the script should work fine to build my java 
projects, but I do have the problem of "paths". I am wondering if there is 
a way to conditionally check and/or set the path based on the platform it 
is being run on?

Thanks.


RE: Checking if properties is set

Posted by Ylan Segal <yl...@digiworks.tv>.
Well Diane, it worked like a charm. Thank you very much. I have written the
target as you suggested and if not all properties are set, then the build
fails with a message saying what properties are needed. This exactly what I
wanted.

Below is the actual xml portion if anyone is interested:

....
<target name="check" description="Checks weather project is ready for
building">
	<tstamp/>
	<echo message="Build started: ${DSTAMP}"/>
	<property name="check.src.home" value="$${src.home}"/>
	<property name="check.compile.to" value="$${compile.to}"/>
	<property name="check.dist.home" value="$${dist.home}"/>
	<property name="check.javadoc.home" value="$${javadoc.home"/>
	<property name="check.doccheck.home" value="$${doccheck.home}"/>
	<property name="check.packages" value="$${packages}"/>
	<property name="check.lib.home" value="$${lib.home}"/>
	<property name="check.extlibs.home" value="$${extlibs.home}"/>
	<condition property="missing.properties">
		<or>
			<equals arg1="${check.src.home}" arg2="${src.home}"/>
			<equals arg1="${check.compile.to}" arg2="${compile.to}"/>
			<equals arg1="${check.dist.home}" arg2="${dist.home}"/>
			<equals arg1="${check.javadoc.home}" arg2="${javadoc.home}"/>
			<equals arg1="${check.doccheck.home}" arg2="${docheck.home}"/>
			<equals arg1="${check.packages}" arg2="${packages}"/>
			<equals arg1="${check.lib.home}" arg2="${lib.home}"/>
			<equals arg1="${check.extlibs.home}" arg2="${extlibs.home}"/>

		</or>
	</condition>
	<antcall target="help"/>
</target>

<target name="help" if="missing.properties">
	<echo>
	Not all needed properties are set!!!
	This build file needs a build.properies file to set the following
properties:
		src.home - The source code (.java files) home.
		compile.to - Where the classes are compiled to.
		dist.home - The directory where distribution files are created.
		javadoc.home - The directory for the javadoc html.
		doccheck.home - The directory for the DocCheck html
		packages - the packages to compile, it accepts * (ie tv.*)
		lib.home - Directory where needed jar's are stored.
		extlibs.hom - Directory where needed jar's are copied from.

	Other properties can also be set in this file (like build.compiler, etc).
	</echo>
	<fail message="Not all needed properties are set!!!"/>
</target>
....

I made my other targets like prepare and clean depend on check, and it
appears to be working great.

Ylan Segal.


RE: Checking if properties is set

Posted by Ylan Segal <yl...@digiworks.tv>.
Thanks Diane I will try that tomorrow morning and I will let you know. But
it looks that like always, you are the top guru.

Ylan


RE: Checking if properties is set

Posted by Diane Holt <ho...@yahoo.com>.
--- Ylan Segal <yl...@digiworks.tv> wrote:
> Thanks, I did not know that you could set more than one property in the
> if or unless.

You can't -- it will simply incorporate the comma(s) into the name of the
property it's looking for (eg., if="a,b,c" will end up checking whether a
property named a,b,c is set.

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

RE: Checking if properties is set

Posted by Ylan Segal <yl...@digiworks.tv>.
Thanks, I did not know that you could set more than one property in the if
or unless. That should do it.,

> -----Original Message-----
> From: Jason Rogers [mailto:jason.rogers@tumbleweed.com]
> Sent: Wednesday, September 19, 2001 1:17 PM
> To: 'ant-user@jakarta.apache.org'
> Subject: RE: Checking if properties is set
>
>
> <target name="preinit" if="property.one, property.two, property.three,
> property.four">
>     <property name="all.okay" value="yes"/>
> </target>
> All of the other targets have <...if="all.okay"...> set.
> -Jason
>
>     > -----Original Message-----
>     > From: Ylan Segal [mailto:ylan@digiworks.tv]
>     > Sent: Wednesday, September 19, 2001 4:04 PM
>     > To: ant-user@jakarta.apache.org
>     > Subject: Checking if properties is set
>     >
>     >
>     > Hi,
>     >
>     >
>     > I am trying to write a target that checks if all needed
>     > properties are set
>     > before it actually does anything else.
>     > Why? because there are several developers working on a
>     > project and since the
>     > build.xml is being checked into cvs, the specific
>     > properties (like src.home,
>     > javadoc.home, etc) are particular to each developer and set in a
>     > build.properties that is NOT checked-in to cvs.
>     > However, I have managed to check with the condition task if the
>     > build.properties is present, but that does not garantee
>     > that all the
>     > properties needed are set, for example, if javadoc.home
>     > is not set, then I
>     > end up having a directory created with the name ${javadoc.home}.
>     > I want the build to fail if not all required properties are set.
>     >
>     > Does anyone have an idea on how to do this? What I want
>     > really, is for the
>     > condition task to be able to check for a specific property.
>     >
>     > All help greatly appreciated.
>     >
>     > Ylan Segal.
>     >
>     >
>     >
>
>