1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  package ca.uhn.hl7v2.conf.classes.generator.builders;
32  
33  import java.io.*;
34  
35  
36  
37  
38  
39  
40  
41  
42  public class AntGenerator {
43     private String baseDir;
44     private String name;
45  		
46     
47  
48  
49     private String antString(){
50        String[] classPath = System.getProperty("java.class.path",".").split(";", -1);
51  		
52        StringBuilder ant =
53                new StringBuilder("<!-- Build file for the Conformance Classes -->\n" +
54                        "<project name=\"" + name + "\" default=\"dist\" basedir=\"" + baseDir + "\">\n" +
55                        "<!--  set global properties for this build -->\n" +
56                        "<property name=\"src\" value=\".\" />\n" +
57                        "<property name=\"build\" value=\"${basedir}/build\" />\n" +
58                        "<property name=\"classes\" value=\"${build}/classes\" />\n" +
59                        "<property name=\"docs\" value=\"${build}/docs\" />\n" +
60                        "<property name=\"dist\" value=\"${basedir}/dist\" />\n" +
61                        "<property name=\"build\" value=\"ca\" />\n" +
62  
63                        "<!-- The class path -->\n" +
64                        "<path id=\"class.path\">\n" +
65                        "<pathelement path=\"${src}\" />\n" +
66                        "<pathelement path=\"${classes}\" />\n");
67       				
68  	     			
69  	   for (String s : classPath) {
70  		   ant.append("<pathelement location=\"").append(s).append("\" />\n");
71  	   }
72      				
73      				ant.append("<pathelement location=\"${java.home}/jre/lib/rt.jar\" />\n" + "</path>\n" + "<!-- Compile the project -->\n" + "<target name=\"compile_core\">\n" + "<mkdir dir=\"${classes}\" />\n" + "<javac srcdir=\"${src}\" destdir=\"${classes}\" includes=\"**\">\n" + "<classpath refid=\"class.path\" />\n" + "</javac>\n" + "</target>\n" + "<!--  Creates JavaDoc documentation (core classes only)   -->\n" + "<target name=\"doc\">\n" + "<mkdir dir=\"${docs}\" />\n" + "<javadoc packagenames=\"*\" classpathref=\"class.path\" sourcepath=\"${src}\" destdir=\"${docs}\" windowtitle=\"HAPI API Documentation\" />\n" + "</target>\n" + "<!-- Add the files to a Jar Archive -->\n" + "<target name=\"jar\" depends=\"compile_core, doc\">\n" + "<mkdir dir=\"${dist}\" />\n" + "<jar jarfile=\"${dist}/").append(name).append(".jar\" basedir=\"${classes}\">\n").append("<fileset dir=\"${docs}\" />\n").append("</jar>\n").append("</target>\n").append("<target name=\"dist\" depends=\"jar,doc\" />\n").append("<target name=\"clean\">\n").append("<delete>\n").append("<fileset dir=\"${build}\" />\n").append("</delete>\n").append("</target>\n").append("</project>\n");
74  			  
75        return ant.toString();
76     }
77  	
78     
79  
80  
81  
82     public void createAnt(String baseDir, String name){
83        this.baseDir = baseDir;
84  	  this.name = name;
85        FileOutputStream fstream;
86  	  try{	
87           File f = new File( baseDir + File.separator + "build.xml");
88           fstream = new FileOutputStream( f ); 
89        } catch ( FileNotFoundException e ) {
90           System.out.println("Filenotfoundexception: " + e.toString() );
91           return;
92        }
93        
94        DataOutputStream ostream = null;
95        try {
96           ostream = new DataOutputStream( fstream );   
97           ostream.writeBytes( this.antString() );
98  	  } catch ( IOException e ) {
99  	     System.out.println("IOexception:\n" + e.toString() + "\n" );
100 	  } finally {
101          try {
102             
103             ostream.flush();
104             fstream.close();
105          } catch (Exception e1) {
106             e1.printStackTrace();
107          }
108       }
109    }
110 }