ANT skript

FIXME Work in progress.

Známá chyba - nefunguje spouštění z JAR :/

build.xml

<project name="project" default="compile" basedir=".">
  <description>1. domaci ukol z PJV</description>
  <property name="main-class" value="main.Main" />
 
  <property name="src" location="src" />
  <property name="build" location="build" />
  <property name="test-src" location="test" />
  <property name="test-build" location="test-build" />
  <property name="lib" location="lib" />
  <property name="dist" location="dist" />
 
  <path id="app-classes" location="${build}"/>
  <path id="test-classes" location="${test-build}"/>
  <path id="junit-jar" path="${lib}/junit.jar;${ant.library.dir}/junit.jar"/>
  <path id="libraries">
      <fileset dir="lib">
        <include name="**/*.jar"/>
      </fileset>
  </path>
 
  <available file="${lib}/junit.jar" property="junit.present"/>
  <available file="${ant.library.dir}/junit.jar" property="junit.present"/>
 
  <target name="init">
    <mkdir dir="${build}"/>
    <mkdir dir="${test-build}"/>
    <mkdir dir="${lib}"/>
  </target>
 
  <target name="clean" description="vymaze zkompilovane soubory" >
    <delete dir="${build}" quiet="true"/>
    <delete dir="${test-build}" quiet="true"/>
    <delete dir="${dist}" quiet="true"/>
  </target>
 
  <target name="compile" depends="init" description="zkompiluje aplikaci" >
    <javac srcdir="${src}" destdir="${build}" includeAntRuntime="false">
      <classpath>
         <path refid="libraries"/>
      </classpath>
    </javac>
  </target>
 
  <target name="compile-tests" depends="init">
    <fail message="Ocekavam    (www.junit.org) v CLASSPATH, nebo v ${lib}, pripadne v ${ant.library.dir}" unless="junit.present"/>
    <javac srcdir="${test-src}" destdir="${test-build}" 
           includeAntRuntime="false">
      <classpath>
        <path refid="app-classes" />
        <path refid="junit-jar" />
      </classpath>
    </javac>
  </target>
 
  <target name="dist" depends="compile" 
          description="Vytvori JAR se zkompilovanou aplikaci" >
    <mkdir dir="${dist}"/>
    <jar jarfile="${dist}/${ant.project.name}.jar" basedir="${build}">
      <manifest>
        <attribute name="Main-Class" value="${main-class}"/>
      </manifest>
    </jar>
  </target>
 
  <target name="run" depends="compile"
          description="Spusti program ze zkompilovanych souboru">
    <java classname="${main-class}" fork="true">
      <classpath>
        <path refid="app-classes"/>
        <path refid="libraries"/>
      </classpath>
    </java>
  </target>
 
  <target name="runjar" depends="dist" 
          description="Spusti program z JAR souboru">
    <java jar="${dist}/${ant.project.name}.jar" fork="true"/>
  </target>
 
  <target name="test" depends="compile,compile-tests" 
    description="Spusti unit-testy">
 
    <junit printsummary="yes" showoutput="yes">
      <classpath>
        <path refid="junit-jar" />
        <path refid="app-classes" />
        <path refid="test-classes" />
      </classpath>
      <batchtest fork="yes">
        <fileset dir="${test-src}" includes="*/*.java"/>
      </batchtest>
    </junit>
  </target>
</project>