You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

We have an integration with Apache Ant which is “a Java-based build tool”. It is now possible to send messages to Apache ESME that describe the progress of your build steps. This is especially useful when Apache ESME is being in development projects where individual developers can be made aware of the status of various-build related actions. For example, a development team could be informed that a build is broken or if it is successful.

Directory Structure- Setup

  1. Install the apache tool "ant"
  2. Create libdirectory and copy "rest-api-0.1-SNAPSHOT.jar", "commons-codec-1.2.jar", "commons-httpclient-3.1.jar" into this directory. Note: You can get these libraries via the Google Code archive
  3. Create src directory and copy the "EsmeAntTask?.java" file to this directory
  4. Change the build.xml file to point to the appropriate directories
  5. Change the token in the "esme" target in the build.xml file to a correct token.
  6. Change the proxy in the "esme" target in the build.xml file to a correct proxy.
  7. call ant dist esme to test the application

Build.xml

<project name="EsmeViaAnt" default="dist" basedir=".">
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>
 
    <path id="project.class.path">
    <pathelement path="./dist/lib/EsmeViaAnt.jar:./lib/esme-rest-api-0.1-SNAPSHOT.jar:./lib/commons-codec-1.2.jar:./lib/commons-logging-1.0.4.jar:./lib/commons-httpclient-3.1.jar/"/>
  </path>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="$

Unknown macro: {build}

"/>
  </target>

  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from $

Unknown macro: {src}

into $

-->
    <javac srcdir="$

Unknown macro: {src}

" destdir="$

Unknown macro: {build}

">
    <classpath refid="project.class.path"/>
                </javac>
  </target>

  <target name="dist" depends="compile"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="$

Unknown macro: {dist}

/lib"/>

    <!-- Put everything in $

into the jar file -->
    <jar jarfile="$

Unknown macro: {dist}

/lib/EsmeViaAnt.jar" basedir="$

Unknown macro: {build}

"/>
  </target>
 
  <target name="esme"
        description="Send Esme" >
        <java fork="true"
         classname="EsmeAntTask">
         <arg value="http://api.esme.us/esme/api"/>
         <arg value="IFDHJ2RNDECAT84ZJZUKDE59TVOIVTXL"/>
         <arg value="proxy:81"/>
         <arg value="A message from the ant build process"/>
         <classpath>
               <pathelement path="./dist/lib/EsmeViaAnt.jar:./lib/esme-rest-api-0.1-SNAPSHOT.jar:./lib/commons-codec-1.2.jar:./lib/commons-logging-1.0.4.jar:./lib/commons-httpclient-3.1.jar/"/>
         </classpath>

       </java>
  </target>
 
</project>

EsmeAntTask? java class

import us.esme.api.EsmeRestApi;
import us.esme.api.Message;
 
public class EsmeAntTask
{

public static void main (String[] args) {

 String apiUrl;
 String authToken;
 String localProxy;
 String message;
 EsmeRestApi esme;    
 
 apiUrl = args[0];
 authToken = args[1];
 localProxy = args[2];
 message = args[3];
 
 try {
 
         esme = new EsmeRestApi(apiUrl);
         
         if ((localProxy != null) && !("".equals(localProxy)))
         

Unknown macro: {                // Split proxyHost}

         
         esme.login(authToken);
         
         Message esmeMsg = new Message();
         
         esmeMsg.setText(message);
         
         String[] tags = new String[1];
         tags[0] = "Ant Task";
         
         esmeMsg.setTags(tags);
         
         esmeMsg.setVia("Ant");
         
         esme.sendMsg(esmeMsg);
 }
 catch (Exception e) {}
 }
}

  • No labels