logger/uihandlerserver/build.xml
author jsedek@netbeans.org
Thu, 08 Nov 2007 18:24:10 +0000
changeset 2681 5ec5bb8e8852
parent 2667 b74061950e68
child 2706 6246dd8792e3
permissions -rw-r--r--
skip.upload not to check upload while parsing logs
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <project name="analytics" default="all" basedir=".">
     3     <description>Builds, tests, and runs the project analytics.</description>
     4     
     5     <import file="nbproject/build-impl.xml"/>
     6     
     7     <condition property="nbroot.defined">
     8         <available file="nbproject/private/private.properties"/>
     9     </condition>
    10     <available file="../../nbbuild/build.xml" property="nbroot" value="../.."/>
    11     <property name="nbroot" location="nball"/>
    12     
    13     <target name="-nbroot-define" unless="nbroot.defined">
    14         <mkdir dir="nbproject/private"/>
    15         <echo file="nbproject/private/private.properties" append="true" message="nbroot=${nbroot}${line.separator}"/>
    16     </target>
    17     
    18     
    19     <property name="cvsmodules" value="openide/util nbbuild libs junit/external xtest core/javahelp/external performance logger/uihandlerlib"/>
    20     <condition property="skip.checkout">
    21         <equals arg1="" arg2="${cvsmodules}"/>
    22     </condition> 
    23     
    24     <target name="-post-test-run" if="have.tests" unless="ignore.test.failure" depends="init,compile-test,-pre-test-run,-do-test-run">
    25         <fail if="tests.failed">Some tests failed; see details above.</fail>
    26     </target>
    27     
    28     <target name="checkout" depends="-nbroot-define,init" unless="skip.checkout" description="Check out all CVS modules which are needed to build the server">
    29         <!-- The following mess is an attempt to guess the correct CVSROOT and branch from the current checkout. -->
    30         <loadfile srcfile="CVS/Root" property="cvsroot" failonerror="false" quiet="true">
    31             <filterchain>
    32                 <striplinebreaks/>
    33             </filterchain>
    34         </loadfile>
    35         <property name="cvsroot" value=":pserver:anoncvs@cvs.netbeans.org:/cvs"/>
    36         <loadfile srcfile="CVS/Tag" property="cvstag" failonerror="false" quiet="true">
    37             <filterchain> 
    38                 <tokenfilter delimoutput="">
    39                     <containsregex pattern="^T(.+)" replace="\1"/>
    40                 </tokenfilter>
    41             </filterchain>
    42         </loadfile>
    43         <property name="cvstag" value=""/>
    44         <!-- on my hudson date 2007.04.20.07.52.56 is not seen as valid date for the cvs task
    45       <loadfile srcfile="CVS/Tag" property="cvsdate" failonerror="false">
    46           <filterchain> 
    47               <tokenfilter delimoutput="">
    48                   <containsregex pattern="^D(.+)" replace="\1"/>
    49               </tokenfilter>
    50           </filterchain>
    51       </loadfile>
    52       -->
    53         <property name="cvsdate" value=""/>
    54         <echo>Right now we'll do checkout of necessary modules from CVS</echo>
    55         <echo>To suppress this you can invoke the Ant script with -Dskip.checkout=true</echo>
    56         <cvs 
    57             command="checkout -P -f" compressionlevel="6" cvsroot="${cvsroot}" 
    58             dest="${nbroot}" package="${cvsmodules}" tag="${cvstag}" date="${cvsdate}" 
    59             quiet="true" failonerror="true" 
    60         />
    61     </target>
    62     
    63     <!--
    64 
    65     There exist several targets which are by default empty and which can be 
    66     used for execution of your tasks. These targets are usually executed 
    67     before and after some main targets. They are: 
    68 
    69       -pre-init:                 called before initialization of project properties 
    70       -post-init:                called after initialization of project properties 
    71       -pre-compile:              called before javac compilation 
    72       -post-compile:             called after javac compilation 
    73       -pre-compile-single:       called before javac compilation of single file
    74       -post-compile-single:      called after javac compilation of single file
    75       -pre-compile-test:         called before javac compilation of JUnit tests
    76       -post-compile-test:        called after javac compilation of JUnit tests
    77       -pre-compile-test-single:  called before javac compilation of single JUnit test
    78       -post-compile-test-single: called after javac compilation of single JUunit test
    79       -pre-dist:                 called before jar building 
    80       -post-dist:                called after jar building 
    81       -post-clean:               called after cleaning build products 
    82       -pre-run-deploy:           called before deploying
    83       -post-run-deploy:          called after deploying
    84 
    85     Example of pluging an obfuscator after the compilation could look like 
    86 
    87         <target name="post-compile">
    88             <obfuscate>
    89                 <fileset dir="${build.classes.dir}"/>
    90             </obfuscate>
    91         </target>
    92 
    93     For list of available properties check the imported 
    94     nbproject/build-impl.xml file. 
    95 
    96 
    97     Other way how to customize the build is by overriding existing main targets.
    98     The target of interest are: 
    99 
   100       init-macrodef-javac:    defines macro for javac compilation
   101       init-macrodef-junit:   defines macro for junit execution
   102       init-macrodef-debug:    defines macro for class debugging
   103       do-dist:                jar archive building
   104       run:                    execution of project 
   105       javadoc-build:          javadoc generation 
   106 
   107     Example of overriding the target for project execution could look like 
   108 
   109         <target name="run" depends="<PROJNAME>-impl.jar">
   110             <exec dir="bin" executable="launcher.exe">
   111                 <arg file="${dist.jar}"/>
   112             </exec>
   113         </target>
   114 
   115     Notice that overridden target depends on jar target and not only on 
   116     compile target as regular run target does. Again, for list of available 
   117     properties which you can use check the target you are overriding in 
   118     nbproject/build-impl.xml file. 
   119 
   120     -->
   121     <target name="all" depends="deploy" description="Builds everything, starts the server, runs the tests">
   122         <antcall target="test">
   123             <param name="ignore.test.failure" value="true"/>
   124         </antcall>
   125     </target>
   126     
   127     <target name="dist" depends="build-all"/>
   128     <target name="build-all" depends="-tomcat-properties,checkout">
   129         <!-- bootstrap builds necessary Ant tasks -->
   130         <ant dir="${nbroot}/nbbuild" target="bootstrap" inheritall="false" inheritrefs="false"/>
   131         <!-- make sure openide/util is built -->
   132         <ant dir="${nbroot}/openide/util" inheritall="false" inheritrefs="false"/>
   133         <!-- make sure testing libraries are present -->
   134         <ant dir="${nbroot}/performance/insanelib" inheritall="false" inheritrefs="false"/>
   135         <ant dir="${nbroot}/performance/insanelibmodule" inheritall="false" inheritrefs="false"/>
   136         <ant dir="${nbroot}/xtest/nbjunit" inheritall="false" inheritrefs="false"/>
   137         <!-- make sure we have all our 3rd party libraries -->
   138         <ant dir="../external"/>
   139         <!-- make sure our library is built -->
   140         <subant inheritall="false" inheritrefs="false" target="jar">
   141             <property name="nbroot" location="${nbroot}"/>
   142             <dirset dir="..">
   143                 <include name="ExceptionUtils"/>
   144             </dirset>
   145         </subant>
   146         <subant inheritall="false" inheritrefs="false" target="jar">
   147             <property name="nbroot" location="${nbroot}"/>
   148             <dirset dir="${nbroot}/logger">
   149                 <include name="uihandlerlib"/>
   150             </dirset>
   151         </subant>
   152         <antcall target="analytics-impl.dist">
   153         </antcall>
   154         <subant inheritall="false" inheritrefs="false" target="default">
   155             <property name="nbroot" location="${nbroot}"/>
   156             <dirset dir="..">
   157                 <include name="issueaillarealm"/>
   158                 <include name="StrutsExceptions"/>
   159             </dirset>
   160         </subant>
   161         <copy todir="${tomcat.base}">
   162             <fileset dir="../ExceptionUtils/tomcat_base">
   163                 <include name="**/*"/>
   164                 <exclude name='**/server.xml'/>
   165                 <exclude name='**/logging.properties'/>
   166             </fileset>
   167         </copy>
   168         <copy todir="${tomcat.base}" encoding="utf-8" filtering="true">
   169             <fileset dir="../ExceptionUtils/tomcat_base">
   170                 <include name='**/server.xml'/>
   171                 <include name='**/logging.properties'/>
   172             </fileset>
   173             <filterset>
   174                 <filter token="PORT" value="${tomcat.port}"/>
   175                 <filter token="PERSISTENCE_UNIT" value="${persistence.unit}"/>
   176                 <filter token="LOGGING_LEVEL" value="${logging.level}"/>
   177                 <filter token="SETTINGS_DIR" value="${settings.dir}"/>
   178             </filterset>
   179         </copy>
   180         <copy todir="${tomcat.base}/common/lib">
   181             <fileset dir="../external">
   182                 <include name="*.jar"/>
   183             </fileset>
   184             <fileset dir="../ExceptionUtils/dist">
   185                 <include name="*.jar"/>
   186             </fileset>
   187         </copy>
   188         <copy todir="${tomcat.base}/server/lib">
   189             <fileset dir="../issueaillarealm/dist">
   190                 <include name="*.jar"/>
   191             </fileset>
   192         </copy>
   193         <mkdir dir="${tomcat.base}/logs/"/>
   194     </target>
   195     
   196     <target name="deploy" depends="-tomcat-properties,build-all,run"/>
   197     <target name="debug" depends="deploy">
   198         <antcall target="connect-debugger">
   199             <param name="jpda.address" value="${tomcat.debug.port}"/>
   200             <param name="jpda.host" value="localhost"/>
   201             <param name="name" value="debug-analytics"/>
   202             <param name="jpda.transport" value="dt_socket"/>
   203         </antcall>
   204     </target>
   205     
   206     <target name="run" depends="-tomcat-properties,start-tomcat">
   207         <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"
   208                  classpath="${tomcat.home}/lib/catalina-ant.jar"/>
   209         
   210         <deploy url="${tomcat.url}/manager" username="${tomcat.username}"
   211                 password="${tomcat.password}" path="/exceptions"
   212                 war="${basedir}/../StrutsExceptions/dist/exceptions.war" update="true"/>
   213         
   214         <deploy url="${tomcat.url}/manager" username="${tomcat.username}"
   215                 password="${tomcat.password}" path="/analytics"
   216                 war="${basedir}/dist/analytics.war" update="true"/>
   217         
   218         <antcall target="-define-analytics-dir" inheritall="true"/>
   219         
   220         <antcall target="-test-server" inheritall="true"/>
   221         <antcall target="-test-server-upload" inheritall="true"/>
   222     </target>
   223     
   224     <target name="-define-analytics-dir" if="analytics.dir">
   225         <waitfor maxwait="10" maxwaitunit="second">
   226             <available file="${tomcat.base}/conf/Catalina/localhost/analytics.xml"/>
   227         </waitfor>
   228         <fail message="Analytics must be deployed: ${tomcat.base}/conf/Catalina/localhost/analytics.xml">
   229             <condition>
   230                 <not><available file="${tomcat.base}/conf/Catalina/localhost/analytics.xml"/></not>
   231             </condition>
   232         </fail>
   233         
   234         <sleep seconds="3"/>
   235         <echo message="Using analytics dir: ${analytics.dir}"/>
   236         <property name="define.analytics.dir.before" value=''/>
   237         <replace 
   238             file="${tomcat.base}/conf/Catalina/localhost/analytics.xml" 
   239             token='&lt;/Context&gt;'
   240             value='&lt;Environment name="analytics/dir" value="${analytics.dir}" type="java.lang.String" override="false"/&gt;${line.separator}&lt;/Context&gt;'
   241             summary="true"
   242         />
   243         <echo message="Modified ${tomcat.base}/conf/Catalina/localhost/analytics.xml"/>
   244     </target>
   245     
   246     <target name="-copy-tomcat-base" unless="tomcat.base">
   247         <mkdir dir="build/tomcat_base"/>
   248         <mkdir dir="build/tomcat_base/logs"/>
   249         <property name="tomcat.base" location="build/tomcat_base/"/>
   250     </target>
   251     
   252     <target name="-tomcat-properties" depends="init,-copy-tomcat-base" unless="tomcat.home">
   253         <property name="tomcat.home" location="../external/apache-tomcat-5.5.23/server/"/>
   254         <property name="tomcat.port" value="8888"/>
   255         <property name="tomcat.debug.port" value="8889"/>
   256         <property name="tomcat.debug.suspend" value="n"/>
   257         <property name="tomcat.host" value="localhost"/>
   258         <property name="tomcat.url" value="http://${tomcat.host}:${tomcat.port}"/>
   259         <property name="tomcat.username" value="tomcat"/>
   260         <property name="tomcat.password" value="tomcat"/>
   261         <property name="persistence.unit" value="TestPU"/>
   262         <property name="settings.dir" value="/space/exceptionsReporter"/>
   263         <property name="logging.level" value="INFO"/>
   264     </target>
   265     
   266     <target name="-check-tomcat" depends="-tomcat-properties">
   267         <tstamp> 
   268             <format pattern="yyyyMMddHHmmssSSS" property="stamp"/>
   269         </tstamp>
   270         
   271         <mkdir dir="${tomcat.base}/webapps/ROOT"/>
   272         <echo file="${tomcat.base}/webapps/ROOT/stamp" message="${stamp}" append="false"/>
   273         
   274         <loadresource property="serverstamp" failonerror="false" quiet="true">
   275             <url url="${tomcat.url}/stamp"/>
   276         </loadresource>
   277         <condition property="tomcat.running">
   278             <equals arg1="${stamp}" arg2="${serverstamp}"/>
   279         </condition>
   280         
   281         <fail message="Port ${tomcat.port} is already in use">
   282             <condition>
   283                 <and>
   284                     <not>
   285                         <istrue value="${tomcat.running}"/>
   286                     </not>
   287                     <socket server="${tomcat.host}" port="${tomcat.port}"/>
   288                 </and>
   289             </condition>
   290         </fail>
   291         <mkdir dir="../ExceptionUtils/tomcat_base/logs"/>
   292     </target>
   293     
   294     <target name="start-tomcat" depends="-check-tomcat" unless="tomcat.running">
   295         <echo message="Starting Tomcat..."/>
   296         <property name="tomcat.root" location="${tomcat.home}/.."/>
   297         <property name="tomcat.opts" value=""/>
   298         
   299         <mkdir dir="${tomcat.base}/temp"/>
   300         <exec os="Windows NT Windows 95 Windows 98 Windows 2000 Windows 2003 Windows XP" 
   301               executable="${tomcat.root}/bin/catalina.bat" dir="${tomcat.root}/bin/"
   302               spawn="true"
   303         >
   304             <arg value="jpda"/>
   305             <arg value="start"/>
   306             
   307             <env key="java.awt.headless" value="true"/>
   308             <env key="CATALINA_HOME" value="${tomcat.root}"/>
   309             <env key="CATALINA_BASE" value="${tomcat.base}"/>
   310             <env key="JAVA_HOME" value="${java.home}"/>
   311             <env key="JAVA_OPTS" value="${tomcat.opts}"/>
   312             <env key="JPDA_ADDRESS" value="${tomcat.debug.port}"/>
   313             <env key="JPDA_SUSPEND"  value="${tomcat.debug.suspend}"/>
   314         </exec>
   315         <exec os="Linux SunOS Solaris Mac OS X"
   316               executable="/bin/sh" dir="${tomcat.root}/bin/"
   317         >
   318             <!--<arg value="-x"/>-->
   319             <arg value="${tomcat.root}/bin/catalina.sh"/>
   320             <arg value="jpda"/>
   321             <arg value="start"/>
   322             
   323             <env key="DISPLAY" value=""/>
   324             <env key="CATALINA_HOME" value="${tomcat.root}"/>
   325             <env key="CATALINA_BASE" value="${tomcat.base}"/>
   326             <env key="JAVA_HOME" value="${java.home}"/>
   327             <env key="JAVA_OPTS" value="${tomcat.opts}"/>
   328             <env key="JPDA_ADDRESS" value="${tomcat.debug.port}"/>
   329             <env key="JPDA_SUSPEND"  value="${tomcat.debug.suspend}"/>
   330         </exec>
   331         <waitfor maxwait="30" maxwaitunit="second" checkevery="5" checkeveryunit="second">
   332             <http url="${tomcat.url}"/>
   333         </waitfor>
   334         
   335         <loadresource property="serverstamp1" failonerror="false" quiet="true">
   336             <url url="${tomcat.url}/stamp"/>
   337         </loadresource>
   338         
   339         <fail message="Tomcat is not started at ${tomcat.url}">
   340             <condition>
   341                 <not>
   342                     <equals arg1="${stamp}" arg2="${serverstamp1}"/>
   343                 </not>
   344             </condition>
   345         </fail>
   346     </target>
   347     
   348     <target name="stop-tomcat" depends="-check-tomcat"  if="tomcat.running">
   349         
   350         <echo message="Stopping Tomcat..."/>
   351         
   352         <property name="tomcat.root" location="${tomcat.home}/.."/>
   353         
   354         <exec os="Windows NT Windows 95 Windows 98 Windows 2000 Windows 2003 Windows XP" 
   355               executable="${tomcat.root}/bin/catalina.bat" dir="${tomcat.root}/bin/"
   356         >
   357             <arg value="stop"/>
   358             
   359             <env key="CATALINA_HOME" value="${tomcat.root}"/>
   360             <env key="CATALINA_BASE" value="${tomcat.base}"/>
   361             <env key="JAVA_HOME" value="${java.home}"/>
   362         </exec>
   363         <exec os="Linux SunOS Solaris Mac OS X"
   364               executable="${tomcat.root}/bin/catalina.sh" dir="${tomcat.root}/bin/"
   365         >
   366             <arg value="stop"/>
   367             
   368             <env key="DISPLAY" value=""/>
   369             <env key="CATALINA_HOME" value="${tomcat.root}"/>
   370             <env key="CATALINA_BASE" value="${tomcat.base}"/>
   371             <env key="JAVA_HOME" value="${java.home}"/>
   372         </exec>
   373         <waitfor maxwait="30" maxwaitunit="second" checkevery="5">
   374             <not>
   375                 <http url="${tomcat.url}"/>
   376             </not>
   377         </waitfor>
   378         
   379     </target>
   380     
   381     <target name="-pre-run-deploy" depends="start-tomcat">
   382         <!-- get the server if not available -->
   383         <!-- place libraries into correct place -->
   384         <!-- maybe: choose some random port -->
   385         <fail message="We need tomcat to run! Specify its location using -Dtomcat.home, or just execute 'ant all' it should download it automatically.">
   386             <condition>
   387                 <not>
   388                     <available file="${tomcat.home}/lib/catalina-ant.jar"/>  
   389                 </not>
   390             </condition> 
   391         </fail>
   392     </target>
   393     <target name="-post-run-deploy">
   394         <!-- configuration changes? -->
   395     </target>
   396     
   397     <target name="run-server" depends="run" if="url.file">
   398         <fail unless="tomcat.url" message="tomcat.url property has to be filled now after starting tomcat"/>
   399         <echo message="${tomcat.url}" file="${url.file}"/>
   400     </target>
   401     
   402     <target name="-test-server">
   403         <tempfile destdir="build" deleteonexit="true" property="index.file"/>
   404         <get src="${tomcat.url}/analytics/index.jsp" dest="${index.file}"/>
   405         <loadfile srcfile="${index.file}" property="${index.content}"/>
   406         <fail message="Valid page must be returned">
   407             <condition>
   408                 <and>
   409                     <contains string="${index.content}" substring="NetBeans Analytics Community"/>
   410                     <contains string="${index.content}" substring="uploaded logs on the server right now"/>
   411                 </and>
   412             </condition>
   413         </fail>
   414     </target>
   415     
   416     <target name="-test-server-upload" unless="skip.upload">
   417         <tempfile deleteonexit="true" property="upload.file"/>
   418         <get src="${tomcat.url}/analytics/upload.jsp" dest="${upload.file}"/>
   419         <loadfile srcfile="${upload.file}" property="${upload.content}"/>
   420         <fail message="upload.jsp file should be accessible">
   421             <condition>
   422                 <and>
   423                     <contains string="${upload.content}" substring="Upload of NetBeans Analytics Logs Finished"/>
   424                 </and>
   425             </condition>
   426         </fail>
   427     </target>
   428 
   429     <target description="Stops the server and clean build products." name="clean" depends="stop-tomcat,analytics-impl.clean"/>
   430     
   431     <target name="javadoc-build"/>
   432 </project>