Can not run ' Ant exec executable="zip" ' - linux

Below is my ant script.
<exec executable="zip" dir="/usr/local/clo/ven/image/manual_bundle/testzip/">
<arg value="-y"/>
<arg value="-r"/>
<arg value="${file.path}"/>
<arg value="*"/>
</exec>
But below error occur.
zip-image_binary:
[exec] zip warning: name not matched: *
[exec]
[exec] zip error: Nothing to do! (try: zip -y -r /usr/local/clo/ven/image/a.zip . -i *)
[exec] Result: 12
My purpose is to zip all the files and directories under /usr/local/clo/ven/image/manual_bundle/testzip/

When you run the command using your shell then the shell expands the * glob pattern. The zip executable doesn't expect any pattern at all but a list of files (usually provided by your shell). If you don't want to use the built-in zip task you can emulate that behaviour by using apply rather than exec. Something like this
<apply executable="zip" parallel="true" relative="true"
dir="/usr/local/clo/ven/image/manual_bundle/testzip/">
<fileset dir="/usr/local/clo/ven/image/manual_bundle/testzip/"/>
<mergemapper to="${file.path}"/>
<arg value="-y"/>
<arg value="-r"/>
<targetfile/>
</apply>
The equivalent zip task is a lot simpler
<zip destfile="${file.path}">
<fileset dir="/usr/local/clo/ven/image/manual_bundle/testzip/"/>
</zip>

Related

Reading source files in MSVS project using xmlstarlet

I am trying to get the source files and include directories from a vcxproj file. Eg of vcsproj:
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
....
<ItemGroup>
<ClCompile Include="$(SrcDir)d1\f1cpp" />
<ClCompile Include="$(SrcDir)d2\f2.cpp" />
</ItemGroup>
...
</Project>
I tried this:
xmlstarlet sel -t -v "//_:ItemGroup/ClCompile/#Include" myProj.vcxproj but didn't work.
However, when I tried this (copying the code from some page that I came across), it works:
echo '<?xml version="1.0" encoding="utf-8"?> <ELEMENT xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<SUB_ELEMENT attribute="attr_value"/>
</ELEMENT>' | xmlstarlet sel -t -v '//_:SUB_ELEMENT/#attribute' --nl
o/p: attr_value
I don't see how the two are different with respect to reading an attribute value from an xml with a namespace. I further tried a stripped down version of the vcxproj file:
echo '<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="$(SrcDir)d1\f1cpp" /> </ItemGroup> </Project>' | xmlstarlet sel -t -v '//_:ItemGroup/#Include' --nl
o/p: <no o/p>
Any indication on why it is not working or how to get this to work would be very helpful.
Edit: Expected output from the vcxproj would be a list of filenames. For the above command it would be $(SrcDir)d1\f1cpp
Any indication on why it is not working or how to get this to work would be very helpful
Since you're using the default namespace add the _:
shortcut on the node test in each
location step,
and the -T (--text)
option to make text mode output:
xmlstarlet select -T -t -v "//_:ItemGroup/_:ClCompile/#Include" -n file.xml

Optional spaces between multiple layout renderers?

I think I must be missing something extremely obvious here but furious doc reading and googling has failed me. I have the following layout for a file name:
<target name="asyncLogFile" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard" >
<target name="mainLogFile" xsi:type="File" fileName="logs/${mdlc:item=GameServer:whenEmpty=Main} ${mdlc:item=Controller}.log"
layout="${longdate} ${level:uppercase=true} | ${logger} | ${message} ${exception:format=toString,Data:maxInnerExceptionLevel=3}" />
</target>
The MDLC items can both be null, in the games of the GameServer it gets replaced with "Main" and the Controller doesn't matter (If the GameServer is null then the Controller will be null).
However this means that if GameServer is null I end up with
Main .log Because of the space I have between the two mdlc entries. How can I make that space optional as part of the GameServer mldc entry!? I have looked at :pad to add a space after the but that doesn't seem to work. I have tried concatenating the mdlc's but that doesn't work.
I was expecting something simple you could add as an ambient property like :suffix but nothing like that exists.
Again I think I must be missing something basic here but it eludes me.
Same ugly, but faster because of less allocation:
<variable name="GameServerLogFile" value="${when:when='${mdlc:item=GameServer}'=='':inner=Main:else=${mdlc:item=GameServer} ${mdlc:item=Controller}}" />
<targets>
<target name="mainLogFile" xsi:type="File" fileName="logs/${GameServerLogFile}.log" />
</targets>
Better to compare against empty-string '', than to call length()-method.
Ugly but this works
<target name="mainLogFile" xsi:type="File" fileName="logs/${when:when=length('${mdlc:item=GameServer}') > 0:inner=${mdlc:item=GameServer} ${mdlc:item=Controller}:else=Main}.log"

How can I sign the files using NSIS?

