Phing: get a filename without the extension - phing

Given a Phing loop such as this
<target name="lessc">
<exec command="lessc ${absolute-filename}" logoutput="false" output="${project.basedir}/public/assets/css/libraries/${filename}" />
</target>
<target name="build-in-loop">
<foreach param="filename" absparam="absolute-filename" target="lessc">
<fileset dir="${project.basedir}/assets/less/libraries/">
<include name="*.less"/>
</fileset>
</foreach>
</target>
In target lessc, how can I extract the file name without extension from the variable absolute-filename? In the example above, the output file will have the extension .less - obviously not what I need.
I know there is a task made for less, and that I could extend Phing to support this specific operation, but I would like to know first if Phing basically allows simple string manipulation on variables.

Found the answer, not sure if it's the best solution, but works for me:
just need to use the mapper tag
<mapper type="glob" from="*.less" to="*"/>
in the foreach loop, like this:
<target name="build-in-loop">
<foreach param="filename" absparam="absolute-filename" target="lessc">
<fileset dir="${project.basedir}/assets/less/libraries/">
<include name="*.less"/>
</fileset>
</foreach>
</target>
At this point, in the variable ${filename} in the target task there will be the filename without extension.

Related

phing toString method with fileset

Phing's documentation shows an example that should display a list all php files of a certain folder using a fileset with an id of "sourcefiles":
https://www.phing.info/guide/chunkhtml/ch04s02.html
(See 4.2.4)
So I put together a build-xml with this task:
<project default="countFile">
<property name="BUILD_DIR" value="./buildTest"/>
<target name="dist" depends="build">
<fileset id="sourcefiles" dir="${BUILD_DIR}">
<include name="./*.*" />
</fileset>
<echo>files in build dir: ${toString:sourcefiles}</echo>
<echo>build dir: ${BUILD_DIR}</echo>
<echo>OS: ${os.name}</echo>
</target>
</project>
I also tried the one-liner version from the documentation: <fileset id="sourcefiles" dir=".build" includes="**/*.txt"/>.
However, the output is nothing else but exactly that dollar-curly-brace-text as text: '${toString:sourcefiles}' instead of its interpolated result.
What would be the proper way to right it? Is this an error in the docs?
(I am not new to deployment, but new to phing.)
The include element inside your fileset has a non valid pattern. From the documentation
In patterns, one asterisk (*) maps to a part of a file/directory name within a
directory level. Two asterisks (**) may include above the "border" of the directory
separator.
Your example becomes:
<project default="countFile">
<property name="BUILD_DIR" value="./buildTest"/>
<target name="dist" depends="build">
<fileset id="sourcefiles" dir="${BUILD_DIR}">
<include name="*.*" />
</fileset>
<echo>files in build dir: ${toString:sourcefiles}</echo>
<echo>build dir: ${BUILD_DIR}</echo>
<echo>OS: ${os.name}</echo>
</target>
</project>
And will output something like:
Buildfile: C:\Users\XXX\test\build.xml
[autoloader] Loading autoloader from C:\Users\XXX\test/bootstrap.php
[php] Evaluating PHP expression: ini_set('error_reporting', -1);
[php] Evaluating PHP expression: ini_set('memory_limit', -1);
[php] Evaluating PHP expression: ini_set('date.timezone', 'UTC');
Phing Build Tests > test:
[echo] files in build dir: bootstrap.php;build.xml;phpunit-sparse.xml;phpunit.xml
BUILD FINISHED
Total time: 0.4785 seconds
Build finished at 30.11.2020 23:19 with exit code 0.
Also note that the ${toString:XXX} feature is only available for phing 3.x

Add Xom to managed URI In res

