source: release-kits/lirk3/resources/ISCustomCode.java@ 15093

Last change on this file since 15093 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 11.6 KB
Line 
1package com.installshield.greenstone3_digital_library_software.event;
2
3import java.io.*;
4import java.net.*;
5import java.util.ArrayList;
6import java.util.StringTokenizer;
7import com.installshield.event.*;
8import com.installshield.event.ui.*;
9import com.installshield.event.wizard.*;
10import com.installshield.event.product.*;
11import com.installshield.wizard.*;
12import com.installshield.wizard.service.*;
13import com.installshield.wizard.service.file.*;
14import com.installshield.wizard.awt.*;
15import com.installshield.wizard.swing.*;
16import com.installshield.wizard.console.*;
17import com.installshield.product.*;
18import com.installshield.util.*;
19import com.installshield.ui.controls.*;
20import com.installshield.database.designtime.*;
21import com.installshield.product.service.product.*;
22
23public class InstallScript
24{
25
26 /* DONE
27
28 public void onInstalled_AntBuildFiles(ISContext context) {
29
30 String productInstallLocation = context.resolveString("$P(absoluteInstallLocation)");
31 String configFile = context.resolveString("$PATH(" + productInstallLocation +", build.properties)");
32 String tomcatPort = context.resolveString("$V(START_PORT)");
33 String tomcatShutdownPort = context.resolveString("$V(SHUTDOWN_PORT)");
34
35 System.out.println("tomcatPort: "+tomcatPort);
36 System.out.println("java version = "+context.resolveString("$J(java.version)"));
37 ArrayList fileLines = readInFile(configFile);
38
39 if (fileLines != null) {
40 setupReplace(fileLines, "tomcat.port", tomcatPort);
41 setupReplace(fileLines, "tomcat.shutdown.port", tomcatShutdownPort);
42 writeOutFile(configFile, fileLines);
43 }
44 }
45
46 public void onReplaced_AntBuildFiles(ComponentReplaceContext context) {
47 onInstalled_AntBuildFiles(context);
48 }
49
50 */
51
52 public void onInstalled_Tomcat(ISContext context) {
53
54 /* DONE
55 // modify server.xml
56 String installLocation = context.resolveString("$P(absoluteInstallLocation)");
57 String templateServerXML = context.resolveString("$PATH(" + installLocation +", resources/tomcat/server.xml)");
58 String finalServerXML = context.resolveString("$PATH(" + installLocation +", packages/tomcat/conf/server.xml)");
59
60 String tomcatPort = context.resolveString("$V(START_PORT)");
61 String tomcatShutdownPort=context.resolveString("$V(SHUTDOWN_PORT)");
62
63 ArrayList fileLines = readInFile(templateServerXML);
64 if (fileLines != null) {
65 queryReplace(fileLines, "@port@", tomcatPort);
66 queryReplace(fileLines, "@shutdown-port@", tomcatShutdownPort);
67 writeOutFile(finalServerXML, fileLines);
68 }
69
70
71
72 // copy greenstone3.xml into tomcat directory
73 String templateGreenstone3Context = context.resolveString("$PATH(" + installLocation +", resources/tomcat/greenstone3.xml)");
74 String finalGreenstone3Context = context.resolveString("$PATH(" + installLocation +", packages/tomcat/conf/Catalina/localhost/greenstone3.xml)");
75
76 fileLines = readInFile(templateGreenstone3Context);
77 String webDir = context.resolveString("$PATH(" + installLocation +", web)");
78 if (context.resolveString("$J(os.name)").startsWith("Windows")) {
79 // replace \ with \\ (I think)
80 webDir = webDir.replaceAll("\\\\", "\\\\\\\\\\\\\\\\");
81 }
82
83 if (fileLines != null) {
84 queryReplace(fileLines, "@gsdl3webhome@", webDir);
85 writeOutFile(finalGreenstone3Context, fileLines);
86 }
87
88 System.out.println("java version = "+context.resolveString("$J(java.version)"));
89
90 }
91
92
93 public void onReplaced_Tomcat(ComponentReplaceContext context)
94 {
95 onInstalled_Tomcat(context);
96 }
97
98
99 public void onInstalled_GS2BuildSetupBat(ISContext context) {
100
101 if (context.resolveString("$J(os.name)").startsWith("Windows")) {
102 String installLocation = context.resolveString("$P(absoluteInstallLocation)");
103 String setupBatFile = context.resolveString("$PATH("+ installLocation+", gs2build/setup.bat)");
104 String gsdlhome = context.resolveString("$PATH("+ installLocation+", gs2build)");
105 ArrayList fileLines = readInFile(setupBatFile);
106 gsdlhome = gsdlhome.replaceAll("\\\\", "/");
107 if (fileLines != null) {
108 queryReplace(fileLines, "@gsdlhome@",gsdlhome);
109 writeOutFile(setupBatFile, fileLines);
110 }
111 }
112 }
113
114
115 public void onReplaced_GS2BuildSetupBat(ComponentReplaceContext context) {
116 onInstalled_GS2BuildSetupBat(context);
117 }
118 */
119
120 public void onInstalled_WebDirectory(ISContext context)
121 {
122 String installLocation = context.resolveString("$P(absoluteInstallLocation)");
123 // rename some jar files if Java version is 1.5
124 /*String java_ver = context.resolveString("$J(java.version)");
125
126 if (java_ver.equals("1.5")) {
127
128 String xalanTmpFile = context.resolveString("$PATH(" + installLocation +", web/WEB-INF/lib/xalan.jar.tmp)");
129 String xalanJarFile = context.resolveString("$PATH(" + installLocation +", web/WEB-INF/lib/xalan.jar)");
130 renameFile(context,xalanTmpFile,xalanJarFile);
131
132 String xercesImplTmpFile = context.resolveString("$PATH(" + installLocation +", web/WEB-INF/lib/xercesImpl.jar.tmp)");
133 String xercesImplJarFile = context.resolveString("$PATH(" + installLocation +", web/WEB-INF/lib/xercesImpl.jar)");
134 renameFile(context,xercesImplTmpFile,xercesImplJarFile);
135 }
136
137
138 String webDir = context.resolveString("$PATH(" + installLocation +", web)");
139 // on windows, turn the path back into linux style
140 if (context.resolveString("$J(os.name)").startsWith("Windows")) {
141 webDir = webDir.replaceAll("\\\\", "/");
142 }
143
144 String tomcatPort = context.resolveString("$V(START_PORT)");
145
146 // Set up global.properties
147 String templateGlobalProperties = context.resolveString("$PATH(" + installLocation +", resources/java/global.properties.in)");
148 String finalGlobalProperties = context.resolveString("$PATH(" + installLocation +", web/WEB-INF/classes/global.properties)");
149
150
151 ArrayList fileLines = readInFile(templateGlobalProperties);
152 if (fileLines != null) {
153 queryReplace(fileLines, "@gsdl3home@", webDir);
154 queryReplace(fileLines, "@tomcat.server@", "localhost");
155 queryReplace(fileLines, "@tomcat.port@", tomcatPort);
156 writeOutFile(finalGlobalProperties, fileLines);
157 }
158
159
160 // Set up log4j.properties
161 String templateLog4jProperties = context.resolveString("$PATH(" + installLocation +", resources/java/log4j.properties.in)");
162 String finalLog4jProperties = context.resolveString("$PATH(" + installLocation +", web/WEB-INF/classes/log4j.properties)");
163
164 fileLines = readInFile(templateLog4jProperties);
165 if (fileLines != null) {
166 queryReplace(fileLines, "@gsdl3home@", webDir);
167 writeOutFile(finalLog4jProperties, fileLines);
168 }
169 */
170
171 }
172
173 public void onReplaced_WebDirectory(ComponentReplaceContext context)
174 {
175 onInstalled_WebDirectory(context);
176 }
177
178 // --------------------------------------------------
179 // General methods
180 // --------------------------------------------------
181
182 public ArrayList readInFile(String file) {
183 try {
184 ArrayList fileLines = new ArrayList();
185 String line = null;
186 BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
187 while ((line = bufferedReader.readLine()) != null ) {
188 fileLines.add(line);
189 }
190 bufferedReader.close();
191 return fileLines;
192 } catch (Exception e) {
193 System.err.println("exception: "+e);
194 return null;
195 }
196
197 }
198
199
200 public void writeOutFile(String file, ArrayList fileLines) {
201 try {
202 PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter(file)));
203 for (int i=0; i<fileLines.size(); i++) {
204 printWriter.println(fileLines.get(i));
205 }
206 printWriter.flush();
207 printWriter.close();
208 } catch (Exception e) {
209 System.err.println("exception: "+e);
210 return;
211 }
212 }
213
214 public void queryReplace(ArrayList strings, String fromText, String toText) {
215 for (int i=0; i<strings.size(); i++) {
216 strings.set(i, ((String)strings.get(i)).replaceAll(fromText, toText));
217 }
218 }
219
220 public ArrayList setupReplace (ArrayList fileLines, String param, String newValue){
221
222 String oneLine=null;
223 String newLine=null;
224 String name=null;
225 param=param.trim();
226
227 for (int i=0;i<fileLines.size();i++) {
228 oneLine=((String) fileLines.get(i)).trim();
229 StringTokenizer st=new StringTokenizer(oneLine,"=");
230
231 if(st.hasMoreTokens()){
232 name=st.nextToken();
233 if(param.equals(name)){
234 newLine=param+"="+newValue;
235 fileLines.set(i,newLine);
236 break;
237 }
238
239 }
240 }
241 return fileLines;
242 }
243
244 private void renameFile(ISContext context, String sourceFilePathRelative, String targetFilePathRelative)
245 {
246 String installLocation = context.resolveString("$P(absoluteInstallLocation)");
247
248 try {
249 FileService fileService = (FileService) context.getService(FileService.NAME);
250 String sourceFilePath = context.resolveString("$PATH(" + installLocation + ", " + sourceFilePathRelative + ")");
251 String targetFilePath = context.resolveString("$PATH(" + installLocation + ", " + targetFilePathRelative + ")");
252 fileService.moveFile(sourceFilePath, targetFilePath, true);
253 }
254 catch (ServiceException exception) {
255 System.err.println("Exception: " + exception);
256 exception.printStackTrace();
257 }
258 }
259
260
261 private void deleteFile(ISContext context, String filePathAbsolute)
262 {
263
264 try {
265 FileService fileService = (FileService) context.getService(FileService.NAME);
266 fileService.deleteFile(filePathAbsolute);
267 }
268 catch (ServiceException exception) {
269 System.err.println("Exception: " + exception);
270 exception.printStackTrace();
271 }
272 }
273
274 private void copyFile(ISContext context, String sourceFilePathRelative, String targetFilePathRelative)
275 {
276 String installLocation = context.resolveString("$P(absoluteInstallLocation)");
277
278 try {
279 FileService fileService = (FileService) context.getService(FileService.NAME);
280 String sourceFilePath = context.resolveString("$PATH(" + installLocation + ", " + sourceFilePathRelative + ")");
281 String targetFilePath = context.resolveString("$PATH(" + installLocation + ", " + targetFilePathRelative + ")");
282 fileService.copyFile(sourceFilePath, targetFilePath, true);
283 }
284 catch (ServiceException exception) {
285 System.err.println("Exception: " + exception);
286 exception.printStackTrace();
287 }
288 }
289
290
291 public void onInstalled_ant(ComponentInstallContext context)
292 {
293 String installLocation = context.resolveString("$P(absoluteInstallLocation)");
294
295 String linuxsetupfile = context.resolveString("$PATH(" + installLocation +", gs3-setup.sh)");
296 String windowssetupfile = context.resolveString("$PATH(" + installLocation +", gs3-setup.bat)");
297
298 // Set up ANT_HOME and put it in PATH for linux
299 String anthome = context.resolveString("$PATH(" + installLocation +", packages/ant)");
300 ArrayList fileLines = readInFile(linuxsetupfile);
301 System.out.println("------------------------- fileLines !=null : "+(fileLines !=null));
302 if (fileLines !=null){
303 fileLines.add("export ANT_HOME="+anthome+"\n");
304 fileLines.add("export PATH=$ANT_HOME/bin:$PATH"+"\n");
305 writeOutFile(linuxsetupfile, fileLines);
306 }
307
308 fileLines = readInFile(windowssetupfile);
309 if (fileLines !=null){
310 fileLines.add("set ANT_HOME="+anthome+"\n");
311 fileLines.add("set PATH=%ANT_HOME%/bin;%PATH%"+"\n");
312 writeOutFile(windowssetupfile, fileLines);
313 }
314
315 }
316
317
318}
Note: See TracBrowser for help on using the repository browser.