Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant immutable properties to mutable

i have a problem. I'm use antrun plugin for maven and do next: i have folder and subfolders(I do not know what are called sub-folders and their number) and i'm do archive for this subfolders with their name(subfolder name - "1", archive name - "1.acp").

               <tasks>
                  <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${settings.localRepository}/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar" />
                  <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${settings.localRepository}/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar" />
                  <for param="file">
                      <path>
                          <dirset dir="src/main/bootstrap" includes="/*" />
                      </path>
                      <sequential>
                          <basename property="dir" file="@{file}" />
                          <zip destfile="${project.build.outputDirectory}/alfresco/extension/agilent/${dir}.acp" basedir="@{file}" />
                      </sequential>
                  </for>
              </tasks>

But property dir is immutable!!! And all archive has name "1.acp". How to make this property mutable or do this another way?

like image 365
VladislavLysov Avatar asked Jan 25 '12 10:01

VladislavLysov


People also ask

Are properties immutable in ant?

Properties are immutable: whoever sets a property first freezes it for the rest of the build; they are most definitely not variables. There are seven ways to set properties: By supplying both the name and one of value or location attributes.

What are immutable properties?

An immutable type is a type of which its properties can only be set at initialization. Once an object is created, nothing can be changed anymore. An immutable property is simply a read-only property.

How do you set an ant property?

The <property> task is used to set the Ant properties. The property value is immutable, once the value is set you cannot change it. To set a property to a specific value you use Name/value assignment. To set a property to a location you use Name/location assignment.


2 Answers

You may use a 1.8 Ant's Local task

In your case:

<sequential>
  <local name="dir"/>
  <basename property="dir" file="@{file}"/>
  <zip
    destfile="${project.build.outputDirectory}/alfresco/extension/agilent/${dir}.acp" 
    basedir="${dir}"
  />
</sequential>
like image 184
Alexander Pogrebnyak Avatar answered Oct 18 '22 03:10

Alexander Pogrebnyak


You can use the var task from ant contrib.

The property unset, lets you reset values(example from above link):

    <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 -->

So you will have to fix it to:

 <sequential>
   <var name="dir" unset="true"/>
   <basename property="dir" file="@{file}" />
   <zip destfile="${project.build.outputDirectory}/alfresco/extension/agilent/${dir}.acp" basedir="@{file}" />
 </sequential>
like image 44
oers Avatar answered Oct 18 '22 02:10

oers