View Javadoc

1   /**
2   The contents of this file are subject to the Mozilla Public License Version 1.1 
3   (the "License"); you may not use this file except in compliance with the License. 
4   You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
5   Software distributed under the License is distributed on an "AS IS" basis, 
6   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
7   specific language governing rights and limitations under the License. 
8   
9   The Original Code is "AntGenerator.java".  Description: 
10  "This class creates an ANT build.xml file" 
11  
12  The Initial Developer of the Original Code is University Health Network. Copyright (C) 
13  2001.  All Rights Reserved. 
14  
15  Contributor(s): James Agnew
16                  Paul Brohman
17                  Mitch Delachevrotiere
18                  Shawn Dyck
19    				Cory Metcalf
20    				
21  Alternatively, the contents of this file may be used under the terms of the 
22  GNU General Public License (the  ?GPL?), in which case the provisions of the GPL are 
23  applicable instead of those above.  If you wish to allow use of your version of this 
24  file only under the terms of the GPL and not to allow others to use your version 
25  of this file under the MPL, indicate your decision by deleting  the provisions above 
26  and replace  them with the notice and other provisions required by the GPL License.  
27  If you do not delete the provisions above, a recipient may use your version of 
28  this file under either the MPL or the GPL. 
29  
30  */
31  package ca.uhn.hl7v2.conf.classes.generator.builders;
32  
33  import java.io.*;
34  
35  /** This class creates an ANT build.xml file
36   * @author <table><tr>James Agnew</tr>
37   *                <tr>Paul Brohman</tr>
38   *                <tr>Mitch Delachevrotiere</tr>
39   *                <tr>Shawn Dyck</tr>
40   * 				  <tr>Cory Metcalf</tr></table>
41   */
42  public class AntGenerator {
43     private String baseDir;
44     private String name;
45  		
46     /** Returns a String representation of the ANT build.xml file
47  	* @return a String representation of the ANT build.xml file
48  	*/
49     private String antString(){
50        String classPath[] = System.getProperty("java.class.path",".").split(";", -1);
51  		
52        String ant = 
53           "<!-- 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  	     			// add locations on the class path
69       				for(int i = 0; i < classPath.length; i++){
70          					ant += "<pathelement location=\"" + classPath[i] + "\" />\n";
71          			}
72      				
73      				ant += "<pathelement location=\"${java.home}/jre/lib/rt.jar\" />\n" +
74    					"</path>\n" +
75   
76    				"<!-- Compile the project -->\n" +
77    				"<target name=\"compile_core\">\n" +
78      				"<mkdir dir=\"${classes}\" />\n" +
79      				"<javac srcdir=\"${src}\" destdir=\"${classes}\" includes=\"**\">\n" +
80        					"<classpath refid=\"class.path\" />\n" +
81      				"</javac>\n" +
82    				"</target>\n" +
83   
84    				"<!--  Creates JavaDoc documentation (core classes only)   -->\n" +
85    				"<target name=\"doc\">\n" +
86      				"<mkdir dir=\"${docs}\" />\n" +
87        				"<javadoc packagenames=\"*\" classpathref=\"class.path\" sourcepath=\"${src}\" destdir=\"${docs}\" windowtitle=\"HAPI API Documentation\" />\n" +
88    				"</target>\n" +
89     
90  	  		    "<!-- Add the files to a Jar Archive -->\n" +
91  			    "<target name=\"jar\" depends=\"compile_core, doc\">\n" +
92  			      "<mkdir dir=\"${dist}\" />\n" +
93  			        "<jar jarfile=\"${dist}/" + name + ".jar\" basedir=\"${classes}\">\n" +
94  			          "<fileset dir=\"${docs}\" />\n" +
95  			        "</jar>\n" +
96  			    "</target>\n" +
97  			  
98  			
99  			    "<target name=\"dist\" depends=\"jar,doc\" />\n" +
100 			    "<target name=\"clean\">\n" +
101 			      "<delete>\n" +
102 			        "<fileset dir=\"${build}\" />\n" +
103 			      "</delete>\n" +
104 			    "</target>\n" +
105 			  "</project>\n";
106 			  
107       return ant;
108    }
109 	
110    /** Creates the ANT build.xml file
111 	* @param baseDir the directory where the ANT build.xml file will be saved
112 	* @param name the name of the project
113 	*/
114    public void createAnt(String baseDir, String name){
115       this.baseDir = baseDir;
116 	  this.name = name;
117       FileOutputStream fstream;
118 	  try{	
119          File f = new File( baseDir + File.separator + "build.xml");
120          fstream = new FileOutputStream( f ); /* open file stream */
121       } catch ( FileNotFoundException e ) {
122          System.out.println("Filenotfoundexception: " + e.toString() );
123          return;
124       }
125       
126       DataOutputStream ostream = null;
127       try {
128          ostream = new DataOutputStream( fstream );   /* open object stream */
129          ostream.writeBytes( this.antString() );
130 	  } catch ( IOException e ) {
131 	     System.out.println("IOexception:\n" + e.toString() + "\n" );
132 	  } finally {
133          try {
134             /* clean-up */
135             ostream.flush();
136             fstream.close();
137          } catch (Exception e1) {
138             e1.printStackTrace();
139          }
140       }
141    }
142 }