Java/Ant/Task

Материал из Java эксперт
Версия от 06:37, 1 июня 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Define task with taskdef

 
//https://amateur.dev.java.net/
//GNU General Public License (GPL v. 2.0)
<?xml version="1.0" encoding="UTF-8"?>
<project name="Amateur" default="compile" basedir=".">
    
    <!-- ???? need a help target -->
    
    <property name="JUNIT_HOME" value="/Applications/eclipse/plugins/org.junit_3.8.1"/>
    <property name="QTJava" value="/System/Library/Java/Extensions/QTJava.zip"/>
    <taskdef name="jarbundler"
             classpath="lib/jarbundler-1.8.1.jar"
             classname="net.sourceforge.jarbundler.JarBundler" /> 
    
    <path id="project.classpath">
        <pathelement location="bin"/>
        <pathelement location="${QTJava}"/>
    </path>
    
    <path id="test.classpath">
        <path refid="project.classpath"/>
        <pathelement location="${JUNIT_HOME}/junit.jar"/>
    </path>
    
    <target name="init">
        <tstamp/>
        <property name="Name"    value="Amateur"/>
        <property name="name"    value="amateur"/>
        <property name="version" value="1.0d6"/>
        <property name="year"    value="2006"/>
        <mkdir dir="bin"/>
        <mkdir dir="dist"/>
    </target>
    
    <target name="clean">
        <delete dir="bin"/>
        <delete dir="dist"/>
    </target>
    
    <target name="compile" depends="init">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac destdir="bin">
            <src path="src"/>
            <classpath refid="project.classpath"/>
        </javac>
    </target>
    
    <target name="test">
        <junit fork="yes" printsummary="withOutAndErr">
            <formatter type="plain"/>
            <test name="com.elharo.quicktime.tests.AmateurTests"/>
            <classpath refid="test.classpath"/>
        </junit>
    </target>
    
    <target name="run">
        <java fork="yes" classname="com.elharo.quicktime.Main" failonerror="true">
            <classpath refid="project.classpath"/>
        </java>
    </target>
    
    <target name="jar" depends="compile">
       <jar jarfile="dist/${name}-${version}.jar"
             basedir="bin"
             index="no"
             compress="yes"
             includes="com/elharo/quicktime/*"
             excludes="com/elharo/quicktime/tests/* com/elharo/quicktime/pantry/*">
          <manifest>
            <attribute name="Built-By" value="${user.name}"/>
            <attribute name="Specification-Title"    value="Amateur"/>
            <attribute name="Specification-Version"  value="${version}"/>
            <attribute name="Specification-Vendor"   value="Elliotte Rusty Harold"/>
            <attribute name="Implementation-Title"   value="Amateur"/>
            <attribute name="Implementation-Version" value="${version}"/>
            <attribute name="Implementation-Vendor"  value="Elliotte Rusty Harold"/>          
            <attribute name="Main-Class" value="com.elharo.quicktime.Main"/>
            <section name="com/elharo/quicktime/">
              <attribute name="Sealed" value="true"/>
              <attribute name="Specification-Title"   value="Amateur core classes"/>
              <attribute name="Implementation-Title"  value="com.elharo.quicktime"/>
            <attribute name="Implementation-Version" value="${version}"/>
            <attribute name="Implementation-Vendor"  value="Elliotte Rusty Harold"/>          
           </section>
          </manifest>
        </jar>        
    </target>
    
    <target name="app" depends="jar">
      <delete dir="dist/Amateur.app"/>
        <jarbundler dir="dist" jars="dist/${name}-${version}.jar" 
                    name="Amateur" 
                    mainclass="com.elharo.quicktime.Main" 
                    infostring=" ${version}"
                    version=" ${version}"
                    screenmenu="true"
                    signature="QTAM"
                    bundleid="com.elharo.quicktime"
                    icon="Amateur.icns"
        >
          <documenttype name="Amateur Media"
                    mimetypes="image/jpeg image/png image/gif video/mpeg video/quicktime audio/mpeg" 
                    role="Viewer"/>
          <documenttype name="Amateur Media"
                    extensions="jpg mov mpg mp3 gif png pdf" 
                    role="Viewer"/>
        </jarbundler>
    </target>
    
    <target name="image" depends="app">
      <exec executable="hdiutil" os="Mac OS X">
          <arg value="create"/>
          <arg value="-srcfolder"/>
          <arg value="dist/${Name}.app"/>
          <arg value="-ov"/>
          <arg value="dist/${Name}-${version}.dmg"/>
      </exec>
    </target>

    <taskdef classpath="lib/cobertura.jar" resource="tasks.properties" />
    
    <target name="instrument">
      <cobertura-instrument todir="bin/instrumented-classes">
        <fileset dir="bin/classes">
          <include name="**/*.class"/>
        </fileset>
      </cobertura-instrument>
    </target>
    
    <target name="cover-test" depends="instrument">
      <mkdir dir="${testreportdir}" />
      <junit dir="./" failureproperty="test.failure" printSummary="yes" 
             fork="true" haltonerror="true">
        <!-- Normally you can create this task by copying your existing JUnit
             target, changing its name, and adding these next two lines.
             You may need to change the locations to point to wherever 
             you"ve put the cobertura.jar file and the instrumented classes. -->
        <classpath location="lib/cobertura.jar"/>
        <classpath location="bin/instrumented-classes"/>
        <classpath>
          <fileset dir="${libdir}">
            <include name="*.jar" />
          </fileset>
          <pathelement path="${testclassesdir}" />
          <pathelement path="${classesdir}" />
        </classpath>
        <batchtest todir="${testreportdir}">
          <fileset dir="src">
            <include name="**/*Test.java" />
          </fileset>
        </batchtest>
      </junit>
    </target>
    
</project>





Task depends

 
<?xml version="1.0"?>
<project name="Template Buildfile" default="compile" basedir=".">
  <property name="dir.src" value="src"/>
  <property name="dir.build" value="build"/>
  <property name="dir.dist" value="dist"/>
  <!-- Creates the output directories -->
  <target name="prepare">
    <mkdir dir="${dir.build}"/>
    <mkdir dir="${dir.dist}"/>
  </target>
  <target name="clean"
          description="Remove all generated files.">
    <delete dir="${dir.build}"/>
    <delete dir="${dir.dist}"/>
  </target>
  <target name="compile" depends="prepare"
          description="Compile all source code.">
    <javac srcdir="${dir.src}" destdir="${dir.build}"/>
  </target>
  <target name="jar" depends="compile"
          description="Generates jexp.jar in the "dist" directory.">
    <jar jarfile="${dir.dist}/jexp.jar" 
         basedir="${dir.build}"/>
  </target>
</project>