Can't run "preverify.exe" using Ant's <exec> task - blackberry

I am having trouble getting my Ant script (for BlackBerry build) to run the preverify.exe command & pass the correct parameters to it.
In the command prompt (Windows 7), this works 100% - the parameters as given work properly:
preverify -verbose -classpath C:\development\tools\bb-jde\jde5.0\components\lib\net_rim_api.jar -d build\classes\preverified build\classes\preverified build\classes\unverified
I tried to put this into my Ant script using the following target - trying to use the same parameters:
<target name="preverify">
<mkdir dir="${dest.dir}/classes/preverified" />
<exec executable="${jde.home}/bin/preverify">
<arg value="-verbose" />
<arg value="-classpath C:\development\tools\bb-jde\jde5.0\components\lib\net_rim_api.jar" />
<arg value="-d build\classes\preverified" />
<arg value="build\classes\unverified" />
</exec>
</target>
This does not work. I get the following error:
Illegal option
-classpath C:\development\tools\bb-jde\jde5.0\components\lib\net_rim_api.jar
this classpath was perfectly acceptable from the command line (often java commands accept JAR files as directories, since they are basically ZIP files).
How can I get Ant to send the correct parameters to this command, as in the command line version? There must be something about exec that I'm missing?
Here is the full Ant output from running this target in verbose mode, if it helps:
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Trying the default build file: build.xml
Buildfile: C:\development\ant\test_using_javac_jar_preverify_then_rapc\Cobi\build.xml
Detected Java version: 1.6 in: C:\Java\jdk1.6.0_24\jre
Detected OS: Windows 7
parsing buildfile C:\development\ant\test_using_javac_jar_preverify_then_rapc\Cobi\build.xml with URI = file:/C:/development/ant/test_using_javac_jar_preverify_then_rapc/Cobi/build.xml
Project base dir set to: C:\development\ant\test_using_javac_jar_preverify_then_rapc\Cobi
parsing buildfile jar:file:/C:/development/tools/apache-ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/development/tools/apache-ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Importing file C:\development\ant\common\constants.xml from C:\development\ant\test_using_javac_jar_preverify_then_rapc\Cobi\build.xml
Overriding previous definition of reference to ant.projectHelper
parsing buildfile C:\development\ant\common\constants.xml with URI = file:/C:/development/ant/common/constants.xml
parsing buildfile jar:file:/C:/development/tools/bb-ant-tools/bb-ant-tools.jar!/bb-ant-defs.xml with URI = jar:file:/C:/development/tools/bb-ant-tools/bb-ant-tools.jar!/bb-ant-defs.xml from a zip file
Overriding previous definition of reference to ant.projectHelper
[property] Loading C:\development\ant\test_using_javac_jar_preverify_then_rapc\Cobi\project.properties
[property] Loading C:\development\ant\common\jde5.0.properties
[property] Loading C:\development\ant\common\common.properties
[pathconvert] Set property net_rim_api.jar.dos = C:\development\tools\bb-jde\jde5.0\components\lib\net_rim_api.jar
Build sequence for target(s) `preverify' is [preverify]
Complete build sequence is [preverify, javac, build, sign, clean, ]
preverify:
[mkdir] Skipping C:\development\ant\test_using_javac_jar_preverify_then_rapc\Cobi\build\classes\preverified because it already exists.
[exec] Current OS is Windows 7
[exec] Executing 'C:\development\tools\bb-jde\jde5.0\components\bin\preverify' with arguments:
[exec] '-verbose'
[exec] '-classpath C:\development\tools\bb-jde\jde5.0\components\lib\net_rim_api.jar'
[exec] '-d build\classes\preverified'
[exec] 'build\classes\unverified'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
[exec] preverify: Illegal option -classpath C:\development\tools\bb-jde\jde5.0\components\lib\net_rim_api.jar
[exec]
[exec] Usage: preverify [options] classnames|dirnames ...
[exec]
[exec] where options include:
[exec] -classpath <directories separated by ';'>
[exec] Directories in which to look for classes
[exec] -d <directory> Directory in which output is written (default is ./output/)
[exec] -cldc1.0 Checks for existence of language features prohibited
[exec] by CLDC 1.0 (native methods, floating point and finalizers)
[exec] -nofinalize No finalizers allowed
[exec] -nonative No native methods allowed
[exec] -nofp No floating point operations allowed
[exec] #<filename> Read command line arguments from a text file
[exec] Command line arguments must all be on a single line
[exec] Directory names must be enclosed in double quotes (")
[exec]
[exec] Result: 1
BUILD SUCCESSFUL
Total time: 1 second

This doesn't look like an ANT issue. The error message is being returned by the preverify command, proving that ANT is executing it...
I don't understand what this command is supposed to be doing, however the usage message gives a hint as to the root cause:
[exec] Usage: preverify [options] classnames|dirnames ...
[exec]
[exec] where options include:
[exec] -classpath <directories separated by ';'>
[exec] Directories in which to look for classes
You haven't specified a list of directories as the "classpath" parameter.... You've supplied a jar file. Is the command able support jar files?

The way you are passing the parameters is incorrect. The space between the -classpath tag, and the JAR name is not allowed.
You must break that line (and the -d below it) onto 2 lines. This works:
<exec executable="${jde.home}/bin/preverify">
<arg value="-verbose" />
<!-- classpath to the RIM api -->
<arg value="-classpath" />
<arg value="C:\development\tools\bb-jde\jde5.0\components\lib\net_rim_api.jar" />
<!-- destination folder -->
<arg value="-d" />
<arg value="build\classes\preverified" />
<!-- source folder -->
<arg value="build\classes\unverified" />
</exec>

I solved this problem by including the jdk\bin directory path in environment variable PATH.

Related

Malformed Collection Error

Moving on from the first issue I reported here :
Running an OS command using apache-ant to IIS config
I am trying to run the second part of the IIS config.
<exec executable="cmd.exe" dir="C:/Windows/System32/inetsrv"
failonerror="true">
<arg line="/c appcmd set config /section:handlers
/[name=&apos;ExtensionlessUrlHandler-Integrated-
4.0&apos;].verb:GET,POST,PUT,DELETE,OPTIONS,CONNECT"/>
</exec>
I have no double quotes in this line, and I am using apos; to indicate my single quotes. However I'm getting the following error which Im struggling to find an explanation for :
confIIS:
[echo] Configuring IIS
[exec] ERROR ( message:Malformed collection indexer; format is
[#position,name='value',name2='value2',...]. The #position specifier is
optional, and be '#start', '#end', or
#N' where N is a numeric index into the collection. )
quick Update :
I've tried dbl quotes but no luck. I've done some more digging and the issue is that the single quotes are being dropped.
If I run the cmd line in the dos prompt without the single quotes it fails in the same way.
cmd line :
appcmd set config /section:handlers /[name='ExtensionlessUrlHandler-
Integrated-4.0'].verb:GET
Ant script (debug) output
[exec] 'appcmd'
[exec] 'set'
[exec] 'config'
[exec] '/section:handlers'
[exec] '/[name=ExtensionlessUrlHandler-Integrated-
4.0].verb:GET,POST,PUT,DELETE,OPTIONS,CONNECT'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
ute:Java13CommandLauncher: Executing 'cmd.exe' with arguments:

Executing MSBuild from Ant

I am trying to run msbuild on a Windows Server 2012 machine using Ant 1.9.7 exec task from Jenkins.
The command line I am attempting to recreate is:
msbuild solution.sln /p:Platform="Any CPU" /p:Configuration:Release
My latest attempt at the exec task looks something like:
<property name="platformParameter" value='/p:Platform="Any CPU"' />
<echo message="platformParameter = ${platformParameter}" />
<exec executable="msbuild" failonerror="true">
<arg value="solution.sln" />
<arg value="/p:Configuration=Release" />
<arg value="${platformParameter}" />
</exec>
The environment is correct so msbuild is available. The output from the above that I am getting is:
[echo] platformParameter = /p:Platform="Any CPU"
[exec] Microsoft (R) Build Engine version 12.0.40629.0
[exec] [Microsoft .NET Framework, version 4.0.30319.34014]
[exec] Copyright (C) Microsoft Corporation. All rights reserved.
[exec]
[exec] MSBUILD : error MSB1008: Only one project can be specified.
[exec] Switch: CPU
The echo output shows that the platformParameter correctly contains what I want with double speech marks around Any CPU as required by msbuild. Using single speech marks, no speech marks or AnyCPU when attempting to build a solution does not work. I believe that if I were building a project rather than solution I would be able to use AnyCPU instead of "Any CPU" for the platform.
The error appears to be that msbuild is not seeing the Platform parameter correctly formed and therefore probably thinks I'm doing:
msbuild solution.sln /p:Platform=Any CPU /p:Configuration:Release
where it thinks CPU is a second project/solution.
I've tried a few different things to try and get this argument containing double speech marks to msbuild via the exec task (e.g. using &quote; in place of the double speech marks), usually with the same result as shown above.
Can anyone suggest the correct/a working method to get the Platform parameter into an arg for the exec task to run to msbuild?
i.e. How define an arg containing a double speech mark delimited element to a exec task?
Thanks in advance.
Problem solved.
It appears I was attempting to pre-empt/solve something that did not need solving.
From a windows command prompt to get MSBuild to work I needed to do:
msbuild solution.sln /p:Platform="Any CPU" /p:Configuration:Release
as stated in my question.
For the ant exec task arguments, the Platform parameter appears to work perfectly fine if I do:
<exec executable="msbuild" failonerror="true">
<arg value="solution.sln" />
<arg value="/p:Configuration=Release" />
<arg value="/p:Platform=Any CPU" />
</exec>

Execute wmic command in ant target

How to execute the below command in ant target with < exec > task.
wmic nic where 'netconnectionid like '%'' get netconnectionid
If I run above in command line, I can get this output:
NetConnectionID
Local Area Connection
Local Area Connection 2
However, if I call this command via this way:
<target name="test">
<exec executable="wmic">
<arg line="nic where 'netconnectionid like '%'' get netconnectionid"/>
</exec>
</target>
I got below error:
[exec] Node - MyComputer
[exec] ERROR:
[exec] Description = Invalid query
[exec]
[exec]
[exec] Result: -2147217385
Anyone can help me?
Thank you!
80041017 is your error number. numbers greater than 80040200 are component specific errors (and a general OLE errors under 0x80040200).
WBEMDisp.h says this
wbemErrInvalidQuery = 0x80041017
But your query is for EVERYTHING, so you can omit your where alltogether.
wmic nic get netconnectionid

Executing Python script from Phing

I have the following in my Phing build file:
<target name="fixModifiedTime">
<echo msg="Fixing file modified time" />
<exec executable="python" >
<arg value="c:\scm\scripts\git-restore-mtime.py" />
<arg value="-v" />
</exec>
</target>
This is causing the following error in my Jenkins output:
[exec] Executing command: python c:\scm\scripts\git-restore-mtime.py -v 2>&1
[exec] 'python' is not recognized as an internal or external command,
[exec] operable program or batch file.
I am able to execute the same command from the Jenkins workspace directory and it works perfectly. The Python directory is added to my environment variables and the script has the right permissions.
I have also tried adding the script to my repository and running it from within the build environment but have the same error.
Any thoughts please?
I suggest the following:
Try creating Windows batch build step in your Jenkins and put the command in it. See if it runs
It's obvious your Jenkins environment is not the same is your console. See what's missing in Jenkins
Add the python home and path in the Jenkins configuration
I hope this helps

Passing filepath to ANT from BAT script

I am trying to invoke an ANT target from Windows (right-click) file context menu.
I have setup the registry entries to invoke a batch script which invokes my ANT EXEC target.
I need to pass the path of the file (on which user right-clicked) to my ANT target. So I am using %~dp1 to set an ANT properties in my bat script:
Set tobeusedfilepath=%~dp1
Set tobeusedfile=%~n1
resulting in:
tobeusedfilepath=D:\Project\Rel L\
tobeusedfile=file
The problem is %~dp1 returns a string with "\" as file separator. But ANT EXEC task wants "/"
[exec] '-source'
[exec] 'D:ProjectRel L/file'
[exec] ......
[exec] The file, 'D:ProjectRel L/file', does not exist.
Any suggestions how to get around this path separators?
set AntPath="D:\Project\Rel L\"
set AntPath=%AntPath:\=/%
set AntPath=%AntPath::/=:%
gives
set AntPath="D:\Project\Rel L\"
set AntPath="D:/Project/Rel L/"
set AntPath="D:Project/Rel L/"
If you are running on Windows Ant will happily accept OS directory separator which is \.
Upon examination of the output of your program I see that the path separators are missing: you have D:ProjectRel not D:\Project\Rel. I may only guess that you are trying to exec a Cygwin program. Cygwin programs will use \ as an escape character. Therefore you need to use a <pathconvert> property to adjust the directory separators.
Code snippet below illustrates how to do this
<property name="tobeusedfilepath" location="D:\Project\Rel L\"/>
<property name="tobeusedfile" value="file"/>
<property name="system-path-filename"
location="${tobeusedfilepath}/${tobeusedfile}"
/>
<pathconvert property="unixized-filename" targetos="unix">
<path location="${system-path-filename}"/>
</pathconvert>
<echo message="system-path-filename=${system-path-filename}"/>
<echo message="unixized-filename=${unixized-filename}"/>
And here is the output of this run:
[echo] system-path-filename=D:\Project\Rel L\file
[echo] unixized-filename=D:/Project/Rel L/file

Resources