0001: /**
0002: * $RCSfile: VAArchiver.java,v $
0003: * @creation 26/01/99
0004: * @modification $Date: 2005/05/14 10:14:17 $
0005: */package com.memoire.vainstall;
0006:
0007: import java.io.BufferedReader;
0008: import java.io.BufferedWriter;
0009: import java.io.ByteArrayInputStream;
0010: import java.io.ByteArrayOutputStream;
0011: import java.io.File;
0012: import java.io.FileFilter;
0013: import java.io.FileInputStream;
0014: import java.io.FileOutputStream;
0015: import java.io.FileReader;
0016: import java.io.FileWriter;
0017: import java.io.IOException;
0018: import java.io.InputStream;
0019: import java.io.InputStreamReader;
0020: import java.io.LineNumberReader;
0021: import java.io.ObjectOutputStream;
0022: import java.io.OutputStreamWriter;
0023: import java.io.PrintWriter;
0024: import java.io.Reader;
0025: import java.io.UnsupportedEncodingException;
0026: import java.net.URL;
0027: import java.net.URLClassLoader;
0028: import java.text.NumberFormat;
0029: import java.util.Hashtable;
0030: import java.util.Iterator;
0031: import java.util.Locale;
0032: import java.util.Map;
0033: import java.util.Properties;
0034: import java.util.StringTokenizer;
0035: import java.util.Vector;
0036: import java.util.jar.JarEntry;
0037: import java.util.jar.JarInputStream;
0038: import java.util.jar.JarOutputStream;
0039: import java.util.zip.CRC32;
0040: import java.util.zip.GZIPOutputStream;
0041: import java.util.zip.ZipEntry;
0042: import java.util.zip.ZipOutputStream;
0043:
0044: /**
0045: * @version $Id: VAArchiver.java,v 1.43 2005/05/14 10:14:17 deniger Exp $
0046: * @author Axel von Arnim
0047: */
0048: public class VAArchiver {
0049: private static final String JAVA_HOME = System
0050: .getProperty("java.home");
0051:
0052: // search path is appended to JAVA_HOME to determine the location of the
0053: // javac executable. Don't include trailing or leading slashes
0054: private static final String[] JAVAC_SEARCH_PATH = new String[] {
0055: "../bin", "bin" };
0056:
0057: private static final String JAVAC = "javac";
0058:
0059: private static final String JDK_HOME = System
0060: .getProperty("java.home")
0061: + File.separator + "..";
0062:
0063: private static String RC_DIR = null;
0064:
0065: private static String VAILOGO = null;
0066:
0067: private static final String[] JAR_FILES_COMMON = new String[] {
0068: "com/memoire/vainstall/Language_da_DK.class",
0069: "com/memoire/vainstall/Language_de_DE.class",
0070: "com/memoire/vainstall/Language_en_UK.class",
0071: "com/memoire/vainstall/Language_fr_FR.class",
0072: "com/memoire/vainstall/Language_it_IT.class",
0073: "com/memoire/vainstall/Language_ja_JP.class",
0074: "com/memoire/vainstall/AbstractInstall.class",
0075: "com/memoire/vainstall/Setup.class",
0076: "com/memoire/vainstall/VAClassLoader.class",
0077: "com/memoire/vainstall/SetupFileFilter.class",
0078: "com/memoire/vainstall/UpgradeInfo.class",
0079: "com/memoire/vainstall/LogInfo.class",
0080: "com/memoire/vainstall/Uninstall.class",
0081: "com/memoire/vainstall/VAGlobals.class",
0082: "com/memoire/vainstall/VAStats.class",
0083: "com/memoire/vainstall/VAStep.class",
0084: "com/memoire/vainstall/VAStepFactory.class",
0085: "com/memoire/vainstall/VAWelcomeStep.class",
0086: "com/memoire/vainstall/VAReadmeStep.class",
0087: "com/memoire/vainstall/VALanguageStep.class",
0088: "com/memoire/vainstall/VALicenseStep.class",
0089: "com/memoire/vainstall/VALicenseKeyStep.class",
0090: "com/memoire/vainstall/VADirectoryStep.class",
0091: "com/memoire/vainstall/VAInstallStep.class",
0092: "com/memoire/vainstall/VAUpgradeStep.class",
0093: "com/memoire/vainstall/VAShortcutStep.class",
0094: "com/memoire/vainstall/VAEndStep.class",
0095: "com/memoire/vainstall/VAWizardInterface.class",
0096: "com/memoire/vainstall/VALinkDebian.class",
0097: "com/memoire/vainstall/VALinkLinux.class",
0098: "com/memoire/vainstall/VAShortcutEntry.class",
0099: "com/memoire/vainstall/VAConstant.class",
0100: "com/memoire/vainstall/VALinkGnome.class",
0101: "com/memoire/vainstall/VALinkKDE.class",
0102: "com/memoire/vainstall/VALinkWindows.class",
0103: "com/memoire/vainstall/VAFile.class",
0104: "com/memoire/vainstall/LicenseKeySupport.class",
0105: "com/memoire/vainstall/LicenseKeySupport$FieldInfo.class",
0106: "com/memoire/vainstall/DefaultLicenseKeySupport.class",
0107: "com/memoire/vainstall/TestLicenseKeySupport.class" };
0108:
0109: private static final String[] JAR_FILES_JNISHORTCUT = new String[] {
0110: "JNIWinShortcut.dll",
0111: "com/memoire/vainstall/JNIWindowsShortcut.class" };
0112:
0113: private static final String[] JAR_FILES_JNIREGISTRY = new String[] {
0114: "ICE_JNIRegistry.dll",
0115: "com/ice/jni/registry/NoSuchKeyException.class",
0116: "com/ice/jni/registry/NoSuchValueException.class",
0117: "com/ice/jni/registry/RegBinaryValue.class",
0118: "com/ice/jni/registry/RegDWordValue.class",
0119: "com/ice/jni/registry/RegMultiStringValue.class",
0120: "com/ice/jni/registry/RegStringValue.class",
0121: "com/ice/jni/registry/Registry.class",
0122: "com/ice/jni/registry/RegistryException.class",
0123: "com/ice/jni/registry/RegistryKey.class",
0124: "com/ice/jni/registry/RegistryValue.class",
0125: "com/ice/text/HexNumberFormat.class",
0126: "com/ice/util/AWTUtilities.class",
0127: "com/ice/util/ClassUtilities.class",
0128: "com/ice/util/FileLog.class",
0129: "com/ice/util/HTTPUtilities.class",
0130: "com/ice/util/HexDump.class",
0131: "com/ice/util/StringUtilities.class",
0132: "com/ice/util/URLUtilities.class",
0133: "com/ice/util/UserProperties.class" };
0134:
0135: private static final String[] JAR_FILES_TEXT_UI = new String[] {
0136: "com/memoire/vainstall/tui/Language_da_DK.class",
0137: "com/memoire/vainstall/tui/Language_de_DE.class",
0138: "com/memoire/vainstall/tui/Language_en_UK.class",
0139: "com/memoire/vainstall/tui/Language_fr_FR.class",
0140: "com/memoire/vainstall/tui/Language_it_IT.class",
0141: "com/memoire/vainstall/tui/Language_ja_JP.class",
0142: "com/memoire/vainstall/tui/NullOutputStream.class",
0143: "com/memoire/vainstall/tui/TuiDefaultStep.class",
0144: "com/memoire/vainstall/tui/TuiDirectoryStep.class",
0145: "com/memoire/vainstall/tui/TuiInstallStep.class",
0146: "com/memoire/vainstall/tui/TuiLanguageStep.class",
0147: "com/memoire/vainstall/tui/TuiLicenseStep.class",
0148: "com/memoire/vainstall/tui/TuiReadmeStep.class",
0149: "com/memoire/vainstall/tui/TuiShortcutStep.class",
0150: "com/memoire/vainstall/tui/TuiWelcomeStep.class",
0151: "com/memoire/vainstall/tui/TuiWizard.class",
0152: "com/memoire/vainstall/tui/VATextUI.class",
0153: "com/memoire/vainstall/tui/TuiUpgradeStep.class",
0154: "com/memoire/vainstall/tui/TuiEndStep.class" };
0155:
0156: private static final String[] JAR_FILES_ANSI_UI = new String[] { // Requires
0157: // files
0158: // from
0159: // JAR_FILES_TEXT_UI
0160: "com/memoire/vainstall/aui/VAAnsiUI.class", };
0161:
0162: private static final String[] JAR_FILES_UNATTENDED_UI = new String[] {
0163: "com/memoire/vainstall/uui/VAUnattendedUI.class",
0164: "com/memoire/vainstall/uui/UuiDefaultStep.class",
0165: "com/memoire/vainstall/uui/UuiDirectoryStep.class",
0166: "com/memoire/vainstall/uui/UuiEndStep.class",
0167: "com/memoire/vainstall/uui/UuiInstallStep.class",
0168: "com/memoire/vainstall/uui/UuiLanguageStep.class",
0169: "com/memoire/vainstall/uui/UuiLicenseStep.class",
0170: "com/memoire/vainstall/uui/UuiReadmeStep.class",
0171: "com/memoire/vainstall/uui/UuiShortcutStep.class",
0172: "com/memoire/vainstall/uui/UuiUpgradeStep.class",
0173: "com/memoire/vainstall/uui/UuiWelcomeStep.class",
0174: "com/memoire/vainstall/uui/UuiWizard.class" };
0175:
0176: private static final String[] JAR_FILES_GRAPHIC_UI = new String[] {
0177: "com/memoire/vainstall/gui/Language_da_DK.class",
0178: "com/memoire/vainstall/gui/Language_de_DE.class",
0179: "com/memoire/vainstall/gui/Language_en_UK.class",
0180: "com/memoire/vainstall/gui/Language_fr_FR.class",
0181: "com/memoire/vainstall/gui/Language_it_IT.class",
0182: "com/memoire/vainstall/gui/Language_ja_JP.class",
0183: "com/memoire/vainstall/gui/VABlueScreen.class",
0184: "com/memoire/vainstall/gui/VABlueScreen$1.class",
0185: "com/memoire/vainstall/gui/VAGraphicUI.class",
0186: "com/memoire/vainstall/gui/VAWizard.class",
0187: "com/memoire/vainstall/gui/VAWizard$1.class",
0188: "com/memoire/vainstall/gui/VAPanel.class",
0189: "com/memoire/vainstall/gui/VAWelcomePanel.class",
0190: "com/memoire/vainstall/gui/VAImagePanel.class",
0191: "com/memoire/vainstall/gui/VAInstallPanel.class",
0192: "com/memoire/vainstall/gui/VALanguagePanel.class",
0193: "com/memoire/vainstall/gui/VALicensePanel.class",
0194: "com/memoire/vainstall/gui/VALicenseKeyPanel.class",
0195: "com/memoire/vainstall/gui/VALicenseKeyPanel$1.class",
0196: "com/memoire/vainstall/gui/VAReadmePanel.class",
0197: "com/memoire/vainstall/gui/VADirectoryPanel.class",
0198: "com/memoire/vainstall/gui/VADirectoryPanel$1.class",
0199: "com/memoire/vainstall/gui/VAUpgradePanel.class",
0200: "com/memoire/vainstall/gui/VAShortcutPanel.class",
0201: "com/memoire/vainstall/gui/VAEndPanel.class", };
0202:
0203: private static final String[] JAR_FILES_XTRA_UI = new String[] {
0204: "com/memoire/vainstall/xui/Language_da_DK.class",
0205: "com/memoire/vainstall/xui/Language_de_DE.class",
0206: "com/memoire/vainstall/xui/Language_en_UK.class",
0207: "com/memoire/vainstall/xui/Language_fr_FR.class",
0208: "com/memoire/vainstall/xui/Language_it_IT.class",
0209: "com/memoire/vainstall/xui/Language_ja_JP.class",
0210: "com/memoire/vainstall/xui/XuiBlueScreen.class",
0211: "com/memoire/vainstall/xui/XuiWizard.class",
0212: "com/memoire/vainstall/xui/XuiAbstractPanel.class",
0213: "com/memoire/vainstall/xui/XuiPanel.class",
0214: "com/memoire/vainstall/xui/XuiImagePanel.class",
0215: "com/memoire/vainstall/xui/XuiTitle.class",
0216: "com/memoire/vainstall/xui/XuiButton.class",
0217: "com/memoire/vainstall/xui/XuiButtonBorder.class",
0218: "com/memoire/vainstall/xui/XuiLabel.class",
0219: "com/memoire/vainstall/xui/XuiList.class",
0220: "com/memoire/vainstall/xui/XuiRadioButton.class",
0221: "com/memoire/vainstall/xui/XuiOptionPane.class",
0222: "com/memoire/vainstall/xui/XuiWelcomePanel.class",
0223: "com/memoire/vainstall/xui/XuiReadmePanel.class",
0224: "com/memoire/vainstall/xui/XuiLicensePanel.class",
0225: "com/memoire/vainstall/xui/XuiLicenseKeyPanel.class",
0226: "com/memoire/vainstall/xui/XuiLicenseKeyPanel$1.class",
0227: "com/memoire/vainstall/xui/XuiInstallPanel.class",
0228: "com/memoire/vainstall/xui/XuiShortcutPanel.class",
0229: "com/memoire/vainstall/xui/XuiUpgradePanel.class",
0230: "com/memoire/vainstall/xui/XuiLanguagePanel.class",
0231: "com/memoire/vainstall/xui/XuiEndPanel.class",
0232: "com/memoire/vainstall/xui/XuiDirectoryPanel$1.class",
0233: "com/memoire/vainstall/xui/XuiDirectoryPanel.class",
0234: "com/memoire/vainstall/xui/VAXtraUI.class", };
0235:
0236: // internal classes for package-specific pre-instal
0237: // and post-install processing
0238: private static final String[] JAR_FILES_CUSTOM_PRE_POST = new String[] {
0239: "com/memoire/vainstall/AbstractCustomPrePost.class",
0240: "com/memoire/vainstall/InputStreamToDetails.class", };
0241:
0242: private File filelist_;
0243:
0244: private String destPath_;
0245:
0246: private String archMethod_;
0247:
0248: private long archOffset_;
0249:
0250: private long installClassOffset_;
0251:
0252: private long installClassSize_;
0253:
0254: private long jarSize_;
0255:
0256: private String licenseKeySupportClassName_, encodeKey_;
0257:
0258: private LicenseKeySupport licenseKeySupport_;
0259:
0260: private String uiMode_;
0261:
0262: private String uiBluescreen_;
0263:
0264: private String uiBluescreenColor_;
0265:
0266: private String image_;
0267:
0268: private String appName_, appVersion_;
0269:
0270: private String linkSectionName_, linkSectionIcon_, linkEntryName_,
0271: linkEntryIcon_;
0272:
0273: private String instClassName_;
0274:
0275: private boolean createUninstallShortcut_;
0276:
0277: private String[] targets_;
0278:
0279: private String currentTarget_;
0280:
0281: private String jarAlias_, jarPassphrase_, jarCodebase_, jarVendor_,
0282: jarHomepage_;
0283:
0284: private File license_;
0285:
0286: private File readme_;
0287:
0288: private ByteArrayOutputStream archiveInfos_;
0289:
0290: private int archivecount_;
0291:
0292: private Vector archiveEntryList_;
0293:
0294: private String additionalFiles_;
0295:
0296: // used for properties in install.class f.ex. language
0297: private Properties installProperties = new Properties();
0298:
0299: // used for package-specific pre/post install processing
0300: private String customPrePostClassName_;
0301:
0302: private String customPrePostJarfileName_;
0303:
0304: private static String getJavaBinPath() {
0305: String path = null;
0306: for (int i = 0; i < JAVAC_SEARCH_PATH.length && path == null; i++) {
0307: String aPath;
0308: aPath = JAVA_HOME + File.separator + JAVAC_SEARCH_PATH[i];
0309: if (new File(aPath).exists()) {
0310: path = aPath;
0311: }
0312: }
0313: return path;
0314: }
0315:
0316: public VAArchiver() {
0317: filelist_ = null;
0318: destPath_ = null;
0319: archMethod_ = null;
0320: installClassOffset_ = -10987654321L;
0321: installClassSize_ = -1234543210L;
0322: archOffset_ = -1234567890L;
0323: uiMode_ = null;
0324: uiBluescreenColor_ = null;
0325: uiBluescreen_ = null;
0326: appName_ = appVersion_ = null;
0327: linkSectionName_ = linkSectionIcon_ = linkEntryName_ = linkEntryIcon_ = null;
0328: instClassName_ = null;
0329: targets_ = new String[0];
0330: jarAlias_ = jarPassphrase_ = jarCodebase_ = jarHomepage_ = jarVendor_ = null;
0331: license_ = null;
0332: readme_ = null;
0333: archiveInfos_ = null;
0334: archivecount_ = 0;
0335: archiveEntryList_ = new Vector();
0336: licenseKeySupportClassName_ = "com.memoire.vainstall.DefaultLicenseKeySupport";
0337: }
0338:
0339: public void start() {
0340: if (!processProperties())
0341: return;
0342: try {
0343: System.out.println();
0344: System.out.println(VAGlobals
0345: .i18n("VAArchiver_CompressingFiles"));
0346: archiveInfos_ = new ByteArrayOutputStream();
0347: File zip = makeArchive("archive.zip");
0348: zip.deleteOnExit();
0349: System.out.println();
0350: System.out.println(VAGlobals
0351: .i18n("VAArchiver_CreatingJarFiles"));
0352: archiveInfos_.flush();
0353: byte[] infosbytes = archiveInfos_.toByteArray();
0354: File jar = makeJar("install.jar", zip, license_, readme_,
0355: infosbytes);
0356: jarSize_ = jar.length();
0357: archiveInfos_.close();
0358: jar.deleteOnExit();
0359: File installJavaFile = new File(instClassName_ + ".java");
0360: installJavaFile.deleteOnExit();
0361: File instClass = null;
0362: boolean deleteInstallClass = true;
0363: for (int i = 0; i < targets_.length; i++) {
0364: System.out.println();
0365: System.out.println(targets_[i]
0366: + VAGlobals.i18n("VAArchiver_Target"));
0367: currentTarget_ = targets_[i];
0368: System.out.println(VAGlobals
0369: .i18n("VAArchiver_GeneratingInstallClass"));
0370: // this pass of generation of installClass is to calculate
0371: // installClassSize
0372: // with TARGET_TYPE being set to its correct value
0373: // well, this is not useful for jnlp, but it won't hurt
0374: generateInstallCode(
0375: installJavaFile,
0376: "com/memoire/vainstall/resources/Install.vaitpl",
0377: "com/memoire/vainstall/VAClassLoader.class");
0378: System.out.println(VAGlobals
0379: .i18n("VAArchiver_CompilingInstallClass"));
0380: instClass = compile(installJavaFile.getName());
0381: installClassSize_ = instClass.length();
0382: VAGlobals.printDebug(" InstallClass size="
0383: + installClassSize_);
0384: if ("jar".equals(targets_[i])) {
0385: File jarTarget = new File(instClassName_ + ".jar");
0386: File mfFile = new File(instClassName_ + ".mf");
0387: mfFile.deleteOnExit();
0388: System.out.println(VAGlobals
0389: .i18n("VAArchiver_CreatingManifestFile"));
0390: generateManifestFile(mfFile);
0391: // Build the JAR
0392: System.out.println(VAGlobals
0393: .i18n("VAArchiver_UpdatingJarFile"));
0394: copy(jar, jarTarget);
0395: jar("uvfm", jarTarget, new File[] { mfFile,
0396: instClass });
0397: // Sign the JAR
0398: if (jarAlias_ != null
0399: && !"".equals(jarAlias_.trim())
0400: && jarPassphrase_ != null
0401: && !"".equals(jarPassphrase_.trim())) {
0402: System.out.println(VAGlobals
0403: .i18n("VAArchiver_SigningJarFile"));
0404: jarsign(jarPassphrase_, jarTarget, jarAlias_);
0405: }
0406: } else if ("jnlp".equals(targets_[i])) {
0407: File jnlpFile = new File(instClassName_ + ".jnlp");
0408: System.out.println(VAGlobals
0409: .i18n("VAArchiver_CreatingJnlpFile"));
0410: generateJnlpFile(jnlpFile);
0411: } else if ("java".equals(targets_[i])) {
0412: installClassOffset_ = -10987654321L;
0413: deleteInstallClass = false;
0414: if (archMethod_.equals("append")) {
0415: archOffset_ = instClass.length();
0416: VAGlobals.printDebug(VAGlobals
0417: .i18n("VAArchiver_ArchiveOffset")
0418: + archOffset_);
0419: generateInstallCode(
0420: installJavaFile,
0421: "com/memoire/vainstall/resources/Install.vaitpl",
0422: "com/memoire/vainstall/VAClassLoader.class");
0423: System.out
0424: .println(VAGlobals
0425: .i18n("VAArchiver_CompilingInstallClass"));
0426: compile(installJavaFile.getName());
0427: System.out.println(VAGlobals
0428: .i18n("VAArchiver_AppendingArchive"));
0429: appendArchive(instClass);
0430: }
0431: } else if ("unix".equals(targets_[i])) {
0432: File unixShellFile = new File(instClassName_
0433: + ".sh");
0434: installClassOffset_ = generateUnixInstallShell(
0435: unixShellFile,
0436: "com/memoire/vainstall/resources/Install-sh.vaitpl",
0437: instClass);
0438: VAGlobals.printDebug(VAGlobals
0439: .i18n("VAArchiver_InstallClassOffset")
0440: + installClassOffset_);
0441: if (archMethod_.equals("append")) {
0442: archOffset_ = unixShellFile.length();
0443: VAGlobals.printDebug(VAGlobals
0444: .i18n("VAArchiver_ArchiveOffset")
0445: + archOffset_);
0446: generateInstallCode(
0447: installJavaFile,
0448: "com/memoire/vainstall/resources/Install.vaitpl",
0449: "com/memoire/vainstall/VAClassLoader.class");
0450: System.out
0451: .println(VAGlobals
0452: .i18n("VAArchiver_CompilingInstallClass"));
0453: compile(installJavaFile.getName());
0454: generateUnixInstallShell(
0455: unixShellFile,
0456: "com/memoire/vainstall/resources/Install-sh.vaitpl",
0457: instClass);
0458: System.out.println(VAGlobals
0459: .i18n("VAArchiver_AppendingArchive"));
0460: appendArchive(unixShellFile);
0461: }
0462: } else if (("win95".equals(targets_[i]))
0463: || ("linux-i386".equals(targets_[i]))) {
0464: File nativeExeFile = null;
0465: if ("win95".equals(targets_[i]))
0466: nativeExeFile = new File(instClassName_
0467: + ".exe");
0468: else if ("linux-i386".equals(targets_[i]))
0469: nativeExeFile = new File(instClassName_
0470: + ".lin");
0471: installClassOffset_ = generateNativeInstallExe(
0472: nativeExeFile,
0473: "com/memoire/vainstall/resources/Install-"
0474: + targets_[i] + "-exe.vaitpl",
0475: instClass);
0476: VAGlobals.printDebug(VAGlobals
0477: .i18n("VAArchiver_InstallClassOffset")
0478: + installClassOffset_);
0479: if (archMethod_.equals("append")) {
0480: archOffset_ = nativeExeFile.length();
0481: VAGlobals.printDebug(VAGlobals
0482: .i18n("VAArchiver_ArchiveOffset")
0483: + archOffset_);
0484: generateInstallCode(
0485: installJavaFile,
0486: "com/memoire/vainstall/resources/Install.vaitpl",
0487: "com/memoire/vainstall/VAClassLoader.class");
0488: System.out
0489: .println(VAGlobals
0490: .i18n("VAArchiver_CompilingInstallClass"));
0491: compile(installJavaFile.getName());
0492: generateNativeInstallExe(nativeExeFile,
0493: "com/memoire/vainstall/resources/Install-"
0494: + targets_[i] + "-exe.vaitpl",
0495: instClass);
0496: System.out.println(VAGlobals
0497: .i18n("VAArchiver_AppendingArchive"));
0498: appendArchive(nativeExeFile);
0499: System.out.println("win95 end");
0500: }
0501: }
0502: }
0503: if (instClass != null && deleteInstallClass)
0504: instClass.delete();
0505: } catch (IOException e) {
0506: e.printStackTrace();
0507: }
0508: }
0509:
0510: File lnfFile_;
0511:
0512: private boolean processProperties() {
0513: String tempString;
0514: RC_DIR = "com/memoire/vainstall/resources";
0515: VAILOGO = RC_DIR + "/vailogo.gif";
0516: // get information about choosen language
0517: VAGlobals.setLanguage("default");
0518: String tmp = VAProperties.PROPERTIES
0519: .getProperty("vainstall.destination.language");
0520: if (tmp != null && !"".equals(tmp)) {
0521: installProperties
0522: .put("vainstall.destination.language", tmp);
0523: }
0524: // the user want to use full path every times
0525: String useFullPath = VAProperties.PROPERTIES
0526: .getProperty("vainstall.script.java.fullpath");
0527: if (useFullPath != null && "true".equalsIgnoreCase(useFullPath)) {
0528: installProperties.put("vainstall.script.java.fullpath",
0529: "true");
0530: }
0531: //the min max version
0532: String minJavaVersion = VAProperties.PROPERTIES.getProperty(
0533: "vainstall.java.version.min", null);
0534: String maxJavaVersion = VAProperties.PROPERTIES.getProperty(
0535: "vainstall.java.version.max", null);
0536: //the vendor sun,ibm
0537: String javaVendor = VAProperties.PROPERTIES.getProperty(
0538: "vainstall.java.vendor", null);
0539: if (minJavaVersion != null
0540: && minJavaVersion.trim().length() > 0) {
0541: installProperties.put("vainstall.java.version.min",
0542: minJavaVersion);
0543: }
0544: if (maxJavaVersion != null
0545: && maxJavaVersion.trim().length() > 0) {
0546: installProperties.put("vainstall.java.version.max",
0547: maxJavaVersion);
0548: }
0549: if (javaVendor != null && javaVendor.trim().length() > 0) {
0550: installProperties.put("vainstall.java.vendor", javaVendor);
0551: }
0552: String key = "vainstall.java.download.url";
0553: String val = VAProperties.PROPERTIES.getProperty(key, null);
0554: if (val != null)
0555: installProperties.put(key, val);
0556:
0557: String shortcutsInInstallDir = VAProperties.PROPERTIES
0558: .getProperty("vainstall.shortcut.in.installdir");
0559: if (shortcutsInInstallDir != null
0560: && "true".equalsIgnoreCase(shortcutsInInstallDir)) {
0561: installProperties.put("vainstall.shortcut.in.installdir",
0562: "true");
0563: }
0564: tmp = VAProperties.PROPERTIES
0565: .getProperty("vainstall.archive.filelist");
0566: if (tmp == null || "".equals(tmp)) {
0567: System.err.println("vainstall.archive.filelist null");
0568: return false;
0569: }
0570: filelist_ = new File(tmp);
0571: if ((!filelist_.exists()) || (!filelist_.canRead())) {
0572: System.err.println(VAGlobals.i18n("VAArchiver_CanNotRead")
0573: + filelist_);
0574: return false;
0575: }
0576: destPath_ = VAProperties.PROPERTIES
0577: .getProperty("vainstall.destination.defaultPath");
0578: if (destPath_ == null || "".equals(destPath_)) {
0579: System.err
0580: .println("vainstall.destination.defaultPath null");
0581: return false;
0582: } else {
0583: if (!checkVaiPath(destPath_)) {
0584: System.err.println("vainstall.destination.defaultPath"
0585: + VAGlobals
0586: .i18n("VAArchiver_HasIncorrectFormat"));
0587: return false;
0588: }
0589: }
0590: tmp = VAProperties.PROPERTIES
0591: .getProperty("vainstall.destination.installMode");
0592: if (("update".equals(tmp))) {
0593: destPath_ = "[UPDATE]";
0594: } else if (("module".equals(tmp))) {
0595: destPath_ = "[MODULE]";
0596: } else if (!"install".equals(tmp)) {
0597: System.err.println(VAGlobals
0598: .i18n("VAArchiver_NoValidInstallmode")
0599: + ":"
0600: + VAGlobals.i18n("VAArchiver_DefaultingTo")
0601: + "install");
0602: }
0603: tmp = VAProperties.PROPERTIES
0604: .getProperty("vainstall.destination.targets");
0605: if (tmp == null || "".equals(tmp)) {
0606: System.err.println(VAGlobals
0607: .i18n("VAArchiver_NoTargetSpecified")
0608: + " (vainstall.destination.targets)");
0609: return false;
0610: }
0611: StringTokenizer tok = new StringTokenizer(tmp, ",");
0612: Vector v = new Vector();
0613: while (tok.hasMoreTokens()) {
0614: String t = tok.nextToken().trim().toLowerCase();
0615: if ((!"java".equals(t)) && (!"jar".equals(t))
0616: && (!"jnlp".equals(t)) && (!"unix".equals(t))
0617: && (!"win95".equals(t))
0618: && (!"linux-i386".equals(t))) {
0619: System.err.println(VAGlobals
0620: .i18n("VAArchiver_UnknownTarget")
0621: + t);
0622: return false;
0623: }
0624: if (!v.contains(t))
0625: v.add(t);
0626: }
0627: // jar is needed for jnlp
0628: if (v.contains("jnlp") && !v.contains("jar"))
0629: v.add("jar");
0630: targets_ = new String[v.size()];
0631: // the order is important here
0632: // jar first, exes after, java last
0633: int i = 0;
0634: if (v.contains("jar"))
0635: targets_[i++] = "jar";
0636: if (v.contains("jnlp"))
0637: targets_[i++] = "jnlp";
0638: if (v.contains("unix"))
0639: targets_[i++] = "unix";
0640: if (v.contains("linux-i386"))
0641: targets_[i++] = "linux-i386";
0642: if (v.contains("win95"))
0643: targets_[i++] = "win95";
0644: if (v.contains("java"))
0645: targets_[i++] = "java";
0646: if (v.contains("jar")) {
0647: jarAlias_ = VAProperties.PROPERTIES
0648: .getProperty("vainstall.jarsigner.alias");
0649: jarPassphrase_ = VAProperties.PROPERTIES
0650: .getProperty("vainstall.jarsigner.passphrase");
0651: }
0652: if (v.contains("jnlp")) {
0653: jarCodebase_ = VAProperties.PROPERTIES
0654: .getProperty("vainstall.jnlp.codebase");
0655: if (jarCodebase_ == null || "".equals(jarCodebase_)) {
0656: System.err.println("vainstall.jnlp.codebase null");
0657: return false;
0658: }
0659: jarHomepage_ = VAProperties.PROPERTIES
0660: .getProperty("vainstall.jnlp.homepage");
0661: if (jarHomepage_ == null || "".equals(jarHomepage_)) {
0662: System.err.println("vainstall.jnlp.homepage null");
0663: return false;
0664: }
0665: jarVendor_ = VAProperties.PROPERTIES
0666: .getProperty("vainstall.jnlp.vendor");
0667: if (jarVendor_ == null || "".equals(jarVendor_)) {
0668: System.err.println("vainstall.jnlp.vendor null");
0669: return false;
0670: }
0671: }
0672: archMethod_ = VAProperties.PROPERTIES
0673: .getProperty("vainstall.archive.archivingMethod");
0674: if (archMethod_ == null || "".equals(archMethod_)) {
0675: archMethod_ = "append";
0676: }
0677: uiMode_ = VAProperties.PROPERTIES
0678: .getProperty("vainstall.destination.ui");
0679: if (uiMode_ == null || "".equals(uiMode_)) {
0680: uiMode_ = "graphic";
0681: }
0682: //lnf
0683: if ("graphic".equals(uiMode_)) {
0684: String lnfClass = VAProperties.PROPERTIES
0685: .getProperty("vainstall.lnf.class");
0686: if (lnfClass != null) {
0687: installProperties.put("vainstall.lnf.class", lnfClass);
0688: String lnfFileName = VAProperties.PROPERTIES
0689: .getProperty("vainstall.lnf.jar");
0690: if (lnfFileName != null) {
0691: File jarFile = new File(lnfFileName);
0692: if (jarFile.exists()) {
0693: //we save the lnf file
0694: lnfFile_ = jarFile;
0695: installProperties.put("vainstall.lnf.jar",
0696: jarFile.getName());
0697:
0698: } else {
0699: System.err
0700: .println("lnf jar File does NOT exist "
0701: + jarFile.getAbsolutePath());
0702: }
0703: }
0704: }
0705: }
0706:
0707: uiBluescreen_ = VAProperties.PROPERTIES
0708: .getProperty("vainstall.destination.ui.bluescreen");
0709: if (uiBluescreen_ == null || "".equals(uiBluescreen_)) {
0710: uiBluescreen_ = "yes";
0711: }
0712: uiBluescreenColor_ = VAProperties.PROPERTIES
0713: .getProperty("vainstall.destination.ui.bluescreen.colour");
0714: if ((uiBluescreenColor_ != null)
0715: && (!"".equals(uiBluescreenColor_))) {
0716: try {
0717: Integer.parseInt(uiBluescreenColor_, 16);
0718: } catch (NumberFormatException nfe) {
0719: System.err
0720: .println("vainstall.destination.ui.bluescreen.colour"
0721: + VAGlobals
0722: .i18n("VAArchiver_HasIncorrectFormat"));
0723: return false;
0724: }
0725: }
0726: tmp = VAProperties.PROPERTIES
0727: .getProperty("vainstall.destination.ui.image");
0728: if ((tmp == null) || (tmp.equals(""))) {
0729: System.err.println("vainstall.destination.ui.image null:"
0730: + VAGlobals.i18n("VAArchiver_WillUseDefaultImage"));
0731: // java.net.URL url = new
0732: // java.net.URL("jar:file:///"+System.getProperties().getProperty("user.dir")+"/lib/vainstall.jar!/com/memoire/vainstall/resources/banner.gif");
0733: image_ = RC_DIR + "/banner.gif";
0734: } else {
0735: image_ = tmp;
0736: File img = new File(image_);
0737: if ((!img.exists()) || (!img.canRead())) {
0738: System.err
0739: .println(VAGlobals
0740: .i18n("VAArchiver_CanNotRead")
0741: + image_
0742: + ":"
0743: + VAGlobals
0744: .i18n("VAArchiver_WillUseDefaultImage"));
0745: image_ = RC_DIR + "/banner.gif";
0746: }
0747: }
0748: appName_ = VAProperties.PROPERTIES
0749: .getProperty("vainstall.destination.appName");
0750: if (appName_ == null || "".equals(appName_)) {
0751: System.err.println("vainstall.destination.appName null");
0752: return false;
0753: }
0754: appVersion_ = VAProperties.PROPERTIES
0755: .getProperty("vainstall.destination.appVersion");
0756: if (appVersion_ == null || "".equals(appVersion_)) {
0757: System.out
0758: .println("vainstall.destination.appVersion null, assuming it is an unversioned plugin");
0759: // return false;
0760: }
0761: linkSectionName_ = VAProperties.PROPERTIES
0762: .getProperty("vainstall.destination.linkSectionName");
0763: if (linkSectionName_ == null || "".equals(linkSectionName_)) {
0764: System.err
0765: .println("vainstall.destination.linkSectionName null:"
0766: + VAGlobals.i18n("VAArchiver_DefaultingTo")
0767: + "\"Applications\"");
0768: linkSectionName_ = "Applications";
0769: }
0770: linkSectionIcon_ = VAProperties.PROPERTIES
0771: .getProperty("vainstall.destination.linkSectionIcon");
0772: if ((linkSectionIcon_ == null) || "".equals(linkSectionIcon_)) {
0773: System.err
0774: .println("vainstall.destination.linkSectionIcon null");
0775: linkSectionIcon_ = "";
0776: }
0777: linkEntryName_ = VAProperties.PROPERTIES
0778: .getProperty("vainstall.destination.linkEntryName");
0779: if (linkEntryName_ == null || "".equals(linkEntryName_)) {
0780: System.err
0781: .println("vainstall.destination.linkEntryName null:"
0782: + VAGlobals.i18n("VAArchiver_DefaultingTo")
0783: + "\"" + appName_ + "\"");
0784: linkEntryName_ = appName_;
0785: }
0786: linkEntryIcon_ = VAProperties.PROPERTIES
0787: .getProperty("vainstall.destination.linkEntryIcon");
0788: if ((linkEntryIcon_ == null) || "".equals(linkEntryIcon_)) {
0789: System.err
0790: .println("vainstall.destination.linkEntryIcon null");
0791: linkEntryIcon_ = "";
0792: }
0793: tempString = VAProperties.PROPERTIES
0794: .getProperty("vainstall.destination.createUninstallShortcut");
0795: if (tempString != null && tempString.equals("yes"))
0796: createUninstallShortcut_ = true;
0797: else
0798: createUninstallShortcut_ = false;
0799: instClassName_ = VAProperties.PROPERTIES
0800: .getProperty("vainstall.archive.installClassName");
0801: if (instClassName_ == null || "".equals(instClassName_)) {
0802: instClassName_ = "Install_" + appName_;
0803: }
0804: tmp = VAProperties.PROPERTIES
0805: .getProperty("vainstall.archive.license");
0806: if (tmp == null || "".equals(tmp)) {
0807: System.err.println("vainstall.archive.license null");
0808: return false;
0809: }
0810: license_ = new File(tmp);
0811: if ((!license_.exists()) || (!license_.canRead())) {
0812: System.err.println(VAGlobals.i18n("VAArchiver_CanNotRead")
0813: + license_);
0814: return false;
0815: }
0816: try {
0817: InputStream licenseStream = new FileInputStream(license_);
0818: String licenseEncoding = VAProperties.PROPERTIES
0819: .getProperty("vainstall.archive.license.encoding");
0820: if (licenseEncoding != null
0821: && licenseEncoding.equals("") == false) {
0822: try {
0823: InputStreamReader isrLicense = new InputStreamReader(
0824: licenseStream, licenseEncoding);
0825: } catch (UnsupportedEncodingException exc) {
0826: System.err
0827: .println("Unsuported encoding for license!");
0828: return false;
0829: }
0830: }
0831: } catch (Exception exc) {
0832: System.err.println("Problems reading license file!");
0833: return false;
0834: }
0835: tmp = VAProperties.PROPERTIES
0836: .getProperty("vainstall.license.key.support");
0837: if (tmp != null && !"".equals(tmp)) {
0838: licenseKeySupportClassName_ = tmp;
0839: }
0840: encodeKey_ = VAProperties.PROPERTIES
0841: .getProperty("vainstall.license.key.support.encode.key");
0842: additionalFiles_ = VAProperties.PROPERTIES
0843: .getProperty("vainstall.additional.files");
0844: Class cls = null;
0845: try {
0846: cls = Class.forName(licenseKeySupportClassName_);
0847: } catch (Exception ex) {
0848: if ((cls == null) && (additionalFiles_ != null)) {
0849: StringTokenizer fmi = new StringTokenizer(
0850: additionalFiles_, ",");
0851: while (fmi.hasMoreTokens()) {
0852: StringTokenizer fm = new StringTokenizer(fmi
0853: .nextToken(), "!");
0854: String classFound = fm.nextToken();
0855: if ((classFound != null)
0856: && (classFound
0857: .indexOf(licenseKeySupportClassName_) > -1)) {
0858: try {
0859: URLClassLoader urlcl = new URLClassLoader(
0860: new URL[] { new File(classFound)
0861: .getParentFile().toURL() });
0862: cls = urlcl
0863: .loadClass(licenseKeySupportClassName_);
0864: } catch (Exception ex2) {
0865: System.out
0866: .println("License key support could not be initialized with specific URLCLassLoader"
0867: + ex2);
0868: }
0869: break;
0870: }
0871: }
0872: }
0873: }
0874: if (cls == null) {
0875: throw new RuntimeException(
0876: "License key support could not be initialized: ");
0877: }
0878: try {
0879: System.out.println(cls.getName());
0880: licenseKeySupport_ = (LicenseKeySupport) cls.newInstance();
0881: } catch (Exception ex) {
0882: System.err
0883: .println("LicenseKeySupport can't be instantiated"
0884: + ex);
0885: }
0886: tmp = VAProperties.PROPERTIES
0887: .getProperty("vainstall.archive.readme");
0888: if (tmp == null || "".equals(tmp)) {
0889: System.err.println("vainstall.archive.readme null");
0890: return false;
0891: }
0892: readme_ = new File(tmp);
0893: if ((!readme_.exists()) || (!readme_.canRead())) {
0894: System.err.println(VAGlobals.i18n("VAArchiver_CanNotRead")
0895: + readme_);
0896: return false;
0897: }
0898: try {
0899: InputStream readmeStream = new FileInputStream(readme_);
0900: String readmeEncoding = VAProperties.PROPERTIES
0901: .getProperty("vainstall.archive.readme.encoding");
0902: if (readmeEncoding != null
0903: && readmeEncoding.equals("") == false) {
0904: try {
0905: InputStreamReader isrReadme = new InputStreamReader(
0906: readmeStream, readmeEncoding);
0907: } catch (UnsupportedEncodingException exc) {
0908: System.err
0909: .println("Unsupported encoding for readme!");
0910: return false;
0911: }
0912: }
0913: } catch (Exception exc) {
0914: System.err.println("Problems reading readme file!");
0915: return false;
0916: }
0917: // custom pre/post processing
0918: customPrePostClassName_ = VAProperties.PROPERTIES
0919: .getProperty("vainstall.install.customprepost.className");
0920: if (customPrePostClassName_ == null) {
0921: customPrePostClassName_ = "";
0922: } else if (!"com.memoire.vainstall.AbstractCustomPrePost"
0923: .equals(customPrePostClassName_)) {
0924: customPrePostJarfileName_ = VAProperties.PROPERTIES
0925: .getProperty("vainstall.install.customprepost.jarFileName");
0926: if (customPrePostJarfileName_ == null
0927: || "".equals(customPrePostJarfileName_)) {
0928: System.err
0929: .println("vainstall.install.customprepost.jarFileName null");
0930: return false;
0931: }
0932: }
0933: installProperties.put(
0934: "vainstall.install.customprepost.className",
0935: customPrePostClassName_);
0936: return true;
0937: }
0938:
0939: private File makeArchive(String filename) throws IOException {
0940: LineNumberReader files = new LineNumberReader(new FileReader(
0941: filelist_));
0942: String line = files.readLine();
0943: if (line == null) {
0944: files.close();
0945: throw new IOException(VAGlobals
0946: .i18n("VAArchiver_EmptyFilelist"));
0947: }
0948: File zip = new File(filename);
0949: File parent = zip.getParentFile();
0950: if ((parent != null) && (!parent.canWrite()))
0951: throw new IOException(zip
0952: + VAGlobals.i18n("VAArchiver_NotWritten"));
0953: ZipOutputStream stream = new ZipOutputStream(
0954: new GZIPOutputStream(licenseKeySupport_.encodeStream(
0955: new FileOutputStream(zip), encodeKey_)));
0956: stream.setLevel(0);
0957: Vector archiveExeList = new Vector();
0958: FileNameGroup fileNameGroup = null;
0959: ObjectOutputStream infos = new ObjectOutputStream(archiveInfos_);
0960: Vector scripts = new Vector();
0961: while (line != null) {
0962: if ((!line.trim().equals(""))
0963: && (!line.trim().startsWith("#"))) {
0964: if (line.trim().startsWith("{")) {
0965: String script = addScript(files, scripts);
0966: if (script != null)
0967: archiveExeList.add("[SCRIPT]" + script);
0968: line = files.readLine();
0969: continue;
0970: }
0971: fileNameGroup = new FileNameGroup(line);
0972: File file = new File(convertToLocalPath(fileNameGroup
0973: .getOrigin()));
0974: String entryName = fileNameGroup.getDestination();
0975: if (!checkVaiPath(entryName))
0976: throw new IOException(VAGlobals
0977: .i18n("VAArchiver_InvalidPathInFilelist")
0978: + files.getLineNumber() + "): " + entryName);
0979: if (fileNameGroup.isExecutable()) {
0980: archiveExeList.add(entryName);
0981: }
0982: FileFilter filter = null;
0983: try {
0984: filter = fileNameGroup.getFileFilter();
0985: } catch (IllegalArgumentException iae) {
0986: throw new IOException(VAGlobals
0987: .i18n("VAArchiver_InFilelist")
0988: + files.getLineNumber()
0989: + "): "
0990: + iae.getMessage());
0991: }
0992: addToArchive(stream, file, filter, entryName,
0993: fileNameGroup.isRecursive() ? Integer.MAX_VALUE
0994: : 1);
0995: }
0996: line = files.readLine();
0997: }
0998: stream.close();
0999: files.close();
1000: infos.writeInt(archivecount_);
1001: infos.writeObject(scripts);
1002: infos.writeObject(archiveExeList);
1003: infos.flush();
1004: return zip;
1005: }
1006:
1007: private String addScript(LineNumberReader files, Vector scripts)
1008: throws IOException {
1009: String destName = null;
1010: int blocLineNbr = files.getLineNumber();
1011: String line = files.readLine();
1012: String cmd = null;
1013: Hashtable keywords = new Hashtable();
1014: if (line != null)
1015: cmd = line.trim();
1016: System.out.println(" script: " + cmd);
1017: line = files.readLine();
1018: while ((line != null) && (!line.trim().equals("}"))) {
1019: line = line.trim();
1020: int ind = line.indexOf('=');
1021: if ((ind > 0) && ((ind + 1) < line.length())) {
1022: keywords.put(line.substring(0, ind), line
1023: .substring(ind + 1));
1024: }
1025: line = files.readLine();
1026: }
1027: if ((cmd == null) || (line == null))
1028: throw new IOException("Unterminated script bloc : line "
1029: + blocLineNbr);
1030: //fred a tout casse
1031: //The options are not reorder. Only the Class and the Jar properties
1032: // are
1033: //tested :they are required
1034: if (cmd.equals("JavaLauncher")) {
1035: String k = (String) keywords.get("Class");
1036: if (k == null)
1037: throw new IOException("Invalid script bloc : line "
1038: + blocLineNbr + " (no Class)");
1039: else
1040: System.out.println(" Class=" + k);
1041:
1042: } else if (cmd.equals("JarLauncher")) {
1043: String k = (String) keywords.get("Jar");
1044: if (k != null) {
1045: System.out.println(" Jar=" + k);
1046: } else
1047: throw new IOException("Invalid script bloc : line "
1048: + blocLineNbr + " (no Jar)");
1049: } else {
1050: throw new IOException("Unsupported script : line "
1051: + blocLineNbr + " (" + cmd + ")");
1052: }
1053: //valeur par defaut
1054: // if((cmd.equals("JarLauncher") || cmd.equals("JavaLauncher")) &&
1055: // (keywords.get("JavaMode")==null){
1056: // keywords.put("JavaModel","console");
1057: // }
1058: String k = (String) keywords.get("ScriptName");
1059: if (k != null) {
1060: System.out.println(" ScriptName=" + k);
1061: destName = k;
1062: } else
1063: throw new IOException("Invalid script bloc : line "
1064: + blocLineNbr + " (no ScriptName)");
1065: //build the new string to add to the script list
1066: //PropertyName
1067: //propertyValue
1068: String lineSep = "\n";
1069: StringBuffer buf = new StringBuffer();
1070: //the command
1071: buf.append("CMD").append(lineSep).append(cmd);
1072: for (Iterator it = keywords.entrySet().iterator(); it.hasNext();) {
1073: Map.Entry e = (Map.Entry) it.next();
1074: if (e.getValue() != null) {
1075: buf.append(lineSep).append((String) e.getKey()).append(
1076: lineSep).append((String) e.getValue());
1077: }
1078: }
1079: if (buf.length() > 0)
1080: scripts.add(buf.toString());
1081: return destName;
1082: }
1083:
1084: private void addToArchive(ZipOutputStream stream, File file,
1085: FileFilter filter, String entryName, int recurseDepth)
1086: throws IOException {
1087: if (file.exists()) {
1088: if (file.isDirectory()) {
1089: File[] ls = file.listFiles(filter);
1090: if (ls.length == 0) {
1091: // empty dir
1092: if (archiveEntryList_.contains(entryName + "/")) {
1093: System.err
1094: .println(" warning: duplicate entry: "
1095: + entryName + "/"
1096: + ". Skipping.");
1097: } else {
1098: System.out.println(" " + file);
1099: ZipEntry newEntry = new ZipEntry(entryName
1100: + "/");
1101: stream.putNextEntry(newEntry);
1102: stream.closeEntry();
1103: archiveEntryList_.add(entryName + "/");
1104: }
1105: }
1106: for (int i = 0; i < ls.length; i++) {
1107: String ename = ls[i].getAbsolutePath();
1108: ename = entryName
1109: + ename.substring(file.getAbsolutePath()
1110: .length());
1111: ename = convertToGenericPath(ename);
1112: if (ename.startsWith("/"))
1113: ename = ename.substring(1);
1114: if (recurseDepth > 0)
1115: addToArchive(stream, ls[i], filter, ename,
1116: recurseDepth - 1);
1117: }
1118: } else if (archiveEntryList_.contains(entryName)) {
1119: System.err.println(" warning: duplicate entry: "
1120: + entryName + ". Skipping.");
1121: } else {
1122: System.out.println(" " + file);
1123: /*
1124: * String s=" "+file; while(s.length() <79) s+=' ';
1125: * System.out.print(s+"\r");
1126: */
1127: archivecount_++;
1128: ZipEntry newEntry = new ZipEntry(entryName);
1129: stream.putNextEntry(newEntry);
1130: FileInputStream in = new FileInputStream(file);
1131: byte[] buf = new byte[2048];
1132: int read = in.read(buf, 0, buf.length);
1133: while (read > 0) {
1134: stream.write(buf, 0, read);
1135: read = in.read(buf, 0, buf.length);
1136: }
1137: in.close();
1138: stream.closeEntry();
1139: archiveEntryList_.add(entryName);
1140: }
1141: } else {
1142: System.err.println(" error: file " + file
1143: + " does not exist. Skipping.");
1144: }
1145: }
1146:
1147: private String convertToLocalPath(String entry) throws IOException {
1148: String res = Setup.expandDirectory(entry, true, null);
1149: if (res == null)
1150: throw new IOException("Invalid path: " + entry);
1151: return res.replace('/', File.separatorChar);
1152: }
1153:
1154: private String convertToGenericPath(String line) {
1155: return line.replace(File.separatorChar, '/');
1156: }
1157:
1158: private void generateInstallCode(File javaFile,
1159: String instTemplate, String classLoader) throws IOException {
1160: String tempString;
1161: PrintWriter writer = new PrintWriter(new FileWriter(javaFile));
1162: int read = 0;
1163: byte[] buf = new byte[128];
1164: // LineNumberReader reader=new LineNumberReader(new
1165: // FileReader(instTemplate));
1166: InputStream is = getClass().getResourceAsStream(
1167: "/" + instTemplate);
1168: InputStreamReader isr = new InputStreamReader(is);
1169: LineNumberReader reader = new LineNumberReader(isr);
1170: System.out.println(VAGlobals
1171: .i18n("VAArchiver_GeneratingInstallClassCode"));
1172: String line = reader.readLine();
1173: while ((line != null)
1174: && (!line.startsWith("// --> InstallClassName"))) {
1175: writer.println(line);
1176: line = reader.readLine();
1177: }
1178: writer.println("public class " + instClassName_ + " {");
1179: writer.println(" private static final Class installClass=new "
1180: + instClassName_ + "().getClass();");
1181: line = reader.readLine();
1182: while ((line != null)
1183: && (!line.startsWith("// --> ArchivingMethod"))) {
1184: writer.println(line);
1185: line = reader.readLine();
1186: }
1187: writer.println(" private static String ARCH_METHOD=\""
1188: + archMethod_ + "\";");
1189: line = reader.readLine();
1190: while ((line != null)
1191: && (!line.startsWith("// --> TargetType"))) {
1192: writer.println(line);
1193: line = reader.readLine();
1194: }
1195: writer.println(" private static String TARGET_TYPE=\""
1196: + currentTarget_ + "\";");
1197: line = reader.readLine();
1198: while ((line != null)
1199: && (!line.startsWith("// --> InstallClassOffset"))) {
1200: writer.println(line);
1201: line = reader.readLine();
1202: }
1203: writer.println(" private static long ICLASS_OFFSET="
1204: + installClassOffset_ + "L;");
1205: line = reader.readLine();
1206: while ((line != null)
1207: && (!line.startsWith("// --> InstallClassSize"))) {
1208: writer.println(line);
1209: line = reader.readLine();
1210: }
1211: if (installClassSize_ != archOffset_)
1212: writer.println(" private static long ICLASS_SIZE="
1213: + installClassSize_ + "L;");
1214: else
1215: writer
1216: .println(" private static long ICLASS_SIZE=-1234543210L;");
1217: line = reader.readLine();
1218: while ((line != null)
1219: && (!line.startsWith("// --> ArchiveOffset"))) {
1220: writer.println(line);
1221: line = reader.readLine();
1222: }
1223: writer.println(" private static long ARCH_OFFSET="
1224: + archOffset_ + "L;");
1225: line = reader.readLine();
1226: while ((line != null) && (!line.startsWith("// --> JarSize"))) {
1227: writer.println(line);
1228: line = reader.readLine();
1229: }
1230: writer.println(" private static long JAR_SIZE=" + jarSize_
1231: + "L;");
1232: line = reader.readLine();
1233: while ((line != null) && (!line.startsWith("// --> UIMode"))) {
1234: writer.println(line);
1235: line = reader.readLine();
1236: }
1237: writer.println(" private static String UI_MODE=\"" + uiMode_
1238: + "\";");
1239: line = reader.readLine();
1240: while ((line != null)
1241: && (!line.startsWith("// --> UIBluescreen"))) {
1242: writer.println(line);
1243: line = reader.readLine();
1244: }
1245: writer.println(" private static String UI_BLUESCREEN=\""
1246: + uiBluescreen_ + "\";");
1247: line = reader.readLine();
1248: while ((line != null)
1249: && (!line.startsWith("// --> UIBluescreenColor"))) {
1250: writer.println(line);
1251: line = reader.readLine();
1252: }
1253: writer.println(" private static String UI_BLUESCREEN_COLOR=\""
1254: + uiBluescreenColor_ + "\";");
1255: line = reader.readLine();
1256: while ((line != null) && (!line.startsWith("// --> DestPath"))) {
1257: writer.println(line);
1258: line = reader.readLine();
1259: }
1260: writer.println(" private static String DEST_PATH=\""
1261: + destPath_ + "\";");
1262: line = reader.readLine();
1263: while ((line != null) && (!line.startsWith("// --> AppInfo"))) {
1264: writer.println(line);
1265: line = reader.readLine();
1266: }
1267: writer.println(" private static String APP_NAME=\"" + appName_
1268: + "\";");
1269: if (appVersion_ != null)
1270: writer.println(" private static String APP_VERSION=\""
1271: + appVersion_ + "\";");
1272: else
1273: writer.println(" private static String APP_VERSION=null;");
1274: line = reader.readLine();
1275: while ((line != null) && (!line.startsWith("// --> LinkInfos"))) {
1276: System.out.println("fred " + line);
1277: writer.println(line);
1278: line = reader.readLine();
1279: }
1280: writer.println(" private static String LINK_SECTION_NAME=\""
1281: + linkSectionName_ + "\";");
1282: writer.println(" private static String LINK_SECTION_ICON=\""
1283: + linkSectionIcon_ + "\";");
1284: writer.println(" private static String LINK_ENTRY_NAME=\""
1285: + linkEntryName_ + "\";");
1286: writer.println(" private static String LINK_ENTRY_ICON=\""
1287: + linkEntryIcon_ + "\";");
1288: if (createUninstallShortcut_)
1289: tempString = "true";
1290: else
1291: tempString = "false";
1292: writer
1293: .println(" private static boolean CREATE_UNINSTALL_SHORTCUT="
1294: + tempString + ";");
1295: line = reader.readLine();
1296: while ((line != null)
1297: && (!line.startsWith("// --> LicenseKey"))) {
1298: writer.println(line);
1299: line = reader.readLine();
1300: }
1301: writer
1302: .println(" private static String LICENSE_KEY_SUPPORT_NAME=\""
1303: + licenseKeySupportClassName_ + "\";");
1304: System.out.println(VAGlobals
1305: .i18n("VAArchiver_AppendingClassloader"));
1306: line = reader.readLine();
1307: while ((line != null)
1308: && (!line.startsWith("// --> ClassLoader"))) {
1309: writer.println(line);
1310: line = reader.readLine();
1311: }
1312: InputStream isClassLoader = getClass().getResourceAsStream(
1313: "/" + classLoader);
1314: // System.out.println(" CLASSLOADER = "+"/"+classLoader);
1315: writer.println(" private static String[] CL_CLASS={");
1316: read = isClassLoader.read(buf);
1317: while (read > 0) {
1318: writer.println("\"" + codeLine(buf, read) + "\",");
1319: read = isClassLoader.read(buf);
1320: }
1321: isClassLoader.close();
1322: writer.println(" };\n}");
1323: reader.close();
1324: writer.close();
1325: // HFALK
1326: is.close();
1327: isr.close();
1328: }
1329:
1330: private void generateJnlpFile(File jnlpFile) throws IOException {
1331: PrintWriter out = new PrintWriter(new BufferedWriter(
1332: new OutputStreamWriter(new FileOutputStream(jnlpFile),
1333: "UTF-8")));
1334: out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
1335: out.println("<jnlp spec=\"1.0\"");
1336: out.println(" codebase=\"" + jarCodebase_ + "\"");
1337: out.println(" href=\"" + instClassName_ + ".jnlp\">");
1338: out.println(" <information>");
1339: if (appVersion_ != null)
1340: out.println(" <title>" + appName_ + " " + appVersion_
1341: + " Installer</title>");
1342: else
1343: out.println(" <title>" + appName_ + " "
1344: + " Installer</title>");
1345: out.println(" <vendor>" + jarVendor_ + "</vendor>");
1346: out.println(" <homepage href=\"" + jarHomepage_ + "\"/>");
1347: if (appVersion_ != null)
1348: out.println(" <description>Installer for " + appName_
1349: + " " + appVersion_ + "</description>");
1350: else
1351: out.println(" <description>Installer for " + appName_
1352: + "</description>");
1353: //out.println("<icon href=\"alma-jnlp.png\" width=\"128\"
1354: // height=\"128\"/>");
1355: out.println(" <offline/>");
1356: out.println(" </information>");
1357: out.println(" <resources>");
1358: out.println(" <j2se version=\"1.3 1.2\"/>");
1359: out.println(" <jar href=\"" + instClassName_ + ".jar\"/>");
1360: out.println(" <property name=\"DEBUG\" value=\"yes\"/>");
1361: out.println(" </resources>");
1362: out.println(" <security>");
1363: out.println(" <all-permissions/>");
1364: out.println(" </security>");
1365: out.println(" <application-desc main-class=\""
1366: + instClassName_ + "\"/>");
1367: out.println("</jnlp>");
1368: out.close();
1369: }
1370:
1371: private void generateManifestFile(File mfFile) throws IOException {
1372: PrintWriter out = new PrintWriter(new BufferedWriter(
1373: new OutputStreamWriter(new FileOutputStream(mfFile),
1374: "UTF-8")));
1375: out.println("Manifest-Version: 1.0");
1376: out.println("Main-Class: " + instClassName_);
1377: out.close();
1378: }
1379:
1380: private long generateUnixInstallShell(File unixShellFile,
1381: String instTemplate, File instClassFile) throws IOException {
1382: FileOutputStream byteWriter = new FileOutputStream(
1383: unixShellFile);
1384: InputStream is = getClass().getResourceAsStream(
1385: "/" + instTemplate);
1386: InputStreamReader isr = new InputStreamReader(is);
1387: LineNumberReader reader = new LineNumberReader(isr);
1388: String content = "";
1389: String installClassStartStr = "000000000000";
1390: NumberFormat nf = NumberFormat.getInstance(Locale.US);
1391: nf.setGroupingUsed(false);
1392: nf.setMinimumIntegerDigits(installClassStartStr.length());
1393: int installClassStartPos = 0;
1394: long installClassOffset = 0;
1395: System.out.println(VAGlobals
1396: .i18n("VAArchiver_GenerateInstallShell"));
1397: String line = reader.readLine();
1398: while ((line != null)
1399: && (!line.startsWith("# InstallClassStart"))) {
1400: content += line + "\n";
1401: line = reader.readLine();
1402: }
1403: content += "InstallClassStart=" + installClassStartStr + "\n";
1404: installClassStartPos = content.length() - 1 - 1
1405: - installClassStartStr.length();
1406: line = reader.readLine();
1407: while ((line != null)
1408: && (!line.startsWith("# InstallClassSize"))) {
1409: content += line + "\n";
1410: line = reader.readLine();
1411: }
1412: content += new String("InstallClassSize="
1413: + instClassFile.length() + "\n");
1414: line = reader.readLine();
1415: while ((line != null)
1416: && (!line.startsWith("# InstallClassName"))) {
1417: content += line + "\n";
1418: line = reader.readLine();
1419: }
1420: content += new String("InstallClassName=" + instClassName_
1421: + "\n");
1422: line = reader.readLine();
1423: while ((line != null) && (!line.startsWith("# Install class"))) {
1424: content += line + "\n";
1425: line = reader.readLine();
1426: }
1427: if (line != null)
1428: content += line + "\n";
1429: byteWriter.write(content.substring(0, installClassStartPos + 1)
1430: .getBytes());
1431: byteWriter.write(nf.format(content.length()).getBytes());
1432: byteWriter.write(content.substring(
1433: installClassStartPos + 1
1434: + installClassStartStr.length()).getBytes());
1435: installClassOffset = content.length();
1436: content = null;
1437: FileInputStream classStream = new FileInputStream(instClassFile);
1438: byte[] buf = new byte[2048];
1439: int read = classStream.read(buf);
1440: while (read > 0) {
1441: byteWriter.write(buf, 0, read);
1442: read = classStream.read(buf);
1443: }
1444: classStream.close();
1445: reader.close();
1446: byteWriter.close();
1447: return installClassOffset;
1448: }
1449:
1450: private void shiftArray(byte[] array) {
1451: for (int i = 0; i < (array.length - 1); i++)
1452: array[i] = array[i + 1];
1453: array[array.length - 1] = 0;
1454: }
1455:
1456: private long generateNativeInstallExe(File nativeInstallFile,
1457: String instTemplate, File instClassFile) throws IOException {
1458: // method: we look for the items "clname_here", "clstart_here" et
1459: // "clstop_here_".
1460: // -> We read bytes one by one, but we write them with a 12 bytes
1461: // latency,
1462: // so we can have a 12 bytes "preview" window to test "clstart_here" or
1463: // "clstop_here_".
1464: // We replace "clname_here" with the name of the class and we end with a
1465: // dot.
1466: // We replace "clstart_here" with the size of the template file (the
1467: // class
1468: // is appended after it).
1469: // We remember the position of "clstop_here_", and we finish with the
1470: // file
1471: // in normal mode (bulk copy). We append the class, we calculate the
1472: // total
1473: // size in bytes, and we write it in place of "clstop_here_" (of which
1474: // we
1475: // know the position). We then only have to write all these bytes in the
1476: // destination file.
1477: // FileInputStream reader=new FileInputStream(instTemplate);
1478: InputStream reader = getClass().getResourceAsStream(
1479: "/" + instTemplate);
1480: // InputStreamReader reader = new InputStreamReader(is);
1481: // System.out.println("generateNativeInstallExe = /"+instTemplate);
1482: // System.out.println("reader length="+reader.available());
1483: ByteArrayOutputStream content = new ByteArrayOutputStream();
1484: String installClassVarStr = "000000000000";
1485: byte[] buf = new byte[installClassVarStr.length()];
1486: NumberFormat nf = NumberFormat.getInstance(Locale.US);
1487: nf.setGroupingUsed(false);
1488: nf.setMinimumIntegerDigits(installClassVarStr.length());
1489: int installClassStopPos = 0;
1490: long installClassOffset = reader.available();
1491: int position = 0;
1492: System.out.println(VAGlobals
1493: .i18n("VAArchiver_GenerateInstallExe"));
1494: // read the 12 first bytes
1495: reader.read(buf, 0, buf.length);
1496: // set write position with a 12 bytes latency
1497: position = 1;
1498: // look for the 3 anchors clname, clstart and clstop
1499: for (int n = 0; n < 3; n++) {
1500: // buf contains the preview window that we want to test.
1501: while ((!new String(buf).equals("clname_here_"))
1502: && (!new String(buf).equals("clstart_here"))
1503: && (!new String(buf).equals("clstop_here_"))) {
1504: content.write(buf[0]);
1505: // read a byte
1506: int nextb = reader.read();
1507: position++;
1508: shiftArray(buf);
1509: // write a byte
1510: buf[buf.length - 1] = (byte) nextb;
1511: }
1512: if (new String(buf).equals("clname_here_")) {
1513: VAGlobals.printDebug(" clname_here_ found at "
1514: + (position - 1));
1515: StringBuffer clnameBuffer = new StringBuffer(64);
1516: clnameBuffer.append(instClassName_);
1517: for (int i = clnameBuffer.length() - 1; i < 64; i++) {
1518: clnameBuffer.append('.');
1519: }
1520: byte[] clnameBytes = clnameBuffer.toString().getBytes();
1521: // write name of the class in place of "clname_here"
1522: for (int i = 0; i < 64; i++) {
1523: content.write(clnameBytes[i]);
1524: position++;
1525: }
1526: // skip 64 bytes ("clstart_here")
1527: reader.skip(64 - buf.length);
1528: // read 12 next bytes
1529: reader.read(buf, 0, buf.length);
1530: } else if (new String(buf).equals("clstart_here")) {
1531: VAGlobals.printDebug(" clstart_here found at "
1532: + (position - 1));
1533: buf = nf.format(installClassOffset).getBytes();
1534: // write size of template file in place of "clstart_here"
1535: for (int i = 0; i < buf.length; i++) {
1536: content.write(buf[i]);
1537: position++;
1538: }
1539: // read 12 next bytes
1540: reader.read(buf, 0, buf.length);
1541: } else if (new String(buf).equals("clstop_here_")) {
1542: VAGlobals.printDebug(" clstop_here_ found at "
1543: + (position - 1));
1544: // found "clstop_here_": remember it's position
1545: installClassStopPos = position - 1;
1546: // write "clstop_here_" (we don't know yet its value)
1547: content.write(buf);
1548: position += 12;
1549: // read 12 next bytes
1550: reader.read(buf, 0, buf.length);
1551: }
1552: }
1553: content.write(buf);
1554: // finish read/write in the normal way
1555: buf = new byte[2048];
1556: int read = reader.read(buf);
1557: while (read > 0) {
1558: content.write(buf, 0, read);
1559: read = reader.read(buf);
1560: }
1561: reader.close();
1562: // append the class
1563: FileInputStream classStream = new FileInputStream(instClassFile);
1564: read = classStream.read(buf);
1565: while (read > 0) {
1566: content.write(buf, 0, read);
1567: read = classStream.read(buf);
1568: }
1569: classStream.close();
1570: content.close();
1571: // the total size of written bytes is put in place of "clstop_here_"
1572: byte[] contentBytes = content.toByteArray();
1573: installClassVarStr = nf.format(contentBytes.length);
1574: byte[] installClassVarBytes = installClassVarStr.getBytes();
1575: for (int i = 0; i < installClassVarBytes.length; i++) {
1576: contentBytes[installClassStopPos + i] = installClassVarBytes[i];
1577: }
1578: // write whole content in destination file
1579: FileOutputStream out = new FileOutputStream(nativeInstallFile);
1580: out.write(contentBytes);
1581: out.close();
1582: return installClassOffset;
1583: }
1584:
1585: private void appendArchive(File instClass) throws IOException {
1586: FileOutputStream out = new FileOutputStream(
1587: instClass.getName(), true);
1588: FileInputStream zipStream = new FileInputStream("install.jar");
1589: byte[] buf = new byte[2048];
1590: int read = zipStream.read(buf);
1591: while (read > 0) {
1592: out.write(buf, 0, read);
1593: read = zipStream.read(buf);
1594: }
1595: zipStream.close();
1596: out.close();
1597: }
1598:
1599: private void copy(File fin, File fout) throws IOException {
1600: FileOutputStream out = null;
1601: FileInputStream in = null;
1602: try {
1603: out = new FileOutputStream(fout);
1604: in = new FileInputStream(fin);
1605: byte[] buf = new byte[2048];
1606: int read = in.read(buf);
1607: while (read > 0) {
1608: out.write(buf, 0, read);
1609: read = in.read(buf);
1610: }
1611: } catch (IOException _e) {
1612: throw _e;
1613: } finally {
1614: if (in != null)
1615: in.close();
1616: if (out != null)
1617: out.close();
1618: }
1619: }
1620:
1621: private void jar(String options, File jarFile, File[] files)
1622: throws IOException {
1623: Process p = null;
1624: Vector argsv = new Vector();
1625: argsv.add(getJavaBinPath() + File.separator + "jar");
1626: if (options != null && !options.equals(""))
1627: argsv.add(options);
1628: argsv.add(jarFile.getName());
1629: for (int i = 0; i < files.length; i++)
1630: argsv.add(files[i].getName());
1631: String[] args = new String[argsv.size()];
1632: for (int i = 0; i < args.length; i++)
1633: args[i] = (String) argsv.get(i);
1634: try {
1635: p = Runtime.getRuntime().exec(args);
1636: p.waitFor();
1637: } catch (Exception rte) {
1638: throw new IOException(
1639: "Runtime exception: check if you have installed the JDK and run java from the JDK\n"
1640: + "Exception message: " + rte.getMessage());
1641: }
1642: printCmdOutput(p, "jar");
1643: if (p.exitValue() != 0)
1644: throw new RuntimeException(" abnormal exit");
1645: }
1646:
1647: private void jarsign(String passphrase, File jarFile, String alias)
1648: throws IOException {
1649: Process p = null;
1650: try {
1651: p = Runtime.getRuntime().exec(
1652: new String[] {
1653: JDK_HOME + File.separator + "bin"
1654: + File.separator + "jarsigner",
1655: "-storepass", passphrase,
1656: jarFile.getName(), alias });
1657: p.waitFor();
1658: } catch (Exception rte) {
1659: throw new IOException(
1660: "Runtime exception: check if you have installed the JDK and run java from the JDK\n"
1661: + "Exception message: " + rte.getMessage());
1662: }
1663: printCmdOutput(p, "jarsign");
1664: if (p.exitValue() != 0)
1665: throw new RuntimeException(" abnormal exit");
1666: }
1667:
1668: private File compile(String javafile) throws IOException {
1669: File classFile = null;
1670: Process p = null;
1671: try {
1672: p = Runtime.getRuntime().exec(
1673: new String[] {
1674: getJavaBinPath() + File.separator + JAVAC,
1675: javafile });
1676: p.waitFor();
1677: } catch (Exception rte) {
1678: throw new IOException(
1679: "Runtime exception: check if you have installed the JDK and run java from the JDK\n"
1680: + "Exception message: " + rte.getMessage());
1681: }
1682: printCmdOutput(p, "javac");
1683: if (p.exitValue() != 0)
1684: throw new RuntimeException(" abnormal exit");
1685: classFile = new File(javafile.substring(0, javafile
1686: .lastIndexOf('.'))
1687: + ".class");
1688: System.out.println(" " + classFile + " " + classFile.exists());
1689: //if( !classFile.exists() ) throw new IOException("could not compile
1690: // "+javafile);
1691: return classFile;
1692: }
1693:
1694: private void printCmdOutput(Process p, String cmdName)
1695: throws IOException {
1696: BufferedReader psIn = new BufferedReader(new InputStreamReader(
1697: p.getInputStream()));
1698: BufferedReader psErr = new BufferedReader(
1699: new InputStreamReader(p.getErrorStream()));
1700: int n = 0;
1701: System.out.println(" --- start " + cmdName + " ---");
1702: String inLine = psIn.readLine();
1703: String errLine = psErr.readLine();
1704: while ((inLine != null) || (errLine != null)) {
1705: if (inLine != null)
1706: System.out.println(" " + inLine);
1707: if (errLine != null)
1708: System.err.println(" " + errLine);
1709: inLine = psIn.readLine();
1710: errLine = psErr.readLine();
1711: }
1712: psIn.close();
1713: psErr.close();
1714: System.out.println(" --- end " + cmdName + " ---");
1715: }
1716:
1717: private File makeJar(String filename, File archive, File license,
1718: File readme, byte[] archiveInfos) throws IOException {
1719: File jar = new File(filename);
1720: JarOutputStream out = new JarOutputStream(new FileOutputStream(
1721: jar));
1722: // copy common files to jar file
1723: copyInternalToJar(out, JAR_FILES_COMMON);
1724: copyInternalToJar(out, JAR_FILES_JNIREGISTRY);
1725: copyInternalToJar(out, JAR_FILES_JNISHORTCUT);
1726: // text and ansi uis are always provided
1727: copyInternalToJar(out, JAR_FILES_TEXT_UI);
1728: copyInternalToJar(out, JAR_FILES_ANSI_UI);
1729: if (uiMode_.equals("graphic"))
1730: copyInternalToJar(out, JAR_FILES_GRAPHIC_UI);
1731: if (uiMode_.equals("xtra"))
1732: copyInternalToJar(out, JAR_FILES_XTRA_UI);
1733: if (uiMode_.equals("unattended"))
1734: copyInternalToJar(out, JAR_FILES_UNATTENDED_UI);
1735: // custom pre/post processing classes
1736: if (customPrePostClassName_.length() > 0) {
1737: copyInternalToJar(out, JAR_FILES_CUSTOM_PRE_POST);
1738: // copy from jar file only if developer used new class
1739: if (!"com.memoire.vainstall.AbstractCustomPrePost"
1740: .equals(customPrePostClassName_)) {
1741: copyJarFilesToJar(out, customPrePostJarfileName_);
1742: }
1743: }
1744: // archive infos
1745: addToJar(out, new ByteArrayInputStream(archiveInfos),
1746: "com/memoire/vainstall/archive_infos",
1747: archiveInfos.length);
1748: // archive.zip
1749: addToJar(out, new FileInputStream(archive),
1750: "com/memoire/vainstall/archive.zip", archive.length());
1751: // license
1752: InputStream licenseStream = new FileInputStream(license);
1753: String licenseEncoding = VAProperties.PROPERTIES
1754: .getProperty("vainstall.archive.license.encoding");
1755: if (licenseEncoding == null
1756: || licenseEncoding.equals("") == true) {
1757: // Use default encoding
1758: licenseEncoding = new InputStreamReader(licenseStream)
1759: .getEncoding();
1760: }
1761: InputStreamReader isrLicense = new InputStreamReader(
1762: licenseStream, licenseEncoding);
1763: addToJarEncoded(out, isrLicense,
1764: "com/memoire/vainstall/license.txt", license.length());
1765: // readme
1766: InputStream readmeStream = new FileInputStream(readme);
1767: String readmeEncoding = VAProperties.PROPERTIES
1768: .getProperty("vainstall.archive.readme.encoding");
1769: if (readmeEncoding == null || readmeEncoding.equals("") == true) {
1770: // Use default encoding
1771: readmeEncoding = new InputStreamReader(readmeStream)
1772: .getEncoding();
1773: }
1774: InputStreamReader isrReadme = new InputStreamReader(
1775: readmeStream, readmeEncoding);
1776: addToJarEncoded(out, isrReadme,
1777: "com/memoire/vainstall/readme.txt", readme.length());
1778: // image
1779: InputStream invaiimage = null;
1780: try {
1781: invaiimage = new FileInputStream(new File(image_));
1782: } catch (Exception exc) {
1783: image_ = "/" + image_;
1784: invaiimage = getClass().getResourceAsStream(image_);
1785: }
1786: if (invaiimage == null) {
1787: invaiimage = getClass().getResourceAsStream(
1788: "com/memoire/vainstall/resources/banner.gif");
1789: image_ = "com/memoire/vainstall/resources/banner.gif";
1790: }
1791: if (invaiimage != null) {
1792: addToJar(out, invaiimage,
1793: "com/memoire/vainstall/resources/banner.gif",
1794: invaiimage.available());
1795: }
1796: // vailogo
1797: InputStream invailogo = getClass().getResourceAsStream(
1798: "/" + VAILOGO);
1799: addToJar(out, invailogo, VAILOGO, invailogo.available());
1800: // add file to control various settings like language
1801: // should be used instead of all those parameters to the setup routine
1802: ByteArrayOutputStream poutstream = new ByteArrayOutputStream();
1803: installProperties.store(poutstream, VAGlobals.NAME + " "
1804: + VAGlobals.VERSION);
1805: ByteArrayInputStream pinstream = new ByteArrayInputStream(
1806: poutstream.toByteArray());
1807: addToJar(out, pinstream,
1808: "com/memoire/vainstall/resources/vainstall.properties",
1809: poutstream.toByteArray().length);
1810: if (lnfFile_ != null) {
1811: System.out.println("add lnf jar file: "
1812: + lnfFile_.getAbsolutePath());
1813: addToJar(out, new FileInputStream(lnfFile_),
1814: "com/memoire/vainstall/resources/"
1815: + lnfFile_.getName(), lnfFile_.length());
1816: }
1817: System.out.println("additionalFiles");
1818: if (additionalFiles_ != null) {
1819: StringTokenizer fmi = new StringTokenizer(additionalFiles_,
1820: ",");
1821: while (fmi.hasMoreTokens()) {
1822: StringTokenizer fm = new StringTokenizer(fmi
1823: .nextToken(), "!");
1824: File sf = new File(fm.nextToken());
1825: String df = fm.nextToken();
1826: addToJar(out, new FileInputStream(sf), df, sf.length());
1827: }
1828: System.out.println("additionalFiles FIN");
1829: }
1830: out.close();
1831: return jar;
1832: }
1833:
1834: /**
1835: * Copy all files from a jar file from inside a jar file to a target jar
1836: * file
1837: *
1838: * @param out
1839: * JarOutputStream
1840: * @param jarSourceName
1841: * String
1842: */
1843: private void copyInternalToJar(JarOutputStream out,
1844: String[] JAR_FILES) throws IOException {
1845: for (int i = 0; i < JAR_FILES.length; i++) {
1846: String sourceName = JAR_FILES[i];
1847: if (sourceName.endsWith(".jar")) {
1848: copyJarFilesToJar(out, sourceName);
1849: } else {
1850: InputStream is = getClass().getResourceAsStream(
1851: "/" + sourceName);
1852: if (is == null) {
1853: System.out
1854: .println("Cannot add the resource "
1855: + sourceName
1856: + " to the jar, since it cannot be found (bummer!)");
1857: } else {
1858: addToJar(out, is, sourceName, is.available());
1859: }
1860: }
1861: } // endfor
1862: }
1863:
1864: /**
1865: * Copy all files from a jar file from inside a jar file to a target jar
1866: * file
1867: *
1868: * @param out
1869: * JarOutputStream
1870: * @param jarSourceName
1871: * String
1872: */
1873: private void copyJarFilesToJar(JarOutputStream out,
1874: String jarSourceName) throws IOException {
1875: byte[] buffer = new byte[2048];
1876: InputStream isJar = getClass().getResourceAsStream(
1877: "/" + jarSourceName);
1878: JarInputStream zin = new JarInputStream(isJar);
1879: JarEntry entry = null;
1880: while ((entry = zin.getNextJarEntry()) != null) {
1881: ByteArrayOutputStream bos = new ByteArrayOutputStream();
1882: while (true) {
1883: int read = zin.read(buffer);
1884: if (read == -1)
1885: break;
1886: bos.write(buffer, 0, read);
1887: }
1888: ByteArrayInputStream bais = new ByteArrayInputStream(bos
1889: .toByteArray());
1890: addToJar(out, bais, entry.getName(),
1891: bos.toByteArray().length);
1892: bos.close();
1893: zin.closeEntry();
1894: } // endwhile
1895: zin.close();
1896: isJar.close();
1897: }
1898:
1899: private void addToJar(JarOutputStream out, InputStream in,
1900: String entryName, long length) throws IOException {
1901: byte[] buf = new byte[2048];
1902: ZipEntry entry = new ZipEntry(entryName);
1903: CRC32 crc = new CRC32();
1904: entry.setSize(length);
1905: entry.setCrc(crc.getValue());
1906: out.putNextEntry(entry);
1907: int read = in.read(buf);
1908: while (read > 0) {
1909: crc.update(buf, 0, read);
1910: out.write(buf, 0, read);
1911: read = in.read(buf);
1912: }
1913: entry.setCrc(crc.getValue());
1914: // System.out.println(" entry = "+entry.getName()+" "+entry.getSize());
1915: in.close();
1916: out.closeEntry();
1917: }
1918:
1919: private void addToJarEncoded(JarOutputStream out,
1920: InputStreamReader isr, String entryName, long length)
1921: throws IOException {
1922: StringBuffer buffer = new StringBuffer();
1923: Reader reader = new BufferedReader(isr);
1924: int ch;
1925: while ((ch = reader.read()) > -1) {
1926: buffer.append((char) ch);
1927: }
1928: reader.close();
1929: isr.close();
1930: ByteArrayOutputStream baos = new ByteArrayOutputStream();
1931: OutputStreamWriter osw = new OutputStreamWriter(baos, "UTF8");
1932: osw.write(buffer.toString());
1933: osw.flush();
1934: ByteArrayInputStream bais = new ByteArrayInputStream(baos
1935: .toByteArray());
1936: addToJar(out, bais, entryName, length);
1937: }
1938:
1939: // private static long
1940: private boolean checkVaiPath(String dir) {
1941: int index = dir.indexOf(']');
1942: if (!dir.startsWith("["))
1943: return true;
1944: if (index <= 2)
1945: return false;
1946: String prefix = dir.substring(1, index).trim();
1947: /*
1948: * if( ("HOME".equals(prefix))|| ("PROGRAM".equals(prefix)) ) return
1949: * true;
1950: */
1951: if ("HOME".equals(prefix) || "PROGRAM".equals(prefix)
1952: || prefix.startsWith("ENV{")) {
1953: return true;
1954: }
1955: if ((prefix.length() == 2) && (prefix.endsWith(":"))
1956: && (Character.isLetter(prefix.charAt(0))))
1957: return true;
1958: return false;
1959: }
1960:
1961: private String codeLine(byte[] data, int siz) {
1962: String res = null;
1963: byte[] convert = new byte[2 * siz];
1964: for (int i = 0; i < siz; i++) {
1965: convert[2 * i] = (byte) (65 + (data[i] & 0x0F));
1966: convert[2 * i + 1] = (byte) (65 + (data[i] & 0xF0) / 16);
1967: }
1968: res = new String(convert);
1969: return res;
1970: }
1971: }
1972:
1973: class FileNameGroup {
1974: String originBase_, destBase_, commonPath_, extensions_;
1975:
1976: boolean executable_;
1977:
1978: boolean recursive_;
1979:
1980: public FileNameGroup(String line) {
1981: executable_ = false;
1982: recursive_ = true;
1983: if (line.startsWith("(E)")) {
1984: line = line.substring(3);
1985: executable_ = true;
1986: }
1987: if (line.startsWith("(N)")) {
1988: line = line.substring(3);
1989: recursive_ = false;
1990: }
1991: StringTokenizer tok = new StringTokenizer(new String(line),
1992: "|", true);
1993: originBase_ = tok.nextToken();
1994: if (originBase_.endsWith("/"))
1995: originBase_ = originBase_.substring(0,
1996: originBase_.length() - 1);
1997: tok.nextToken();
1998: destBase_ = tok.nextToken();
1999: if (destBase_.equals("|"))
2000: destBase_ = null;
2001: else {
2002: if (destBase_.endsWith("/"))
2003: destBase_ = destBase_.substring(0,
2004: destBase_.length() - 1);
2005: tok.nextToken();
2006: }
2007: extensions_ = null;
2008: commonPath_ = null;
2009: if (tok.hasMoreTokens()) {
2010: commonPath_ = tok.nextToken();
2011: if (commonPath_.equals("|"))
2012: commonPath_ = null;
2013: if (tok.hasMoreTokens()) {
2014: if (commonPath_ != null)
2015: tok.nextToken();
2016: if (tok.hasMoreTokens())
2017: extensions_ = tok.nextToken();
2018: }
2019: }
2020: }
2021:
2022: public String getOrigin() {
2023: if (commonPath_ == null)
2024: return originBase_;
2025: return originBase_ + "/" + commonPath_;
2026: }
2027:
2028: public String getDestination() {
2029: if ((destBase_ == null) && (commonPath_ == null))
2030: return "";
2031: if (destBase_ == null)
2032: return commonPath_;
2033: if (commonPath_ == null)
2034: return destBase_;
2035: return destBase_ + "/" + commonPath_;
2036: }
2037:
2038: public FileFilter getFileFilter() throws IllegalArgumentException {
2039: String[] ext = null;
2040: if (extensions_ != null) {
2041: StringTokenizer t = new StringTokenizer(extensions_, ",");
2042: ext = new String[t.countTokens()];
2043: for (int i = 0; i < ext.length; i++) {
2044: ext[i] = t.nextToken();
2045: if ((ext[i].length() >= 2) && (ext[i].startsWith("*")))
2046: ext[i] = ext[i].substring(1);
2047: else if ((ext[i].length() >= 3)
2048: && (ext[i].startsWith("!*")))
2049: ext[i] = "!" + ext[i].substring(2);
2050: else
2051: throw new IllegalArgumentException(
2052: "invalid pattern: " + ext[i]);
2053: }
2054: }
2055: return new VaiFileFilter(ext);
2056: }
2057:
2058: public boolean isExecutable() {
2059: return executable_;
2060: }
2061:
2062: public boolean isRecursive() {
2063: return recursive_;
2064: }
2065: }
2066:
2067: class VaiFileFilter implements FileFilter {
2068: String[] ext_;
2069:
2070: public VaiFileFilter(String[] ext) {
2071: ext_ = ext;
2072: }
2073:
2074: public boolean accept(File pathname) {
2075: boolean a = true;
2076: if (ext_ == null)
2077: return true;
2078: String p = pathname.getName();
2079: for (int i = 0; i < ext_.length; i++) {
2080: if (ext_[i].startsWith("!")) {
2081: a = a && (!p.endsWith(ext_[i].substring(1)));
2082: } else {
2083: a = a && (p.endsWith(ext_[i]));
2084: }
2085: }
2086: return a;
2087: }
2088: }
|