Enunciate REST API doc generation using ant - ant

I am trying to integrate Enunicate to generate REST documentation of our existing API's.
I get a warning "WARNING: Unknown artifact 'docs'. Artifact will not be exported." when the ant task is executed.
Is there something that is missing in my setup?
The enunicate.xml is :
<?xml version="1.0"?>
<enunciate label="Empath REST api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.23.xsd">
<modules>
<!-- Docs -->
<docs splashPackage="com.parc.perceptum.common" title="Empath REST API"
copyright="PARC"> <download name="License" file="LICENSE.txt" description="The license file governing the use of this API." />
</docs>
</modules>
</enunciate>
And the relevant ant fragment is :
<path id="enunciate.classpath">
<fileset refid="project.libs"/>
<fileset dir="${java.home}">
<include name="lib/tools.jar"/>
</fileset>
<pathelement path="${servlet-lib}" />
<pathelement path="${mysql-lib}" />
</path>
<taskdef name="enunciate" classname="org.codehaus.enunciate.main.EnunciateTask">
<classpath refid="enunciate.classpath"/>
</taskdef>
<target name="new-rest-api-doc">
<enunciate basedir="src/com/parc/perceptum/">
<include name="**/*.java"/>
<classpath refid="enunciate.classpath"/>
<export artifactId="docs" destination="restapi"/>
</enunciate>
</target>
Thanks
Venu

Looks like you might not have the enunciate libraries on your classpath. So Enunciate doesn't pick up any of its modules (including the docs module, which provides the 'docs' artifact).

The value of artifactId should be 'war.file'

Related

Ant task is unable to recognize android private libraries

I am trying to run findbugs through ant. This is a snippet of a part of my build file:
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" >
<classpath>
<fileset dir="${findbugs.home}/lib" includes="**/*.jar"/>
<pathelement location="${project.target.android.jar}" />
</classpath>
</taskdef>
<path id="build.classpath">
<pathelement location="${project.target.android.jar}" />
<fileset dir="libs">
<include name="*.jar"/>
</fileset>
</path>
<target name="findbugs" >
<findbugs home="${findbugs.home}" output="html" outputFile="findbugs/findbugs.html">
<class location="${out.classes.absolute.dir}" />
<auxClasspath refId="build.classpath"/>
<sourcePath path="${source.absolute.dir}" />
</findbugs>
</target>
This is unable to recognize the android library and gives errors like: cannot find android.os.Bundle,
etc,...
How do I make it recognize android libraries? I have tried including it using , but this doesn't seem to work.
I am not aware of the complete build file, but the main project compilation works fine, and the android lib included there are in this format:
<gettarget
androidJarFileOut="project.target.android.jar"
...
Findbugs works on Java's class file format. Android uses another format called dex. So Findbugs will not work on that.

ANT - Converting a String to Path with location attribute