I am Working on ILOG.Currently I am using an Ant script for deploying ruleapp to res.My Problem is when I am deploying it is working fine but I want to add xom automatically to " ADD Managed URI" tab present in res. xom is getting attached to ruleapp but i want to get it attached to managed uri section.
Thanks in advance.
Have you tried this way - Got it from IBM Help.I have not tried it, but looks like, it should work. ( IBM ODM.8.0.1)
<target name="deployruleappwithxom">
<res-deploy hostname="${hostname}" portnumber="${portnumber}" webapp="${webapp}" userid="${userid}" password="${password}" file="my-ruleapp.jar">
<xompath rulesetpath="/MyRuleApp/MyRuleset">
<fileset dir="${lib}">
<include name="**/myxom.jar" />
</fileset>
</xompath>
<xompath rulesetpath="/AnotherRuleApp/AnotherRuleset">
<fileset dir="${otherlib}">
<include name="**/otherxom.jar" />
</fileset>
</xompath>
</res-deploy>
</target>
if you just looking for managing xomuri property, you can try this.
<target name="runloanvalidation">
<res-deploy-xom
hostname="localhost"
portnumber="9080"
webapp="res"
userid="resAdmin"
password="resAdmin"
jarMajorVersion="false"
libName="person"
outputRulesetProperty="ruleset.managedxom.uris">
<xompath>
<fileset dir="hello">
<include name="*.jar"/>
</fileset>
</xompath>
</res-deploy-xom>
<echo message="Resulting property: ${ruleset.managedxom.uris}"/>
</target>
And for more information, you can visit this.
http://www-01.ibm.com/support/knowledgecenter/#!/SSQP76_8.6.0/com.ibm.odm.dserver.rules.ref.res/ant_tasks/con_ant_res_deploy_xom.html

Ant search in text file some text expression

Ant search in text file some text expression, if it NOT found I try to delete file that txt was. So my code in Ant is down, but I don't know how put NOT correctly
<target name="ifDelete">
<if>
<length when="greater" length="0">
<fileset file="MyText.txt">
<!--containsregexp negate="true"-->
<containsregexp expression="findME" />
<!--/containsregexp-->
</fileset>
</length>
<then>
<delete includeemptydirs="true">
<fileset dir="FileIgonnaDelete">
</fileset>
</delete>
</then>
</if>
</target>
To search and delete - means seek and destroy - files in a fileset that do not contain a specific text, use something like :
<delete verbose="true">
<fileset dir="rootdir/to/search" includes="**/*.txt">
<not>
<contains text="findMe"/>
</not>
</fileset>
</delete>
you may use one or more nested resource collections (fileset, dirset ...) within delete.
see Ant manual delete, fileset and selectors for details.

Include/Exclude buildfiles

How do you do this? Given several build files, I only want to include the ones where the target (specified from the command line) exists. Using target::exists in does not seem to work. Thanks.
<target name="*">
<property name="curr.target" value="${target::get-current-target()}"/>
<nant target="${curr.target}">
<buildfiles>
<include name="*.build" if="${target::exists(curr.target)}"/>
<!-- avoid recursive execution of current build file-->
<exclude name="${project::get-buildfile-path()}" />
</buildfiles>
</nant>
</target>
Using robaker's solution, my final build file looks like this. It does not fail anymore if the target is not found in a certain build file (unlike my previous code).
<project>
<include buildfile="A.build"/>
<include buildfile="B.build"/>
<target name="*">
<nant target="${target::get-current-target()}"/>
</target>
</project>
Why not just use the include task to include all your child build scripts instead?

In nant, how to delete contents of a directory, but not the directory itself?

Suppose I were scripting a deployment using nant on a Windows server to a file share: \\server\share. I want a nant script to delete all files from the share then copy in new files.
I have this code to delete the files, but I'm getting an error that it can't delete "\server\share". But I didn't want to delete the share, just the contents in it.
<delete>
<fileset basedir="\\server\share">
<include name="**/**" />
</fileset>
</delete>
Output:
BUILD FAILED
D:\code\xxx\xxx.deploy(177,8):
Cannot delete directory '\\server\share'.
Access to the path '\\server\share' is denied.
If I modified it to instead delete contents of a directory in the share, say \\server\share\somedir, it'll delete "somedir" without error. But still, I didn't want to delete the dir, just the contents. Is there a way?
This works for me - no workarounds required:
<delete>
<fileset basedir="\\server\share">
<include name="**\*" />
</fileset>
</delete>
You could introduce an "exclude" tag and exclude a dummy file. That'll leave the root folder intact.
I'm using the following:
<target name="clean">
<delete>
<fileset basedir="${DeployTo}">
<include name="**/*" />
<exclude name="**/aspnet_client/**" />
</fileset>
</delete>
</target>
Taking cue from nsr81, I was able to come up with this workaround that works for me:
<touch file="${DeployTo}/deleteme" />
<delete>
<fileset basedir="${DeployTo}">
<include name="**/**" />
<exclude name="deleteme" />
</fileset>
</delete>
<delete file="${DeployTo}/deleteme" />