KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $RCSfile: VAArchiver.java,v $
3  * @creation 26/01/99
4  * @modification $Date: 2005/05/14 10:14:17 $
5  */

6 package com.memoire.vainstall;
7
8 import java.io.BufferedReader JavaDoc;
9 import java.io.BufferedWriter JavaDoc;
10 import java.io.ByteArrayInputStream JavaDoc;
11 import java.io.ByteArrayOutputStream JavaDoc;
12 import java.io.File JavaDoc;
13 import java.io.FileFilter JavaDoc;
14 import java.io.FileInputStream JavaDoc;
15 import java.io.FileOutputStream JavaDoc;
16 import java.io.FileReader JavaDoc;
17 import java.io.FileWriter JavaDoc;
18 import java.io.IOException JavaDoc;
19 import java.io.InputStream JavaDoc;
20 import java.io.InputStreamReader JavaDoc;
21 import java.io.LineNumberReader JavaDoc;
22 import java.io.ObjectOutputStream JavaDoc;
23 import java.io.OutputStreamWriter JavaDoc;
24 import java.io.PrintWriter JavaDoc;
25 import java.io.Reader JavaDoc;
26 import java.io.UnsupportedEncodingException JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.net.URLClassLoader JavaDoc;
29 import java.text.NumberFormat JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Locale JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.Properties JavaDoc;
35 import java.util.StringTokenizer JavaDoc;
36 import java.util.Vector JavaDoc;
37 import java.util.jar.JarEntry JavaDoc;
38 import java.util.jar.JarInputStream JavaDoc;
39 import java.util.jar.JarOutputStream JavaDoc;
40 import java.util.zip.CRC32 JavaDoc;
41 import java.util.zip.GZIPOutputStream JavaDoc;
42 import java.util.zip.ZipEntry JavaDoc;
43 import java.util.zip.ZipOutputStream JavaDoc;
44
45 /**
46  * @version $Id: VAArchiver.java,v 1.43 2005/05/14 10:14:17 deniger Exp $
47  * @author Axel von Arnim
48  */

