huw 2003/02/18 22:46:13 Modified: . build.xml Added: . check-targets.properties ant.properties.sample check-targets.ent Log: 1) standardizes on the check-targets include structure for handling dependencies 2) 3rd party jars can be specified in the ant.properties file 3) warning message tells user to download dependant jars or setup ant.properties file. Revision Changes Path 1.95 +44 -120 avalon-logkit/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/avalon-logkit/build.xml,v retrieving revision 1.94 retrieving revision 1.95 diff -u -r1.94 -r1.95 --- build.xml 9 Feb 2003 23:33:20 -0000 1.94 +++ build.xml 19 Feb 2003 06:46:13 -0000 1.95 @@ -1,4 +1,8 @@ <?xml version="1.0"?> + <!DOCTYPE project [ + <!ENTITY check-targets SYSTEM "file:check-targets.ent"> + ]> + <!-- ============================================================================== @@ -71,9 +75,7 @@ <property name="src.dist.dir" value="src-dist"/> <property name="tools.jar" value="${java.home}/../lib/tools.jar"/> - <property name="junit.jar" value="${tools.dir}/lib/junit-3.7.jar"/> <property name="j2ee.jar" value="${cjan.dir}/j2ee.jar"/> - <property name="jdbc.driver.jar" value=""/> <property name="dist.name" value="${Name}-${version}"/> <property name="dist.base" value="distributions"/> @@ -83,17 +85,23 @@ <property name="announce2readme" value="${tools.dir}/announcement2readme.xsl"/> <property name="announce2site" value="${tools.dir}/announcement2site.xsl"/> - <property name="servlet.jar" value="${lib.dir}/servlet.jar"/> - <property name="mail.jar" value="${lib.dir}/mail.jar"/> + <property name="servletapi.jar" value=""/> + <property name="mail.jar" value=""/> + <property name="jms.jar" value=""/> + <property name="junit.jar" value=""/> + <property name="jdbc.jar" value=""/> + <property name="log4j.jar" value=""/> + <property name="avalon-site.dir" value="../avalon-site"/> <path id="project.class.path"> <pathelement path="${java.class.path}" /> - <pathelement location="${junit.jar}"/> - <pathelement path="${servlet.jar}" /> + <pathelement path="${servletapi.jar}" /> <pathelement path="${mail.jar}"/> <pathelement path="${j2ee.jar}" /> - <pathelement path="${jdbc.driver.jar}" /> + <pathelement path="${jdbc.jar}" /> + <pathelement path="${jms.jar}" /> + <pathelement path="${log4j.jar}" /> <fileset dir="${lib.dir}"> <include name="*.jar" /> </fileset> @@ -109,6 +117,8 @@ <path refid="project.class.path"/> </path> + &check-targets; + <!-- Main target --> <target name="main" depends="jar" description="Build complete"/> @@ -127,6 +137,8 @@ <echo message=" jar -> generates the ${Name} jar file"/> <echo message=" javadocs -> generates the API documentation (java 1.2+ only)"/> <echo message=" real-clean -> cleans up all genereated files and directories"/> + <echo message=" import-all-auto-dependencies -> "/> + <echo message=" downloads all automatically downloadable jars"/> <echo message=""/> <echo message="-------------------------------------------------------------"/> <echo message=""/> @@ -139,35 +151,7 @@ </target> - <target name="import-servlet-jar" description="Imports the servlet API if required"> - - <mkdir dir="tmp-imports"/> - - <property name="jar-version" value="3.2.3"/> - - <get src="http://jakarta.apache.org/builds/jakarta-tomcat/release/v${jar-version}/bin/jakarta-servletapi-${jar-version}.zip" - dest="tmp-imports/jakarta-servletapi-${jar-version}.zip" - verbose="true" - usetimestamp="true"/> - - <unzip src="tmp-imports/jakarta-servletapi-${jar-version}.zip" dest="tmp-imports" /> - - <copy file="tmp-imports/jakarta-servletapi-${jar-version}/lib/servlet.jar" todir="${lib.dir}"/> - - <delete dir="tmp-imports" /> - - </target> - - <target name="import-log4j-jar" description="Imports the Log4J API if required"> - - <get src="http://www.ibiblio.org/maven/log4j/jars/log4j-1.2.7.jar" - dest="${lib.dir}/log4j-1.2.7.jar" - verbose="true" - usetimestamp="true"/> - - </target> - - <target name="import-avalon-site" description="Imports the avalon-site" depends="import-log4j-jar"> + <target name="import-avalon-site" description="Imports the avalon-site" depends="import-log4j"> <!-- these are really old releases. Need to verify we can get the latest of everything and just download that! --> <mkdir dir="${avalon-site.dir}"/> @@ -208,86 +192,12 @@ </target> - - <target name="optional-tests" description="Tests for classes missing to the environment"> - - <available property="servlet.present" - classname="javax.servlet.ServletContext" - classpathref="project.class.path" /> - - <available property="javax.sql.present" - classname="javax.sql.DataSource" - classpathref="project.class.path" /> - - <available property="javax.jms.present" - classname="javax.jms.TopicConnection" - classpathref="project.class.path" /> - - <available property="javax.mail.present" - classname="javax.mail.Message" - classpathref="project.class.path" /> - - <available property="log4j.present" - classname="org.apache.log4j.Appender" - classpathref="project.class.path" /> - + <target name="optional-tests" + depends="check-all-dependencies" + description="Tests for classes missing to the environment"> <available property="avalon-site.present" file="${avalon-site.dir}/lib/velocity-1.4-dev.jar" type="file" /> - - </target> - - <target name="op-warning"> - <echo>******************7****************************</echo> - <echo>*</echo> - <echo>* Classes needed for output via ${thing} are not </echo> - <echo>* available. Logkit should build without them</echo> - <echo>*</echo> - <echo>* Recovery:</echo> - <echo>* ${recovery}</echo> - <echo>*</echo> - <echo>***********************************************</echo> - <echo/> - </target> - - <target name="servlet-warn" unless="servlet.present"> - <antcall target="op-warning"> - <param name="thing" value="Servlet"/> - <param name="recovery" - value="Run the build target import-servlet-jar and it will download the servlet api jar - you should be online for that."/> - </antcall> - </target> - - <target name="mail-warn" unless="javax.mail.present"> - <antcall target="op-warning"> - <param name="thing" value="SMTP"/> - <param name="recovery" - value="Get mail.jar from inside javamail-1_2.zip from http://java.sun.com/products/javamail/ and place it in the lib dir"/> - </antcall> - </target> - - <target name="jms-warn" unless="javax.jms.present"> - <antcall target="op-warning"> - <param name="thing" value="JMS"/> - <param name="recovery" - value="Get jms.jar from inside jms-1_0_2b.zip from http://java.sun.com/products/jms/docs.html and place it in the lib dir"/> - </antcall> - </target> - - <target name="sql-warn" unless="javax.sql.present"> - <antcall target="op-warning"> - <param name="thing" value="SQL databases"/> - <param name="recovery" - value="Get jdbc2_0-stdext.jar (listed as 'JDBC 2.0 Optional Package Binary') from http://java.sun.com/products/jdbc/download.html and place it in the lib dir"/> - </antcall> - </target> - - <target name="log4j-warn" unless="log4j.present"> - <antcall target="op-warning"> - <param name="thing" value="Log4J"/> - <param name="recovery" - value="Run the build target import-log4j-jar and it will download the Log4J api jar - you should be online for that."/> - </antcall> </target> <target name="avalon-site-warn" unless="avalon-site.present"> @@ -314,14 +224,18 @@ <mkdir dir="${avalon-site.dir}/lib"/> </target> - <target name="optional-warnings" depends="jms-warn,sql-warn,servlet-warn,mail-warn,log4j-warn,avalon-site-warn"> - </target> - - <!-- Prepares the build directory --> - <target name="compile" depends="optional-tests, optional-warnings" description="Compile project"> + <!-- Prepares the build directory --> + <target name="prepare" depends="optional-tests, avalon-site-warn"> + <tstamp/> <mkdir dir="${build.dir}"/> <mkdir dir="${build.classes}"/> - + </target> + + <!-- Prepares the build directory --> + <target name="compile" + depends="setup-properties,setup-dependencies,prepare" + description="Compile project"> + <javac srcdir="${java.dir}" destdir="${build.classes}" @@ -336,7 +250,7 @@ <src path="${test.dir}"/> <src path="${compat.dir}"/> <exclude name="org/apache/log/output/ServletOutputLogTarget.java" - unless="servlet.present"/> + unless="javax.servlet.present"/> <exclude name="org/apache/log/output/net/SMTPOutputLogTarget.java" unless="javax.mail.present"/> <exclude name="org/apache/log/output/db/**" @@ -347,6 +261,16 @@ unless="javax.sql.present"/> <exclude name="org/apache/log/output/lf5/**" unless="log4j.present"/> + + <!-- leave out test cases if junit not installed --> + <exclude name="org/apache/log/util/test/**" + unless="junit.present"/> + <exclude name="org/apache/log/test/**" + unless="junit.present"/> + <exclude name="org/apache/log/output/test/**" + unless="junit.present"/> + <exclude name="org/apache/log/format/test/**" + unless="junit.present"/> </javac> <copy todir="${build.classes}"> 1.1 avalon-logkit/check-targets.properties Index: check-targets.properties =================================================================== # sets up properties for the dependency download mechanism jar.repository=http://www.ibiblio.org/maven asl.license=Apache Software License asl.license.url=http://www.opensource.org/licenses/apachepl.php cpl.license=Common Public License cpl.license.url=http://www.opensource.org/licenses/cpl.php sbcl.license=Sun Binary Code License # JavaMail javamail.version=1.2 javamail.id=javamail javamail.license=${sbcl.license} javamail.license.url=http://java.sun.com/products/javamail/ javamail.dist.url=http://java.sun.com/products/javamail/ # JDBC jdbc.version=2.0 jdbc.id=jdbc jdbc.license=${sbcl.license} jdbc.license.url=http://java.sun.com/products/jdbc/ jdbc.dist.url=http://java.sun.com/products/jdbc/ # JMS jms.version=1.0.2 jms.id=jms jms.license=${sbcl.license} jms.license.url=http://java.sun.com/products/jms/ jms.dist.url=http://java.sun.com/products/jms/ # JUnit junit.version=3.7 junit.id=junit junit.license=${cpl.license} junit.license.url=${cpl.license.url} junit.dist.url=http://www.junit.org/ # Log4J log4j.version=1.2.7 log4j.id=log4j log4j.license=${asl.license} log4j.license.url=${asl.license.url} log4j.dist.url=http://jakarta.apache.org/log4j/ # Servlet API servletapi.version=2.3 servletapi.id=servletapi servletapi.license=${sbcl.license} servletapi.license.url=http://java.sun.com/products/servlet/download.html servletapi.dist.url=http://java.sun.com/products/servlet/download.html 1.1 avalon-logkit/ant.properties.sample Index: ant.properties.sample =================================================================== # This file is a sample ant.properties file used for building Avalon-LogKit. It # allows variables defined in build.xml to be overridden according to users' # specific needs. # # One thing it may be useful for is to specify the location of 3rd party jars # instead of downloading them to the /lib directory. To do so uncomment and then modify # the lines below. # # Don't forget to rename this file to ant.properties or [user_home]/.ant.properties. # # <-- starts a comment # servletapi.jar= # mail.jar= # jms.jar= # junit.jar= # jdbc.jar= # log4j.jar= 1.1 avalon-logkit/check-targets.ent Index: check-targets.ent =================================================================== <!-- This build.xml snippet contains targets for ant 1.5 that check whether a specific libary is present, and offers targets for downloading them if they're not. It's kinda of a replacement for some maven functionality until maven becomes stable. Usage: 1) Copy this file to somewhere in your project. 2) Add the following to the top of your project's Ant build.xml script (adjusting the path): <!DOCTYPE project [ <!ENTITY check-targets SYSTEM "file:./check-targets.ent"> ]> 3) Before the closing '</project>' in your build.xml, add this: &check-targets; 4) define the properties - lib.dir - project.class.path - Name This is like expanding a macro: it pulls in the contents of this file. A minimal build.xml would thus be: <!DOCTYPE project [ <!ENTITY check-targets SYSTEM "file:./check-targets.ent"> ]> <project default="check-all-dependencies"> <property name="Name" value="My Project"/> <property name="lib.dir" value="lib"/> <path id="project.class.path"> <fileset dir="${lib.dir}"> <include name="*.jar" /> </fileset> </path> &check-targets; </project> --> <!-- Set up properties --> <property file="check-targets.properties"/> <target name="setup-dependencies"> <available property="javax.jms.present" classname="javax.jms.TopicConnection" classpathref="project.class.path" /> <available property="javax.mail.present" classname="javax.mail.Message" classpathref="project.class.path" /> <available property="javax.sql.present" classname="javax.sql.DataSource" classpathref="project.class.path" /> <available property="junit.present" classname="junit.framework.Test" classpathref="project.class.path" /> <available property="log4j.present" classname="org.apache.log4j.Level" classpathref="project.class.path" /> <available property="javax.servlet.present" classname="javax.servlet.ServletContext" classpathref="project.class.path" /> </target> <!-- called if a dependency is missing which has a BSD or ASL or similar license for which autodownload is okay. --> <target name="missing-dependency"> <echo> ************************************************************************* Classes needed for compiling ${Name} against the ${id} API are not available. The build may fail or some functionality may not be available. Recovery: Run the build target import-${id} and it will download the needed jar - you should be online for that. - OR - Set the ${id}.jar property in the ant.properties file to the full path of the jar. If you have a fast connection you can also just run the build target import-all-auto-dependencies, which will download all external jars this buildfile knows about. Note this may download unused jars as well. ************************************************************************* </echo> <echo/> </target> <!-- called if a dependency is missing which we cannot autodownload due to licensing--> <target name="missing-dependency-noauto"> <echo> ************************************************************************* Classes needed for compiling ${Name} against the ${id} API are not available. The build may fail or some functionality may not be available. Recovery: Get the ${id} jar from the ${id} distribution at ${dist.url} and place it in ${lib.dir}. - OR - Set the ${id}.jar property in the ant.properties file to the full path of the jar. Please note that ${id} is licensed under the ${license} and that by downloading it you are agreeing to that license. You can read this license at ${license.url} ************************************************************************* </echo> <echo/> </target> <!-- this target fetches a file from a maven repository --> <target name="import-dependency"> <get src="${license.url}" dest="${lib.dir}/${id}.LICENSE.html" usetimestamp="true"/> <loadfile property="license.text" srcFile="${lib.dir}/${id}.LICENSE.html"/> <echo> ************************************************************************* You have requested to download the ${id} jar, which is licensed under the ${license}. A copy of this license has been saved to ${lib.dir}/${id}.LICENSE.html Please view it now. ************************************************************************* </echo> <input message="Do you agree to the terms of this license?" validargs="y,n" addproperty="do.download"/> <condition property="do.abort"> <equals arg1="n" arg2="${do.download}"/> </condition> <fail if="do.abort">Download aborted.</fail> <get src="${jar.repository}/${id}/jars/${jar.id}-${version}.jar" dest="${lib.dir}/${id}-${version}.jar" verbose="true" usetimestamp="true"/> </target> <target name="check-all-dependencies" depends="javamail-check,jdbc-check,jms-check,junit-check,log4j-check" description="checks for all dependencies we know about. This is usually more than the minimum needed to build this project; actual use is not recommended." /> <target name="import-all-auto-dependencies" depends="import-junit,import-log4j" description="checks for all dependencies we know about. This is usually more than the minimum needed to build this project; actual use is not recommended." /> <!-- JavaMail --> <target name="javamail-check" unless="javax.mail.present" depends="setup-dependencies"> <antcall target="missing-dependency-noauto"> <param name="id" value="${javamail.id}"/> <param name="jar.id" value="${javamail.id}"/> <param name="version" value="${javamail.version}"/> <param name="license" value="${javamail.license}"/> <param name="license.url" value="${javamail.license.url}"/> <param name="dist.url" value="${javamail.dist.url}"/> </antcall> </target> <!-- JDBC --> <target name="jdbc-check" unless="javax.sql.present" depends="setup-dependencies"> <antcall target="missing-dependency-noauto"> <param name="id" value="${jdbc.id}"/> <param name="jar.id" value="${jdbc.id}"/> <param name="version" value="${jl.version}"/> <param name="license" value="${jdbc.license}"/> <param name="license.url" value="${jdbc.license.url}"/> <param name="dist.url" value="${jdbc.dist.url}"/> </antcall> </target> <!-- JMS --> <target name="jms-check" unless="javax.jms.present" depends="setup-dependencies"> <antcall target="missing-dependency-noauto"> <param name="id" value="${jms.id}"/> <param name="jar.id" value="${jms.id}"/> <param name="version" value="${jms.version}"/> <param name="license" value="${jms.license}"/> <param name="license.url" value="${jms.license.url}"/> <param name="dist.url" value="${jms.dist.url}"/> </antcall> </target> <!-- JUnit --> <target name="junit-check" unless="junit.present" depends="setup-dependencies"> <antcall target="missing-dependency"> <param name="id" value="${junit.id}"/> <param name="jar.id" value="${junit.id}"/> <param name="version" value="${junit.version}"/> <param name="license" value="${junit.license}"/> <param name="license.url" value="${junit.license.url}"/> </antcall> </target> <target name="import-junit" depends="setup-dependencies"> <antcall target="import-dependency"> <param name="id" value="${junit.id}"/> <param name="jar.id" value="${junit.id}"/> <param name="version" value="${junit.version}"/> <param name="license" value="${junit.license}"/> <param name="license.url" value="${junit.license.url}"/> </antcall> </target> <!-- Log4J --> <target name="log4j-check" unless="log4j.present" depends="setup-dependencies"> <antcall target="missing-dependency"> <param name="id" value="${log4j.id}"/> <param name="jar.id" value="${log4j.id}"/> <param name="version" value="${log4j.version}"/> <param name="license" value="${log4j.license}"/> <param name="license.url" value="${log4j.license.url}"/> </antcall> </target> <target name="import-log4j" depends="setup-dependencies"> <antcall target="import-dependency"> <param name="id" value="${log4j.id}"/> <param name="jar.id" value="${log4j.id}"/> <param name="version" value="${log4j.version}"/> <param name="license" value="${log4j.license}"/> <param name="license.url" value="${log4j.license.url}"/> </antcall> </target> <!-- Servlet API --> <target name="servletapi-check" unless="javax.servlet.present" depends="setup-dependencies"> <antcall target="missing-dependency-noauto"> <param name="id" value="${servletapi.id}"/> <param name="jar.id" value="${servletapi.id}"/> <param name="version" value="${servletapi.version}"/> <param name="license" value="${servletapi.license}"/> <param name="license.url" value="${servletapi.license.url}"/> <param name="dist.url" value="${servletapi.dist.url}"/> </antcall> </target>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]