I'm using the propertyfile task shown below in my build script:
<target name="build-brand" depends="-init" description="Adds version information to branding files.">
<propertyfile file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties">
<entry key="currentVersion" value="${app.windowtitle} ${app.version}" />
</propertyfile>
</target>
The task works as expected, except that each time I build the project, the date comment line of the Bundle.properties file is updated with the current time stamp. This occurs even if the app.version variable does not change and results in an un-necessary commit to version control consisting solely of the following diff:
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
## -1,4 +1,4 ##
-#Thu, 22 Jul 2010 15:05:24 -0400
+#Tue, 10 Aug 2010 13:38:27 -0400
How can I prevent addition of or remove this date comment from the .properties file? I considered a delete operation in propertyfile nested entry element, but a key value is required.
This isn't a great solution, but how about removing the comment all together?
<target name="build-brand" depends="-init" description="Adds version information to branding files.">
<propertyfile file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties">
<entry key="currentVersion" value="${app.windowtitle} ${app.version}" />
</propertyfile>
<replaceregexp file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties" match="^#.*\n" replace=""/>
</target>
If you need to put a single property in a file just use echo:
<echo output="somefiles.properties">lastmodified=${lastmodified}</echo>
Try: <propertyfile file="..." comment="">
Edit: Which probably won't work :(. It looks like the culprit is actually Properties.store(OutputStream, String):
Next, a comment line is always
written, consisting of an ASCII #
character, the current date and time
(as if produced by the toString method
of Date for the current time), and a
line separator as generated by the
Writer.
Related
My Ant junit task is currently set to output minimal information. On the console, for each test class, it prints the class name, how many tests were run, failed, and errored, along with the elapsed time for each test. If the test failed, there's an additional line saying the test failed.
I'd like to get additional detail on the console, but ONLY if a test fails. If I follow advice like this, by adding an additional plain formatter with usefile=false, then I get additional redundant detail for ALL tests, even if all tests pass. This includes printing each test method executed, and a redundant line for each test class.
Is it possible to get this?
I believe I've implemented a reasonable solution.
The key points of the solution are:
* Executing a task after the unit tests are complete, which only runs if "test.failed"
* Use the "xmltask" task library to parse the test results files and emit concise results
I wrote the following target to do this:
<target name="show-unit-test-failures" if="test.failed">
<taskdef if:set="xmltask.present" name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
<echo if:set="xmltask.present" message="Unit test failure report details:"/>
<xmltask if:set="xmltask.present">
<fileset dir="gen/reports/artifacts/junit">
<include name="TEST-*Test.xml"/>
</fileset>
<call path="//testcase[./error]">
<parThatam name="className" path="#classname"/>
<param name="methodName" path="#name"/>
<param name="errorText" path="./error/text()"/>
<actions>
<echo>---------------------------------</echo>
<echo>#{className}.#{methodName}:</echo>
<echo>#{errorText}</echo>
</actions>
</call>
<call path="//testcase[./failure]">
<param name="className" path="#classname"/>
<param name="methodName" path="#name"/>
<param name="errorText" path="./failure/text()"/>
<actions>
<echo>---------------------------------</echo>
<echo>#{className}.#{methodName}:</echo>
<echo>#{errorText}</echo>
</actions>
</call>
</xmltask>
</target>
Note that I also let it "fail gracefully" if the "xmltask.jar" file isn't available. The ability to reference namespaces in tasks is a new feature in Ant 1.9.1 and newer.
I call this target at the end of my "run-unit-test" target.
So, I have this setup in ant:
<target name="context">
<echo>docbase: ${docbase.dir}</echo>
<antcall target="_context.docbase"/>
<antcall target="_context.nodocbase"/>
</target>
<target name="_context.docbase" if="${docbase.dir}">
<echo>Context with docbase</echo>
<context.md docbase="..."/>
</target>
<target name="_context.nodocbase" unless="${docbase.dir}">
<echo>Context without docbase</echo>
<context.md/>
</target>
And when docbase.dir is set to true or false things work as you'd expect. But when docbase.dir is set to an actual value (e.g., /tmp/docbase) for some reason it hits the _context.nodocbase target instead of the expected _context.docbase target.
Reading the docs it implies that if the expanded property isn't one of the "truthy" for "falsey" constants then it will just interpret it as before, but this isn't what I'm seeing.
What am I doing wrong? Should I use a different approach?
Note: I'm using Ant 1.8.2 (and conditional parameter expansion started in 1.8.0).
As mentioned here: http://ant.apache.org/manual/properties.html
As of Ant 1.8.0, you may instead use property expansion; a value of true (or on or yes) will enable the item, while false (or off or no) will disable it. Other values are still assumed to be property names and so the item is enabled only if the named property is defined.
This is some really subtle information here. So what's going on in your code is ${docbase.dir} is expanded to "/tmp/docbase". That's not true/on/yes/false/off/no so Ant then looks for a property named "/tmp/docbase". It can't find it, so it runs the unless.
Here's an example that I hope will clarify things. This will run only the if target:
<project name="MyProject" default="context" basedir=".">
<target name="context">
<echo>docbase: ${docbase.dir}</echo>
<property name="/tmp/docbase" value="i exist!"/>
<antcall target="_context.docbase"/>
<antcall target="_context.nodocbase"/>
</target>
<target name="_context.docbase" if="${docbase.dir}">
<echo>Context with docbase</echo>
</target>
<target name="_context.nodocbase" unless="${docbase.dir}">
<echo>Context without docbase</echo>
</target>
</project>
The important thing here is this line:
<property name="/tmp/docbase" value="i exist!"/>
Because that property is defined, it will run the if and not the unless.
So the overall problem is this:
We have multiple property files
<property file="prop1"/>
<property file="prop2"/>
prop1 contains a property looking like:
mg.prop = ${mg2.prop}
prop2 contains mg2.prop
mg2.prop = Hello
If they were in the same file and I queried mg.prop, I'd get "Hello" back. Since they are in separate files this does not work (I need to load prop1 before prop2!)
I wrote a custom ant task that does the following:
String resolved = resolveProperty(propertyName);
getProject().setProperty(propertyName, resolved);
If I run
log("Resolved property value = " + getProject().getProperty(propertyName));
Right after, I get the correct value.
However in the Ant script, if I do
<echo message="${mg.prop}"/>
it shows me the original value.
Any thoughts on how to solve this?
From the Ant manual:
"Properties are immutable: whoever sets a property first freezes it for the rest of the build; they are most definitely not variables."
http://ant.apache.org/manual/Tasks/property.html
Depending on your situation, you might be able to accomplish what you want by loading prop1 twice, using loadproperties and a filter chain that the first time takes only lines not containing "{mg2.prop}", and the second time takes only lines that do contain it.
http://ant.apache.org/manual/Tasks/loadproperties.html
http://ant.apache.org/manual/Types/filterchain.html#linecontains
You can also use the var task of ant-contrib to reset values.
From the doc:
The next example shows a property being set, echoed, unset, then
reset:
<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 -->
Here's how I ended up resolving this - I turfed the custom ant task.
I ended up concatenating all the properties files into one, in the reverse order of precedence.
So if I wanted properties from 3.properties to override those in 2.properties and 1.properties, I did the following:
<concat destfile="resolved.properties">
<fileset file="1.properties" />
<fileset file="2.properties" />
<fileset file="3.properties" />
</concat>
<property file="resolved.properties"/>
I have a java project and an ANT script to build and then distribute the project to other projects with a simple copy command.
I would like to only name the place where to copy to files to once in the header of the ant script, and not have an explicit copy-task for every project that is dependent on this project.
I can't find anything like arrays in ANT, so what would be the cleanest way of distributing something to multiple directories?
According to what I commented under Martin's answer, I'd like to post my version of solution as another choice. And I am using property names from Martin's answer to make it clear.
<target name="deploy" >
<property name="dest.dirs" value="/dir/one,/dir/two,/dir/thr/ee" />
<for list="${dest.dirs}" param="dest.dir" parallel="true" delimiter="," >
<sequential>
<copy todir="#{dest.dir}" >
<fileset dir="${srd.dir}" />
</copy>
</sequential>
</for>
</target>
Please note that "for" is an Ant-Contrib task, and it's using Macrodef in the back so you should use #{} to refer to "dest.dir"; the "dest.dirs" will be splited into a list (maybe String[]) by delimiter. Here we use comma to split it (and the default value to delimiter is comma). I also added "parallel" to make it copy files to all the "dest.dirs" at same time, however, if the project to copy is large, you should delete "parallel".
Please check http://ant-contrib.sourceforge.net/tasks/tasks/for.html
and http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html for more information.
I don't believe you have many viable options: the copy task accepts only a single directory.
Create your own copy task that takes a list of directories.
Exec a script/program that does the copying.
Have the subprojects do a pull.
I'm really hesitant about having a project push to other projects, because that makes the assumption that those projects will work with the newly-pushed code. IMO the "sub-"projects should be making the decision if they want the new version or not.
To me this sounds more like a dependency management issue, better handled with Ivy/Maven/Gradle (or other Maven-alike).
All that said, it sounds like you'd want to do option 1, create a custom Ant task that accepts a list of destination directories; it might be pretty easy to just extend the existing copy task to get all its functionality--just add a "todirs" property.
You might consider using a scriptmapper in your copy task with enablemultiplemappings true.
First, list the target directories in a property and create a filelist from it. (You could use a dirset, but the API for filelist is simpler.) Then run the copy, with the scriptmapper setting up the multiple destinations.
<property name="dest.dirs" value="/dir/one,/dir/two,/dir/thr/ee" />
<filelist id="dests" dir="/" files="${dest.dirs}" />
<copy todir="/" enablemultiplemappings="yes">
<fileset dir="${srd.dir}" />
<scriptmapper language="javascript">
<![CDATA[
// Obtain a reference to the filelist
var filelist = project.getReference( "dests" );
var dests = filelist.getFiles( project );
for ( var i = 0; i < dests.length; i++ )
{
self.addMappedName( dests[i] + "/" + source );
}
]]>
</scriptmapper>
</copy>
This question is similar to question https://stackoverflow.com/questions/3362965/problem-with-ddlutils-in-oracle-10g. Since my problem is (or at least i think it is) slightly different to the question mentioned, i post a new one.
I am using DdlUtils-1.0, Java-6 (OpenJdk), ojdbc6.jar and Oracle 11.1.0. The migration is started by ant tasks. The task looks like this:
<target name="dump-db" description="Dumps DB" depends="">
<taskdef name="databaseToDdl" classname="org.apache.ddlutils.task.DatabaseToDdlTask">
<classpath>
<path refid="runtime-classpath"/>
<path refid="project-classpath"/>
</classpath>
</taskdef>
<databaseToDdl modelname="${modelname}" verbosity="DEBUG" databasetype="${source.platform}"
usedelimitedsqlidentifiers="true" tabletypes="TABLE" schemapattern="${schemapattern}">
<database url="${source.url}"
driverClassName="${source.driver}"
username="${source.username}"
password="${source.passwd}"
initialsize="5"
testonborrow="true"
testonreturn="true"/>
<writeschemasqltofile failonerror="false" outputfile="${out.dir}/${schema.file.sql}"/>
<writedtdtofile outputfile="${out.dir}/${schema.file.dtd}"/>
<writeSchemaToFile failonerror="false" outputFile="${out.dir}/${schema.file.xml}"/>
<writedatatofile failonerror="false" outputfile="${out.dir}/${data.file.xml}" determineschema="true"/>
</databaseToDdl>
</target>
${source.platform} is set to 'oracle10', since oracle11 is not supported by ddlutils. Creation of schema definitions works quite well, but when dumping the data i face the following exception:
[databaseToDdl] org.apache.ddlutils.model.ModelException: Unknown JDBC type code 2007
[databaseToDdl] at org.apache.ddlutils.model.Column.setTypeCode(Column.java:215)
[databaseToDdl] at org.apache.ddlutils.platform.JdbcModelReader.readColumn(JdbcModelReader.java:781)
[databaseToDdl] at org.apache.ddlutils.platform.oracle.Oracle8ModelReader.readColumn(Oracle8ModelReader.java:117)
[databaseToDdl] at org.apache.ddlutils.platform.JdbcModelReader.readColumns(JdbcModelReader.java:755)
[databaseToDdl] at org.apache.ddlutils.platform.JdbcModelReader.readTable(JdbcModelReader.java:565)
[databaseToDdl] at org.apache.ddlutils.platform.oracle.Oracle8ModelReader.readTable(Oracle8ModelReader.java:102)
[databaseToDdl] at org.apache.ddlutils.platform.oracle.Oracle10ModelReader.readTable(Oracle10ModelReader.java:80)
[databaseToDdl] at
...
In http://download.oracle.com/javase/6/docs/api/constant-values.html#java.sql.Types.BIT the jdbc type codes are listed. Apparently ddlutils gets this type code from the jdbc driver but could not find a corresponding type in java.sql.Types.
Does anybody have an idea how to solve this?
It's very late, after 5 years,
However thought, can be helpful for few in in future.
Visit: org.apache.ddlutils.model.TypeMap
Method: getJdbcTypeName(int typeCode)
write small logic, to set 2007 to 12
ie;
if(typeCode == 2007){
typeCode = java.sql.Types.VARCHAR;
}
Issue: TypeMapping in DdlUtils, is done with exisitinf java.sql.Types enum. Whereas, for the Oracle11g, the are few extra types. Hence issue raised.
Hope it helps.