49 public class VAArchiver {
50     private static final String JavaDoc JAVA_HOME = System.getProperty("java.home");
51
52     // search path is appended to JAVA_HOME to determine the location of the
53
// javac executable. Don't include trailing or leading slashes
54
private static final String JavaDoc[] JAVAC_SEARCH_PATH = new String JavaDoc[] { "../bin",
55             "bin" };
56
57     private static final String JavaDoc JAVAC = "javac";
58
59     private static final String JavaDoc JDK_HOME = System.getProperty("java.home")
60             + File.separator + "..";
61
62     private static String JavaDoc RC_DIR = null;
63
64     private static String JavaDoc VAILOGO = null;
65
66     private static final String JavaDoc[] JAR_FILES_COMMON = new String JavaDoc[] {
67             "com/memoire/vainstall/Language_da_DK.class",
68             "com/memoire/vainstall/Language_de_DE.class",
69             "com/memoire/vainstall/Language_en_UK.class",
70             "com/memoire/vainstall/Language_fr_FR.class",
71             "com/memoire/vainstall/Language_it_IT.class",
72             "com/memoire/vainstall/Language_ja_JP.class",
73             "com/memoire/vainstall/AbstractInstall.class",
74             "com/memoire/vainstall/Setup.class",
75             "com/memoire/vainstall/VAClassLoader.class",
76             "com/memoire/vainstall/SetupFileFilter.class",
77             "com/memoire/vainstall/UpgradeInfo.class",
78             "com/memoire/vainstall/LogInfo.class",
79             "com/memoire/vainstall/Uninstall.class",
80             "com/memoire/vainstall/VAGlobals.class",
81             "com/memoire/vainstall/VAStats.class",
82             "com/memoire/vainstall/VAStep.class",
83             "com/memoire/vainstall/VAStepFactory.class",
84             "com/memoire/vainstall/VAWelcomeStep.class",
85             "com/memoire/vainstall/VAReadmeStep.class",
86             "com/memoire/vainstall/VALanguageStep.class",
87             "com/memoire/vainstall/VALicenseStep.class",
88             "com/memoire/vainstall/VALicenseKeyStep.class",
89             "com/memoire/vainstall/VADirectoryStep.class",
90             "com/memoire/vainstall/VAInstallStep.class",
91             "com/memoire/vainstall/VAUpgradeStep.class",
92             "com/memoire/vainstall/VAShortcutStep.class",
93             "com/memoire/vainstall/VAEndStep.class",
94             "com/memoire/vainstall/VAWizardInterface.class",
95             "com/memoire/vainstall/VALinkDebian.class",
96             "com/memoire/vainstall/VALinkLinux.class",
97             "com/memoire/vainstall/VAShortcutEntry.class",
98             "com/memoire/vainstall/VAConstant.class",
99             "com/memoire/vainstall/VALinkGnome.class",
100             "com/memoire/vainstall/VALinkKDE.class",
101             "com/memoire/vainstall/VALinkWindows.class",
102             "com/memoire/vainstall/VAFile.class",
103             "com/memoire/vainstall/LicenseKeySupport.class",
104             "com/memoire/vainstall/LicenseKeySupport$FieldInfo.class",
105             "com/memoire/vainstall/DefaultLicenseKeySupport.class",
106             "com/memoire/vainstall/TestLicenseKeySupport.class" };
107
108     private static final String JavaDoc[] JAR_FILES_JNISHORTCUT = new String JavaDoc[] {
109             "JNIWinShortcut.dll",
110             "com/memoire/vainstall/JNIWindowsShortcut.class" };
111
112     private static final String JavaDoc[] JAR_FILES_JNIREGISTRY = new String JavaDoc[] {
113             "ICE_JNIRegistry.dll",
114             "com/ice/jni/registry/NoSuchKeyException.class",
115             "com/ice/jni/registry/NoSuchValueException.class",
116             "com/ice/jni/registry/RegBinaryValue.class",
117             "com/ice/jni/registry/RegDWordValue.class",
118             "com/ice/jni/registry/RegMultiStringValue.class",
119             "com/ice/jni/registry/RegStringValue.class",
120             "com/ice/jni/registry/Registry.class",
121             "com/ice/jni/registry/RegistryException.class",
122             "com/ice/jni/registry/RegistryKey.class",
123             "com/ice/jni/registry/RegistryValue.class",
124             "com/ice/text/HexNumberFormat.class",
125             "com/ice/util/AWTUtilities.class",
126             "com/ice/util/ClassUtilities.class", "com/ice/util/FileLog.class",
127             "com/ice/util/HTTPUtilities.class", "com/ice/util/HexDump.class",
128             "com/ice/util/StringUtilities.class",
129             "com/ice/util/URLUtilities.class",
130             "com/ice/util/UserProperties.class" };
131
132     private static final String JavaDoc[] JAR_FILES_TEXT_UI = new String JavaDoc[] {
133             "com/memoire/vainstall/tui/Language_da_DK.class",
134             "com/memoire/vainstall/tui/Language_de_DE.class",
135             "com/memoire/vainstall/tui/Language_en_UK.class",
136             "com/memoire/vainstall/tui/Language_fr_FR.class",
137             "com/memoire/vainstall/tui/Language_it_IT.class",
138             "com/memoire/vainstall/tui/Language_ja_JP.class",
139             "com/memoire/vainstall/tui/NullOutputStream.class",
140             "com/memoire/vainstall/tui/TuiDefaultStep.class",
141             "com/memoire/vainstall/tui/TuiDirectoryStep.class",
142             "com/memoire/vainstall/tui/TuiInstallStep.class",
143             "com/memoire/vainstall/tui/TuiLanguageStep.class",
144             "com/memoire/vainstall/tui/TuiLicenseStep.class",
145             "com/memoire/vainstall/tui/TuiReadmeStep.class",
146             "com/memoire/vainstall/tui/TuiShortcutStep.class",
147             "com/memoire/vainstall/tui/TuiWelcomeStep.class",
148             "com/memoire/vainstall/tui/TuiWizard.class",
149             "com/memoire/vainstall/tui/VATextUI.class",
150             "com/memoire/vainstall/tui/TuiUpgradeStep.class",
151             "com/memoire/vainstall/tui/TuiEndStep.class" };
152
153     private static final String JavaDoc[] JAR_FILES_ANSI_UI = new String JavaDoc[] { // Requires
154
// files
155
// from
156
// JAR_FILES_TEXT_UI
157
"com/memoire/vainstall/aui/VAAnsiUI.class", };
158
159     private static final String JavaDoc[] JAR_FILES_UNATTENDED_UI = new String JavaDoc[] {
160             "com/memoire/vainstall/uui/VAUnattendedUI.class",
161             "com/memoire/vainstall/uui/UuiDefaultStep.class",
162             "com/memoire/vainstall/uui/UuiDirectoryStep.class",
163             "com/memoire/vainstall/uui/UuiEndStep.class",
164             "com/memoire/vainstall/uui/UuiInstallStep.class",
165             "com/memoire/vainstall/uui/UuiLanguageStep.class",
166             "com/memoire/vainstall/uui/UuiLicenseStep.class",
167             "com/memoire/vainstall/uui/UuiReadmeStep.class",
168             "com/memoire/vainstall/uui/UuiShortcutStep.class",
169             "com/memoire/vainstall/uui/UuiUpgradeStep.class",
170             "com/memoire/vainstall/uui/UuiWelcomeStep.class",
171             "com/memoire/vainstall/uui/UuiWizard.class" };
172
173     private static final String JavaDoc[] JAR_FILES_GRAPHIC_UI = new String JavaDoc[] {
174             "com/memoire/vainstall/gui/Language_da_DK.class",
175             "com/memoire/vainstall/gui/Language_de_DE.class",
176             "com/memoire/vainstall/gui/Language_en_UK.class",
177             "com/memoire/vainstall/gui/Language_fr_FR.class",
178             "com/memoire/vainstall/gui/Language_it_IT.class",
179             "com/memoire/vainstall/gui/Language_ja_JP.class",
180             "com/memoire/vainstall/gui/VABlueScreen.class",
181             "com/memoire/vainstall/gui/VABlueScreen$1.class",
182             "com/memoire/vainstall/gui/VAGraphicUI.class",
183             "com/memoire/vainstall/gui/VAWizard.class",
184             "com/memoire/vainstall/gui/VAWizard$1.class",
185             "com/memoire/vainstall/gui/VAPanel.class",
186             "com/memoire/vainstall/gui/VAWelcomePanel.class",
187             "com/memoire/vainstall/gui/VAImagePanel.class",
188             "com/memoire/vainstall/gui/VAInstallPanel.class",
189             "com/memoire/vainstall/gui/VALanguagePanel.class",
190             "com/memoire/vainstall/gui/VALicensePanel.class",
191             "com/memoire/vainstall/gui/VALicenseKeyPanel.class",
192             "com/memoire/vainstall/gui/VALicenseKeyPanel$1.class",
193             "com/memoire/vainstall/gui/VAReadmePanel.class",
194             "com/memoire/vainstall/gui/VADirectoryPanel.class",
195             "com/memoire/vainstall/gui/VADirectoryPanel$1.class",
196             "com/memoire/vainstall/gui/VAUpgradePanel.class",
197             "com/memoire/vainstall/gui/VAShortcutPanel.class",
198             "com/memoire/vainstall/gui/VAEndPanel.class", };
199
200     private static final String JavaDoc[] JAR_FILES_XTRA_UI = new String JavaDoc[] {
201             "com/memoire/vainstall/xui/Language_da_DK.class",
202             "com/memoire/vainstall/xui/Language_de_DE.class",
203             "com/memoire/vainstall/xui/Language_en_UK.class",
204             "com/memoire/vainstall/xui/Language_fr_FR.class",
205             "com/memoire/vainstall/xui/Language_it_IT.class",
206             "com/memoire/vainstall/xui/Language_ja_JP.class",
207             "com/memoire/vainstall/xui/XuiBlueScreen.class",
208             "com/memoire/vainstall/xui/XuiWizard.class",
209             "com/memoire/vainstall/xui/XuiAbstractPanel.class",
210             "com/memoire/vainstall/xui/XuiPanel.class",
211             "com/memoire/vainstall/xui/XuiImagePanel.class",
212             "com/memoire/vainstall/xui/XuiTitle.class",
213             "com/memoire/vainstall/xui/XuiButton.class",
214             "com/memoire/vainstall/xui/XuiButtonBorder.class",
215             "com/memoire/vainstall/xui/XuiLabel.class",
216             "com/memoire/vainstall/xui/XuiList.class",
217             "com/memoire/vainstall/xui/XuiRadioButton.class",
218             "com/memoire/vainstall/xui/XuiOptionPane.class",
219             "com/memoire/vainstall/xui/XuiWelcomePanel.class",
220             "com/memoire/vainstall/xui/XuiReadmePanel.class",
221             "com/memoire/vainstall/xui/XuiLicensePanel.class",
222             "com/memoire/vainstall/xui/XuiLicenseKeyPanel.class",
223             "com/memoire/vainstall/xui/XuiLicenseKeyPanel$1.class",
224             "com/memoire/vainstall/xui/XuiInstallPanel.class",
225             "com/memoire/vainstall/xui/XuiShortcutPanel.class",
226             "com/memoire/vainstall/xui/XuiUpgradePanel.class",
227             "com/memoire/vainstall/xui/XuiLanguagePanel.class",
228             "com/memoire/vainstall/xui/XuiEndPanel.class",
229             "com/memoire/vainstall/xui/XuiDirectoryPanel$1.class",
230             "com/memoire/vainstall/xui/XuiDirectoryPanel.class",
231             "com/memoire/vainstall/xui/VAXtraUI.class", };
232
233     // internal classes for package-specific pre-instal
234
// and post-install processing
235
private static final String JavaDoc[] JAR_FILES_CUSTOM_PRE_POST = new String JavaDoc[] {
236             "com/memoire/vainstall/AbstractCustomPrePost.class",
237             "com/memoire/vainstall/InputStreamToDetails.class", };
238
239     private File JavaDoc filelist_;
240
241     private String JavaDoc destPath_;
242
243     private String JavaDoc archMethod_;
244
245     private long archOffset_;
246
247     private long installClassOffset_;
248
249     private long installClassSize_;
250
251     private long jarSize_;
252
253     private String JavaDoc licenseKeySupportClassName_, encodeKey_;
254
255     private LicenseKeySupport licenseKeySupport_;
256
257     private String JavaDoc uiMode_;
258
259     private String JavaDoc uiBluescreen_;
260
261     private String JavaDoc uiBluescreenColor_;
262
263     private String JavaDoc image_;
264
265     private String JavaDoc appName_, appVersion_;
266
267     private String JavaDoc linkSectionName_, linkSectionIcon_, linkEntryName_,
268             linkEntryIcon_;
269
270     private String JavaDoc instClassName_;
271
272     private boolean createUninstallShortcut_;
273
274     private String JavaDoc[] targets_;
275
276     private String JavaDoc currentTarget_;
277
278     private String JavaDoc jarAlias_, jarPassphrase_, jarCodebase_, jarVendor_,
279             jarHomepage_;
280
281     private File JavaDoc license_;
282
283     private File JavaDoc readme_;
284
285     private ByteArrayOutputStream JavaDoc archiveInfos_;
286
287     private int archivecount_;
288
289     private Vector JavaDoc archiveEntryList_;
290
291     private String JavaDoc additionalFiles_;
292
293     // used for properties in install.class f.ex. language
294
private Properties JavaDoc installProperties = new Properties JavaDoc();
295
296     // used for package-specific pre/post install processing
297
private String JavaDoc customPrePostClassName_;
298
299     private String JavaDoc customPrePostJarfileName_;
300
301     private static String JavaDoc getJavaBinPath() {
302         String JavaDoc path = null;
303         for (int i = 0; i < JAVAC_SEARCH_PATH.length && path == null; i++) {
304             String JavaDoc aPath;
305             aPath = JAVA_HOME + File.separator + JAVAC_SEARCH_PATH[i];
306             if (new File JavaDoc(aPath).exists()) {
307                 path = aPath;
308             }
309         }
310         return path;
311     }
312
313     public VAArchiver() {
314         filelist_ = null;
315         destPath_ = null;
316         archMethod_ = null;
317         installClassOffset_ = -10987654321L;
318         installClassSize_ = -1234543210L;
319         archOffset_ = -1234567890L;
320         uiMode_ = null;
321         uiBluescreenColor_ = null;
322         uiBluescreen_ = null;
323         appName_ = appVersion_ = null;
324         linkSectionName_ = linkSectionIcon_ = linkEntryName_ = linkEntryIcon_ = null;
325         instClassName_ = null;
326         targets_ = new String JavaDoc[0];
327         jarAlias_ = jarPassphrase_ = jarCodebase_ = jarHomepage_ = jarVendor_ = null;
328         license_ = null;
329         readme_ = null;
330         archiveInfos_ = null;
331         archivecount_ = 0;
332         archiveEntryList_ = new Vector JavaDoc();
333         licenseKeySupportClassName_ = "com.memoire.vainstall.DefaultLicenseKeySupport";
334     }
335
336     public void start() {
337         if (!processProperties())
338             return;
339         try {
340             System.out.println();
341             System.out.println(VAGlobals.i18n("VAArchiver_CompressingFiles"));
342             archiveInfos_ = new ByteArrayOutputStream JavaDoc();
343             File JavaDoc zip = makeArchive("archive.zip");
344             zip.deleteOnExit();
345             System.out.println();
346             System.out.println(VAGlobals.i18n("VAArchiver_CreatingJarFiles"));
347             archiveInfos_.flush();
348             byte[] infosbytes = archiveInfos_.toByteArray();
349             File JavaDoc jar = makeJar("install.jar", zip, license_, readme_,
350                     infosbytes);
351             jarSize_ = jar.length();
352             archiveInfos_.close();
353             jar.deleteOnExit();
354             File JavaDoc installJavaFile = new File JavaDoc(instClassName_ + ".java");
355             installJavaFile.deleteOnExit();
356             File JavaDoc instClass = null;
357             boolean deleteInstallClass = true;
358             for (int i = 0; i < targets_.length; i++) {
359                 System.out.println();
360                 System.out.println(targets_[i]
361                         + VAGlobals.i18n("VAArchiver_Target"));
362                 currentTarget_ = targets_[i];
363                 System.out.println(VAGlobals
364                         .i18n("VAArchiver_GeneratingInstallClass"));
365                 // this pass of generation of installClass is to calculate
366
// installClassSize
367
// with TARGET_TYPE being set to its correct value
368
// well, this is not useful for jnlp, but it won't hurt
369
generateInstallCode(installJavaFile,
370                         "com/memoire/vainstall/resources/Install.vaitpl",
371                         "com/memoire/vainstall/VAClassLoader.class");
372                 System.out.println(VAGlobals
373                         .i18n("VAArchiver_CompilingInstallClass"));
374                 instClass = compile(installJavaFile.getName());
375                 installClassSize_ = instClass.length();
376                 VAGlobals
377                         .printDebug(" InstallClass size=" + installClassSize_);
378                 if ("jar".equals(targets_[i])) {
379                     File JavaDoc jarTarget = new File JavaDoc(instClassName_ + ".jar");
380                     File JavaDoc mfFile = new File JavaDoc(instClassName_ + ".mf");
381                     mfFile.deleteOnExit();
382                     System.out.println(VAGlobals
383                             .i18n("VAArchiver_CreatingManifestFile"));
384                     generateManifestFile(mfFile);
385                     // Build the JAR
386
System.out.println(VAGlobals
387                             .i18n("VAArchiver_UpdatingJarFile"));
388                     copy(jar, jarTarget);
389                     jar("uvfm", jarTarget, new File JavaDoc[] { mfFile, instClass });
390                     // Sign the JAR
391
if (jarAlias_ != null && !"".equals(jarAlias_.trim())
392                             && jarPassphrase_ != null
393                             && !"".equals(jarPassphrase_.trim())) {
394                         System.out.println(VAGlobals
395                                 .i18n("VAArchiver_SigningJarFile"));
396                         jarsign(jarPassphrase_, jarTarget, jarAlias_);
397                     }
398                 } else if ("jnlp".equals(targets_[i])) {
399                     File JavaDoc jnlpFile = new File JavaDoc(instClassName_ + ".jnlp");
400                     System.out.println(VAGlobals
401                             .i18n("VAArchiver_CreatingJnlpFile"));
402                     generateJnlpFile(jnlpFile);
403                 } else if ("java".equals(targets_[i])) {
404                     installClassOffset_ = -10987654321L;
405                     deleteInstallClass = false;
406                     if (archMethod_.equals("append")) {
407                         archOffset_ = instClass.length();
408                         VAGlobals.printDebug(VAGlobals
409                                 .i18n("VAArchiver_ArchiveOffset")
410                                 + archOffset_);
411                         generateInstallCode(
412                                 installJavaFile,
413                                 "com/memoire/vainstall/resources/Install.vaitpl",
414                                 "com/memoire/vainstall/VAClassLoader.class");
415                         System.out.println(VAGlobals
416                                 .i18n("VAArchiver_CompilingInstallClass"));
417                         compile(installJavaFile.getName());
418                         System.out.println(VAGlobals
419                                 .i18n("VAArchiver_AppendingArchive"));
420                         appendArchive(instClass);
421                     }
422                 } else if ("unix".equals(targets_[i])) {
423                     File JavaDoc unixShellFile = new File JavaDoc(instClassName_ + ".sh");
424                     installClassOffset_ = generateUnixInstallShell(
425                             unixShellFile,
426                             "com/memoire/vainstall/resources/Install-sh.vaitpl",
427                             instClass);
428                     VAGlobals.printDebug(VAGlobals
429                             .i18n("VAArchiver_InstallClassOffset")
430                             + installClassOffset_);
431                     if (archMethod_.equals("append")) {
432                         archOffset_ = unixShellFile.length();
433                         VAGlobals.printDebug(VAGlobals
434                                 .i18n("VAArchiver_ArchiveOffset")
435                                 + archOffset_);
436                         generateInstallCode(
437                                 installJavaFile,
438                                 "com/memoire/vainstall/resources/Install.vaitpl",
439                                 "com/memoire/vainstall/VAClassLoader.class");
440                         System.out.println(VAGlobals
441                                 .i18n("VAArchiver_CompilingInstallClass"));
442                         compile(installJavaFile.getName());
443                         generateUnixInstallShell(
444                                 unixShellFile,
445                                 "com/memoire/vainstall/resources/Install-sh.vaitpl",
446                                 instClass);
447                         System.out.println(VAGlobals
448                                 .i18n("VAArchiver_AppendingArchive"));
449                         appendArchive(unixShellFile);
450                     }
451                 } else if (("win95".equals(targets_[i]))
452                         || ("linux-i386".equals(targets_[i]))) {
453                     File JavaDoc nativeExeFile = null;
454                     if ("win95".equals(targets_[i]))
455                         nativeExeFile = new File JavaDoc(instClassName_ + ".exe");
456                     else if ("linux-i386".equals(targets_[i]))
457                         nativeExeFile = new File JavaDoc(instClassName_ + ".lin");
458                     installClassOffset_ = generateNativeInstallExe(
459                             nativeExeFile,
460                             "com/memoire/vainstall/resources/Install-"
461                                     + targets_[i] + "-exe.vaitpl", instClass);
462                     VAGlobals.printDebug(VAGlobals
463                             .i18n("VAArchiver_InstallClassOffset")
464                             + installClassOffset_);
465                     if (archMethod_.equals("append")) {
466                         archOffset_ = nativeExeFile.length();
467                         VAGlobals.printDebug(VAGlobals
468                                 .i18n("VAArchiver_ArchiveOffset")
469                                 + archOffset_);
470                         generateInstallCode(
471                                 installJavaFile,
472                                 "com/memoire/vainstall/resources/Install.vaitpl",
473                                 "com/memoire/vainstall/VAClassLoader.class");
474                         System.out.println(VAGlobals
475                                 .i18n("VAArchiver_CompilingInstallClass"));
476                         compile(installJavaFile.getName());
477                         generateNativeInstallExe(nativeExeFile,
478                                 "com/memoire/vainstall/resources/Install-"
479                                         + targets_[i] + "-exe.vaitpl",
480                                 instClass);
481                         System.out.println(VAGlobals
482                                 .i18n("VAArchiver_AppendingArchive"));
483                         appendArchive(nativeExeFile);
484                         System.out.println("win95 end");
485                     }
486                 }
487             }
488             if (instClass != null && deleteInstallClass)
489                 instClass.delete();
490         } catch (IOException JavaDoc e) {
491             e.printStackTrace();
492         }
493     }
494
495     File JavaDoc lnfFile_;
496
497     private boolean processProperties() {
498         String JavaDoc tempString;
499         RC_DIR = "com/memoire/vainstall/resources";
500         VAILOGO = RC_DIR + "/vailogo.gif";
501         // get information about choosen language
502
VAGlobals.setLanguage("default");
503         String JavaDoc tmp = VAProperties.PROPERTIES
504                 .getProperty("vainstall.destination.language");
505         if (tmp != null && !"".equals(tmp)) {
506             installProperties.put("vainstall.destination.language", tmp);
507         }
508         // the user want to use full path every times
509
String JavaDoc useFullPath = VAProperties.PROPERTIES
510                 .getProperty("vainstall.script.java.fullpath");
511         if (useFullPath != null && "true".equalsIgnoreCase(useFullPath)) {
512             installProperties.put("vainstall.script.java.fullpath", "true");
513         }
514         //the min max version
515
String JavaDoc minJavaVersion = VAProperties.PROPERTIES.getProperty(
516                 "vainstall.java.version.min", null);
517         String JavaDoc maxJavaVersion = VAProperties.PROPERTIES.getProperty(
518                 "vainstall.java.version.max", null);
519         //the vendor sun,ibm
520
String JavaDoc javaVendor = VAProperties.PROPERTIES.getProperty(
521                 "vainstall.java.vendor", null);
522         if (minJavaVersion != null && minJavaVersion.trim().length() > 0) {
523             installProperties.put("vainstall.java.version.min", minJavaVersion);
524         }
525         if (maxJavaVersion != null && maxJavaVersion.trim().length() > 0) {
526             installProperties.put("vainstall.java.version.max", maxJavaVersion);
527         }
528         if(javaVendor!=null && javaVendor.trim().length()>0){
529             installProperties.put("vainstall.java.vendor", javaVendor);
530         }
531         String JavaDoc key = "vainstall.java.download.url";
532         String JavaDoc val = VAProperties.PROPERTIES.getProperty(key, null);
533         if (val != null)
534             installProperties.put(key, val);
535
536         String JavaDoc shortcutsInInstallDir = VAProperties.PROPERTIES
537                 .getProperty("vainstall.shortcut.in.installdir");
538         if (shortcutsInInstallDir != null
539                 && "true".equalsIgnoreCase(shortcutsInInstallDir)) {
540             installProperties.put("vainstall.shortcut.in.installdir", "true");
541         }
542         tmp = VAProperties.PROPERTIES.getProperty("vainstall.archive.filelist");
543         if (tmp == null || "".equals(tmp)) {
544             System.err.println("vainstall.archive.filelist null");
545             return false;
546         }
547         filelist_ = new File JavaDoc(tmp);
548         if ((!filelist_.exists()) || (!filelist_.canRead())) {
549             System.err.println(VAGlobals.i18n("VAArchiver_CanNotRead")
550                     + filelist_);
551             return false;
552         }
553         destPath_ = VAProperties.PROPERTIES
554                 .getProperty("vainstall.destination.defaultPath");
555         if (destPath_ == null || "".equals(destPath_)) {
556             System.err.println("vainstall.destination.defaultPath null");
557             return false;
558         } else {
559             if (!checkVaiPath(destPath_)) {
560                 System.err.println("vainstall.destination.defaultPath"
561                         + VAGlobals.i18n("VAArchiver_HasIncorrectFormat"));
562                 return false;
563             }
564         }
565         tmp = VAProperties.PROPERTIES
566                 .getProperty("vainstall.destination.installMode");
567         if (("update".equals(tmp))) {
568             destPath_ = "[UPDATE]";
569         } else if (("module".equals(tmp))) {
570             destPath_ = "[MODULE]";
571         } else if (!"install".equals(tmp)) {
572             System.err.println(VAGlobals.i18n("VAArchiver_NoValidInstallmode")
573                     + ":" + VAGlobals.i18n("VAArchiver_DefaultingTo")
574                     + "install");
575         }
576         tmp = VAProperties.PROPERTIES
577                 .getProperty("vainstall.destination.targets");
578         if (tmp == null || "".equals(tmp)) {
579             System.err.println(VAGlobals.i18n("VAArchiver_NoTargetSpecified")
580                     + " (vainstall.destination.targets)");
581             return false;
582         }
583         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(tmp, ",");
584         Vector JavaDoc v = new Vector JavaDoc();
585         while (tok.hasMoreTokens()) {
586             String JavaDoc t = tok.nextToken().trim().toLowerCase();
587             if ((!"java".equals(t)) && (!"jar".equals(t))
588                     && (!"jnlp".equals(t)) && (!"unix".equals(t))
589                     && (!"win95".equals(t)) && (!"linux-i386".equals(t))) {
590                 System.err.println(VAGlobals.i18n("VAArchiver_UnknownTarget")
591                         + t);
592                 return false;
593             }
594             if (!v.contains(t))
595                 v.add(t);
596         }
597         // jar is needed for jnlp
598
if (v.contains("jnlp") && !v.contains("jar"))
599             v.add("jar");
600         targets_ = new String JavaDoc[v.size()];
601         // the order is important here
602
// jar first, exes after, java last
603
int i = 0;
604         if (v.contains("jar"))
605             targets_[i++] = "jar";
606         if (v.contains("jnlp"))
607             targets_[i++] = "jnlp";
608         if (v.contains("unix"))
609             targets_[i++] = "unix";
610         if (v.contains("linux-i386"))
611             targets_[i++] = "linux-i386";
612         if (v.contains("win95"))
613             targets_[i++] = "win95";
614         if (v.contains("java"))
615             targets_[i++] = "java";
616         if (v.contains("jar")) {
617             jarAlias_ = VAProperties.PROPERTIES
618                     .getProperty("vainstall.jarsigner.alias");
619             jarPassphrase_ = VAProperties.PROPERTIES
620                     .getProperty("vainstall.jarsigner.passphrase");
621         }
622         if (v.contains("jnlp")) {
623             jarCodebase_ = VAProperties.PROPERTIES
624                     .getProperty("vainstall.jnlp.codebase");
625             if (jarCodebase_ == null || "".equals(jarCodebase_)) {
626                 System.err.println("vainstall.jnlp.codebase null");
627                 return false;
628             }
629             jarHomepage_ = VAProperties.PROPERTIES
630                     .getProperty("vainstall.jnlp.homepage");
631             if (jarHomepage_ == null || "".equals(jarHomepage_)) {
632                 System.err.println("vainstall.jnlp.homepage null");
633                 return false;
634             }
635             jarVendor_ = VAProperties.PROPERTIES
636                     .getProperty("vainstall.jnlp.vendor");
637             if (jarVendor_ == null || "".equals(jarVendor_)) {
638                 System.err.println("vainstall.jnlp.vendor null");
639                 return false;
640             }
641         }
642         archMethod_ = VAProperties.PROPERTIES
643                 .getProperty("vainstall.archive.archivingMethod");
644         if (archMethod_ == null || "".equals(archMethod_)) {
645             archMethod_ = "append";
646         }
647         uiMode_ = VAProperties.PROPERTIES
648                 .getProperty("vainstall.destination.ui");
649         if (uiMode_ == null || "".equals(uiMode_)) {
650             uiMode_ = "graphic";
651         }
652         //lnf
653
if ("graphic".equals(uiMode_)) {
654             String JavaDoc lnfClass = VAProperties.PROPERTIES
655                     .getProperty("vainstall.lnf.class");
656             if (lnfClass != null) {
657                 installProperties.put("vainstall.lnf.class", lnfClass);
658                 String JavaDoc lnfFileName = VAProperties.PROPERTIES
659                         .getProperty("vainstall.lnf.jar");
660                 if (lnfFileName != null) {
661                     File JavaDoc jarFile = new File JavaDoc(lnfFileName);
662                     if (jarFile.exists()) {
663                         //we save the lnf file
664
lnfFile_ = jarFile;
665                         installProperties.put("vainstall.lnf.jar", jarFile
666                                 .getName());
667
668                     } else {
669                         System.err.println("lnf jar File does NOT exist "
670                                 + jarFile.getAbsolutePath());
671                     }
672                 }
673             }
674         }
675
676         uiBluescreen_ = VAProperties.PROPERTIES
677                 .getProperty("vainstall.destination.ui.bluescreen");
678         if (uiBluescreen_ == null || "".equals(uiBluescreen_)) {
679             uiBluescreen_ = "yes";
680         }
681         uiBluescreenColor_ = VAProperties.PROPERTIES
682                 .getProperty("vainstall.destination.ui.bluescreen.colour");
683         if ((uiBluescreenColor_ != null) && (!"".equals(uiBluescreenColor_))) {
684             try {
685                 Integer.parseInt(uiBluescreenColor_, 16);
686             } catch (NumberFormatException JavaDoc nfe) {
687                 System.err.println("vainstall.destination.ui.bluescreen.colour"
688                         + VAGlobals.i18n("VAArchiver_HasIncorrectFormat"));
689                 return false;
690             }
691         }
692         tmp = VAProperties.PROPERTIES
693                 .getProperty("vainstall.destination.ui.image");
694         if ((tmp == null) || (tmp.equals(""))) {
695             System.err.println("vainstall.destination.ui.image null:"
696                     + VAGlobals.i18n("VAArchiver_WillUseDefaultImage"));
697             // java.net.URL url = new
698
// java.net.URL("jar:file:///"+System.getProperties().getProperty("user.dir")+"/lib/vainstall.jar!/com/memoire/vainstall/resources/banner.gif");
699
image_ = RC_DIR + "/banner.gif";
700         } else {
701             image_ = tmp;
702             File JavaDoc img = new File JavaDoc(image_);
703             if ((!img.exists()) || (!img.canRead())) {
704                 System.err.println(VAGlobals.i18n("VAArchiver_CanNotRead")
705                         + image_ + ":"
706                         + VAGlobals.i18n("VAArchiver_WillUseDefaultImage"));
707                 image_ = RC_DIR + "/banner.gif";
708             }
709         }
710         appName_ = VAProperties.PROPERTIES
711                 .getProperty("vainstall.destination.appName");
712         if (appName_ == null || "".equals(appName_)) {
713             System.err.println("vainstall.destination.appName null");
714             return false;
715         }
716         appVersion_ = VAProperties.PROPERTIES
717                 .getProperty("vainstall.destination.appVersion");
718         if (appVersion_ == null || "".equals(appVersion_)) {
719             System.out
720                     .println("vainstall.destination.appVersion null, assuming it is an unversioned plugin");
721             // return false;
722
}
723         linkSectionName_ = VAProperties.PROPERTIES
724                 .getProperty("vainstall.destination.linkSectionName");
725         if (linkSectionName_ == null || "".equals(linkSectionName_)) {
726             System.err.println("vainstall.destination.linkSectionName null:"
727                     + VAGlobals.i18n("VAArchiver_DefaultingTo")
728                     + "\"Applications\"");
729             linkSectionName_ = "Applications";
730         }
731         linkSectionIcon_ = VAProperties.PROPERTIES
732                 .getProperty("vainstall.destination.linkSectionIcon");
733         if ((linkSectionIcon_ == null) || "".equals(linkSectionIcon_)) {
734             System.err.println("vainstall.destination.linkSectionIcon null");
735             linkSectionIcon_ = "";
736         }
737         linkEntryName_ = VAProperties.PROPERTIES
738                 .getProperty("vainstall.destination.linkEntryName");
739         if (linkEntryName_ == null || "".equals(linkEntryName_)) {
740             System.err.println("vainstall.destination.linkEntryName null:"
741                     + VAGlobals.i18n("VAArchiver_DefaultingTo") + "\""
742                     + appName_ + "\"");
743             linkEntryName_ = appName_;
744         }
745         linkEntryIcon_ = VAProperties.PROPERTIES
746                 .getProperty("vainstall.destination.linkEntryIcon");
747         if ((linkEntryIcon_ == null) || "".equals(linkEntryIcon_)) {
748             System.err.println("vainstall.destination.linkEntryIcon null");
749             linkEntryIcon_ = "";
750         }
751         tempString = VAProperties.PROPERTIES
752                 .getProperty("vainstall.destination.createUninstallShortcut");
753         if (tempString != null && tempString.equals("yes"))
754             createUninstallShortcut_ = true;
755         else
756             createUninstallShortcut_ = false;
757         instClassName_ = VAProperties.PROPERTIES
758                 .getProperty("vainstall.archive.installClassName");
759         if (instClassName_ == null || "".equals(instClassName_)) {
760             instClassName_ = "Install_" + appName_;
761         }
762         tmp = VAProperties.PROPERTIES.getProperty("vainstall.archive.license");
763         if (tmp == null || "".equals(tmp)) {
764             System.err.println("vainstall.archive.license null");
765             return false;
766         }
767         license_ = new File JavaDoc(tmp);
768         if ((!license_.exists()) || (!license_.canRead())) {
769             System.err.println(VAGlobals.i18n("VAArchiver_CanNotRead")
770                     + license_);
771             return false;
772         }
773         try {
774             InputStream JavaDoc licenseStream = new FileInputStream JavaDoc(license_);
775             String JavaDoc licenseEncoding = VAProperties.PROPERTIES
776                     .getProperty("vainstall.archive.license.encoding");
777             if (licenseEncoding != null && licenseEncoding.equals("") == false) {
778                 try {
779                     InputStreamReader JavaDoc isrLicense = new InputStreamReader JavaDoc(
780                             licenseStream, licenseEncoding);
781                 } catch (UnsupportedEncodingException JavaDoc exc) {
782                     System.err.println("Unsuported encoding for license!");
783                     return false;
784                 }
785             }
786         } catch (Exception JavaDoc exc) {
787             System.err.println("Problems reading license file!");
788             return false;
789         }
790         tmp = VAProperties.PROPERTIES
791                 .getProperty("vainstall.license.key.support");
792         if (tmp != null && !"".equals(tmp)) {
793             licenseKeySupportClassName_ = tmp;
794         }
795         encodeKey_ = VAProperties.PROPERTIES
796                 .getProperty("vainstall.license.key.support.encode.key");
797         additionalFiles_ = VAProperties.PROPERTIES
798                 .getProperty("vainstall.additional.files");
799         Class JavaDoc cls = null;
800         try {
801             cls = Class.forName(licenseKeySupportClassName_);
802         } catch (Exception JavaDoc ex) {
803             if ((cls == null) && (additionalFiles_ != null)) {
804                 StringTokenizer JavaDoc fmi = new StringTokenizer JavaDoc(additionalFiles_, ",");
805                 while (fmi.hasMoreTokens()) {
806                     StringTokenizer JavaDoc fm = new StringTokenizer JavaDoc(fmi.nextToken(),
807                             "!");
808                     String JavaDoc classFound = fm.nextToken();
809                     if ((classFound != null)
810                             && (classFound.indexOf(licenseKeySupportClassName_) > -1)) {
811                         try {
812                             URLClassLoader JavaDoc urlcl = new URLClassLoader JavaDoc(
813                                     new URL JavaDoc[] { new File JavaDoc(classFound)
814                                             .getParentFile().toURL() });
815                             cls = urlcl.loadClass(licenseKeySupportClassName_);
816                         } catch (Exception JavaDoc ex2) {
817                             System.out
818                                     .println("License key support could not be initialized with specific URLCLassLoader"
819                                             + ex2);
820                         }
821                         break;
822                     }
823                 }
824             }
825         }
826         if (cls == null) {
827             throw new RuntimeException JavaDoc(
828                     "License key support could not be initialized: ");
829         }
830         try {
831             System.out.println(cls.getName());
832             licenseKeySupport_ = (LicenseKeySupport) cls.newInstance();
833         } catch (Exception JavaDoc ex) {
834             System.err.println("LicenseKeySupport can't be instantiated" + ex);
835         }
836         tmp = VAProperties.PROPERTIES.getProperty("vainstall.archive.readme");
837         if (tmp == null || "".equals(tmp)) {
838             System.err.println("vainstall.archive.readme null");
839             return false;
840         }
841         readme_ = new File JavaDoc(tmp);
842         if ((!readme_.exists()) || (!readme_.canRead())) {
843             System.err.println(VAGlobals.i18n("VAArchiver_CanNotRead")
844                     + readme_);
845             return false;
846         }
847         try {
848             InputStream JavaDoc readmeStream = new FileInputStream JavaDoc(readme_);
849             String JavaDoc readmeEncoding = VAProperties.PROPERTIES
850                     .getProperty("vainstall.archive.readme.encoding");
851             if (readmeEncoding != null && readmeEncoding.equals("") == false) {
852                 try {
853                     InputStreamReader JavaDoc isrReadme = new InputStreamReader JavaDoc(
854                             readmeStream, readmeEncoding);
855                 } catch (UnsupportedEncodingException JavaDoc exc) {
856                     System.err.println("Unsupported encoding for readme!");
857                     return false;
858                 }
859             }
860         } catch (Exception JavaDoc exc) {
861             System.err.println("Problems reading readme file!");
862             return false;
863         }
864         // custom pre/post processing
865
customPrePostClassName_ = VAProperties.PROPERTIES
866                 .getProperty("vainstall.install.customprepost.className");
867         if (customPrePostClassName_ == null) {
868             customPrePostClassName_ = "";
869         } else if (!"com.memoire.vainstall.AbstractCustomPrePost"
870                 .equals(customPrePostClassName_)) {
871             customPrePostJarfileName_ = VAProperties.PROPERTIES
872                     .getProperty("vainstall.install.customprepost.jarFileName");
873             if (customPrePostJarfileName_ == null
874                     || "".equals(customPrePostJarfileName_)) {
875                 System.err
876                         .println("vainstall.install.customprepost.jarFileName null");
877                 return false;
878             }
879         }
880         installProperties.put("vainstall.install.customprepost.className",
881                 customPrePostClassName_);
882         return true;
883     }
884
885     private File JavaDoc makeArchive(String JavaDoc filename) throws IOException JavaDoc {
886         LineNumberReader JavaDoc files = new LineNumberReader JavaDoc(new FileReader JavaDoc(filelist_));
887         String JavaDoc line = files.readLine();
888         if (line == null) {
889             files.close();
890             throw new IOException JavaDoc(VAGlobals.i18n("VAArchiver_EmptyFilelist"));
891         }
892         File JavaDoc zip = new File JavaDoc(filename);
893         File JavaDoc parent = zip.getParentFile();
894         if ((parent != null) && (!parent.canWrite()))
895             throw new IOException JavaDoc(zip + VAGlobals.i18n("VAArchiver_NotWritten"));
896         ZipOutputStream JavaDoc stream = new ZipOutputStream JavaDoc(new GZIPOutputStream JavaDoc(
897                 licenseKeySupport_.encodeStream(new FileOutputStream JavaDoc(zip),
898                         encodeKey_)));
899         stream.setLevel(0);
900         Vector JavaDoc archiveExeList = new Vector JavaDoc();
901         FileNameGroup fileNameGroup = null;
902         ObjectOutputStream JavaDoc infos = new ObjectOutputStream JavaDoc(archiveInfos_);
903         Vector JavaDoc scripts = new Vector JavaDoc();
904         while (line != null) {
905             if ((!line.trim().equals("")) && (!line.trim().startsWith("#"))) {
906                 if (line.trim().startsWith("{")) {
907                     String JavaDoc script = addScript(files, scripts);
908                     if (script != null)
909                         archiveExeList.add("[SCRIPT]" + script);
910                     line = files.readLine();
911                     continue;
912                 }
913                 fileNameGroup = new FileNameGroup(line);
914                 File JavaDoc file = new File JavaDoc(convertToLocalPath(fileNameGroup
915                         .getOrigin()));
916                 String JavaDoc entryName = fileNameGroup.getDestination();
917                 if (!checkVaiPath(entryName))
918                     throw new IOException JavaDoc(VAGlobals
919                             .i18n("VAArchiver_InvalidPathInFilelist")
920                             + files.getLineNumber() + "): " + entryName);
921                 if (fileNameGroup.isExecutable()) {
922                     archiveExeList.add(entryName);
923                 }
924                 FileFilter JavaDoc filter = null;
925                 try {
926                     filter = fileNameGroup.getFileFilter();
927                 } catch (IllegalArgumentException JavaDoc iae) {
928                     throw new IOException JavaDoc(VAGlobals
929                             .i18n("VAArchiver_InFilelist")
930                             + files.getLineNumber() + "): " + iae.getMessage());
931                 }
932                 addToArchive(stream, file, filter, entryName, fileNameGroup
933                         .isRecursive() ? Integer.MAX_VALUE : 1);
934             }
935             line = files.readLine();
936         }
937         stream.close();
938         files.close();
939         infos.writeInt(archivecount_);
940         infos.writeObject(scripts);
941         infos.writeObject(archiveExeList);
942         infos.flush();
943         return zip;
944     }
945
946     private String JavaDoc addScript(LineNumberReader JavaDoc files, Vector JavaDoc scripts)
947             throws IOException JavaDoc {
948         String JavaDoc destName = null;
949         int blocLineNbr = files.getLineNumber();
950         String JavaDoc line = files.readLine();
951         String JavaDoc cmd = null;
952         Hashtable JavaDoc keywords = new Hashtable JavaDoc();
953         if (line != null)
954             cmd = line.trim();
955         System.out.println(" script: " + cmd);
956         line = files.readLine();
957         while ((line != null) && (!line.trim().equals("}"))) {
958             line = line.trim();
959             int ind = line.indexOf('=');
960             if ((ind > 0) && ((ind + 1) < line.length())) {
961                 keywords.put(line.substring(0, ind), line.substring(ind + 1));
962             }
963             line = files.readLine();
964         }
965         if ((cmd == null) || (line == null))
966             throw new IOException JavaDoc("Unterminated script bloc : line "
967                     + blocLineNbr);
968         //fred a tout casse
969
//The options are not reorder. Only the Class and the Jar properties
970
// are
971
//tested :they are required
972
if (cmd.equals("JavaLauncher")) {
973             String JavaDoc k = (String JavaDoc) keywords.get("Class");
974             if (k == null)
975                 throw new IOException JavaDoc("Invalid script bloc : line "
976                         + blocLineNbr + " (no Class)");
977             else
978                 System.out.println(" Class=" + k);
979
980         } else if (cmd.equals("JarLauncher")) {
981             String JavaDoc k = (String JavaDoc) keywords.get("Jar");
982             if (k != null) {
983                 System.out.println(" Jar=" + k);
984             } else
985                 throw new IOException JavaDoc("Invalid script bloc : line "
986                         + blocLineNbr + " (no Jar)");
987         } else {
988             throw new IOException JavaDoc("Unsupported script : line " + blocLineNbr
989                     + " (" + cmd + ")");
990         }
991         //valeur par defaut
992
// if((cmd.equals("JarLauncher") || cmd.equals("JavaLauncher")) &&
993
// (keywords.get("JavaMode")==null){
994
// keywords.put("JavaModel","console");
995
// }
996
String JavaDoc k = (String JavaDoc) keywords.get("ScriptName");
997         if (k != null) {
998             System.out.println(" ScriptName=" + k);
999             destName = k;
1000        } else
1001            throw new IOException JavaDoc("Invalid script bloc : line " + blocLineNbr
1002                    + " (no ScriptName)");
1003        //build the new string to add to the script list
1004
//PropertyName
1005
//propertyValue
1006
String JavaDoc lineSep = "\n";
1007        StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
1008        //the command
1009
buf.append("CMD").append(lineSep).append(cmd);
1010        for (Iterator JavaDoc it = keywords.entrySet().iterator(); it.hasNext();) {
1011            Map.Entry JavaDoc e = (Map.Entry JavaDoc) it.next();
1012            if (e.getValue() != null) {
1013                buf.append(lineSep).append((String JavaDoc) e.getKey()).append(lineSep)
1014                        .append((String JavaDoc) e.getValue());
1015            }
1016        }
1017        if (buf.length() > 0)
1018            scripts.add(buf.toString());
1019        return destName;
1020    }
1021
1022    private void addToArchive(ZipOutputStream JavaDoc stream, File JavaDoc file,
1023            FileFilter JavaDoc filter, String JavaDoc entryName, int recurseDepth)
1024            throws IOException JavaDoc {
1025        if (file.exists()) {
1026            if (file.isDirectory()) {
1027                File JavaDoc[] ls = file.listFiles(filter);
1028                if (ls.length == 0) {
1029                    // empty dir
1030
if (archiveEntryList_.contains(entryName + "/")) {
1031                        System.err.println(" warning: duplicate entry: "
1032                                + entryName + "/" + ". Skipping.");
1033                    } else {
1034                        System.out.println(" " + file);
1035                        ZipEntry JavaDoc newEntry = new ZipEntry JavaDoc(entryName + "/");
1036                        stream.putNextEntry(newEntry);
1037                        stream.closeEntry();
1038                        archiveEntryList_.add(entryName + "/");
1039                    }
1040                }
1041                for (int i = 0; i < ls.length; i++) {
1042                    String JavaDoc ename = ls[i].getAbsolutePath();
1043                    ename = entryName
1044                            + ename.substring(file.getAbsolutePath().length());
1045                    ename = convertToGenericPath(ename);
1046                    if (ename.startsWith("/"))
1047                        ename = ename.substring(1);
1048                    if (recurseDepth > 0)
1049                        addToArchive(stream, ls[i], filter, ename,
1050                                recurseDepth - 1);
1051                }
1052            } else if (archiveEntryList_.contains(entryName)) {
1053                System.err.println(" warning: duplicate entry: " + entryName
1054                        + ". Skipping.");
1055            } else {
1056                System.out.println(" " + file);
1057                /*
1058                 * String s=" "+file; while(s.length() <79) s+=' ';
1059                 * System.out.print(s+"\r");
1060                 */

1061                archivecount_++;
1062                ZipEntry JavaDoc newEntry = new ZipEntry JavaDoc(entryName);
1063                stream.putNextEntry(newEntry);
1064                FileInputStream JavaDoc in = new FileInputStream JavaDoc(file);
1065                byte[] buf = new byte[2048];
1066                int read = in.read(buf, 0, buf.length);
1067                while (read > 0) {
1068                    stream.write(buf, 0, read);
1069                    read = in.read(buf, 0, buf.length);
1070                }
1071                in.close();
1072                stream.closeEntry();
1073                archiveEntryList_.add(entryName);
1074            }
1075        } else {
1076            System.err.println(" error: file " + file
1077                    + " does not exist. Skipping.");
1078        }
1079    }
1080
1081    private String JavaDoc convertToLocalPath(String JavaDoc entry) throws IOException JavaDoc {
1082        String JavaDoc res = Setup.expandDirectory(entry, true, null);
1083        if (res == null)
1084            throw new IOException JavaDoc("Invalid path: " + entry);
1085        return res.replace('/', File.separatorChar);
1086    }
1087
1088    private String JavaDoc convertToGenericPath(String JavaDoc line) {
1089        return line.replace(File.separatorChar, '/');
1090    }
1091
1092    private void generateInstallCode(File JavaDoc javaFile, String JavaDoc instTemplate,
1093            String JavaDoc classLoader) throws IOException JavaDoc {
1094        String JavaDoc tempString;
1095        PrintWriter JavaDoc writer = new PrintWriter JavaDoc(new FileWriter JavaDoc(javaFile));
1096        int read = 0;
1097        byte[] buf = new byte[128];
1098        // LineNumberReader reader=new LineNumberReader(new
1099
// FileReader(instTemplate));
1100
InputStream JavaDoc is = getClass().getResourceAsStream("/" + instTemplate);
1101        InputStreamReader JavaDoc isr = new InputStreamReader JavaDoc(is);
1102        LineNumberReader JavaDoc reader = new LineNumberReader JavaDoc(isr);
1103        System.out.println(VAGlobals
1104                .i18n("VAArchiver_GeneratingInstallClassCode"));
1105        String JavaDoc line = reader.readLine();
1106        while ((line != null) && (!line.startsWith("// --> InstallClassName"))) {
1107            writer.println(line);
1108            line = reader.readLine();
1109        }
1110        writer.println("public class " + instClassName_ + " {");
1111        writer.println(" private static final Class installClass=new "
1112                + instClassName_ + "().getClass();");
1113        line = reader.readLine();
1114        while ((line != null) && (!line.startsWith("// --> ArchivingMethod"))) {
1115            writer.println(line);
1116            line = reader.readLine();
1117        }
1118        writer.println(" private static String ARCH_METHOD=\"" + archMethod_
1119                + "\";");
1120        line = reader.readLine();
1121        while ((line != null) && (!line.startsWith("// --> TargetType"))) {
1122            writer.println(line);
1123            line = reader.readLine();
1124        }
1125        writer.println(" private static String TARGET_TYPE=\""
1126                + currentTarget_ + "\";");
1127        line = reader.readLine();
1128        while ((line != null)
1129                && (!line.startsWith("// --> InstallClassOffset"))) {
1130            writer.println(line);
1131            line = reader.readLine();
1132        }
1133        writer.println(" private static long ICLASS_OFFSET="
1134                + installClassOffset_ + "L;");
1135        line = reader.readLine();
1136        while ((line != null) && (!line.startsWith("// --> InstallClassSize"))) {
1137            writer.println(line);
1138            line = reader.readLine();
1139        }
1140        if (installClassSize_ != archOffset_)
1141            writer.println(" private static long ICLASS_SIZE="
1142                    + installClassSize_ + "L;");
1143        else
1144            writer.println(" private static long ICLASS_SIZE=-1234543210L;");
1145        line = reader.readLine();
1146        while ((line != null) && (!line.startsWith("// --> ArchiveOffset"))) {
1147            writer.println(line);
1148            line = reader.readLine();
1149        }
1150        writer.println(" private static long ARCH_OFFSET=" + archOffset_
1151                + "L;");
1152        line = reader.readLine();
1153        while ((line != null) && (!line.startsWith("// --> JarSize"))) {
1154            writer.println(line);
1155            line = reader.readLine();
1156        }
1157        writer.println(" private static long JAR_SIZE=" + jarSize_ + "L;");
1158        line = reader.readLine();
1159        while ((line != null) && (!line.startsWith("// --> UIMode"))) {
1160            writer.println(line);
1161            line = reader.readLine();
1162        }
1163        writer.println(" private static String UI_MODE=\"" + uiMode_ + "\";");
1164        line = reader.readLine();
1165        while ((line != null) && (!line.startsWith("// --> UIBluescreen"))) {
1166            writer.println(line);
1167            line = reader.readLine();
1168        }
1169        writer.println(" private static String UI_BLUESCREEN=\""
1170                + uiBluescreen_ + "\";");
1171        line = reader.readLine();
1172        while ((line != null) && (!line.startsWith("// --> UIBluescreenColor"))) {
1173            writer.println(line);
1174            line = reader.readLine();
1175        }
1176        writer.println(" private static String UI_BLUESCREEN_COLOR=\""
1177                + uiBluescreenColor_ + "\";");
1178        line = reader.readLine();
1179        while ((line != null) && (!line.startsWith("// --> DestPath"))) {
1180            writer.println(line);
1181            line = reader.readLine();
1182        }
1183        writer.println(" private static String DEST_PATH=\"" + destPath_
1184                + "\";");
1185        line = reader.readLine();
1186        while ((line != null) && (!line.startsWith("// --> AppInfo"))) {
1187            writer.println(line);
1188            line = reader.readLine();
1189        }
1190        writer
1191                .println(" private static String APP_NAME=\"" + appName_
1192                        + "\";");
1193        if (appVersion_ != null)
1194            writer.println(" private static String APP_VERSION=\""
1195                    + appVersion_ + "\";");
1196        else
1197            writer.println(" private static String APP_VERSION=null;");
1198        line = reader.readLine();
1199        while ((line != null) && (!line.startsWith("// --> LinkInfos"))) {
1200            System.out.println("fred " + line);
1201            writer.println(line);
1202            line = reader.readLine();
1203        }
1204        writer.println(" private static String LINK_SECTION_NAME=\""
1205                + linkSectionName_ + "\";");
1206        writer.println(" private static String LINK_SECTION_ICON=\""
1207                + linkSectionIcon_ + "\";");
1208        writer.println(" private static String LINK_ENTRY_NAME=\""
1209                + linkEntryName_ + "\";");
1210        writer.println(" private static String LINK_ENTRY_ICON=\""
1211                + linkEntryIcon_ + "\";");
1212        if (createUninstallShortcut_)
1213            tempString = "true";
1214        else
1215            tempString = "false";
1216        writer.println(" private static boolean CREATE_UNINSTALL_SHORTCUT="
1217                + tempString + ";");
1218        line = reader.readLine();
1219        while ((line != null) && (!line.startsWith("// --> LicenseKey"))) {
1220            writer.println(line);
1221            line = reader.readLine();
1222        }
1223        writer.println(" private static String LICENSE_KEY_SUPPORT_NAME=\""
1224                + licenseKeySupportClassName_ + "\";");
1225        System.out.println(VAGlobals.i18n("VAArchiver_AppendingClassloader"));
1226        line = reader.readLine();
1227        while ((line != null) && (!line.startsWith("// --> ClassLoader"))) {
1228            writer.println(line);
1229            line = reader.readLine();
1230        }
1231        InputStream JavaDoc isClassLoader = getClass().getResourceAsStream(
1232                "/" + classLoader);
1233        // System.out.println(" CLASSLOADER = "+"/"+classLoader);
1234
writer.println(" private static String[] CL_CLASS={");
1235        read = isClassLoader.read(buf);
1236        while (read > 0) {
1237            writer.println("\"" + codeLine(buf, read) + "\",");
1238            read = isClassLoader.read(buf);
1239        }
1240        isClassLoader.close();
1241        writer.println(" };\n}");
1242        reader.close();
1243        writer.close();
1244        // HFALK
1245
is.close();
1246        isr.close();
1247    }
1248
1249    private void generateJnlpFile(File JavaDoc jnlpFile) throws IOException JavaDoc {
1250        PrintWriter JavaDoc out = new PrintWriter JavaDoc(
1251                new BufferedWriter JavaDoc(new OutputStreamWriter JavaDoc(new FileOutputStream JavaDoc(
1252                        jnlpFile), "UTF-8")));
1253        out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
1254        out.println("<jnlp spec=\"1.0\"");
1255        out.println(" codebase=\"" + jarCodebase_ + "\"");
1256        out.println(" HREF=\"" + instClassName_ + ".jnlp\">");
1257        out.println(" <information>");
1258        if (appVersion_ != null)
1259            out.println(" <title>" + appName_ + " " + appVersion_
1260                    + " Installer</title>");
1261        else
1262            out.println(" <title>" + appName_ + " " + " Installer</title>");
1263        out.println(" <vendor>" + jarVendor_ + "</vendor>");
1264        out.println(" <homepage HREF=\"" + jarHomepage_ + "\"/>");
1265        if (appVersion_ != null)
1266            out.println(" <description>Installer for " + appName_ + " "
1267                    + appVersion_ + "</description>");
1268        else
1269            out.println(" <description>Installer for " + appName_
1270                    + "</description>");
1271        //out.println("<icon HREF=\"alma-jnlp.png\" width=\"128\"
1272
// height=\"128\"/>");
1273
out.println(" <offline/>");
1274        out.println(" </information>");
1275        out.println(" <resources>");
1276        out.println(" <j2se version=\"1.3 1.2\"/>");
1277        out.println(" <jar HREF=\"" + instClassName_ + ".jar\"/>");
1278        out.println(" <property name=\"DEBUG\" value=\"yes\"/>");
1279        out.println(" </resources>");
1280        out.println(" <security>");
1281        out.println(" <all-permissions/>");
1282        out.println(" </security>");
1283        out.println(" <application-desc main-class=\"" + instClassName_
1284                + "\"/>");
1285        out.println("</jnlp>");
1286        out.close();
1287    }
1288
1289    private void generateManifestFile(File JavaDoc mfFile) throws IOException JavaDoc {
1290        PrintWriter JavaDoc out = new PrintWriter JavaDoc(new BufferedWriter JavaDoc(
1291                new OutputStreamWriter JavaDoc(new FileOutputStream JavaDoc(mfFile), "UTF-8")));
1292        out.println("Manifest-Version: 1.0");
1293        out.println("Main-Class: " + instClassName_);
1294        out.close();
1295    }
1296
1297    private long generateUnixInstallShell(File JavaDoc unixShellFile,
1298            String JavaDoc instTemplate, File JavaDoc instClassFile) throws IOException JavaDoc {
1299        FileOutputStream JavaDoc byteWriter = new FileOutputStream JavaDoc(unixShellFile);
1300        InputStream JavaDoc is = getClass().getResourceAsStream("/" + instTemplate);
1301        InputStreamReader JavaDoc isr = new InputStreamReader JavaDoc(is);
1302        LineNumberReader JavaDoc reader = new LineNumberReader JavaDoc(isr);
1303        String JavaDoc content = "";
1304        String JavaDoc installClassStartStr = "000000000000";
1305        NumberFormat JavaDoc nf = NumberFormat.getInstance(Locale.US);
1306        nf.setGroupingUsed(false);
1307        nf.setMinimumIntegerDigits(installClassStartStr.length());
1308        int installClassStartPos = 0;
1309        long installClassOffset = 0;
1310        System.out.println(VAGlobals.i18n("VAArchiver_GenerateInstallShell"));
1311        String JavaDoc line = reader.readLine();
1312        while ((line != null) && (!line.startsWith("# InstallClassStart"))) {
1313            content += line + "\n";
1314            line = reader.readLine();
1315        }
1316        content += "InstallClassStart=" + installClassStartStr + "\n";
1317        installClassStartPos = content.length() - 1 - 1
1318                - installClassStartStr.length();
1319        line = reader.readLine();
1320        while ((line != null) && (!line.startsWith("# InstallClassSize"))) {
1321            content += line + "\n";
1322            line = reader.readLine();
1323        }
1324        content += new String JavaDoc("InstallClassSize=" + instClassFile.length()
1325                + "\n");
1326        line = reader.readLine();
1327        while ((line != null) && (!line.startsWith("# InstallClassName"))) {
1328            content += line + "\n";
1329            line = reader.readLine();
1330        }
1331        content += new String JavaDoc("InstallClassName=" + instClassName_ + "\n");
1332        line = reader.readLine();
1333        while ((line != null) && (!line.startsWith("# Install class"))) {
1334            content += line + "\n";
1335            line = reader.readLine();
1336        }
1337        if (line != null)
1338            content += line + "\n";
1339        byteWriter.write(content.substring(0, installClassStartPos + 1)
1340                .getBytes());
1341        byteWriter.write(nf.format(content.length()).getBytes());
1342        byteWriter.write(content.substring(
1343                installClassStartPos + 1 + installClassStartStr.length())
1344                .getBytes());
1345        installClassOffset = content.length();
1346        content = null;
1347        FileInputStream JavaDoc classStream = new FileInputStream JavaDoc(instClassFile);
1348        byte[] buf = new byte[2048];
1349        int read = classStream.read(buf);
1350        while (read > 0) {
1351            byteWriter.write(buf, 0, read);
1352            read = classStream.read(buf);
1353        }
1354        classStream.close();
1355        reader.close();
1356        byteWriter.close();
1357        return installClassOffset;
1358    }
1359
1360    private void shiftArray(byte[] array) {
1361        for (int i = 0; i < (array.length - 1); i++)
1362            array[i] = array[i + 1];
1363        array[array.length - 1] = 0;
1364    }
1365
1366    private long generateNativeInstallExe(File JavaDoc nativeInstallFile,
1367            String JavaDoc instTemplate, File JavaDoc instClassFile) throws IOException JavaDoc {
1368        // method: we look for the items "clname_here", "clstart_here" et
1369
// "clstop_here_".
1370
// -> We read bytes one by one, but we write them with a 12 bytes
1371
// latency,
1372
// so we can have a 12 bytes "preview" window to test "clstart_here" or
1373
// "clstop_here_".
1374
// We replace "clname_here" with the name of the class and we end with a
1375
// dot.
1376
// We replace "clstart_here" with the size of the template file (the
1377
// class
1378
// is appended after it).
1379
// We remember the position of "clstop_here_", and we finish with the
1380
// file
1381
// in normal mode (bulk copy). We append the class, we calculate the
1382
// total
1383
// size in bytes, and we write it in place of "clstop_here_" (of which
1384
// we
1385
// know the position). We then only have to write all these bytes in the
1386
// destination file.
1387
// FileInputStream reader=new FileInputStream(instTemplate);
1388
InputStream JavaDoc reader = getClass().getResourceAsStream("/" + instTemplate);
1389        // InputStreamReader reader = new InputStreamReader(is);
1390
// System.out.println("generateNativeInstallExe = /"+instTemplate);
1391
// System.out.println("reader length="+reader.available());
1392
ByteArrayOutputStream JavaDoc content = new ByteArrayOutputStream JavaDoc();
1393        String JavaDoc installClassVarStr = "000000000000";
1394        byte[] buf = new byte[installClassVarStr.length()];
1395        NumberFormat JavaDoc nf = NumberFormat.getInstance(Locale.US);
1396        nf.setGroupingUsed(false);
1397        nf.setMinimumIntegerDigits(installClassVarStr.length());
1398        int installClassStopPos = 0;
1399        long installClassOffset = reader.available();
1400        int position = 0;
1401        System.out.println(VAGlobals.i18n("VAArchiver_GenerateInstallExe"));
1402        // read the 12 first bytes
1403
reader.read(buf, 0, buf.length);
1404        // set write position with a 12 bytes latency
1405
position = 1;
1406        // look for the 3 anchors clname, clstart and clstop
1407
for (int n = 0; n < 3; n++) {
1408            // buf contains the preview window that we want to test.
1409
while ((!new String JavaDoc(buf).equals("clname_here_"))
1410                    && (!new String JavaDoc(buf).equals("clstart_here"))
1411                    && (!new String JavaDoc(buf).equals("clstop_here_"))) {
1412                content.write(buf[0]);
1413                // read a byte
1414
int nextb = reader.read();
1415                position++;
1416                shiftArray(buf);
1417                // write a byte
1418
buf[buf.length - 1] = (byte) nextb;
1419            }
1420            if (new String JavaDoc(buf).equals("clname_here_")) {
1421                VAGlobals.printDebug(" clname_here_ found at "
1422                        + (position - 1));
1423                StringBuffer JavaDoc clnameBuffer = new StringBuffer JavaDoc(64);
1424                clnameBuffer.append(instClassName_);
1425                for (int i = clnameBuffer.length() - 1; i < 64; i++) {
1426                    clnameBuffer.append('.');
1427                }
1428                byte[] clnameBytes = clnameBuffer.toString().getBytes();
1429                // write name of the class in place of "clname_here"
1430
for (int i = 0; i < 64; i++) {
1431                    content.write(clnameBytes[i]);
1432                    position++;
1433                }
1434                // skip 64 bytes ("clstart_here")
1435
reader.skip(64 - buf.length);
1436                // read 12 next bytes
1437
reader.read(buf, 0, buf.length);
1438            } else if (new String JavaDoc(buf).equals("clstart_here")) {
1439                VAGlobals.printDebug(" clstart_here found at "
1440                        + (position - 1));
1441                buf = nf.format(installClassOffset).getBytes();
1442                // write size of template file in place of "clstart_here"
1443
for (int i = 0; i < buf.length; i++) {
1444                    content.write(buf[i]);
1445                    position++;
1446                }
1447                // read 12 next bytes
1448
reader.read(buf, 0, buf.length);
1449            } else if (new String JavaDoc(buf).equals("clstop_here_")) {
1450                VAGlobals.printDebug(" clstop_here_ found at "
1451                        + (position - 1));
1452                // found "clstop_here_": remember it's position
1453
installClassStopPos = position - 1;
1454                // write "clstop_here_" (we don't know yet its value)
1455
content.write(buf);
1456                position += 12;
1457                // read 12 next bytes
1458
reader.read(buf, 0, buf.length);
1459            }
1460        }
1461        content.write(buf);
1462        // finish read/write in the normal way
1463
buf = new byte[2048];
1464        int read = reader.read(buf);
1465        while (read > 0) {
1466            content.write(buf, 0, read);
1467            read = reader.read(buf);
1468        }
1469        reader.close();
1470        // append the class
1471
FileInputStream JavaDoc classStream = new FileInputStream JavaDoc(instClassFile);
1472        read = classStream.read(buf);
1473        while (read > 0) {
1474            content.write(buf, 0, read);
1475            read = classStream.read(buf);
1476        }
1477        classStream.close();
1478        content.close();
1479        // the total size of written bytes is put in place of "clstop_here_"
1480
byte[] contentBytes = content.toByteArray();
1481        installClassVarStr = nf.format(contentBytes.length);
1482        byte[] installClassVarBytes = installClassVarStr.getBytes();
1483        for (int i = 0; i < installClassVarBytes.length; i++) {
1484            contentBytes[installClassStopPos + i] = installClassVarBytes[i];
1485        }
1486        // write whole content in destination file
1487
FileOutputStream JavaDoc out = new FileOutputStream JavaDoc(nativeInstallFile);
1488        out.write(contentBytes);
1489        out.close();
1490        return installClassOffset;
1491    }
1492
1493    private void appendArchive(File JavaDoc instClass) throws IOException JavaDoc {
1494        FileOutputStream JavaDoc out = new FileOutputStream JavaDoc(instClass.getName(), true);
1495        FileInputStream JavaDoc zipStream = new FileInputStream JavaDoc("install.jar");
1496        byte[] buf = new byte[2048];
1497        int read = zipStream.read(buf);
1498        while (read > 0) {
1499            out.write(buf, 0, read);
1500            read = zipStream.read(buf);
1501        }
1502        zipStream.close();
1503        out.close();
1504    }
1505
1506    private void copy(File JavaDoc fin, File JavaDoc fout) throws IOException JavaDoc {
1507        FileOutputStream JavaDoc out = null;
1508        FileInputStream JavaDoc in = null;
1509        try {
1510            out = new FileOutputStream JavaDoc(fout);
1511            in = new FileInputStream JavaDoc(fin);
1512            byte[] buf = new byte[2048];
1513            int read = in.read(buf);
1514            while (read > 0) {
1515                out.write(buf, 0, read);
1516                read = in.read(buf);
1517            }
1518        } catch (IOException JavaDoc _e) {
1519            throw _e;
1520        } finally {
1521            if (in != null)
1522                in.close();
1523            if (out != null)
1524                out.close();
1525        }
1526    }
1527
1528    private void jar(String JavaDoc options, File JavaDoc jarFile, File JavaDoc[] files)
1529            throws IOException JavaDoc {
1530        Process JavaDoc p = null;
1531        Vector JavaDoc argsv = new Vector JavaDoc();
1532        argsv.add(getJavaBinPath() + File.separator + "jar");
1533        if (options != null && !options.equals(""))
1534            argsv.add(options);
1535        argsv.add(jarFile.getName());
1536        for (int i = 0; i < files.length; i++)
1537            argsv.add(files[i].getName());
1538        String JavaDoc[] args = new String JavaDoc[argsv.size()];
1539        for (int i = 0; i < args.length; i++)
1540            args[i] = (String JavaDoc) argsv.get(i);
1541        try {
1542            p = Runtime.getRuntime().exec(args);
1543            p.waitFor();
1544        } catch (Exception JavaDoc rte) {
1545            throw new IOException JavaDoc(
1546                    "Runtime exception: check if you have installed the JDK and run java from the JDK\n"
1547                            + "Exception message: " + rte.getMessage());
1548        }
1549        printCmdOutput(p, "jar");
1550        if (p.exitValue() != 0)
1551            throw new RuntimeException JavaDoc(" abnormal exit");
1552    }
1553
1554    private void jarsign(String JavaDoc passphrase, File JavaDoc jarFile, String JavaDoc alias)
1555            throws IOException JavaDoc {
1556        Process JavaDoc p = null;
1557        try {
1558            p = Runtime.getRuntime().exec(
1559                    new String JavaDoc[] {
1560                            JDK_HOME + File.separator + "bin" + File.separator
1561                                    + "jarsigner", "-storepass", passphrase,
1562                            jarFile.getName(), alias });
1563            p.waitFor();
1564        } catch (Exception JavaDoc rte) {
1565            throw new IOException JavaDoc(
1566                    "Runtime exception: check if you have installed the JDK and run java from the JDK\n"
1567                            + "Exception message: " + rte.getMessage());
1568        }
1569        printCmdOutput(p, "jarsign");
1570        if (p.exitValue() != 0)
1571            throw new RuntimeException JavaDoc(" abnormal exit");
1572    }
1573
1574    private File JavaDoc compile(String JavaDoc javafile) throws IOException JavaDoc {
1575        File JavaDoc classFile = null;
1576        Process JavaDoc p = null;
1577        try {
1578            p = Runtime.getRuntime().exec(
1579                    new String JavaDoc[] { getJavaBinPath() + File.separator + JAVAC,
1580                            javafile });
1581            p.waitFor();
1582        } catch (Exception JavaDoc rte) {
1583            throw new IOException JavaDoc(
1584                    "Runtime exception: check if you have installed the JDK and run java from the JDK\n"
1585                            + "Exception message: " + rte.getMessage());
1586        }
1587        printCmdOutput(p, "javac");
1588        if (p.exitValue() != 0)
1589            throw new RuntimeException JavaDoc(" abnormal exit");
1590        classFile = new File JavaDoc(javafile.substring(0, javafile.lastIndexOf('.'))
1591                + ".class");
1592        System.out.println(" " + classFile + " " + classFile.exists());
1593        //if( !classFile.exists() ) throw new IOException("could not compile
1594
// "+javafile);
1595
return classFile;
1596    }
1597
1598    private void printCmdOutput(Process JavaDoc p, String JavaDoc cmdName) throws IOException JavaDoc {
1599        BufferedReader JavaDoc psIn = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(p
1600                .getInputStream()));
1601        BufferedReader JavaDoc psErr = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(p
1602                .getErrorStream()));
1603        int n = 0;
1604        System.out.println(" --- start " + cmdName + " ---");
1605        String JavaDoc inLine = psIn.readLine();
1606        String JavaDoc errLine = psErr.readLine();
1607        while ((inLine != null) || (errLine != null)) {
1608            if (inLine != null)
1609                System.out.println(" " + inLine);
1610            if (errLine != null)
1611                System.err.println(" " + errLine);
1612            inLine = psIn.readLine();
1613            errLine = psErr.readLine();
1614        }
1615        psIn.close();
1616        psErr.close();
1617        System.out.println(" --- end " + cmdName + " ---");
1618    }
1619
1620    private File JavaDoc makeJar(String JavaDoc filename, File JavaDoc archive, File JavaDoc license,
1621            File JavaDoc readme, byte[] archiveInfos) throws IOException JavaDoc {
1622        File JavaDoc jar = new File JavaDoc(filename);
1623        JarOutputStream JavaDoc out = new JarOutputStream JavaDoc(new FileOutputStream JavaDoc(jar));
1624        // copy common files to jar file
1625
copyInternalToJar(out, JAR_FILES_COMMON);
1626        copyInternalToJar(out, JAR_FILES_JNIREGISTRY);
1627        copyInternalToJar(out, JAR_FILES_JNISHORTCUT);
1628        // text and ansi uis are always provided
1629
copyInternalToJar(out, JAR_FILES_TEXT_UI);
1630        copyInternalToJar(out, JAR_FILES_ANSI_UI);
1631        if (uiMode_.equals("graphic"))
1632            copyInternalToJar(out, JAR_FILES_GRAPHIC_UI);
1633        if (uiMode_.equals("xtra"))
1634            copyInternalToJar(out, JAR_FILES_XTRA_UI);
1635        if (uiMode_.equals("unattended"))
1636            copyInternalToJar(out, JAR_FILES_UNATTENDED_UI);
1637        // custom pre/post processing classes
1638
if (customPrePostClassName_.length() > 0) {
1639            copyInternalToJar(out, JAR_FILES_CUSTOM_PRE_POST);
1640            // copy from jar file only if developer used new class
1641
if (!"com.memoire.vainstall.AbstractCustomPrePost"
1642                    .equals(customPrePostClassName_)) {
1643                copyJarFilesToJar(out, customPrePostJarfileName_);
1644            }
1645        }
1646        // archive infos
1647
addToJar(out, new ByteArrayInputStream JavaDoc(archiveInfos),
1648                "com/memoire/vainstall/archive_infos", archiveInfos.length);
1649        // archive.zip
1650
addToJar(out, new FileInputStream JavaDoc(archive),
1651                "com/memoire/vainstall/archive.zip", archive.length());
1652        // license
1653
InputStream JavaDoc licenseStream = new FileInputStream JavaDoc(license);
1654        String JavaDoc licenseEncoding = VAProperties.PROPERTIES
1655                .getProperty("vainstall.archive.license.encoding");
1656        if (licenseEncoding == null || licenseEncoding.equals("") == true) {
1657            // Use default encoding
1658
licenseEncoding = new InputStreamReader JavaDoc(licenseStream)
1659                    .getEncoding();
1660        }
1661        InputStreamReader JavaDoc isrLicense = new InputStreamReader JavaDoc(licenseStream,
1662                licenseEncoding);
1663        addToJarEncoded(out, isrLicense, "com/memoire/vainstall/license.txt",
1664                license.length());
1665        // readme
1666
InputStream JavaDoc readmeStream = new FileInputStream JavaDoc(readme);
1667        String JavaDoc readmeEncoding = VAProperties.PROPERTIES
1668                .getProperty("vainstall.archive.readme.encoding");
1669        if (readmeEncoding == null || readmeEncoding.equals("") == true) {
1670            // Use default encoding
1671
readmeEncoding = new InputStreamReader JavaDoc(readmeStream).getEncoding();
1672        }
1673        InputStreamReader JavaDoc isrReadme = new InputStreamReader JavaDoc(readmeStream,
1674                readmeEncoding);
1675        addToJarEncoded(out, isrReadme, "com/memoire/vainstall/readme.txt",
1676                readme.length());
1677        // image
1678
InputStream JavaDoc invaiimage = null;
1679        try {
1680            invaiimage = new FileInputStream JavaDoc(new File JavaDoc(image_));
1681        } catch (Exception JavaDoc exc) {
1682            image_ = "/" + image_;
1683            invaiimage = getClass().getResourceAsStream(image_);
1684        }
1685        if (invaiimage == null) {
1686            invaiimage = getClass().getResourceAsStream(
1687                    "com/memoire/vainstall/resources/banner.gif");
1688            image_ = "com/memoire/vainstall/resources/banner.gif";
1689        }
1690        if (invaiimage != null) {
1691            addToJar(out, invaiimage,
1692                    "com/memoire/vainstall/resources/banner.gif", invaiimage
1693                            .available());
1694        }
1695        // vailogo
1696
InputStream JavaDoc invailogo = getClass().getResourceAsStream("/" + VAILOGO);
1697        addToJar(out, invailogo, VAILOGO, invailogo.available());
1698        // add file to control various settings like language
1699
// should be used instead of all those parameters to the setup routine
1700
ByteArrayOutputStream JavaDoc poutstream = new ByteArrayOutputStream JavaDoc();
1701        installProperties.store(poutstream, VAGlobals.NAME + " "
1702                + VAGlobals.VERSION);
1703        ByteArrayInputStream JavaDoc pinstream = new ByteArrayInputStream JavaDoc(poutstream
1704                .toByteArray());
1705        addToJar(out, pinstream,
1706                "com/memoire/vainstall/resources/vainstall.properties",
1707                poutstream.toByteArray().length);
1708        if (lnfFile_ != null) {
1709            System.out.println("add lnf jar file: "
1710                    + lnfFile_.getAbsolutePath());
1711            addToJar(out, new FileInputStream JavaDoc(lnfFile_),
1712                    "com/memoire/vainstall/resources/" + lnfFile_.getName(),
1713                    lnfFile_.length());
1714        }
1715        System.out.println("additionalFiles");
1716        if (additionalFiles_ != null) {
1717            StringTokenizer JavaDoc fmi = new StringTokenizer JavaDoc(additionalFiles_, ",");
1718            while (fmi.hasMoreTokens()) {
1719                StringTokenizer JavaDoc fm = new StringTokenizer JavaDoc(fmi.nextToken(), "!");
1720                File JavaDoc sf = new File JavaDoc(fm.nextToken());
1721                String JavaDoc df = fm.nextToken();
1722                addToJar(out, new FileInputStream JavaDoc(sf), df, sf.length());
1723            }
1724            System.out.println("additionalFiles FIN");
1725        }
1726        out.close();
1727        return jar;
1728    }
1729
1730    /**
1731     * Copy all files from a jar file from inside a jar file to a target jar
1732     * file
1733     *
1734     * @param out
1735     * JarOutputStream
1736     * @param jarSourceName
1737     * String
1738     */

