ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@yawido.de
Subject RE: properties handling problem
Date Thu, 03 Aug 2006 10:16:24 GMT
Hi,

both tasks, <foreach> and <for> only works with ant-contrib 0.6 - i suppose...
1.0b2 is without the for-task...

wahtever.. no its running with 0.6

I soluted it with a foreach, for and a macrodef...

For each person who are interested - here's the code:
[sorry for bad format - i use the horde-webmailer - not so easy to format code
inserted by copy-and-paste]

<project name="copytest" default="postalservice"
xmlns:cpptasks="antlib:org.sf.net.antcontrib.cpptasks">
	<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
	<property file="build.properties" />


	<!-- =================================
			      target: Schleife für Verfügbarkeitstest
			     ================================= -->
			<target name="uploadloop">
					<foreach list="${hostlist}" target="upload_start" param="num" />
			</target>
			<!-- =================================
		          target: Macro - Def. sequentielle Abarbeitung der Server - Aufruf
per <antcall> des eigentlich upload-targets
		         ================================= -->
		<target name="upload_start" description="Checking the systems for
upload_start">

			<macrodef name="upload_start_macro">
				<attribute name="hostname"/>
				<attribute name="num"/>
				<attribute name="server" default="@{hostname}_@{num}" />
				<attribute name="user" default="${@{hostname}_@{num}_user}" />
				<attribute name="password" default="${@{hostname}_@{num}_password}"/>
					<sequential>
						<record name="log.txt" action="start" />
						<sshexec host="${@{server}}" username="@{user}" password="@{password}"
command="" trust="yes" failonerror="false" outputproperty="temp" 
timeout="3000"
/>
						<record name="log.txt" action="stop"/>
						<echo>${@{server}} available</echo>

					<for list="${@{server}_dir}" param="dir">
						<sequential>
						<antcall target="upload">
							<param name="dir" value="@{dir}" />
							<param name="host" value="host_@{num}" />
							<param name="chmod" value="${@{hostname}_@{num}_chmod}"/>
							<param name="server" value="${@{server}}"/>
							<param name="user" value="@{user}" />
							<param name="password" value="@{password}"/>
							<param name="num" value="@{num}" />
							</antcall>
							</sequential>
						</for>
					</sequential>
			</macrodef>
				<upload_start_macro hostname="host" num="${num}"/>

		</target>
			  	<!-- =================================
		          target: Upload per SCP und setzen chmod, owner, group
		         ================================= -->
		<target name="upload" description="Uploading the files which are defined in
outputs - dir">

				<scp todir="${user}:${password}@${server}:${dir}" trust="yes"
failonerror="false">
					<fileset dir="${output}">
						<include name="**/*" />
					</fileset>
				</scp>
					<sshexec host="${server}" username="${user}" password="${password}"
trust="yes" failonerror="false" command="chmod ${chmod} ${dir}/**.*" />

		</target>
			<!-- =================================
		          target: Start des Skripts
		         ================================= -->
		<target name="postalservice" depends="uploadloop"/>

</project>


very chaotic... :-))

greetz 2 all...
Beni

Zitat von "Rebhan, Gilbert" <Gilbert.Rebhan@huk-coburg.de>:

>
> Hi,
>
> works fine with ant-contrib 1.0b2 and ant 1.6.5 here.
>
> You should upgrade your ant-contrib version.
>
> The <task> in that version supports the unset attribute.
>
> see http://ant-contrib.sourceforge.net/tasks/tasks/index.html
>
> Property Tasks / Variable
>
> Regards, Gilbert
>
>
> -----Original Message-----
> From: heisch@yawido.de [mailto:heisch@yawido.de]
> Sent: Monday, July 31, 2006 4:21 PM
> To: user@ant.apache.org
> Subject: RE: properties handling problem
>
> Hi,
> first, thanks for your help!!
>
> I tried to implement the pfunctions - lib.. but not so successful..
>
> I think the solution with ant-contrib and the 'for' - iteration is good...
>
> But following problem embarrass me...
>
> BUILD FAILED
> C:\workspace\Synchro - Tool\Ant - Tests\build.xml:24: The <var> type doesn't
> support the "unset" attribute.
>
> this is the code:
> <target name="default" description="--> description">
> 		<echo>"TEST"</echo>
>
> 		<property name="x" value="6"/>
> 		    <echo>${x}</echo>   <!-- will print 6 -->
> 		    <var name="x" unset="true"/>
> 		    <property name="x" value="12"/>
> 		    <echo>${x}</echo>   <!-- will print 12 -->
>
> 		 </target>
>
> same problem was in Gilbert's script??
> What's the problem?
>
> In the official doc for ant-contrib is the task also included.... ?!?!
>
> I've version 0.6 in use - and Ant 1.6.5...
>
>
>
>
>
> Zitat von "Rebhan, Gilbert" <Gilbert.Rebhan@huk-coburg.de>:
>
>>
>> Second suggestion =
>>
>> i think your problem is, that properties are immutable once set
>>
>> here's a workaround with <var> from antcontrib :
>>
>> <fileset id="files" dir="T:/foobar" includes="*.*" />
>>
>>
>> <for param="file">
>> <path>
>> 	<fileset refid="files" />
>> </path>
>> <sequential>
>> <echo>
>> Filepath === @{file}
>>  </echo>
>>
>> <var name="filename" unset="true" />
>> <basename property="filename" file="@{file}" />
>>
>> <echo>
>> Filename === ${filename}
>> </echo>
>>
>> </sequential>
>> </for>
>>
>>
>> the property file is automatically overwritten for every loop, but
>> the property filename has to be unset and set again
>>
>> i think you have to do the same for
>> $hostname} and  ${num} in your script.
>>
>>
>> Regards, Gilbert
>>
>> -----Original Message-----
>> From: heisch@yawido.de [mailto:heisch@yawido.de]
>> Sent: Monday, July 31, 2006 11:06 AM
>> To: user@ant.apache.org
>> Subject: properties handling problem
>>
>> Hi,
>> this is Code for deliver files to different systems with a pre-check...
>>
>> I'll iterate with der foreach-Task.
>>
>> The Problem is, I don't now how to set the properties.
>>
>> Properties
>> available=availability
>> availabledir=/export/home/heisc01/anttest/
>> output=output
>> hostlist=host_1,host_2,host_3
>> hostname=host
>>
>> I think like this: server="${$hostname}_${num}}"
>> but it didn't work..
>>
>> Could somebody help me..
>>
>> best regards..
>> Beni
>>
>>
>> <!-- =================================
>>                      target: Schleife für Verfügbarkeitstest
>>                     ================================= -->
>>        <target name="availableloop">
>>                                <foreach list="1,2,3,4" target="availability"
>> param="num" />
>>                </target>
>>
>>        <!-- =================================
>>                  target: Verfügbarkeitstest der Systeme als Voraussetzung für
>> upload
>>                 ================================= -->
>>        <target name="availability" description="Checking the systems for
>> availability">
>>                <echo message="Verfügbarkeitscheck Nr  ${num}"/>
>>                <delete file="${available}/*.available"/>
>>                <ftp action="get" password="${password}"
>> server="${$hostname}_${num}}"
>> userid="${username}" remotedir="${availabledir}">
>>                        <fileset dir="${available}">
>>                                <include name="*.available" />
>>                        </fileset>
>>                </ftp>
>>                <available
>> file="${available}/"${$hostname}_${num}}".available"
>> property=""${$hostname}_${num}}".ready"/>
>>                <antcall target="upload"></antcall>
>>        </target>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>




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


Mime
View raw message