I have the following ANT script that gives me a list of websphere libraries at runtime based on the websphere root directory. I need to convert the resulting string into separate path location elements
My current script is
<?xml version="1.0" encoding="UTF-8"?>
<project name="TestPath" basedir="." default="print-dirset">
<target name="init" description="Define websphere libraries">
<property name="compile.lib.dir" value="C:\Software\WAS85" />
</target>
<target name="print-dirset" depends="init" description="">
<path id="websphere.libs">
<dirset dir="${compile.lib.dir}">
<include name="*" />
</dirset>
</path>
<property name="websphere.libs.list" refid="websphere.libs" />
<echo message="websphere.libs.list: ${websphere.libs.list}" />
<pathconvert property="websphere.libs.convert" pathsep="${file.separator}*${path.separator}">
<path path="${websphere.libs.list}" />
</pathconvert>
<echo message="websphere.libs.convert: ${websphere.libs.convert}" />
</target>
</project>
which outputs a string like below
[echo] websphere.libs.list: C:\Software\WAS85\Scheduler;C:\Software\WAS85\UDDIReg;C:\Software\WAS85\bin;C:\Software\WAS85\configuration;....C:\Software\WAS85\web;C:\Software\WAS85\wlp
[echo] websphere.libs.convert: C:\Software\WAS85\Scheduler\*;C:\Software\WAS85\UDDIReg\*;C:\Software\WAS85\bin\*;C:\Software\WAS85\configuration\*;...C:\Software\WAS85\web\*;C:\Software\WAS85\wlp
I would like to translate the second string above into a structure like below
<path id="websphere.classpath">
<pathelement location="C:\Software\WAS85\Scheduler\*" />
<pathelement location="C:\Software\WAS85\UDDIReg\*" />
<pathelement location="C:\Software\WAS85\bin\*" />
<pathelement location="C:\Software\WAS85\configuration\*" />
......
<pathelement location="C:\Software\WAS85\web\*" />
<pathelement location="C:\Software\WAS85\wlp\*" />
</path>
The last element in the conversion also needs to add the '\*' part which is not in the original string.
which can then be used with a structure like
<path id="compile.classpath">
<path refid="ext.classpath"/>
<path refid="websphere.classpath"/>
<path refid="module.compile.classpath"/>
</path>
The purpose of the above attempt is to reduce the length of classpath by using wildcard classpath provided by JDK 1.6 and which is available in ANT starting ANT 1.8.2. I am using ANT 1.8.4.
I am not an expert in ANT, I can just get by, by looking at examples.
Is there a way to achieve what I am trying to do? How can I do it? Any example would be very helpful.
If all of your dependencies reside in C:\Software\WAS85, you can use fileset to catch all of your dependencies:
<fileset dir="${compile.lib.dir}" id="compile.files">
<include name="**/*.java"/>
<!-- include name="**/*.jar" /-->
</fileset>
You can then use to refer to this fileset as compile.files elsewhere in your build.xml.
I was able to get the wildcard part to work by using the fork="yes" and executable="path-to-my-executable" attributes in the javac task.
I do not want to mark the question answered, because my basic question was about converting the string. But since the answer received didn't talk about that and also didn't mention how to get wildcard classpath working, and the purpose of my question was to get the wildcard classpath working, i have noted it here for whoever is trying to get that to work
I still need some help in converting the semi-colon separated string to construct like below
<path id="websphere.classpath">
<pathelement location="C:\Software\WAS85\Scheduler\*" />
<pathelement location="C:\Software\WAS85\UDDIReg\*" />
<pathelement location="C:\Software\WAS85\bin\*" />
<pathelement location="C:\Software\WAS85\configuration\*" />
......
<pathelement location="C:\Software\WAS85\web\*" />
<pathelement location="C:\Software\WAS85\wlp\*" />
</path>
Update:
I wrote a custom ANT task to get the wildcard classpath working

in linux,how to create jar files with including external jars and log4j.propeties file using ant

i want to create jar file with external jars and log4j.properties file using ant.i am having only source code alone.
Please let me know how to do this.
Thanks in advance.
This is a simple sketch to start with. You have to specify more details for us to give you a better answer, for example the project layout, the place where external jars and the log4j.properties file are.
<project name="demo" default="build">
<path id='external.classpath'>
<pathelement location='commons-io-1.3.2/commons-io-1.3.2.jar' />
</path>
<target name="build">
<javac debug='true' debuglevel='source,lines,vars' destdir='project\temp' source='1.5' target='1.5' includeAntRuntime='false' encoding='utf-8'>
<src path='src' />
<classpath refid='external.classpath' />
</javac>
<jar jarfile='build\foobar.jar' basedir='project\temp' />
<copy file='commons-io-1.3.2/commons-io-1.3.2.jar' todir='build'/>
<copy file='log4j.properties' todir='build'/>
</target>
</project>

Get list of files from URL

