Changeset 35791 for other-projects


Ignore:
Timestamp:
2021-12-10T11:14:03+13:00 (2 years ago)
Author:
cstephen
Message:

Add updated macroniser code. This is a significant change to the codebase:

  • Servlets now send JSON responses that are easier to consume from other services.
  • Error responses are better conveyed and more infomative.
  • Monogram components have been touched up. They now bubble errors up and, where applicable, implement relevant interfaces.
  • The JSP interface has been removed
  • The SQL logging functionality has been deleted. It wasn't used before.
  • Dependencies updated.
Location:
other-projects/the-macronizer/trunk
Files:
82 added
3 edited

Legend:

Unmodified
Added
Removed
  • other-projects/the-macronizer/trunk

    • Property svn:ignore set to
      build
  • other-projects/the-macronizer/trunk/.vscode/settings.json

    r35719 r35791  
    11{
    22    "java.project.referencedLibraries": [
    3         "src/jars/*.jar",
    4         "web/WEB-INF/lib/*.jar"
     3        "lib/**/*.jar"
    54    ]
    65}
  • other-projects/the-macronizer/trunk/build.xml

    r33865 r35791  
    1 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    2 <project basedir="." default="war" name="TheMacronizer">
     1<?xml version="1.0" encoding="UTF-8"?>
    32
    4   <property environment="env"/>
    5   <!--
    6       the associated Greenstone 3 installation folder
    7       You're expected to run/source the gs3-setup script in the GS3
    8       before running the default ant target in this file.
    9       You will be warned of this if you attempt to run this ant
    10       build.xml file without doing gs3-setup.
    11   -->
    12   <property name="gsdl3.web.home" value="${env.GSDL3HOME}"/>
    13   <property name="gsdl3.src.home" value="${env.GSDL3SRCHOME}"/>
    14  
    15   <property name="dist.dir.exp" location="releases" />
    16  
    17   <property name="dist.filename.exp"   value="TheMacronizer.war" />
    18   <property name="build.dir.exp"   location="web" />
    19   <property name="lib.dir.exp"  location="web/WEB-INF/lib" />
    20   <property name="webinf.dir"  location="web/WEB-INF" />
    21   <!-- Properties for MacroniserLogFileProcessor, use FULL PATHS -->
    22   <property name="scripts.dir" location="${basedir}/src/scripts-and-sql" />
    23   <property name="logfileproc.dir" value="${basedir}/logproc"/>
    24  
    25   <!--
    26       If changing these values, make sure you run 'ant clean'
    27   -->
    28   <property name="javac.source" value="1.8" />
    29   <property name="javac.target" value="${javac.source}" />
    30   <property name="javac.debug"  value="true" />
     3<project name="gs3-macroniser-ext" default="usage" basedir=".">
     4    <property name="package.name" value="gs3-macroniser" />
     5    <property environment="env"/>
     6    <property name="gsdl3.src.home" value="${env.GSDL3SRCHOME}"/>
     7    <property name="src.home" value="${basedir}/src/main/java" />
     8    <property name="build.home" value="${basedir}/build" />
     9    <property name="web.dir" value="${basedir}/src/main/webapp" />
     10    <property name="tomcat.webapps.dir" value="${gsdl3.src.home}/packages/tomcat/webapps" />
     11   
     12    <path id="compile.classpath">
     13        <fileset dir="lib/java">
     14            <include name="*.jar" />
     15        </fileset>
     16    </path>
     17   
     18    <!-- Targets -->
     19    <target name="usage" description="Print a help message">
     20        <echo message="Execute 'ant -projecthelp' for a list of targets." />
     21        <echo message="Execute 'ant -help' for Ant help." />
     22    </target>
    3123
     24    <target name="gs3-setup" description="Ensures that the gs3-setup script has been sourced.">
     25        <fail message="Please run 'gs3-setup' (Windows) or 'source gs3-setup.sh' (Linux/Mac) in the Greenstone3 installation that's associated with this installation before running this step.">
     26            <condition>
     27                <not>
     28                    <isset property="env.GSDL3HOME" />
     29                </not>
     30            </condition>
     31        </fail>
     32    </target>
     33   
     34    <target name="compile" description="Compile any java classes.">
     35        <property name="build.classes" value="${build.home}/classes" />
     36   
     37        <!-- Reset the build directory -->
     38        <delete dir="${build.home}" />
     39        <mkdir dir="${build.home}" />
     40        <mkdir dir="${build.classes}" />
     41       
     42        <!-- Compile all java files -->
     43        <javac srcdir="${src.home}" destdir="${build.classes}" debug="true">
     44            <classpath>
     45                <path refid="compile.classpath" />
     46            </classpath>
     47        </javac>
     48    </target>
     49   
     50    <target name="package" depends="compile" description="Create a WAR package.">
     51        <echo message="Creating ${build.home}/${package.name}.war" />
    3252
    33   <path id="classpath.exp">
    34     <fileset dir="${lib.dir.exp}">
    35     <include name="*.jar" />
    36     </fileset>
    37   </path>
    38    
    39  
    40   <target name="clean">
    41     <!-- delete only the class files built by themacronizer -->
    42     <delete dir="${build.dir.exp}/WEB-INF/classes"/>
    43   </target>
     53        <copy todir="${build.classes}/org/atea/nlptools/macroniser/monogram/data">
     54            <fileset dir="${src.home}/org/atea/nlptools/macroniser/monogram/data" includes="**" />
     55        </copy>
     56           
     57        <war destfile="${build.home}/${package.name}.war" webxml="${web.dir}/WEB-INF/web.xml">
     58            <fileset dir="${web.dir}/webContent" includes="**" />
     59            <fileset file="${basedir}/config.properties" />
    4460
    45  
    46   <target name="init">
    47     <!-- has the gs3-setup script been run?? -->
    48     <condition property="gs3-setup-not-done">
    49       <not>
    50     <isset property="env.GSDL3HOME"/>
    51       </not>
    52     </condition>
    53     <fail if="gs3-setup-not-done" message="Please run 'gs3-setup' (Windows) or 'source gs3-setup.sh' (Linux/Mac) in the Greenstone3 installation that's associated with this Macronizer installation before this step."/>
     61            <lib dir="lib/java">
     62                <exclude name="tomcat-servlet-api-8.5.51.jar" /> <!-- The host should already have its own servlet API jar -->
     63            </lib>
     64            <classes dir="${build.classes}" />
    5465
     66            <webinf dir="${web.dir}/WEB-INF" />
     67        </war>
     68    </target>
    5569   
    56     <echo message="${ant.project.name}: ${ant.file}"/>
    57     <mkdir dir="${build.dir.exp}/WEB-INF/classes"/>
    58     <mkdir dir="${build.dir.exp}/WEB-INF/classes/monogram"/>
    59     <copy includeemptydirs="false" todir="${build.dir.exp}/WEB-INF/classes/monogram/data">
    60       <fileset dir="src/java/monogram/data" />
    61     </copy>
    62   </target>
    63    
    64   <target name="build" depends="init">
    65     <javac source="${javac.source}" target="${javac.target}" debug="${javac.debug}"
    66        encoding="utf-8"
    67            destdir="${build.dir.exp}/WEB-INF/classes" includeantruntime="false">                               
    68       <src path="src"/>
    69            
    70       <classpath>
    71     <path refid="classpath.exp"/>
    72     <pathelement location="src/jars/servlet-api.jar"/>
    73     <pathelement path="src/java"/>
    74     <pathelement path="webinf.dir"/>
    75       </classpath>
    76     </javac>
    77 
    78     <!-- http://ant.apache.org/manual/Tasks/copy.html
    79      By default, files are only copied if the source file is newer than the destination file,
    80      or when the destination file does not exist. However, you can explicitly overwrite files
    81      with the overwrite attribute.-->
    82    
    83     <filter token="macronizer.home" value="${basedir}"/>
    84 
    85     <!-- 1a. Create the log4j.properties file from its log4j.properties.in template file and put it into the *Macronizer* installation's web/WEB-INF/classes folder -->
    86     <copy file="${build.dir.exp}/log4j.properties.in" tofile="${build.dir.exp}/WEB-INF/classes/log4j.properties" filtering="true" overwrite="true"/>
    87    
    88     <!-- 1b. Create the mysql.props file -->
    89     <copy file="${build.dir.exp}/mysql.properties.in" tofile="${build.dir.exp}/WEB-INF/classes/mysql.properties" filtering="true" overwrite="true"/>
    90 
    91     <!-- TODO: Ask Ryan Ko if the following message is fit to be known in public:
    92      <echo>Make sure to change the mysql db.password property in WEB-INF/classes/mysql.properties</echo>
    93     -->
    94 
    95     <!-- 2. Create the macronizer.xml tomcat context file from the macronizer.xml.in template file and put it into the correct location in the associated GS3 installation -->
    96     <copy file="${build.dir.exp}/macronizer.xml.in" tofile="${gsdl3.src.home}/packages/tomcat/conf/Catalina/localhost/macron-restoration.xml" filtering="true" overwrite="true"/>
    97    
    98     <!-- mkdir Creates a directory. Also non-existent parent directories are created,
    99      when necessary. Does nothing if the directory already exist. -->
    100     <mkdir dir="${build.dir.exp}/logs"/>
    101 
    102     <!-- For the MacroniserFileLogProcessor, which sets up a nightly cron to send useful logging info
    103      from the daily macron.log.<date> files to a mysqldb, need to do some setup too -->
    104     <copy file="${build.dir.exp}/mysql.properties.in" tofile="${basedir}/mysql.properties" filtering="true" overwrite="true"/>
    105    
    106     <mkdir dir="${logfileproc.dir}"/>
    107    
    108     <filter token="macronizer.scripts" value="${scripts.dir}"/>
    109     <filter token="macronizer.logs" value="${build.dir.exp}/logs"/>
    110     <copy file="${basedir}/src/scripts-and-sql/cron.in" tofile="${basedir}/src/scripts-and-sql/cron.txt" filtering="true" overwrite="true"/>
    111 
    112     <filter token="logfileproc.exec_folder" value="${build.dir.exp}/WEB-INF/classes"/> <!-- where the util.MacroniserLogProcessor compiled code is -->
    113     <filter token="logfileproc.dir" value="${logfileproc.dir}"/>
    114     <filter token="jarlibs.folder" value="${build.dir.exp}/WEB-INF/lib"/>
    115     <filter token="classes.folder" value="${build.dir.exp}/WEB-INF/classes"/>
    116     <!-- Why can't we set the classpath to the mysql.properties file
    117      to be anywhere other than the toplevel Macronizer folder/basedir?
    118      Anything else causes class MySQLAccess of MacroniserLogFileProcessor
    119      to fail with mysql.properties FileNotFoundException -->
    120     <!--<filter token="mysqlprops.dir" value="${logfileproc.dir}"/>-->
    121     <filter token="mysqlprops.dir" value="${basedir}"/>
    122    
    123     <copy file="${scripts.dir}/macronLogToDB.bash.in" tofile="${scripts.dir}/macronLogToDB.bash" filtering="true" overwrite="true"/>
    124     <chmod file="${scripts.dir}/macronLogToDB.bash" perm="ugo+rx"/>
    125    
    126     <echo>*** Run the ant target 'ant logs-to-db-instructions' for instructions on setting up the MacroniserLogFileProcessor***</echo>
    127   </target>
    128 
    129   <target name="logs-to-db-instructions">
    130     <echo>      ************************************************************
    131       Instructions on setting up the MacroniserLogFileProcessor
    132       ************************************************************
    133      
    134       1. Install mysql-5.7.23 as instructed at
    135       http://wiki.greenstone.org/doku.php?id=en:user_advanced:greenstonesqlplugs#getting_and_running_mysql
    136       (And when you run that mysql installation's db server, shut it down or run its mysql client,
    137       do so as per the instructions there)
    138 
    139       2. Use separate terminals to use the above instructions link to:
    140         - Start the mysql server
    141         - Connect to the mysql client
    142      
    143       3. After connecting to the client, in the mysql client terminal
    144         - IMPORTANT: don't forget to immediately follow with 'set names utf8mb4;'
    145         - CREATE AND INITIALISE the Macroniser database and its tables by running
    146     the MySQL_Code.sql script by typing the following and hitting ENTER:
    147             source ${scripts.dir}/MySQL_Code.sql
    148      
    149       3. Edit ${basedir}/mysql.properties to set the db password.
    150         - If you set up a different username for the mysql db, set that in mysql.properties too.
    151         - If nothing is set, MacronLogFileProcessor will assume the username is root.   
    152 
    153       4. Set up the daily cronjob as follows:
    154         - open a terminal and type 'export EDITOR=emacs' (or set to the text editor you prefer)
    155     - type 'crontab -e' and the editor will open the cronfile
    156     - append the contents from ${scripts.dir}/cron.txt to the cronfile
    157     - save file and exit the editor
    158 
    159       5. If you have email rights on the linux you're working from,
    160          type your email into macronLogToDB.bash.in and macronLogToDB.bash
    161          to get sent emails on errors.
    162 
    163       6. All going well, you should get output files in the ${logfileproc.dir}
    164      folder after the cron job runs each night.
    165    
    166       ************************************************************
    167     </echo>
    168   </target>
    169  
    170   <target name="war" depends="build">
    171     <echo>Basedir: ${basedir}</echo>
    172     <jar destfile="${dist.filename.exp}"> 
    173       <fileset dir="${build.dir.exp}" />
    174     </jar>
    175   </target>
    176  
     70    <target name="install" depends="gs3-setup,package" description="Installs the WAR package into tomcat.">
     71        <echo message="Copying war package to ${tomcat.webapps.dir}" />
     72        <copy file="${build.home}/${package.name}.war" todir="${tomcat.webapps.dir}" />
     73        <echo message="Done! Tomcat may take a few seconds to recognise the changes." />
     74    </target>
    17775</project>
Note: See TracChangeset for help on using the changeset viewer.