01: package com.sun.xml.ws.installer;
02:
03: /*
04: * updateSharedLoaderProp.java
05: *
06: */
07:
08: import java.io.File;
09: import java.io.FileInputStream;
10: import java.io.IOException;
11: import java.util.Properties;
12: import org.apache.tools.ant.Project;
13: import org.apache.tools.ant.Task;
14: import org.apache.tools.ant.BuildException;
15: import org.apache.tools.ant.taskdefs.Replace;
16:
17: public class UpdateSharedLoaderProp extends Task {
18:
19: String tomcatLib;
20:
21: public void settomcatLib(String tomcatLib) {
22: this .tomcatLib = tomcatLib;
23: }
24:
25: String catalinaProps;
26:
27: public void setCatalinaProps(String catalinaProps) {
28: this .catalinaProps = catalinaProps;
29: }
30:
31: public void execute() {
32: if (tomcatLib == null) {
33: // Default to shared/lib
34: tomcatLib = new String("${catalina.home}/shared/lib");
35: }
36: if (catalinaProps == null) {
37: throw new BuildException("No catalinaProps set!");
38: }
39: //log("tomcatLib = " + tomcatLib + " catalinaProps = " + catalinaProps, Project.MSG_WARN);
40:
41: //
42: final String jarWildcard = new String("/*.jar");
43: final String metroJars = new String(tomcatLib + jarWildcard);
44: // Read properties file.
45: FileInputStream propsFileStream = null;
46: Properties properties = new Properties();
47: try {
48: propsFileStream = new FileInputStream(catalinaProps);
49: if (propsFileStream != null) {
50: properties.load(propsFileStream);
51: propsFileStream.close();
52: }
53: } catch (IOException e) {
54: throw new BuildException("Missing or inaccessible "
55: + catalinaProps + " file");
56: }
57:
58: String sharedLoader = properties.getProperty("shared.loader");
59: String newSharedLoader = null;
60: if (sharedLoader == null || sharedLoader.length() == 0) {
61: newSharedLoader = metroJars;
62: } else if (sharedLoader.contains(metroJars)) {
63: // already has what is needed
64: return;
65: } else {
66: // has values but not shared/lib/*.jars
67: newSharedLoader = new String(metroJars + "," + sharedLoader);
68: }
69:
70: Replace replace = new Replace();
71: File propsFile = new File(catalinaProps);
72: replace.setProject(this .getProject());
73: replace.setFile(propsFile);
74: replace.setToken("shared.loader=" + sharedLoader);
75: replace.setValue("shared.loader=" + newSharedLoader);
76: try {
77: replace.execute();
78: } catch (Exception e) {
79: e.printStackTrace();
80: }
81: }
82:
83: }
|