What does the includes="**/*.js"/ mean in the below merge code form an Ant file.
<target name="merge grid">
<echo>${grid.file}</echo>
<concat destfile="${grid.file}" fixlastline="yes" append="no">
<fileset dir="${js.src.dir}/dvr/components/grid/" includes="**/*.js"/>
</concat>
</target>
Also what does this part mean :
<target name="merge" depends="merge grid, merge solids"/>
In the fileset
**/*.js
matches files in the filesystem. The ** part means 'in any directory' (under the directory mentioned in the dir attribute). The *.js matches any file ending in .js. Overall, the fileset includes any .js file found in a sub-directory of ${js.src.dir}/dvr/components/grid/ recursively. See Directory-based Tasks. (The trailing / is not part of the includes pattern, it is the closing part of the fileset element in the XML:
<fileset ... attributes ... />
The merge grid target, therefore will concatenate all .js files into a single destination file of name defined in the property grid.file.
The target is the opening of the definition of an Ant target, which is a sequence of Ant tasks that comprise a distinct step in the build. The depends attribute lists other targets - in this case merge grid and merge solids - that must be executed (if needed) before the merge target itself. See Targets.
Related
Is it possible to input a text file which contains the list of files that needs to be deleted using Ant Delete task?
I know there is an option for giving a fileset inside the delete task but since I have 100's of files that need to be deleted using ant delete.
For example
<target name="removeJarsFromList">
<delete includeEmptyDirs="true" failonerror="false">
<fileset dir="${my_base_dir}">
<include name="/a/file1.jar/**"/>
<include name="/b/file2.jar/**"/>
<include name="/somedir/file3.jar/**"/>
<include name="/c/file4.jar/**"/>
</fileset>
</delete>
</target>
Instead is there an option to have the files that needs to be deleted in a text file and give the text file as input.
myDeleteFileList.txt will have contents something like this
/a/file1.jar
/b/file2.jar
/somedir/file3.jar
/c/file4.jar
And give this file as input to the fileset ?
there's a includesfile attribute for the <delete> task.
includesfile: The name of a file. Each line of this file is taken to be an include pattern. All files are relative to the directory specified in dir. See HERE
<delete dir="${base.dir}" includesfile="abc.txt"/>
abc.txt:
(each line is an include pattern, relative to dir; avoid trailing / leading spaces)
**/fileA
/x/y/fileB
z/*.java
normally, the dir attribute in the <delete> task is used to delete the entire directory, but maybe this'll work. (i havent tried this, so) take a backup of your directory or try it on a temporary directory first!
I'm currently looking to run static analysis over a pre-existing project. As the project is created and supplied by an off-site company, I cannot change the build process radically.
The project is split into a lot of sub-modules, located in various places. For other analyisi tools (JDepend, Google Testability Explorer, etc.), I have dynamically detected all build JAR files into a path element as follows:
<path id="built-libs">
<fileset dir="${overall-base}">
<include name="${some-common-base}/**/lib/*.jar" />
</fileset>
</path>
<property name="built-libs-string" refid="built-libs" />
For some tools, I use the build-libs, for others I use the string (in classpath form; x.jar;y.jar).
The trouble is, FindBugs uses a completely different format to any other;
<class location="x.jar"/>
<class location="y.jar"/>
...
Now, I could list all the JAR files manually, but then run the risk of this list going out of synch with the other tool's lists, or of introducing typos.
Another complication is that I also want to run the reports in Jenkins, in this case the extract directory for individual modules will depend on the job that has previously built the module (pipeline builds, modules extracted from SCM and built in parallel, the reporting occurring at the end of the pipline).
I could make a call out to the OS to run FindBugs, passing in the JARs in a space separated list (as in Invoking FindBugs from Ant: passing a space-separated list of files to java). However, I prefer a, Ant solution to an OS <exec... hack.
Note I know I have a similar problem for the sourcepath element, however, I'm assuming that solving the class element problem also solves the sourcepath one.
Ideally, FindBugs should be taking a resource collection rather than separate class elements. I'm not familiar with FindBugs, so I can't comment on why they have chose to go the class element route instead of a resource collection, however your comment about using exec implies that using a resource collection is a valid design alternative.
I would try rolling your own Ant macro, which invokes FindBugs directly using the java task. This should give you the control you need and avoiding the redundancy that the FindBugs Ant task would introduce.
Another option (which is an ugly hack) is to use the fileset to write a mini ant file with a FindBugs target, which you then invoke using the ant task. shudders
The Findbugs Ant task allows you to specify a filelist which can be used to specify multiple files. Quoting from the Findbugs documentation
"In addition to or instead of specifying a class element, the FindBugs
task can contain one or more fileset element(s) that specify files to
be analyzed. For example, you might use a fileset to specify that all
of the jar files in a directory should be analyzed."
Example that includes all jars at ${lib.dir}:
<findbugs home="${findbugs.home}" output="xml" outputFile="findbugs.xml" >
<auxClasspath path="${basedir}/lib/Regex.jar" />
<sourcePath path="${basedir}/src/java" />
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</findbugs>
How do you call a specific target in all build.xml located in all subdirectories using wildcards (ie not hard coding the subdirectory names)? The below answer is hardcoded. Is there a way to do it without hardcode?
Similar to this question: Pass ant target to multiple build.xml files in subdirectories
Use the Ant subant task like this:
<subant target="sometarget">
<fileset dir="." includes="*/build.xml" />
</subant>
If you include an "inheritall" attribute (same as how it's used in but defaults the opposite), you can share all your current project's properties and everything too. This also makes it very easy to overwrite tasks defined in your main build.xml file if you need to.
Read more about it here.
I'll setup different properties within my build.properties file. I use these to dynamically build paths in my targets.
Define the location of your build.properties file:
<!-- all properties are in build.properties -->
<property file="build.properties" />
Use those properties in your targets:
Properties in the build properties are similar to setting up an .ini file:
project.rootdir=c:/Deploy
project.tempbuilddir = c:/Deploy/Temp/Inetpub
project.builddir=c:/Deploy/Inetpub
# Build prefix will be added to that tags urls (.../tags/${project.buildprefix}Build_${today.date})
project.buildprefix=ACA_
I guess you could use a dynamic file as your properties file, if necessary, as long as you define the proper path to the file. You could point it to a server-side file to dynamically write your properties file (ColdFusion, PHP, JSP, whatever).
I've used ant-contrib's foreach task to do something like this.
http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html
Sounds like a perfect candidate for the <subant> task.
Is there a way to have an Ant Fileset->IncludesFile attribute take a property file OR any other file that contains a list of Java class files to exclude?
Eg:
File A.properties OR A.java contains listing
abc.class
mno.class
xyz.class
Is there a way to say to point excludesFile to file A.properties.
<fileset dir="...">
<excludesFile file="A.properties" />
</fileset>
The behavior that I want is when Java runs, it excludes the Java files listed in this file (A.properties)
Hmm...not sure if it's case sensitive. The documentation at http://ant.apache.org/manual/Types/fileset.html shows "excludesfile", all lowercase, as with other ant directives.
I'm not sure exactly what you are asking. If you have a fileset which is including files you would like to exclude, and you want to specify that list of files to exclude in an external file, "excludesfile" is the correct way to do it.
I want to iterate over a list of jars (undefined number) and add them all to the jar file.
To add them I plan to use something like this:
<jar id="files" jarfile="all.jar">
<zipfileset src="first.jar" includes="**/*.java **/*.class"/>
<zipfileset src="second.jar" includes="**/*.java **/*.class"/>
</jar>
but how do I iterate over them? I don't have ant-contrib
Thanks!
Just use zipgroupfileset with the Ant Zip task
<zip destfile="out.jar">
<zipgroupfileset dir="lib" includes="*.jar"/>
</zip>
This will flatten all included jar libraries' content.
If you do not have access to ant-contrib For task, you may end up to have to define your custom Task for doing what you need...
If you have ant1.6 and above, you can also try subant (see New Ant 1.6 Features for Big Projects):
If you use <subant>'s genericantfile attribute it kind of works like <antcall> invoking a target in the same build file that contains the task.
Unlike <antcall>, <subant> takes a list or set of directories and will invoke the target once for each directory setting the project's base directory.
This is useful if you want to perform the exact same operation in an arbitrary number of directories.