I'm trying to troubleshoot a fop problem and I'm thinking that going from the default logging to debug might help. The fop doc says that I need to pass messagelevel="debug", but every variation of the syntax in my ant script fails. I know this is more of an ant question, but I'm wondering is anyone has run into this. Here's my non-working code:
<macrodef name="fop">
<attribute name="in" />
<attribute name="out" />
<sequential>
<java classname="org.apache.fop.cli.Main" fork="true"
failonerror="true">
<arg line="-fo #{in}" />
<arg line="-pdf #{out} messagelevel="debug" />
<arg line="-c ${FopConfig}" />
<classpath>
<pathelement location="${FopBuild}" />
<pathelement location="${FopAvalon}" />
<pathelement location="${FopBatik}" />
<pathelement location="${FopCommonsIo}" />
<pathelement location="${FopCommonsLogging}" />
<pathelement location="${FopFopHyph}" />
<pathelement location="${FopJaiCodec}" />
<pathelement location="${FopJaiCore}" />
<pathelement location="${FopSerializer}" />
<pathelement location="${FopXalan}" />
<pathelement location="${FopXerces}" />
<pathelement location="${FopXmlApis}" />
<pathelement location="${FopXmlApisExt}" />
<pathelement location="${FopXmlGraphics}" />
</classpath>
</java>
</sequential>
</macrodef>
I've also tried this, with the arg as a separate line:
<macrodef name="fop">
<attribute name="in" />
<attribute name="out" />
<sequential>
<java classname="org.apache.fop.cli.Main" fork="true"
failonerror="true">
<arg line="-fo #{in}" />
<arg line="-pdf #{out} />
<arg line"messagelevel="debug"" />
<arg line="-c ${FopConfig}" />
<classpath>
<pathelement location="${FopBuild}" />
<pathelement location="${FopAvalon}" />
<pathelement location="${FopBatik}" />
<pathelement location="${FopCommonsIo}" />
<pathelement location="${FopCommonsLogging}" />
<pathelement location="${FopFopHyph}" />
<pathelement location="${FopJaiCodec}" />
<pathelement location="${FopJaiCore}" />
<pathelement location="${FopSerializer}" />
<pathelement location="${FopXalan}" />
<pathelement location="${FopXerces}" />
<pathelement location="${FopXmlApis}" />
<pathelement location="${FopXmlApisExt}" />
<pathelement location="${FopXmlGraphics}" />
</classpath>
</java>
</sequential>
</macrodef>
I'm sure I'm not seeing something simple.
Try escaping the double quotes (") with ":
<arg line="messagelevel="debug"" />
It seems there is already an Ant task for the purpose of calling FOP. Any reason why you're not using it?
Thanks - your syntax change let me pass that string to the fop processor, which told me that "messagelevel="debug"" is meaningless, but it did spit out the whole usage help file. It turns out that debug mode is invoked with "-d". Anyways, here's the whole usage help text for anybody else:
FOP USAGE
fop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] <outfile>
[OPTIONS]
-version print FOP version and exit
-d debug mode
-x dump configuration settings
-q quiet mode
-c cfg.xml use additional configuration file cfg.xml
-l lang the language to use for user information
-nocs disable complex script features
-r relaxed/less strict validation (where available)
-dpi xxx target resolution in dots per inch (dpi) where xxx is a number
-s for area tree XML, down to block areas only
-v run in verbose mode (currently simply print FOP version and continue)
-o [password] PDF file will be encrypted with option owner password
-u [password] PDF file will be encrypted with option user password
-noprint PDF file will be encrypted without printing permission
-nocopy PDF file will be encrypted without copy content permission
-noedit PDF file will be encrypted without edit content permission
-noannotations PDF file will be encrypted without edit annotation permission
-nofillinforms PDF file will be encrypted without fill in interactive form fields permission
-noaccesscontent PDF file will be encrypted without extract text and graphics permission
-noassembledoc PDF file will be encrypted without assemble the document permission
-noprinthq PDF file will be encrypted without print high quality permission
-a enables accessibility features (Tagged PDF etc., default off)
-pdfprofile prof PDF file will be generated with the specified profile
(Examples for prof: PDF/A-1b or PDF/X-3:2003)
-conserve enable memory-conservation policy (trades memory-consumption for disk I/O)
(Note: currently only influences whether the area tree is serialized.)
-cache specifies a file/directory path location for the font cache file
-flush flushes the current font cache file
[INPUT]
infile xsl:fo input file (the same as the next)
(use '-' for infile to pipe input from stdin)
-fo infile xsl:fo input file
-xml infile xml input file, must be used together with -xsl
-atin infile area tree input file
-ifin infile intermediate format input file
-imagein infile image input file (piping through stdin not supported)
-xsl stylesheet xslt stylesheet
-param name value <value> to use for parameter <name> in xslt stylesheet
(repeat '-param name value' for each parameter)
-catalog use catalog resolver for input XML and XSLT files
[OUTPUT]
outfile input will be rendered as PDF into outfile
(use '-' for outfile to pipe output to stdout)
-pdf outfile input will be rendered as PDF (outfile req'd)
-pdfa1b outfile input will be rendered as PDF/A-1b compliant PDF
(outfile req'd, same as "-pdf outfile -pdfprofile PDF/A-1b")
-awt input will be displayed on screen
-rtf outfile input will be rendered as RTF (outfile req'd)
-pcl outfile input will be rendered as PCL (outfile req'd)
-ps outfile input will be rendered as PostScript (outfile req'd)
-afp outfile input will be rendered as AFP (outfile req'd)
-tiff outfile input will be rendered as TIFF (outfile req'd)
-png outfile input will be rendered as PNG (outfile req'd)
-txt outfile input will be rendered as plain text (outfile req'd)
-at [mime] out representation of area tree as XML (outfile req'd)
specify optional mime output to allow the AT to be converted
to final format later
-if [mime] out representation of document in intermediate format XML (outfile req'd)
specify optional mime output to allow the IF to be converted
to final format later
-print input file will be rendered and sent to the printer
see options with "-print help"
-out mime outfile input will be rendered using the given MIME type
(outfile req'd) Example: "-out application/pdf D:\out.pdf"
(Tip: "-out list" prints the list of supported MIME types and exits)
-svg outfile input will be rendered as an SVG slides file (outfile req'd)
Experimental feature - requires additional fop-sandbox.jar.
-foout outfile input will only be XSL transformed. The intermediate
XSL-FO file is saved and no rendering is performed.
(Only available if you use -xml and -xsl parameters)
[Examples]
fop foo.fo foo.pdf
fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)
fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf
fop -xml foo.xml -xsl foo.xsl -foout foo.fo
fop -xml - -xsl foo.xsl -pdf -
fop foo.fo -mif foo.mif
fop foo.fo -rtf foo.rtf
fop foo.fo -print
fop foo.fo -awt
Related
See the example below.
<concat destfile="dest-file">
<fileset dir="dir1" />
<!-- how to append the output of the executable below without creating a temporary file for that output? -->
<apply executable="command1">...</apply>
</concat>
The apply and exec tasks support redirectors so you can do something like:
<apply executable="command1" >
<redirector append="true" output="file.log" />
</apply>
I am having trouble in doing this.
there is 1 batch file with this line:
set TEST_DIR=C:\temp\dir1
I just want to set some new value to TEST_DIR
But, when I use in my ant script, it escapes forward slashes and gives this result:
set TEST_DIR=C:homedir2
Instead, I want to give it:
set TEST_DIR=C:\home\dir2
I am using this command:
<replaceregexp file="${MT_BATCH_FILE_LOCATION}\myfile.bat" match="TEST_DIR=C:\\temp\\dir1" replace="TEST_DIR=C:\home\dir2" byline="true" />
You can get the result you want by using this replace pattern:
replace="TEST_DIR=C:\\\\home\\\\dir2"
The reason is that you must escape the backslash once for the regex and once for Java - backslash is an escape character in both those contexts.
In answer to your subsequent questions in comments...
I expect the answer will be the same. You will need to double-escape the backslash in the value of ${new_loc}, i.e. use C:\\\\my_projcode not C:\my_projcode.
If new_loc is coming in as an environment variable, you could use the propertyregex task from ant-contrib to escape backslashes in the value:
<project default="test">
<!-- import ant-contrib -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="C:/lib/ant-contrib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<target name="test">
<!-- load environment variables -->
<property environment="env"/>
<!-- escape backslashes in new_loc -->
<propertyregex property="loc" input="${env.new_loc}" regexp="\\" replace="\\\\\\\\\\\\\\\\" />
<echo message="env.new_loc: ${env.new_loc}"/>
<echo message="loc: ${loc}"/>
<!-- do the replace -->
<replaceregexp file="test.bat" match="TEST_DIR=C:\\temp\\dir1" replace="TEST_DIR=${loc}\\\\home\\\\dir2" byline="true" />
</target>
Output:
c:\tmp\ant>set new_loc=c:\foo\bar
c:\tmp\ant>ant
Buildfile: c:\tmp\ant\build.xml
test:
[echo] new_loc: c:\foo\bar
[echo] env.new_loc: c:\foo\bar
[echo] loc: c:\\\\foo\\\\bar
BUILD SUCCESSFUL
Total time: 0 seconds
c:\tmp\ant>type test.bat
set TEST_DIR=c:\foo\bar\home\dir2
I have found another simple solution use replace instead of replaceregexp.
<replace file="${MT_BATCH_FILE_LOCATION}\myfile.bat"
token='TEST_DIR=C:\temp\dir1'
value='TEST_DIR=${new_loc}\home\dir2' />
I have a zip file and, separately, a directory that contains some files. From the zip file I'd like to extract only those files that exist in the directory (performing a filename transformation on the files as they are being extracted..basically, I'm making backups of those files).
There is no problem doing something similar with a <copy> that has a fileset with a <present> element, but it doesn't seem to be working for me with unzip:
<unzip src="${cur.srcdir.live}" dest="${cur.srcdir.archive-files.dir}" overwrite="true">
<fileset dir=".">
<present present="both" targetdir="${cur.srcdir}" />
<type type="file" />
</fileset>
<globmapper from="*" to="*.${backup.suffix}" />
</unzip>
Has anyone done something like this before? This is Ant 1.8.0. Thanks!
I was able to solve my problem by "faking" the <present> selector that can be used in <copy>. Here's how:
First I used pathconvert to create a list of the files in my folder:
<pathconvert property="extract.list" pathsep="
">
<path>
<fileset dir="${extract.src.dir}" includes="${extract.src.dir.relpath}">
<type type="file" />
</fileset>
</path>
<map from="${extract.src.dir}\" to="" />
</pathconvert>
Notice the user of a map to have the list be relative paths instead of absolute paths. Plus, the delimiter is a newline.
Then this list gets written to a file:
<echo file="${props.tmp.file}" message="~~~~noop~~~~
${extract.list}" append="false" />
I put that "nooop" entry in there so that the file always has at least one line. This is important because of our next step where we use this as an includesfile. If the includesfile is empty, Ant interprets that as "allow anything"...but we want to make sure that an empty list results in nothing getting extracted from the zip.
Last step is to extract from the zip using our temp file from above as an includes file. The globmapper renames the files upon extraction, to the appropriate backup names:
<unzip src="${extract.archive}" dest="${extract.dest.dir}" overwrite="true">
<patternset>
<includesfile name="${props.tmp.file}" />
</patternset>
<globmapper from="*" to="*.${backup.suffix}" />
</unzip>
Adding this here in case someone needs to change the directory structure on extraction. I've spent so much trying to make this working. Ant Unzip task accepts cutdirsmapper.
<unzip dest="${build.dir}/packages">
<fileset dir="${src.dir}/packages" includes="*.pkg" />
<!-- Exctract build folder contents also moving one level up. -->
<cutdirsmapper dirs="1" />
<patternset>
<include name="build/" />
</patternset>
</unzip>
You can try calling unzip command via exec task.
The sample that I checked on Windows that refresh only changed files in dest.folder:
<property name="zip.file_name" value="Archive.zip"/>
<property name="src.folder" value="d:\"/>
<property name="dest.folder" value="d:\55"/>
<target name="unzip">
<echo>unzip -fo ${src.folder}${zip.file_name}</echo>
<exec dir="${dest.folder}" executable="cmd.exe" output="${src.folder}operation_result.txt">
<arg line="/c unzip -fo ${src.folder}${zip.file_name}"/>
</exec>
</target>
If you want to stay your original files you can use this command:
<arg line="/c unzip -foB ${src.folder}${zip.file_name}"/>
In case using -B parameter your original files (stored in folder) will be renamed - the tilde symbol will be appended. You get two sets of files - extracted from archive and old original files.
After that you can rename files with the help of move task.
What does it mean to extend a path with another path in ANT?
if I have the folloing:
<path>
<pathelement path="build/classes;lib/junit.jar" />
</path>
Does it mean that Ant breaks build/classes;lib/junit.jar into build/classes and lib/junit.jar
in other words, does ant think that we are defining two path elements?
Thank you so much in advance. Any help will be appreciated.
Your example:
<path>
<pathelement path="build/classes;lib/junit.jar" />
</path>
is equivalent to:
<path>
<pathelement path="build/classes" />
<pathelement path="lib/junit.jar" />
</path>
in both cases the path that created includes the contents of the build/classes directory plus the contents of the jarfile lib/junit.jar.
This mechanism allows you to dynamically create the required paths within your build file, rather than having to construct the combined string build/classes;lib/junit.jar.
For example, if you had the classes directory and the path to the junit jar specified in properties, you could than combine them into a single path:
<property name="classes.dir" location="build/classes" />
<property name="junit.jar" location="lib/junit.jar" />
...
<path>
<pathelement path="${classes.dir}" />
<pathelement path="${junit.jar}" />
</path>
This path would be the same as the examples above.
You could also refer to each of these items individually in other parts of your build file, and would only have to make changes in one place if either value needed to be changed.
The operation of the pathelement tag is documented here
You can specify PATH- and
CLASSPATH-type references using both
":" and ";" as separator characters.
Ant will convert the separator to the
correct character of the current
operating system.
I have a set of input files, each of which is processed to generate an output file. In one case it's hibernate xml files as input, and java files as output, but that isn't the only case I have to deal with.
In make, I would have set up a rule to tell it how to generate a .java file from an .hbm.xml file (modulo the .hbm.xml specifying a different class name to generate), and modifying a single .hbm.xml files would trigger the build of a single .java file.
How do I express the dependencies in ant so it will only build the out of date .java files and not all of them just because one .hbm.xml changed?
I'm looking at apply and up-to-date, but not seeing a solution yet...
Have you looked at ant-contrib outofdate task?
The example at the end of the doc looks like something you could use:
<outofdate property="manual.outofdate"
outputsources="grammer.sources">
<sourcefiles>
<fileset dir="${src.grammer}" includes="**/*.y"/>
</sourcefiles>
<mapper type="glob" dir="${src.grammer}" from="*.y" to="${gen.grammer}/*.c"/>
<mapper type="glob" dir="${src.grammer}" from="*.y" to="${gen.grammer}/*.h"/>
<sequential>
<shellscript shell="bash">
cd ${gen.grammer}
for g in ${grammer.sources}
do
gengrammer $g
done
</shellscript>
</sequential>
</outofdate>
Also note that you might use ant-contrib "for" task in the body of the outofdate task.
To initialize ant-contrib do this:
<property name="ant-contrib.jar" location="..."/>
<taskdef
resource="net/sf/antcontrib/antlib.xml"
uri="http://ant-contrib.sourceforge.net"
>
<classpath>
<pathelement location="${ant-contrib.jar}"/>
</classpath>
</taskdef>