I'll like to automate somehow keeping my Netbeans Daily build with what's available.
Basically is as follows:
Get file list from http://bits.netbeans.org/download/trunk/nightly/latest/zip/
Download file (let's say I'm interested in the java.zip)
Unzip
I have an ant script capable of doing 2 and 3. I need to figure out how to do the first. See below:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Netbeans Daily Build" basedir=".">
<description>Updates the daily build</description>
<property name="zip.name" value="netbeans-6.9.1-201007282301-ml-javase.zip"/>
<property name="dist" value="Z:/Program Files/Netbeans 7.0/"/>
<property name="zip.url" value="http://bits.netbeans.org/download/trunk/nightly/latest/zip/"/>
<fileset id="ant-contrib-jar" dir="./">
<include name="ant-contrib-*.jar" />
</fileset>
<pathconvert property="ant-contrib-jar" refid="ant-contrib-jar" pathsep="," />
<basename property="ant-contrib-filename" file="${ant-contrib-jar}"/>
<property name="ant-contrib-loc" value="./${ant-contrib-filename}"/>
<available file="${ant-contrib-loc}" property="ant-contrib.present"/>
<fail unless="ant-contrib.present" message="The ant-contrib jar doesn't exist at: ${ant-contrib-loc}, can't build. Check your settings!" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${ant-contrib-loc}"/>
</classpath>
</taskdef>
<!--Delete old copies of platforms-->
<delete>
<fileset dir="${dist}" includes="**/*.zip" excludes="${zip.name}"/>
</delete>
<available file="${zip.url}${zip.name}" property="file.exists"/>
<if>
<not>
<isset property="file.exists"/>
</not>
<then>
<get src="${zip.url}${zip.name}" dest="./" skipexisting="true" verbose="true"/>
<!--Only overwrite if newer
<unzip src="${dist}/${zip.name}" dest="${dist}" overwrite="false"/>-->
</then>
</if>
</project>
I need to somehow figure out the correct file name to download.
Doing everything in a batch file (without ant) is acceptable as well.
Thanks in advance!
How about you just check out the latest version using mercurial? This should tell you how: http://netbeans.org/community/sources/hg.html
Looks like there's a project for this. Looks like I'll be joining the team...
http://kenai.com/projects/nb-nightly-updater

Why cannot Ant taskdef cannot load a resource outside ./net

When declaring external ant tasks using taskdef, for instance ant-contrib, the proposed setup is to use the followin taskdef:
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="lib/ant-contrib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
This works when antcontrib.properties is located in net/sf/antcontrib relative to the build.xml file.
But when I put it in lib/net/sf/antcontrib and changes the taskdef into
<taskdef resource="lib/net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="lib/ant-contrib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
Ant is not able to find the properties file, it gives the error
[taskdef] Could not load definitions from resource
lib/net/sf/antcontrib/antcontrib.properties. It could not be found.
It seems like ant treats the lib directory separately and fails to load a taskdef resource from there.
As Alex said, you shouldn't need to unzip the jar. The <taskdef> can load antcontrib.properties directly out of the jar.
The error you got is because you changed the resource path, but the path to the file inside the compressed jar/zip is still the same. The taskdef isn't paying attention to the properties file you moved because the <classpath> you provided to <taskdef> tells it to only look in the jar.
Use antlib.xml resource:
Here is the taskdef definition that I use:
<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>
You do not need to extract anything from the jar file. Also, uri attribute is optional if you do not want to use namespaces with antcontrib tasks.
To handle classpath for tasks definitions, I use a classpath ref in Ant, it's way easier. You can link either a directory containing classes, either a directory containing many .jar, either (of course) a single .jar.
For example :
<!-- Properties -->
<property name="lib" value="lib/" />
<property name="classes" value="bin/" />
<!-- Classpath definition -->
<path id="runtime-classpath" >
<pathelement location="${bin}" />
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</path>
<!-- Taskdefs definitions -->
<taskdef name="myTask" classname="org.stackoverflow.tasks.MyTask" classpathref="runtime-classpath" />
<!-- Tasks -->
<target name="test" description="Test Action">
<myTask parameter1="value" />
</target>

Resources