Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
165 lines (136 sloc) 6.44 KB
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project name="hello-ivy" default="run"
xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<!-- Sonar task def -->
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml" />
<property name="sonar.host.url" value="http://localhost:9000" />
<property name="sonar.jdbc.url" value="jdbc:derby://localhost:9527/sonar" />
<property name="sonar.jdbc.driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="sonar.jdbc.username" value="sonar" />
<property name="sonar.jdbc.password" value="sonar" />
<!-- some variables used -->
<property name="lib.dir" value="lib" />
<property name="build.dir" value="build" />
<property name="src.dir" value="src" />
<!-- paths used for compilation and run -->
<path id="lib.path.id">
<fileset dir="${lib.dir}" />
</path>
<path id="run.path.id">
<path refid="lib.path.id" />
<path location="${build.dir}" />
</path>
<!-- =================================
target: resolve
================================= -->
<target name="resolve" description="--> retreive dependencies with ivy">
<ivy:retrieve/>
</target>
<!-- =================================
target: report
================================= -->
<target name="report" depends="resolve" description="--> generates a report of dependencies">
<ivy:report todir="${build.dir}"/>
</target>
<!-- =================================
target: run
================================= -->
<target name="run" depends="resolve" description="--> compile and run the project">
<mkdir dir="${build.dir}" />
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="lib.path.id" />
<property name="msg" value="hello ivy !"/>
<java classpathref="run.path.id" classname="example.Hello">
<arg value="-message"/>
<arg value="${msg}"/>
</java>
</target>
<!-- =================================
target: clean
================================= -->
<target name="clean" description="--> clean the project">
<delete includeemptydirs="true">
<fileset dir="${basedir}">
<exclude name="src/**" />
<exclude name="build.xml" />
<exclude name="ivy.xml" />
</fileset>
</delete>
</target>
<!-- =================================
target: clean-cache
================================= -->
<target name="clean-cache" description="--> clean the ivy cache">
<ivy:cleancache />
</target>
<!-- target: jar -->
<target name="jar">
<mkdir dir="${build.dir}/jar"/>
<jar destfile="${build.dir}/jar/Hello.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="example.Hello"/>
</manifest>
</jar>
</target>
<!-- target: deploy -->
<target name="deploy" depends="clean,resolve,jar" description="--> deploy artifact to maven repo">
<artifact:pom id="mypom" groupId="org.apache" artifactId="hello-ivy" version="1.0-SNAPSHOT" name="Example Ant/Ivy project.">
<license name="apache" url="http://www.apache.org"/>
</artifact:pom>
<artifact:writepom pomRefId="mypom" file="${build.dir}/pom.xml"/>
<artifact:install file="${build.dir}/jar/hello.jar">
<pom refid="mypom" file="${build.dir}/pom.xml"/>
</artifact:install>
<artifact:install-provider artifactId="wagon-http" version="1.0-beta-2"/>
<artifact:deploy file="${build.dir}/jar/hello.jar">
<remoteRepository id="artifactory" url="http://localhost:8081/artifactory/libs-snapshot-local"/>
<pom refid="mypom" file="${build.dir}/pom.xml"/>
</artifact:deploy>
</target>
<!-- Fetch Ivy -->
<property name="ivy.install.version" value="2.2.0" />
<condition property="ivy.home" value="${env.IVY_HOME}">
<isset property="env.IVY_HOME" />
</condition>
<property name="ivy.home" value="${user.home}/.ant" />
<property name="ivy.jar.dir" value="${ivy.home}/lib" />
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" />
<target name="download-ivy" unless="offline">
<mkdir dir="${ivy.jar.dir}"/>
<!-- download Ivy from web site so that it can be used even without any special installation -->
<get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
dest="${ivy.jar.file}" usetimestamp="true"/>
</target>
<target name="init-ivy" depends="download-ivy">
<!-- try to load ivy here from ivy home, in case the user has not already dropped
it into ant's lib dir (note that the latter copy will always take precedence).
We will not fail as long as local lib dir exists (it may be empty) and
ivy is in at least one of ant's lib dir or the local lib dir. -->
<ivy:settings file="${ivy.settings.dir}/ivysettings.xml" refid="ivy.classpath" />
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<target name="sonar" depends="report" >
<!-- list of mandatories Sonar properties -->
<property name="sonar.sources" value="src" />
<sonar:sonar key="org.apache:hello-ivy" version="1.0-SNAPSHOT" xmlns:sonar="antlib:org.sonar.ant"/>
</target>
</project>