Is there a way to pass the option -mark-generated, which is applicable to xjc.bat:
%JAXB_HOME%\bin\xjc.bat -mark-generated c:\TEMP\my.xsd
to the corresponding ant task?
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath refid="classpath" />
</taskdef>
<xjc schema="my.xsd" destdir="src" package="gen.example">
<produces dir="src/gen" includes="**/*.java" />
</xjc>
You can pass -mark-generated and other options which are not directly supported in an tag nested under the tag, like this:
<xjc schema="simple.xsd" destdir="src" package="gen.example">
<produces dir="src/gen" includes="**/*.java" />
<arg line="-mark-generated"/>
</xjc>
See the Ant Task reference for details. Happy marshalling!
Related
I have a question based from this question
Replacing characters in Ant property
I want to build a variable (i can't use a property because i'm in a loop) that is pretty much StringA - StringB.
(maybe this is a misunderstanding of properties on my part but they can only be assigned once correct?)
I guess I could build a script function to calculate that, but my guess is that it must be possible to do it in an already existing function, probably something i'm missing.
this would be an example of the code
<for param="file">
<path>
<fileset dir="${mydir}" >
<include name="*.war"/>
</fileset>
</path>
<sequential>
<var name="undeploy_name" value="#{file} function_here ${mydir}" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="${undeploy_name}" />
</JBossCLI>
<deployToLiferay file="#{file}" />
</sequential>
</for>
in general I want to deploy several wars. this works fine when I run it once but if I want to make it re-runnable I need to undeploy them first.
I'm just a consumer of this interfaces, Ideally deployToLiferay would auto undeploy but it does not.
thanks for an feedback
edit: if I use something similar to what is define on the linked page i get:
<loadresource property="file-to-deploy">
<propertyresource name="#{file}"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replacestring from="${mydir}" to=""/>
</tokenfilter>
</filterchain>
</loadresource>
10:52:49.541: * /data/contribution.xml:171: The following error occurred while executing this line:
10:52:49.541: * /data/contribution.xml:178: null doesn't exist
line 178 is my loadresource part
ANT is not a programming language. Personally I'd recommend embedding a scripting language like Groovy to process a group of files:
<target name="process-files" depends="resolve">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="wars" dir="src/wars" includes="*.war"/>
<groovy>
project.references.wars.each {
ant.echo(message: "I want to do something with this ${it} file")
}
</groovy>
</target>
Example
├── build.xml
└── src
└── wars
├── app1.war
├── app2.war
└── app3.war
Example
process-files:
[echo] I want to do something with this /../src/wars/app1.war file
[echo] I want to do something with this /../src/wars/app2.war file
[echo] I want to do something with this /../src/wars/app3.war file
Update
The following working example shows how Apache ivy can be used to manage build dependencies. This is a capability that exists in other Java build tools like Maven.
<project name="demo" default="process-files" xmlns:ivy="antlib:org.apache.ivy.ant">
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<!--
==================
Normal ANT targets
==================
-->
<target name="process-files" depends="resolve">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="wars" dir="src/wars" includes="*.war"/>
<groovy>
project.references.wars.each {
ant.echo(message: "I want to do something with this ${it} file")
}
</groovy>
</target>
<!--
=============================
Dependency management targets
=============================
-->
<target name="resolve" depends="install-ivy">
<ivy:cachepath pathid="build.path">
<dependency org="org.codehaus.groovy" name="groovy-all" rev="2.4.7" conf="default"/>
</ivy:cachepath>
</target>
<target name="install-ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
</project>
I have a continuous integration server that discovers and runs assemblies with NUnit tests. I would like to add some assemblies with xUnit.net tests to the mix. How would I do that?
Download xunit-build-xyzw.zip from xUnit.net on CodePlex and extract it to, for example, C:\Program Files\xUnit.net. Add this location to PATH environment variable
be sure to have no trailing semicolon
Modify your CC.NET *.build script to discover assemblies by convention, as outlined below
note that command line argument syntax no longer has equals sign
In C:\Program Files\CruiseControl.NET\server\ccnet.config, Merge XML files produced by NUnit runner and by xUnit.net runner, as outlined below
merging happens after build, irrespective of build status
be sure results of test run get deleted in the beginning of build script
Restart CC.NET
Download xUnitSummary.xsl from xUnit.net on GitHub and place it in C:\Program Files (x86)\CruiseControl.NET\WebDashboard\xsl
In C:\Program Files\CruiseControl.NET\WebDashboard\dashboard.config, modify buildPlugins element as outlined below
Restart IIS
Additional info:
CruiseControl.Net – Server Installation at Neal's Blog
Step 2:
<project default="RunTests_xUnit">
<target name="RunTests_xUnit" description="Runs the discovered xUnit.net unit tests" depends="someCompileStep">
<!-- Outer loop to search through a list of different locations -->
<!-- Folders to be searched should listed as a semicolon deliminated list in the 'in' attribute -->
<foreach item="String" in="${TestAssemblyOutputPath}" delim=" ;" property="testsPath">
<echo message="Searching for xUnit.net test suites in ${testsPath}" />
<!-- Inner loop to search for dlls containing unit tests -->
<foreach item="File" property="filename">
<in>
<items basedir="${testsPath}">
<!-- see http://nant.sourceforge.net/release/0.91/help/types/fileset.html for how to include or exclude specific files or file patterns -->
<!-- attempt to run tests in any dlls whose name ends with UnitTestSuite.dll' -->
<include name="**UnitTestSuite.dll" />
</items>
</in>
<do>
<property name="testDLLName" value="${path::get-file-name-without-extension(filename)}" />
<echo message="Testing ${testDLLName} with xUnit.net" />
<exec program="${xunit-console.exe}" failonerror="true" resultproperty="resultVal">
<arg line="${testsPath}\${testDLLName}.dll /xml ${xUnitTestLogsFolder}${testDLLName}-xUnitResults.xml" />
</exec>
<fail message="Failures reported in ${testDLLName}." failonerror="true" unless="${int::parse(resultVal)==0}" />
</do>
</foreach>
</foreach>
</target>
</project>
Step 3:
<publishers>
<merge>
<files>
<file>C:\logs-location\xUnitTestLogs\*UnitTestSuite-xUnitResults.xml</file>
<file>C:\logs-location\TestLogs\*Tests-Results.xml</file>
</files>
</merge>
<xmllogger />
<statistics />
</publishers>
Step 5:
<buildPlugins>
<buildReportBuildPlugin>
<xslFileNames>
...
<xslFile>xsl\xUnitSummary.xsl</xslFile>
</xslFileNames>
</buildReportBuildPlugin>
...
<xslReportBuildPlugin description="xUnit.net Report" actionName="xUnitReport" xslFileName="xsl\xUnitSummary.xsl" />
...
</buildPlugins>
Parse provides docs as external Parse-1.5.1-javadoc folder.
I would like to have Parse javadoc connected within Android Studio. How do I achieve that?
I'm using AndroidStudio 0.6 and parse 1.5.1.
Same problem:
Android Studio: How to attach javadoc
Android issue tracker:
https://code.google.com/p/android/issues/detail?id=59220
Here is the only solution I've found so far:
Open /YourProjectDir/.idea/libraries/Parse_versionCode.xml"
Add the following lines:
<JAVADOC>
<root url="https://www.parse.com/docs/android/api/" />
</JAVADOC>
So it should look something like this:
<component name="libraryTable">
<library name="Parse-1.8.3">
<CLASSES>
<root url="jar://$PROJECT_DIR$/app/libs/Parse-1.8.3.jar!/" /> <!-- check version! -->
</CLASSES>
<JAVADOC>
<root url="https://www.parse.com/docs/android/api/" />
</JAVADOC>
<SOURCES />
</library>
</component>
Currently the file is only keeping the latest revision. I want to use a different file where the history is kept. Each time ANT is used, I want it to append the time and revision number on that file. On the home screen I will just have a link to that file.
This is how its written now:
<target name="compile-java" depends="prepare,compile">
<exec dir="${project.dir}" executable="tools/version.sh" output="${src.web.dir}/date_compile.jsp">
<arg line="" />
</exec>
<propertyfile file="${src.web.dir}/date_compile.jsp">
</propertyfile>
</target>
I want to append new revision while keeping old revision data too.
This is just a matter of using the BuildNumber or PropertyFile task to create the build version number file and then read the file to get that number, create also a timestamp of the build and then append them both to another file.
Here is a basic idea of how to do it. Starting from that you should be able to write something of the likes of this:
<project default="increment">
<target name="increment">
<tstamp>
<format property="build.time" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<propertyfile file="build.properties">
<entry key="build.number" type="int" operation="+" default="0" />
</propertyfile>
<property file="build.properties" />
<echo message="Build ${build.number} on ${build.time}
" append="true" file="build.history" />
</target>
</project>
This creates two files: build.properties with your build number (always the last number as it is overwritten on each build) and build.history that contains a list of build numbers and a timestamp of each build.
EDIT : Based on the comments, if the version.sh outputs the revision and date to date_compile.jsp and overrides it on each build then - to keep history - you just need to load date_compile.jsp in your build and append its content to another file, something like this:
<target name="compile-java" depends="prepare,compile">
<exec dir="${project.dir}" executable="tools/version.sh" output="${src.web.dir}/date_compile.jsp">
<arg line="" />
</exec>
<loadfile property="revision" srcfile="${src.web.dir}/date_compile.jsp" />
<echo message="${revision}<br>
" append="true" file="${src.web.dir}/compile_history.jsp" />
</target>
Not 100% sure what you want, but it looks like a combination of <tstamp/>, <echo>, and <propertyfile/>.
You can use <propertyfile> to specify the property file where the build number is stored, and for editing it:
<propertyfile file="${build.prop.file}">
<entry key="build.number"
value="1"
default="0"
operation="+"/>
</propertyfile>
Now, you can include that property file in your build:
<property file="${build.prop.file}"/>
Which will set ${build.number}.
Next, you're going to get the date and time:
<tstamp>
<format property="build.time.stamp"
pattern="yyyy-mmm-dd.hh:mm:ss-zzzzz"/>
</tstamp>
Now, you'll append this to your log file
<echo append="true" file="${build.log}"
message="Building build # ${build.number} on ${build.time.stamp}"/>
I'd like to search for a string within my source files with Ant. (I'd like my build to fail in case certain string is found within my source files).
So, I should be able to recursively search for a certain string within a file set.
I already found that I can use loadfile task to check whether a string pattern is found within one file. But that seems to be working & sensible only with a single file.
On the other hand, replace task would provide recursively search-and-replace. I guess I could do that before build and replace my string with something that would break the build but I wonder if there is some cleaner solution?
br, Touko
You might consider using fileset selectors to do this. Selectors allow you to choose files based on content, size, editability and so on. You can combine selectors with name-based includes and excludes, or patternsets.
Below is an example. The second fileset is derived from the first, with a selector that simply matches on file content. For more sophisticated matching there is the containsregexp selector. The result is a fileset containing only files matching the string. A fail task with a resourcecount condition is then used to fail the build, unless that fileset is empty.
<property name="src.dir" value="src" />
<property name="search.string" value="BAD" />
<fileset id="existing" dir="${src.dir}">
<patternset id="files">
<!-- includes/excludes for your source here -->
</patternset>
</fileset>
<fileset id="matches" dir="${src.dir}">
<patternset refid="files" />
<contains text="${search.string}" />
</fileset>
<fail message="Found '${search.string}' in one or more files in '${src.dir}'">
<condition>
<resourcecount when="greater" count="0" refid="matches" />
</condition>
</fail>
(Old answer): If adjusting or reusing filesets might be problematic, here's an illustration of a relatively simple alternative.
The idea is to make a copy of the files,
then replace the string you wish to search for
with some flag value in the copied files.
This will update the last modified time on any matching file.
The uptodate task can then be used to look for affected files.
Finally, unless no files matched, you can fail the build.
<property name="src.dir" value="src" />
<property name="work.dir" value="work" />
<property name="search.string" value="BAD" />
<delete dir="${work.dir}" />
<mkdir dir="${work.dir}" />
<fileset dir="${src.dir}" id="src.files">
<include name="*.txt" />
</fileset>
<copy todir="${work.dir}" preservelastmodified="true">
<fileset refid="src.files" />
</copy>
<fileset dir="${work.dir}" id="work.files">
<include name="*.txt" />
</fileset>
<replaceregexp match="${search.string}"
replace="FOUND_${search.string}">
<fileset refid="work.files" />
</replaceregexp>
<uptodate property="files.clean">
<srcfiles refid="work.files" />
<regexpmapper from="(.*)" to="${basedir}/${src.dir}/\1" />
</uptodate>
<fail message="Found '${search.string}' in one or more files in dir '${src.dir}'"
unless="files.clean" />
This was very helpful as a start, but I have a list of strings which should be checked in a fileset.
My current code sofar is:
<property name="search4" value="XYZ"/>
<fileset id="existing" dir="../src">
<patternset id="files">
<include name="content/**/*.txt"/>
</patternset>
</fileset>
<resourcecount property="count">
<fileset id="matches" dir="../src">
<patternset refid="files" />
<contains text="${search4}" />
</fileset>
</resourcecount>
<echo message="Found '${search4}' in files : '${count}'"/>
That works well, but how to expand that so the ${search4} is read from a list. Actually the list can be read from a file containing each search item is on a separate line.
Slightly more concise variation on the first part of #martinclayton's answer:
<property name="log.dir" value="logs" />
<property name="fail.string" value=" FAILED " />
<fileset id="build.failures" dir="${log.dir}" includes="*.log">
<contains text="${fail.string}"/>
</fileset>
<fail status="1" message="One or more failures detected">
<condition>
<resourcecount when="greater" count="0" refid="build.failures" />
</condition>
</fail>