S3 upload using ant task - ant

I am trying to upload files using ant to the s3 bucket.
For this i have added
1.awstasks-0.3.jar
2.jets3t-0.8.0.jar
3.commons-httpclient-3.1.jar
4.commons-logging-1.1.1.jar
5.java-xmlbuilder-0.4.jar
Here is the task that i am trying to excute:-
<taskdef name="S3Upload" classname="dak.ant.taskdefs.S3Upload">
<classpath refid="classpath.compile" />
</taskdef>
<target name="upload">
<S3Upload verbose="true" accessId="myaccesskey" secretKey="je+mysecretkey" bucket="bucketname" publicRead="true">
<fileset dir="lib" includes="mail.jar" />
</S3Upload>
</target>
After running the task following error is shown :-
java.lang.NoSuchMethodError: org.jets3t.service.impl.rest.httpclient.RestS3Service.(Lorg/jets3t/service/security/AWSCredentials;)V

Looks like this method is not available in 0.8.0 version of jets3t. Perhaps you should try with jets36-0.7.4.jar.

Related

How to integrate Ant with Checkstyle and PMD plug-ins in Jenkins

I want to integrate Checkstyle and PMD plug-ins in Jenkins for checking quality code automatically.
I followed the instructions from: http://www.treselle.com/blog/static-code-analysis-jenkins/
My build.xml in workspace was appended those codes:
<taskdef name="checkstyle" classpath="WEB-INF/libs/checkstyle-5.6.jar" classname="com.puppycrawl.tools.checkstyle.CheckStyleTask" />
<target name="checkstyle" description="Generates a report of code convention violations.">
<checkstyle config="sun_checks.xml" failOnViolation="false">
<formatter type="xml" tofile="checkstyle_report.xml" />
<fileset dir="WEB-INF/src" includes="**/*.java" />
</checkstyle>
</target>
<taskdef name="pmd" classpath="WEB-INF/libs/pmd.jar" classname="net.sourceforge.pmd.ant.PMDTask" />
<target name="pmd" depends="compress">
<pmd rulesetfiles="java-imports">
<formatter type="xml" toFile="pmd_report.x.ml" />
<fileset dir="WEB-INF/src">
<include name="**/*.java" />
</fileset>
</pmd>
</target>
I also added enough library, but when I builded Jobs, I got a exception:
taskdef class com.puppycrawl.tools.checkstyle.CheckStyleTask cannot be found using the classloader AntClassLoader[]
Why is there such error? And How do I integrate them correctly?
Thanks a lot!
Try later version of check style as checkstyle-8.0-all.jar.
See example
classname="com.puppycrawl.tools.checkstyle.CheckStyleTask" />
taskdef class com.puppycrawl.tools.checkstyle.CheckStyleTask cannot be found
The class is named CheckstyleAntTask.
See https://github.com/checkstyle/checkstyle/blob/master/config/ant-phase-verify.xml on an example on how to use CheckstyleAntTask.
checkstyle-5.6.jar
I recommend upgrading to a newer version. Checkstyle is currently on version 8.

Ant for script how to continue if any iteration fails

I writing an ant build file to check all translate files in a directory.
I want the ant for script to continue checking the rest files if an checking error in any file appear.
My ant task:
<taskdef name="validate" classname="ValidateTranslateFile">
<classpath>
<pathelement location="${ant-libs-dir}/TranslateFileUtilities.jar" />
<pathelement location="../web/WEB-INF/lib/commons-io-2.5.jar" />
<pathelement location="../web/WEB-INF/lib/commons-lang3-3.5.jar" />
</classpath>
</taskdef>
<for param="program">
<path>
<fileset dir="../web/WEB-INF" includes="*.txt" />
</path>
<sequential>
<validate targetFile="#{program}" checkLanguages="true" checkKeysOrder="true" />
</sequential>
</for>
</target>
the Result:
it checks the files till the first error appear, and then the BUILD FAILED.
Could any one help me with that?
The for task is not part of standard ANT. It is a 3rd party extension documented here:
http://ant-contrib.sourceforge.net/tasks/tasks/for.html
The documentation suggests using a "keepgoing" attribute to ignore errors, this might be the answer you're looking for.
If this is a custom ANT task you are writing, perhaps you should consider refactoring the code to operate on a fileset? This would enable you to call task as follows:
<validate checkLanguages="true" checkKeysOrder="true">
<fileset dir="../web/WEB-INF" includes="*.txt" />
</validate>
Simpler and more robust.

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.

Using Ant for S3 Uploading

I tried to implement the awstasks Class for uploading files via an ant script to an S3 bucket.
Downloaded all dependencies and used the following code:
<taskdef name="S3Upload" classname="dak.ant.taskdefs.S3Upload">
<classpath refid="classpath.compile"/>
</taskdef>
<target name="final2S3">
<basename property="customer.id" file="${basedir}"/>
<basename property="customer.name" file="${basedir.parent.parent}"/>
<basename property="customer.campaign" file="${basedir.parent}"/>
<basename property="customer.final" file="${basedir.parent}\_final\${customer.id}\"/>
<S3Upload verbose="true"
accessId="${aws.accessId}"
secretKey="${aws.secretKey}"
bucket="${aws.bucket}\${customer.id}"
publicRead="true">
<fileset dir="${customer.final}">
<include name="**/*.json"/>
<include name="**/*.swf"/>
</fileset>
</S3Upload>
</target>
I get the following error:
Reference classpath.compile not found.
I tried to set the property classpath.compile to the lib folder in the Ant home but nothing changes.

Inconsistent NoClassDefFoundError in subant java task

My ant build script starts with a java task that uses fork=true
<java fork="true"
classname="org.apache.tools.ant.launch.Launcher"
jvm="${java.home}/bin/java"
classpathref="class.path">
<arg value="-f" />
<arg value="${ant.file}" />
<arg value="generate" />
</java>
The <arg value="generate" /> points to another task in the same ant build file.
This task starts another target with a subant task that points to another file.
<subant verbose="true" target="replace">
<fileset dir="${basedir}" includes="refactor.xml" />
</subant>
This file refactor.xml starts a java task again with fork=true.
<java classpathref="class.path"
classname="namespace.Tool"
fork="true"/>
The strange behaviour is: everything works fine, except once in a while I get the NoClassDefFoundError error for the namespace.Tool java source file.
After e.g. closing, reopening the file the error may disappear, however there is no reproducible behaviour.
I tried avoiding the subant construction (used to unclutter) but this doesn't help.
Finally the class.path that is referenced is like this:
<path id="class.path">
<pathelement location="../common/bin" />
<pathelement location="./bin" />
<fileset dir="${build.dir}">
<include name="...jar" />
</fileset>
</path>
Any ideas?
Cause was <pathelement location="./bin" />.
This bin folder was recompiled by Eclipse as soon as in other steps in the sequence of Ant tasks e.g. a folder was deleted. The default setting in Eclipse is to recompile all code at such a moment.
As a result the Ant process may or may not find a specific class in this bin folder resulting in the inconsistent NoClassDefFoundError.

Resources