KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > memoire > vainstall > AbstractCustomPrePost


1 package com.memoire.vainstall;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.PrintWriter JavaDoc;
6
7 /**
8   * To provide custom pre-install and post-install steps,
9   * create a subclass of this one and pass the name of the subclass
10   * to the package builder by as the value of the key
11   * "vainstall.install.customprepost.className" in the config file for
12   * your project.
13   * <p>
14   * If you are overriding this class, note that the class VAGlobals
15   * has many useful static fields and methods that provide things
16   * such as the application name, version, destination directory,
17   * and language in use for localization.
18 */

19
20 public class AbstractCustomPrePost {
21
22     /** Method called just before intallation begins.
23       * @param write PrintWriter a writer to which you can write the names
24       * of files that you create and want to add to the list of
25       * package files so that they will be deleted when
26       * your package is uninstalled. File names are fully qualified.
27       * See a copy of uninstall.vai
28       * in the .vainstall directory of an installed package for
29       * detail.
30       * @param step VAInstallStep interface containing methods that
31       * provide access to the GUI.
32       * @exception java.lang.Exception could be anything. You are likely
33       * to throw exceptions if you do anything interesting.
34     */

35
36     public static boolean preInstall(PrintWriter JavaDoc filelog,
37                 VAInstallStep step) throws Exception JavaDoc {
38         step.details(":-)");
39         VAGlobals.printDebug("AbstractCustomPrePost.preInstall");
40         return true;
41     }
42
43     /** Method called just after intallation ends.
44       * @param write PrintWriter a writer to which you can write the names
45       * of files that you create and want to add to the list of
46       * package files so that they will be deleted when
47       * your package is uninstalled. File names are fully qualified.
48       * See a copy of uninstall.vai
49       * in the .vainstall directory of an installed package for
50       * detail.
51       * @param step VAInstallStep interface containing methods that
52       * provide access to the GUI.
53       * @exception java.lang.Exception could be anything. You are likely
54       * to throw exceptions if you do anything interesting.
55     */

56
57     public static boolean postInstall(PrintWriter JavaDoc filelog,
58                 VAInstallStep step)
59                     throws Exception JavaDoc {
60         step.details(";-)");
61         VAGlobals.printDebug("AbstractCustomPrePost.postInstall");
62         return true;
63     }
64
65     /** Method called just before upgrade begins.
66       * @param oldversion String containing existing version.
67       * @param write PrintWriter a writer to which you can write the names
68       * of files that you create and want to add to the list of
69       * package files so that they will be deleted when
70       * your package is uninstalled. File names are fully qualified.
71       * See a copy of uninstall.vai
72       * in the .vainstall directory of an installed package for
73       * detail.
74       * @param step VAInstallStep interface containing methods that
75       * provide access to the GUI.
76       * @exception java.lang.Exception could be anything. You are likely
77       * to throw exceptions if you do anything interesting.
78     */

79
80     public static boolean preUpgrade(String JavaDoc oldversion,
81                 PrintWriter JavaDoc filelog,
82                 VAInstallStep step)
83                         throws Exception JavaDoc {
84         step.details(":-)");
85         VAGlobals.printDebug("AbstractCustomPrePost.preUpgrade");
86         return true;
87     }
88
89
90     public static boolean postUpgrade(String JavaDoc oldversion,
91                 PrintWriter JavaDoc filelog,
92                 VAInstallStep step)
93                         throws Exception JavaDoc {
94         step.details(";-)");
95         VAGlobals.printDebug("AbstractCustomPrePost.postUpgrade");
96         return true;
97     }
98
99     /** Method called just before uninstall begins.
100       * @param step VAInstallStep interface containing methods that
101       * provide access to the GUI.
102       * @exception java.lang.Exception could be anything. You are likely
103       * to throw exceptions if you do anything interesting.
104     */

105
106     public static boolean preUninstall(VAInstallStep step)
107                     throws Exception JavaDoc {
108         step.details(":-)");
109         VAGlobals.printDebug("AbstractCustomPrePost.preUninstall");
110         return true;
111     }
112
113     /** Method called just after uninstall ends.
114       * @param step VAInstallStep interface containing methods that
115       * provide access to the GUI.
116       * @exception java.lang.Exception Could be anything. You are likely
117       * to throw exceptions if you do anything interesting.
118     */

119
120     public static boolean postUninstall(VAInstallStep step)
121                     throws Exception JavaDoc {
122         step.details(";-)");
123         VAGlobals.printDebug("AbstractCustomPrePost.postUninstall");
124         return true;
125     }
126
127     /////////////// protected below /////////////////////////////////////
128

129     /**
130       * Use Runtime.exec to run the given command in the given working
131       * directory. Standard output of the command is captured
132       * and fed to the the details method of the VAInstallStep object
133       * provided as well as to VAGlobals.printDebug.
134       * @param workdir File directory that will be the working directory of
135       * the command run.
136       * @param args String[] the command to be run. Each argument is one
137       * member of the array.
138       * @param step VAInstallStep the interface to the GUI through which
139       * output from the command will be fed.
140       * @exception java.io.IOException should only occur with problems
141       * running the command and reading the standard out as
142       * input.
143       * @exception java.lang.InterruptedException may occur while
144       * waiting for the command to finish running.
145     */

146         // WORK HERE -
147
// Need to use Java 1.3 exec(File directory)
148
protected static final int runCommand(File JavaDoc workdir, String JavaDoc[] args,
149                 VAInstallStep step)
150             throws IOException JavaDoc, InterruptedException JavaDoc {
151         VAGlobals.printDebug("AbastractCustomPrePost.runCommand");
152         VAGlobals.printDebug("\tworking dir = "
153             + workdir.getAbsolutePath());
154         for (int idx = 0; idx < args.length; idx ++) {
155             VAGlobals.printDebug("\targ " + idx + " = " +args[idx]);
156         }
157         Process JavaDoc proc = Runtime.getRuntime().exec(args, null, workdir);
158         InputStreamToDetails relay = new
159             InputStreamToDetails(proc.getInputStream(), step);
160         relay.start();
161         proc.waitFor();
162         int rc = proc.exitValue();
163         VAGlobals.printDebug("AbstractCustomPrepost.runCommand cmd"
164             + " returned " + rc);
165         return rc;
166     }
167
168 }
169
Popular Tags