How can I sign the files using NSIS?
We changed WIX installer to NSIS.
Earlier in the WIX installer it was used like as shown below in the .xml file to sign the files.
<property name="FileSigningDrive" location="${env.FILE_SIGNING}"/>
<!--echo message="Signing Setup.exe ....." />
<exec dir="${FileSigningDrive}\"
executable="${FileSigningDrive}\signcode.exe" failonerror="true">
<arg value='-spc' />
<arg value='mycredentials.spc' />
<arg value='-v' />
<arg value='testkey.pvk' />
<arg value='-t' />
<arg value='http://timestamp.verisign.com/scripts/timpstamp.dll' />
<arg value='"${install}\RootCDDir\setup.exe"' />
</exec-->
Similarly, how to sign the files in NSIS?
You can sign the installer by executing a command of your choice with !finalize:
!finalize 'signcode -t http://example.com/timestamp "%1"' = 0 ; %1 is replaced by the install exe to be signed.
Signing the uninstaller is a bit annoying and requires you to generate the uninstaller and then signing it.
This is an update to #Anders answer.
From v3.08, you can straight away use !uninstfinalize to sign the uninstaller.
So now you can write your code like this.
!finalize 'signcode -t http://example.com/timestamp "%1"' = 0 ; %1 is replaced by the install exe to be signed.
!uninstfinalize 'signcode -t http://example.com/timestamp "%1"' = 0 ; %1 is replaced by the uninstaller exe to be signed.
Keep in mind that you must append = 0 at !finalize and !uninstfinalize. That will stop running both in parallel. Otherwise, the signtool.exe will fail because it can't run in parallel.

shell script sed replace

I have this file config.xml
<widget id="com.example.hello" version="0.0.1">
<name>HelloWorld</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#callback.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<enter>PASSWORD</enter>
<content src="index.html" />
<access origin="*" />
I tried to do it with sed without success.
I need to do this:
$./script.sh config.xml NEWPASSWORD
to get:
<widget id="com.example.hello" version="0.0.1">
<name>HelloWorld</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#callback.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<enter>NEWPASSWORD</enter>
<content src="index.html" />
<access origin="*" />
Using backreference:
sed "s/^\( *<enter>\)\([^>]*\)</\1$2</" "$1"
^\( *<enter>\): search for lines starting with any number of spaces followed by <enter>. Matching characters are captured with escaped parentheses.
\([^>]*\)<: following characters up top next < are captured in a second group.
\1$2<: in the substitution string, characters from first group are output(\1) followed by the second parameter value passed to the script, ($2, the new password value)
The command is applied to $1, the file passed as first parameter to the script (the file name).
To edit the file in place, use the -i flag:
sed -i "s/^\( *<enter>\)\([^>]*\)</\1$2</" "$1"
The good result is:
$cat script.sh
#!/bin/sh
file=$1
sed -i "s/^\( *<enter>\)\([^>]*\)</\1$2</" "$1"
Then:
$./script.sh config.xml NEWPASSWORD
Many thanks to everyone, especially to Kenavoz.

Trouble with quotes in ant's <exec>

This is the command that runs just fine on terminal
egrep Version ./path/fileName.java | cut -d"\"" -f4
I've used the following in my code
<exec command="egrep Version ./path/fileName.java | cut -d"\" -f4)" outputproperty="VER"/>
But getting errors
the command attribute is deprecated.
[exec] Please use the executable attribute and nested arg elements.
[exec] Result: 1
[echo] "Version: egrep: invalid argument `\\' for `--directories'
[echo] Valid arguments are:
[echo] - `read'
[echo] - `recurse'
[echo] - `skip'
[echo] Usage: egrep [OPTION]... PATTERN [FILE]...
[echo] Try `egrep --help' for more information."
there is one less quot; in the command because if I write 2 quots, it will give me number of quots unbalanced error.
Ant's <exec> uses Java's rules for execution, in particular it is not a shell and does not understand pipes and redirections on its own. Probably your best bet will be to invoke a shell. You will also need to capture the output in a property if you want to make use of it later in your build:
<exec executable="sh" outputproperty="version.number">
<arg value="-c" />
<arg value="egrep Version ./path/fileName.java | cut -d'"' -f4" />
</exec>
Alternatively, you could forget the exec and implement the required logic directly in Ant using loadfile with a filterchain rather than calling an external process:
<loadfile srcFile="path/fileName.java" property="version.number"
encoding="UTF-8">
<filterchain>
<tokenfilter>
<!-- equivalent of egrep Version -->
<containsregex pattern="Version" />
<!-- equivalent of the cut - extract the bit between the third and
fourth double quote marks -->
<containsregex pattern='^[^"]*"[^"]*"[^"]*"([^"]*)".*$$'
replace="\1" />
</tokenfilter>
<!-- I'm guessing you don't want a trailing newline on your version num -->
<striplinebreaks />
</filterchain>
</loadfile>
Try using ' in your xml
<exec command='egrep Version ./path/fileName.java | cut -d"\"" -f4)' outputproperty="VER"/>

Resources