1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.geronimo.ews.ws4j2ee.toWs.misc;
18
19 import java.io.File;
20 import java.io.FileWriter;
21 import java.io.IOException;
22 import java.io.PrintWriter;
23 import java.util.ArrayList;
24 import java.util.StringTokenizer;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.geronimo.ews.ws4j2ee.context.InputOutputFile;
29 import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
30 import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
31 import org.apache.geronimo.ews.ws4j2ee.toWs.Generator;
32 import org.apache.geronimo.ews.ws4j2ee.toWs.dd.JaxrpcMapperGenerator;
33 import org.apache.geronimo.ews.ws4j2ee.utils.FileUtils;
34
35 /***
36 * @author Srinath Perera(hemapani@opensource.lk)
37 */
38 public class BuildFileConfigurer implements Generator {
39 private J2EEWebServiceContext j2eewscontext;
40
41 protected static Log log =
42 LogFactory.getLog(JaxrpcMapperGenerator.class.getName());
43
44 public BuildFileConfigurer(J2EEWebServiceContext j2eewscontext) throws GenerationFault {
45 this.j2eewscontext = j2eewscontext;
46 }
47
48 public void generate() throws GenerationFault {
49 try {
50 FileUtils.copyFile(new File("conf/common.xml"),new File(j2eewscontext.getMiscInfo().getOutPutPath() + "/common.xml"));
51
52 String buildfile = j2eewscontext.getMiscInfo().getOutPutPath() + "/build.xml";
53 if (j2eewscontext.getMiscInfo().isVerbose())
54 log.info("genarating " + buildfile + ".................");
55 PrintWriter out = new PrintWriter(new FileWriter(buildfile));
56
57
58 out.write("<?xml version=\"1.0\"?>\n");
59 out.write("<!DOCTYPE project [\n");
60 out.write(" <!ENTITY properties SYSTEM \"file:common.xml\">\n");
61 out.write("]>\n");
62 out.write("<project basedir=\".\" default=\"dist\">\n");
63
64 out.write("\t&properties;\n");
65
66 writeproperty("mapping.file",j2eewscontext.getMiscInfo().getJaxrpcfile(), out);
67 writeproperty("wsdl.file",j2eewscontext.getMiscInfo().getWsdlFile(), out);
68 writeproperty("webservice.file",j2eewscontext.getMiscInfo().getWsconffile(), out);
69
70 out.write(" <path id=\"local.classpath\" >\n");
71 File file = new File(".");
72 File tempfile = new File(file,"target/classes");
73 if(tempfile.exists()){
74 out.write(" <pathelement location=\""+tempfile.getCanonicalPath()+"\"/>\n");
75 }
76
77 tempfile = new File(file,"target/test-classes");
78 if(tempfile.exists()){
79 out.write(" <pathelement location=\""+tempfile.getCanonicalPath()+"\"/>\n");
80 }
81
82 ArrayList classpathelements = j2eewscontext.getMiscInfo().getClasspathElements();
83 if (classpathelements != null) {
84 for (int i = 0; i < classpathelements.size(); i++) {
85 File pathFile = (File) classpathelements.get(i);
86 System.out.println(pathFile.getName());
87 out.write(" <pathelement location=\""
88 + pathFile.getCanonicalPath() + "\"/>\n");
89 }
90 }
91 out.write(" </path>\n");
92
93
94
95
96 out.write("\t<target name=\"copy-j2ee-resources\">\n");
97
98
99
100 for (int i = 0; i < classpathelements.size(); i++) {
101 File pathelement = (File) classpathelements.get(i);
102 if(pathelement.isFile() ){
103 out.write(" <unzip src=\""+pathelement.getCanonicalPath()+"\" dest=\"${build.classes}\"></unzip>\n");
104 }else{
105 out.write(" <copy todir=\"${build.classes}\">\n");
106 out.write(" <fileset dir=\""+pathelement.getCanonicalPath()+"\">\n");
107 out.write(" <include name=\"**/*.class\"/>\n");
108 out.write(" <include name=\"**/*.xml\"/>\n");
109 out.write(" <include name=\"**/*.wsdl\"/>\n");
110 out.write(" </fileset>\n");
111 out.write(" </copy>\n");
112 }
113
114 }
115 out.write("\t</target>\n");
116
117
118 out.write("</project>\n");
119 out.close();
120 } catch (IOException e) {
121 log.error(e);
122 throw GenerationFault.createGenerationFault(e);
123 }
124 }
125
126 private StringTokenizer getClasspathComponets() {
127 String classpath = System.getProperty("java.class.path");
128 String spearator = System.getProperties().getProperty("path.separator");
129 return new StringTokenizer(classpath, spearator);
130 }
131
132 private void writeproperty(String property, InputOutputFile file, PrintWriter out) throws GenerationFault {
133 try {
134 if (file != null) {
135 String fileName = file.fileName();
136 if (fileName != null) {
137 File absFile = new File(fileName);
138 if (absFile.exists())
139 out.write("<property name=\""+property+"\" value=\""+absFile.getCanonicalPath()+"\"/>\n");
140 }
141 }
142 } catch (Exception e) {
143 }
144 }
145 }