1739    private void copyInternalToJar(JarOutputStream JavaDoc out, String JavaDoc[] JAR_FILES)
1740            throws IOException JavaDoc {
1741        for (int i = 0; i < JAR_FILES.length; i++) {
1742            String JavaDoc sourceName = JAR_FILES[i];
1743            if (sourceName.endsWith(".jar")) {
1744                copyJarFilesToJar(out, sourceName);
1745            } else {
1746                InputStream JavaDoc is = getClass().getResourceAsStream(
1747                        "/" + sourceName);
1748                if (is == null) {
1749                    System.out
1750                            .println("Cannot add the resource "
1751                                    + sourceName
1752                                    + " to the jar, since it cannot be found (bummer!)");
1753                } else {
1754                    addToJar(out, is, sourceName, is.available());
1755                }
1756            }
1757        } // endfor
1758
}
1759
1760    /**
1761     * Copy all files from a jar file from inside a jar file to a target jar
1762     * file
1763     *
1764     * @param out
1765     * JarOutputStream
1766     * @param jarSourceName
1767     * String
1768     */

1769    private void copyJarFilesToJar(JarOutputStream JavaDoc out, String JavaDoc jarSourceName)
1770            throws IOException JavaDoc {
1771        byte[] buffer = new byte[2048];
1772        InputStream JavaDoc isJar = getClass().getResourceAsStream("/" + jarSourceName);
1773        JarInputStream JavaDoc zin = new JarInputStream JavaDoc(isJar);
1774        JarEntry JavaDoc entry = null;
1775        while ((entry = zin.getNextJarEntry()) != null) {
1776            ByteArrayOutputStream JavaDoc bos = new ByteArrayOutputStream JavaDoc();
1777            while (true) {
1778                int read = zin.read(buffer);
1779                if (read == -1)
1780                    break;
1781                bos.write(buffer, 0, read);
1782            }
1783            ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(bos
1784                    .toByteArray());
1785            addToJar(out, bais, entry.getName(), bos.toByteArray().length);
1786            bos.close();
1787            zin.closeEntry();
1788        } // endwhile
1789
zin.close();
1790        isJar.close();
1791    }
1792
1793    private void addToJar(JarOutputStream JavaDoc out, InputStream JavaDoc in,
1794            String JavaDoc entryName, long length) throws IOException JavaDoc {
1795        byte[] buf = new byte[2048];
1796        ZipEntry JavaDoc entry = new ZipEntry JavaDoc(entryName);
1797        CRC32 JavaDoc crc = new CRC32 JavaDoc();
1798        entry.setSize(length);
1799        entry.setCrc(crc.getValue());
1800        out.putNextEntry(entry);
1801        int read = in.read(buf);
1802        while (read > 0) {
1803            crc.update(buf, 0, read);
1804            out.write(buf, 0, read);
1805            read = in.read(buf);
1806        }
1807        entry.setCrc(crc.getValue());
1808        // System.out.println(" entry = "+entry.getName()+" "+entry.getSize());
1809
in.close();
1810        out.closeEntry();
1811    }
1812
1813    private void addToJarEncoded(JarOutputStream JavaDoc out, InputStreamReader JavaDoc isr,
1814            String JavaDoc entryName, long length) throws IOException JavaDoc {
1815        StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
1816        Reader JavaDoc reader = new BufferedReader JavaDoc(isr);
1817        int ch;
1818        while ((ch = reader.read()) > -1) {
1819            buffer.append((char) ch);
1820        }
1821        reader.close();
1822        isr.close();
1823        ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
1824        OutputStreamWriter JavaDoc osw = new OutputStreamWriter JavaDoc(baos, "UTF8");
1825        osw.write(buffer.toString());
1826        osw.flush();
1827        ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(baos.toByteArray());
1828        addToJar(out, bais, entryName, length);
1829    }
1830
1831    // private static long
1832
private boolean checkVaiPath(String JavaDoc dir) {
1833        int index = dir.indexOf(']');
1834        if (!dir.startsWith("["))
1835            return true;
1836        if (index <= 2)
1837            return false;
1838        String JavaDoc prefix = dir.substring(1, index).trim();
1839        /*
1840         * if( ("HOME".equals(prefix))|| ("PROGRAM".equals(prefix)) ) return
1841         * true;
1842         */

1843        if ("HOME".equals(prefix) || "PROGRAM".equals(prefix)
1844                || prefix.startsWith("ENV{")) {
1845            return true;
1846        }
1847        if ((prefix.length() == 2) && (prefix.endsWith(":"))
1848                && (Character.isLetter(prefix.charAt(0))))
1849            return true;
1850        return false;
1851    }
1852
1853    private String JavaDoc codeLine(byte[] data, int siz) {
1854        String JavaDoc res = null;
1855        byte[] convert = new byte[2 * siz];
1856        for (int i = 0; i < siz; i++) {
1857            convert[2 * i] = (byte) (65 + (data[i] & 0x0F));
1858            convert[2 * i + 1] = (byte) (65 + (data[i] & 0xF0) / 16);
1859        }
1860        res = new String JavaDoc(convert);
1861        return res;
1862    }
1863}
1864
1865class FileNameGroup {
1866    String JavaDoc originBase_, destBase_, commonPath_, extensions_;
1867
1868    boolean executable_;
1869
1870    boolean recursive_;
1871
1872    public FileNameGroup(String JavaDoc line) {
1873        executable_ = false;
1874        recursive_ = true;
1875        if (line.startsWith("(E)")) {
1876            line = line.substring(3);
1877            executable_ = true;
1878        }
1879        if (line.startsWith("(N)")) {
1880            line = line.substring(3);
1881            recursive_ = false;
1882        }
1883        StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(new String JavaDoc(line), "|", true);
1884        originBase_ = tok.nextToken();
1885        if (originBase_.endsWith("/"))
1886            originBase_ = originBase_.substring(0, originBase_.length() - 1);
1887        tok.nextToken();
1888        destBase_ = tok.nextToken();
1889        if (destBase_.equals("|"))
1890            destBase_ = null;
1891        else {
1892            if (destBase_.endsWith("/"))
1893                destBase_ = destBase_.substring(0, destBase_.length() - 1);
1894            tok.nextToken();
1895        }
1896        extensions_ = null;
1897        commonPath_ = null;
1898        if (tok.hasMoreTokens()) {
1899            commonPath_ = tok.nextToken();
1900            if (commonPath_.equals("|"))
1901                commonPath_ = null;
1902            if (tok.hasMoreTokens()) {
1903                if (commonPath_ != null)
1904                    tok.nextToken();
1905                if (tok.hasMoreTokens())
1906                    extensions_ = tok.nextToken();
1907            }
1908        }
1909    }
1910
1911    public String JavaDoc getOrigin() {
1912        if (commonPath_ == null)
1913            return originBase_;
1914        return originBase_ + "/" + commonPath_;
1915    }
1916
1917    public String JavaDoc getDestination() {
1918        if ((destBase_ == null) && (commonPath_ == null))
1919            return "";
1920        if (destBase_ == null)
1921            return commonPath_;
1922        if (commonPath_ == null)
1923            return destBase_;
1924        return destBase_ + "/" + commonPath_;
1925    }
1926
1927    public FileFilter JavaDoc getFileFilter() throws IllegalArgumentException JavaDoc {
1928        String JavaDoc[] ext = null;
1929        if (extensions_ != null) {
1930            StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(extensions_, ",");
1931            ext = new String JavaDoc[t.countTokens()];
1932            for (int i = 0; i < ext.length; i++) {
1933                ext[i] = t.nextToken();
1934                if ((ext[i].length() >= 2) && (ext[i].startsWith("*")))
1935                    ext[i] = ext[i].substring(1);
1936                else if ((ext[i].length() >= 3) && (ext[i].startsWith("!*")))
1937                    ext[i] = "!" + ext[i].substring(2);
1938                else
1939                    throw new IllegalArgumentException JavaDoc("invalid pattern: "
1940                            + ext[i]);
1941            }
1942        }
1943        return new VaiFileFilter(ext);
1944    }
1945
1946    public boolean isExecutable() {
1947        return executable_;
1948    }
1949
1950    public boolean isRecursive() {
1951        return recursive_;
1952    }
1953}
1954
1955class VaiFileFilter implements FileFilter JavaDoc {
1956    String JavaDoc[] ext_;
1957
1958    public VaiFileFilter(String JavaDoc[] ext) {
1959        ext_ = ext;
1960    }
1961
1962    public boolean accept(File JavaDoc pathname) {
1963        boolean a = true;
1964        if (ext_ == null)
1965            return true;
1966        String JavaDoc p = pathname.getName();
1967        for (int i = 0; i < ext_.length; i++) {
1968            if (ext_[i].startsWith("!")) {
1969                a = a && (!p.endsWith(ext_[i].substring(1)));
1970            } else {
1971                a = a && (p.endsWith(ext_[i]));
1972            }
1973        }
1974        return a;
1975    }
1976}
Popular Tags