Source Code Cross Referenced for VAInstallTask.java in  » Installer » VAInstall » com » memoire » vainstall » ant » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Installer » VAInstall » com.memoire.vainstall.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * $RCSfile: VAInstallTask.java,v $
0003:         * @modification $Date: 2005/03/06 23:04:20 $
0004:         * @version      $Id: VAInstallTask.java,v 1.24 2005/03/06 23:04:20 deniger Exp $
0005:         *
0006:         */
0007:
0008:        package com.memoire.vainstall.ant;
0009:
0010:        import org.apache.tools.ant.*;
0011:        import org.apache.tools.ant.taskdefs.*;
0012:        import org.apache.tools.ant.types.*;
0013:        import org.apache.tools.ant.util.*;
0014:
0015:        // **** VAArchiver imports begins here
0016:        import com.memoire.vainstall.*;
0017:        import java.util.zip.*;
0018:        import java.util.jar.*;
0019:        import java.util.*;
0020:        import java.text.*;
0021:        import java.io.*;
0022:        import java.net.*;
0023:
0024:        // **** VAArchiver imports ends here
0025:
0026:        /**
0027:         * Ant Task that integrates VAInstall into Ant
0028:         *
0029:         * The code is based on com.memoire.vainstall.VAArchiver
0030:         *
0031:         * In this version we extends Task which is a problem
0032:         * since we would like to extend VAArchiver too.
0033:         *
0034:         * @see com.memoire.vainstall.VAArchiver
0035:         *
0036:         * @author Henrik Falk
0037:         * @version $Id: VAInstallTask.java,v 1.24 2005/03/06 23:04:20 deniger Exp $
0038:         *
0039:         */
0040:        public class VAInstallTask extends Task {
0041:
0042:            // **** VAArchiver attributes begins here
0043:
0044:            private static final String JAVA_HOME = System
0045:                    .getProperty("java.home");
0046:            private static final String JDK_HOME = System
0047:                    .getProperty("java.home")
0048:                    + File.separator + "..";
0049:            private static String VAILOGO = null;
0050:
0051:            private static final String[] JAR_FILES_COMMON = new String[] {
0052:                    "com/memoire/vainstall/Language_da_DK.class",
0053:                    "com/memoire/vainstall/Language_de_DE.class",
0054:                    "com/memoire/vainstall/Language_en_UK.class",
0055:                    "com/memoire/vainstall/Language_fr_FR.class",
0056:                    "com/memoire/vainstall/Language_ja_JP.class",
0057:                    "com/memoire/vainstall/Language_it_IT.class",
0058:                    "com/memoire/vainstall/AbstractInstall.class",
0059:                    "com/memoire/vainstall/Setup.class",
0060:                    "com/memoire/vainstall/VAClassLoader.class",
0061:                    "com/memoire/vainstall/SetupFileFilter.class",
0062:                    "com/memoire/vainstall/UpgradeInfo.class",
0063:                    "com/memoire/vainstall/LogInfo.class",
0064:                    "com/memoire/vainstall/Uninstall.class",
0065:                    "com/memoire/vainstall/VAGlobals.class",
0066:                    "com/memoire/vainstall/VAStats.class",
0067:                    "com/memoire/vainstall/VAStep.class",
0068:                    "com/memoire/vainstall/VAStepFactory.class",
0069:                    "com/memoire/vainstall/VAWelcomeStep.class",
0070:                    "com/memoire/vainstall/VAReadmeStep.class",
0071:                    "com/memoire/vainstall/VALanguageStep.class",
0072:                    "com/memoire/vainstall/VALicenseStep.class",
0073:                    "com/memoire/vainstall/VALicenseKeyStep.class",
0074:                    "com/memoire/vainstall/VADirectoryStep.class",
0075:                    "com/memoire/vainstall/VAInstallStep.class",
0076:                    "com/memoire/vainstall/VAUpgradeStep.class",
0077:                    "com/memoire/vainstall/VAShortcutStep.class",
0078:                    "com/memoire/vainstall/VAEndStep.class",
0079:                    "com/memoire/vainstall/VAWizardInterface.class",
0080:                    "com/memoire/vainstall/VALinkDebian.class",
0081:                    "com/memoire/vainstall/VALinkGnome.class",
0082:                    "com/memoire/vainstall/VALinkWindows.class",
0083:                    "com/memoire/vainstall/VALinkKDE.class",
0084:
0085:                    "com/memoire/vainstall/LicenseKeySupport.class",
0086:                    "com/memoire/vainstall/LicenseKeySupport$FieldInfo.class",
0087:                    "com/memoire/vainstall/DefaultLicenseKeySupport.class",
0088:                    "com/memoire/vainstall/TestLicenseKeySupport.class" };
0089:
0090:            private static final String[] JAR_FILES_JNISHORTCUT = new String[] {
0091:                    "JNIWindowsShortcut.dll",
0092:                    "com/memoire/vainstall/JNIWindowsShortcut.class", };
0093:
0094:            private static final String[] JAR_FILES_JNIREGISTRY = new String[] {
0095:                    "ICE_JNIRegistry.dll",
0096:                    "com/ice/jni/registry/NoSuchKeyException.class",
0097:                    "com/ice/jni/registry/NoSuchValueException.class",
0098:                    "com/ice/jni/registry/RegBinaryValue.class",
0099:                    "com/ice/jni/registry/RegDWordValue.class",
0100:                    "com/ice/jni/registry/RegMultiStringValue.class",
0101:                    "com/ice/jni/registry/RegStringValue.class",
0102:                    "com/ice/jni/registry/Registry.class",
0103:                    "com/ice/jni/registry/RegistryException.class",
0104:                    "com/ice/jni/registry/RegistryKey.class",
0105:                    "com/ice/jni/registry/RegistryValue.class",
0106:                    "com/ice/text/HexNumberFormat.class",
0107:                    "com/ice/util/AWTUtilities.class",
0108:                    "com/ice/util/ClassUtilities.class",
0109:                    "com/ice/util/FileLog.class",
0110:                    "com/ice/util/HTTPUtilities.class",
0111:                    "com/ice/util/HexDump.class",
0112:                    "com/ice/util/StringUtilities.class",
0113:                    "com/ice/util/URLUtilities.class",
0114:                    "com/ice/util/UserProperties.class" };
0115:
0116:            private static final String[] JAR_FILES_TEXT_UI = new String[] {
0117:                    "com/memoire/vainstall/tui/Language_da_DK.class",
0118:                    "com/memoire/vainstall/tui/Language_de_DE.class",
0119:                    "com/memoire/vainstall/tui/Language_en_UK.class",
0120:                    "com/memoire/vainstall/tui/Language_fr_FR.class",
0121:                    "com/memoire/vainstall/tui/Language_ja_JP.class",
0122:                    "com/memoire/vainstall/tui/NullOutputStream.class",
0123:                    "com/memoire/vainstall/tui/TuiDefaultStep.class",
0124:                    "com/memoire/vainstall/tui/TuiDirectoryStep.class",
0125:                    "com/memoire/vainstall/tui/TuiInstallStep.class",
0126:                    "com/memoire/vainstall/tui/TuiLanguageStep.class",
0127:                    "com/memoire/vainstall/tui/TuiLicenseStep.class",
0128:                    "com/memoire/vainstall/tui/TuiReadmeStep.class",
0129:                    "com/memoire/vainstall/tui/TuiShortcutStep.class",
0130:                    "com/memoire/vainstall/tui/TuiWelcomeStep.class",
0131:                    "com/memoire/vainstall/tui/TuiWizard.class",
0132:                    "com/memoire/vainstall/tui/VATextUI.class",
0133:                    "com/memoire/vainstall/tui/TuiUpgradeStep.class",
0134:                    "com/memoire/vainstall/tui/TuiEndStep.class", };
0135:
0136:            private static final String[] JAR_FILES_ANSI_UI = new String[] {
0137:            // Requires files from JAR_FILES_TEXT_UI
0138:            "com/memoire/vainstall/aui/VAAnsiUI.class", };
0139:
0140:            private static final String[] JAR_FILES_GRAPHIC_UI = new String[] {
0141:                    "com/memoire/vainstall/gui/Language_da_DK.class",
0142:                    "com/memoire/vainstall/gui/Language_de_DE.class",
0143:                    "com/memoire/vainstall/gui/Language_en_UK.class",
0144:                    "com/memoire/vainstall/gui/Language_fr_FR.class",
0145:                    "com/memoire/vainstall/gui/Language_ja_JP.class",
0146:                    "com/memoire/vainstall/gui/VABlueScreen.class",
0147:                    "com/memoire/vainstall/gui/VABlueScreen$1.class",
0148:                    "com/memoire/vainstall/gui/VAGraphicUI.class",
0149:                    "com/memoire/vainstall/gui/VAWizard.class",
0150:                    "com/memoire/vainstall/gui/VAPanel.class",
0151:                    "com/memoire/vainstall/gui/VAWelcomePanel.class",
0152:                    "com/memoire/vainstall/gui/VAImagePanel.class",
0153:                    "com/memoire/vainstall/gui/VAInstallPanel.class",
0154:                    "com/memoire/vainstall/gui/VALanguagePanel.class",
0155:                    "com/memoire/vainstall/gui/VALicensePanel.class",
0156:                    "com/memoire/vainstall/gui/VALicenseKeyPanel.class",
0157:                    "com/memoire/vainstall/gui/VALicenseKeyPanel$1.class",
0158:                    "com/memoire/vainstall/gui/VAReadmePanel.class",
0159:                    "com/memoire/vainstall/gui/VADirectoryPanel.class",
0160:                    "com/memoire/vainstall/gui/VADirectoryPanel$1.class",
0161:                    "com/memoire/vainstall/gui/VAUpgradePanel.class",
0162:                    "com/memoire/vainstall/gui/VAShortcutPanel.class",
0163:                    "com/memoire/vainstall/gui/VAEndPanel.class", };
0164:
0165:            private static final String[] JAR_FILES_XTRA_UI = new String[] {
0166:                    "com/memoire/vainstall/xui/Language_da_DK.class",
0167:                    "com/memoire/vainstall/xui/Language_de_DE.class",
0168:                    "com/memoire/vainstall/xui/Language_en_UK.class",
0169:                    "com/memoire/vainstall/xui/Language_fr_FR.class",
0170:                    "com/memoire/vainstall/xui/Language_ja_JP.class",
0171:                    "com/memoire/vainstall/xui/XuiBlueScreen.class",
0172:                    "com/memoire/vainstall/xui/XuiWizard.class",
0173:                    "com/memoire/vainstall/xui/XuiAbstractPanel.class",
0174:                    "com/memoire/vainstall/xui/XuiPanel.class",
0175:                    "com/memoire/vainstall/xui/XuiImagePanel.class",
0176:                    "com/memoire/vainstall/xui/XuiTitle.class",
0177:                    "com/memoire/vainstall/xui/XuiButton.class",
0178:                    "com/memoire/vainstall/xui/XuiButtonBorder.class",
0179:                    "com/memoire/vainstall/xui/XuiLabel.class",
0180:                    "com/memoire/vainstall/xui/XuiRadioButton.class",
0181:                    "com/memoire/vainstall/xui/XuiOptionPane.class",
0182:                    "com/memoire/vainstall/xui/XuiWelcomePanel.class",
0183:                    "com/memoire/vainstall/xui/XuiReadmePanel.class",
0184:                    "com/memoire/vainstall/xui/XuiLicensePanel.class",
0185:                    "com/memoire/vainstall/xui/XuiInstallPanel.class",
0186:                    "com/memoire/vainstall/xui/XuiShortcutPanel.class",
0187:                    "com/memoire/vainstall/xui/XuiUpgradePanel.class",
0188:                    "com/memoire/vainstall/xui/XuiLanguagePanel.class",
0189:                    "com/memoire/vainstall/xui/XuiEndPanel.class",
0190:                    "com/memoire/vainstall/xui/XuiDirectoryPanel$1.class",
0191:                    "com/memoire/vainstall/xui/XuiDirectoryPanel.class",
0192:                    "com/memoire/vainstall/xui/VAXtraUI.class", };
0193:
0194:            private final static String IMAGE_KEY = "com/memoire/vainstall/resources/banner.gif";
0195:
0196:            private File filelist_;
0197:            private String destPath_;
0198:            private String archMethod_;
0199:            private long archOffset_;
0200:            private long installClassOffset_;
0201:            private long installClassSize_;
0202:            private long jarSize_;
0203:            private String licenseKeySupportClassName_ = "com.memoire.vainstall.DefaultLicenseKeySupport";
0204:            private String encodeKey_;
0205:            private LicenseKeySupport licenseKeySupport_;
0206:            private String additionalFiles_;
0207:
0208:            private String uiMode_;
0209:            private String uiBluescreen_;
0210:            private String uiBluescreenColor_;
0211:
0212:            private String image_;
0213:
0214:            private String appName_, appVersion_;
0215:            private String linkSectionName_, linkSectionIcon_, linkEntryName_,
0216:                    linkEntryIcon_;
0217:            private String instClassName_;
0218:            private String[] targets_;
0219:            private String currentTarget_;
0220:            private String jarAlias_, jarPassphrase_, jarCodebase_, jarVendor_,
0221:                    jarHomepage_;
0222:            private File license_;
0223:            private File readme_;
0224:            private ByteArrayOutputStream archiveInfos_;
0225:            private int archivecount_;
0226:            private Vector archiveEntryList_;
0227:
0228:            // used for properties in install.class f.ex. language
0229:            private Properties installProperties = new Properties();
0230:
0231:            // **** VAArchiver attributes ends here
0232:
0233:            protected Vector filesets = new Vector();
0234:
0235:            protected Vector javaLauncherList = new Vector();
0236:
0237:            /**
0238:             * Adds a set of files (nested fileset attribute).
0239:             */
0240:            public void addFileset(FileSet set) {
0241:                filesets.addElement(set);
0242:            }
0243:
0244:            public JavaLauncherArgument createJavaLauncher() {
0245:                JavaLauncherArgument ga = new JavaLauncherArgument();
0246:                javaLauncherList.addElement(ga);
0247:                return ga;
0248:            }
0249:
0250:            public class JavaLauncherArgument {
0251:                private String scriptname; // required
0252:                private String javaclass; // required
0253:
0254:                private String classargs; // optional
0255:                private String javamode; // optional
0256:                private String javaargs; // optional
0257:                private String classpath; // optional
0258:
0259:                public JavaLauncherArgument() {
0260:                }
0261:
0262:                public void setScriptname(String arg) {
0263:                    scriptname = arg;
0264:                }
0265:
0266:                public String getScriptname() {
0267:                    return scriptname;
0268:                }
0269:
0270:                public void setJavaclass(String arg) {
0271:                    javaclass = arg;
0272:                }
0273:
0274:                public String getJavaclass() {
0275:                    return javaclass;
0276:                }
0277:
0278:                public void setClassargs(String arg) {
0279:                    classargs = arg;
0280:                }
0281:
0282:                public String getClassargs() {
0283:                    return classargs;
0284:                }
0285:
0286:                public void setJavamode(String arg) {
0287:                    javamode = arg;
0288:                }
0289:
0290:                public String getJavamode() {
0291:                    return javamode;
0292:                }
0293:
0294:                public void setJavaargs(String arg) {
0295:                    javaargs = arg;
0296:                }
0297:
0298:                public String getJavaargs() {
0299:                    return javaargs;
0300:                }
0301:
0302:                public void setClasspath(String arg) {
0303:                    classpath = arg;
0304:                }
0305:
0306:                public String getClasspath() {
0307:                    return classpath;
0308:                }
0309:
0310:            } // end innerclass
0311:
0312:            public void execute() throws BuildException {
0313:
0314:                validateAttributes();
0315:
0316:                start();
0317:            }
0318:
0319:            protected void validateAttributes() throws BuildException {
0320:                if (filesets.size() == 0) {
0321:                    throw new BuildException("Specify at least one fileset.");
0322:                }
0323:
0324:                // validate JavaLauncher
0325:                for (int l = 0; l < javaLauncherList.size(); l++) {
0326:                    JavaLauncherArgument arg = (JavaLauncherArgument) javaLauncherList
0327:                            .elementAt(l);
0328:                    if (arg.getScriptname() == null
0329:                            || arg.getJavaclass() == null) {
0330:                        throw new BuildException(
0331:                                "'scriptname' and 'javaclass' is required for 'javalauncher'.");
0332:                    }
0333:                } // endfor
0334:            }
0335:
0336:            private void addFilesetsToArchive(ZipOutputStream stream)
0337:                    throws java.io.IOException {
0338:
0339:                // deal with the filesets
0340:                for (int i = 0; i < filesets.size(); i++) {
0341:                    FileSet fs = (FileSet) filesets.elementAt(i);
0342:                    DirectoryScanner ds = fs.getDirectoryScanner(project);
0343:                    String workDirAsString = fs.getDir(project).toString();
0344:
0345:                    String[] srcFiles = ds.getIncludedFiles();
0346:                    String[] srcDirs = ds.getIncludedDirectories();
0347:
0348:                    // Add directories
0349:                    /*
0350:                     for(int k=0;k<srcDirs.length;k++)
0351:                     {
0352:                     System.out.println("dir="+srcDirs[k]+"/");
0353:
0354:                     ZipEntry newEntry=new ZipEntry(srcDirs[k]+"/");
0355:                     stream.putNextEntry(newEntry);
0356:                     stream.closeEntry();
0357:                     // Add directory to entrylist
0358:                     archiveEntryList_.add(srcDirs[k]+"/");
0359:                     }
0360:                     */
0361:                    // add files
0362:                    for (int j = 0; j < srcFiles.length; j++) {
0363:                        System.out.println("file=" + srcFiles[j]);
0364:                        ZipEntry newEntry = new ZipEntry(srcFiles[j]);
0365:                        stream.putNextEntry(newEntry);
0366:                        FileInputStream in = new FileInputStream(
0367:                                workDirAsString + File.separator + srcFiles[j]);
0368:                        byte[] buf = new byte[2048];
0369:                        int read = in.read(buf, 0, buf.length);
0370:                        while (read > 0) {
0371:                            stream.write(buf, 0, read);
0372:                            read = in.read(buf, 0, buf.length);
0373:                        }
0374:                        in.close();
0375:                        stream.closeEntry();
0376:                        archivecount_++;
0377:                        archiveEntryList_.add(srcFiles[j]);
0378:                    }
0379:
0380:                } // endfor
0381:
0382:            }
0383:
0384:            // **** VAArchiver code begins here
0385:
0386:            public VAInstallTask() {
0387:                filelist_ = null;
0388:                destPath_ = null;
0389:                archMethod_ = null;
0390:                installClassOffset_ = -10987654321L;
0391:                installClassSize_ = -1234543210L;
0392:                archOffset_ = -1234567890L;
0393:                uiMode_ = null;
0394:                uiBluescreenColor_ = null;
0395:                uiBluescreen_ = null;
0396:                appName_ = appVersion_ = null;
0397:                linkSectionName_ = linkSectionIcon_ = linkEntryName_ = linkEntryIcon_ = null;
0398:                instClassName_ = null;
0399:                targets_ = new String[0];
0400:                jarAlias_ = jarPassphrase_ = jarCodebase_ = jarHomepage_ = jarVendor_ = null;
0401:                license_ = null;
0402:                readme_ = null;
0403:                archiveInfos_ = null;
0404:                archivecount_ = 0;
0405:                archiveEntryList_ = new Vector();
0406:            }
0407:
0408:            public void start() {
0409:                if (!processProperties())
0410:                    return;
0411:
0412:                try {
0413:                    log(VAGlobals.i18n("VAArchiver_CompressingFiles"));
0414:
0415:                    archiveInfos_ = new ByteArrayOutputStream();
0416:                    File zip = makeArchive("archive.zip");
0417:                    zip.deleteOnExit();
0418:
0419:                    System.out.println(VAGlobals
0420:                            .i18n("VAArchiver_CreatingJarFiles"));
0421:                    archiveInfos_.flush();
0422:                    byte[] infosbytes = archiveInfos_.toByteArray();
0423:                    File jar = makeJar("install.jar", zip, license_, readme_,
0424:                            infosbytes);
0425:                    jarSize_ = jar.length();
0426:                    archiveInfos_.close();
0427:                    jar.deleteOnExit();
0428:
0429:                    File installJavaFile = new File(instClassName_ + ".java");
0430:                    installJavaFile.deleteOnExit();
0431:                    File instClass = null;
0432:                    boolean deleteInstallClass = true;
0433:
0434:                    for (int i = 0; i < targets_.length; i++) {
0435:
0436:                        System.out.println();
0437:                        System.out.println(targets_[i]
0438:                                + VAGlobals.i18n("VAArchiver_Target"));
0439:                        currentTarget_ = targets_[i];
0440:                        System.out.println(VAGlobals
0441:                                .i18n("VAArchiver_GeneratingInstallClass"));
0442:                        // this pass of generation of installClass is to calculate installClassSize
0443:                        // with TARGET_TYPE being set to its correct value
0444:                        // well, this is not useful for jnlp, but it won't hurt
0445:                        generateInstallCode(
0446:                                installJavaFile,
0447:                                "com/memoire/vainstall/resources/Install.vaitpl",
0448:                                "com/memoire/vainstall/VAClassLoader.class");
0449:                        System.out.println(VAGlobals
0450:                                .i18n("VAArchiver_CompilingInstallClass"));
0451:                        instClass = compile(installJavaFile.getName());
0452:                        installClassSize_ = instClass.length();
0453:                        VAGlobals.printDebug("  InstallClass size="
0454:                                + installClassSize_);
0455:
0456:                        if ("jar".equals(targets_[i])) {
0457:                            File jarTarget = new File(instClassName_ + ".jar");
0458:                            File mfFile = new File(instClassName_ + ".mf");
0459:                            mfFile.deleteOnExit();
0460:                            System.out.println(VAGlobals
0461:                                    .i18n("VAArchiver_CreatingManifestFile"));
0462:                            generateManifestFile(mfFile);
0463:                            // Build the JAR
0464:                            System.out.println(VAGlobals
0465:                                    .i18n("VAArchiver_UpdatingJarFile"));
0466:                            copy(jar, jarTarget);
0467:                            jar("uvfm", jarTarget, new File[] { mfFile,
0468:                                    instClass });
0469:                            // Sign the JAR
0470:                            if (jarAlias_ != null
0471:                                    && !"".equals(jarAlias_.trim())
0472:                                    && jarPassphrase_ != null
0473:                                    && !"".equals(jarPassphrase_.trim())) {
0474:                                System.out.println(VAGlobals
0475:                                        .i18n("VAArchiver_SigningJarFile"));
0476:                                jarsign(jarPassphrase_, jarTarget, jarAlias_);
0477:                            }
0478:                        } else if ("jnlp".equals(targets_[i])) {
0479:                            File jnlpFile = new File(instClassName_ + ".jnlp");
0480:                            System.out.println(VAGlobals
0481:                                    .i18n("VAArchiver_CreatingJnlpFile"));
0482:                            generateJnlpFile(jnlpFile);
0483:                        } else
0484:
0485:                        if ("java".equals(targets_[i])) {
0486:                            installClassOffset_ = -10987654321L;
0487:                            deleteInstallClass = false;
0488:                            if (archMethod_.equals("append")) {
0489:                                archOffset_ = instClass.length();
0490:                                VAGlobals.printDebug(VAGlobals
0491:                                        .i18n("VAArchiver_ArchiveOffset")
0492:                                        + archOffset_);
0493:                                generateInstallCode(
0494:                                        installJavaFile,
0495:                                        "com/memoire/vainstall/resources/Install.vaitpl",
0496:                                        "com/memoire/vainstall/VAClassLoader.class");
0497:                                System.out
0498:                                        .println(VAGlobals
0499:                                                .i18n("VAArchiver_CompilingInstallClass"));
0500:                                compile(installJavaFile.getName());
0501:                                System.out.println(VAGlobals
0502:                                        .i18n("VAArchiver_AppendingArchive"));
0503:                                appendArchive(instClass);
0504:                            }
0505:                        } else if ("unix".equals(targets_[i])) {
0506:                            File unixShellFile = new File(instClassName_
0507:                                    + ".sh");
0508:
0509:                            installClassOffset_ = generateUnixInstallShell(
0510:                                    unixShellFile,
0511:                                    "com/memoire/vainstall/resources/Install-sh.vaitpl",
0512:                                    instClass);
0513:                            VAGlobals.printDebug(VAGlobals
0514:                                    .i18n("VAArchiver_InstallClassOffset")
0515:                                    + installClassOffset_);
0516:
0517:                            if (archMethod_.equals("append")) {
0518:                                archOffset_ = unixShellFile.length();
0519:                                VAGlobals.printDebug(VAGlobals
0520:                                        .i18n("VAArchiver_ArchiveOffset")
0521:                                        + archOffset_);
0522:                                generateInstallCode(
0523:                                        installJavaFile,
0524:                                        "com/memoire/vainstall/resources/Install.vaitpl",
0525:                                        "com/memoire/vainstall/VAClassLoader.class");
0526:                                System.out
0527:                                        .println(VAGlobals
0528:                                                .i18n("VAArchiver_CompilingInstallClass"));
0529:                                compile(installJavaFile.getName());
0530:                                generateUnixInstallShell(
0531:                                        unixShellFile,
0532:                                        "com/memoire/vainstall/resources/Install-sh.vaitpl",
0533:                                        instClass);
0534:                                System.out.println(VAGlobals
0535:                                        .i18n("VAArchiver_AppendingArchive"));
0536:                                appendArchive(unixShellFile);
0537:                            }
0538:                        } else if (("win95".equals(targets_[i]))
0539:                                || ("linux-i386".equals(targets_[i]))) {
0540:                            File nativeExeFile = null;
0541:                            if ("win95".equals(targets_[i]))
0542:                                nativeExeFile = new File(instClassName_
0543:                                        + ".exe");
0544:                            else if ("linux-i386".equals(targets_[i]))
0545:                                nativeExeFile = new File(instClassName_
0546:                                        + ".lin");
0547:
0548:                            installClassOffset_ = generateNativeInstallExe(
0549:                                    nativeExeFile,
0550:                                    "com/memoire/vainstall/resources/Install-"
0551:                                            + targets_[i] + "-exe.vaitpl",
0552:                                    instClass);
0553:                            VAGlobals.printDebug(VAGlobals
0554:                                    .i18n("VAArchiver_InstallClassOffset")
0555:                                    + installClassOffset_);
0556:
0557:                            if (archMethod_.equals("append")) {
0558:                                archOffset_ = nativeExeFile.length();
0559:                                VAGlobals.printDebug(VAGlobals
0560:                                        .i18n("VAArchiver_ArchiveOffset")
0561:                                        + archOffset_);
0562:                                generateInstallCode(
0563:                                        installJavaFile,
0564:                                        "com/memoire/vainstall/resources/Install.vaitpl",
0565:                                        "com/memoire/vainstall/VAClassLoader.class");
0566:                                System.out
0567:                                        .println(VAGlobals
0568:                                                .i18n("VAArchiver_CompilingInstallClass"));
0569:                                compile(installJavaFile.getName());
0570:                                generateNativeInstallExe(nativeExeFile,
0571:                                        "com/memoire/vainstall/resources/Install-"
0572:                                                + targets_[i] + "-exe.vaitpl",
0573:                                        instClass);
0574:                                System.out.println(VAGlobals
0575:                                        .i18n("VAArchiver_AppendingArchive"));
0576:                                appendArchive(nativeExeFile);
0577:                            }
0578:                        }
0579:                    }
0580:                    if (instClass != null && deleteInstallClass)
0581:                        instClass.delete();
0582:
0583:                } catch (IOException e) {
0584:                    e.printStackTrace();
0585:                }
0586:            }
0587:
0588:            private boolean processProperties() {
0589:                VAILOGO = "com/memoire/vainstall/resources/vailogo.gif";
0590:                // get information about choosen language
0591:                VAGlobals.setLanguage("default");
0592:                String tmp = getProject().getProperty(
0593:                        "vainstall.destination.language");
0594:                if (tmp != null) {
0595:                    installProperties
0596:                            .put("vainstall.destination.language", tmp);
0597:                }
0598:                //the user want to use full path every times
0599:                String useFullPath = getProject().getProperty(
0600:                        "vainstall.script.java.fullpath");
0601:                System.err.println("use full path " + useFullPath);
0602:                if (useFullPath != null && "true".equalsIgnoreCase(useFullPath)) {
0603:                    installProperties.put("vainstall.script.java.fullpath",
0604:                            Boolean.TRUE);
0605:                }
0606:
0607:                // get information about default destination for installation package
0608:                destPath_ = getProject().getProperty(
0609:                        "vainstall.destination.defaultPath");
0610:                if (destPath_ == null) {
0611:                    log("Note: Property 'vainstall.destination.defaultPath' = null");
0612:                    return false;
0613:                } else {
0614:                    if (checkVaiPath(destPath_) == false) {
0615:                        log("Note: Property 'vainstall.destination.defaultPath' has incorrect format.");
0616:                        return false;
0617:                    }
0618:                }
0619:
0620:                // get information about the install mode
0621:                tmp = getProject().getProperty(
0622:                        "vainstall.destination.installMode");
0623:                if ("update".equals(tmp) == true) {
0624:                    destPath_ = "[UPDATE]";
0625:                } else {
0626:                    if (!"install".equals(tmp)) {
0627:                        log("Note: Property 'vainstall.destination.installMode'. No valid install mode specified: Defaulting to 'install'.");
0628:                        System.err
0629:                                .println("no valid installMode specified: defaulting to install");
0630:                    }
0631:                }
0632:
0633:                // get information on package targets java, unix etc.
0634:                tmp = getProject().getProperty("vainstall.destination.targets");
0635:                if (tmp == null) {
0636:                    log("Note: Property 'vainstall.destination.targets'. No target specified.");
0637:                    return false;
0638:                }
0639:                StringTokenizer tok = new StringTokenizer(tmp, ",");
0640:                Vector v = new Vector();
0641:                while (tok.hasMoreTokens()) {
0642:                    String t = tok.nextToken().trim().toLowerCase();
0643:                    if ((!"java".equals(t)) && (!"jar".equals(t))
0644:                            && (!"jnlp".equals(t)) && (!"unix".equals(t))
0645:                            && (!"win95".equals(t))
0646:                            && (!"linux-i386".equals(t))) {
0647:                        System.err.println("unknown target: " + t);
0648:                        return false;
0649:                    }
0650:                    if (!v.contains(t))
0651:                        v.add(t);
0652:                }
0653:                // jar is needed for jnlp
0654:                if (v.contains("jnlp") && !v.contains("jar"))
0655:                    v.add("jar");
0656:                targets_ = new String[v.size()];
0657:                // the order is important here
0658:                // jar first, exes after, java last
0659:                int i = 0;
0660:                if (v.contains("jar"))
0661:                    targets_[i++] = "jar";
0662:                if (v.contains("jnlp"))
0663:                    targets_[i++] = "jnlp";
0664:                if (v.contains("unix"))
0665:                    targets_[i++] = "unix";
0666:                if (v.contains("linux-i386"))
0667:                    targets_[i++] = "linux-i386";
0668:                if (v.contains("win95"))
0669:                    targets_[i++] = "win95";
0670:                if (v.contains("java"))
0671:                    targets_[i++] = "java";
0672:
0673:                if (v.contains("jar")) {
0674:                    jarAlias_ = VAProperties.PROPERTIES
0675:                            .getProperty("vainstall.jarsigner.alias");
0676:                    jarPassphrase_ = VAProperties.PROPERTIES
0677:                            .getProperty("vainstall.jarsigner.passphrase");
0678:                }
0679:
0680:                if (v.contains("jnlp")) {
0681:                    jarCodebase_ = VAProperties.PROPERTIES
0682:                            .getProperty("vainstall.jnlp.codebase");
0683:                    if (jarCodebase_ == null || "".equals(jarCodebase_)) {
0684:                        System.err.println("vainstall.jnlp.codebase null");
0685:                        return false;
0686:                    }
0687:
0688:                    jarHomepage_ = VAProperties.PROPERTIES
0689:                            .getProperty("vainstall.jnlp.homepage");
0690:                    if (jarHomepage_ == null || "".equals(jarHomepage_)) {
0691:                        System.err.println("vainstall.jnlp.homepage null");
0692:                        return false;
0693:                    }
0694:
0695:                    jarVendor_ = VAProperties.PROPERTIES
0696:                            .getProperty("vainstall.jnlp.vendor");
0697:                    if (jarVendor_ == null || "".equals(jarVendor_)) {
0698:                        System.err.println("vainstall.jnlp.vendor null");
0699:                        return false;
0700:                    }
0701:                }
0702:
0703:                // get information about archiver method
0704:                archMethod_ = getProject().getProperty(
0705:                        "vainstall.archive.archivingMethod");
0706:                if (archMethod_ == null) {
0707:                    archMethod_ = "append";
0708:                }
0709:
0710:                // get information about destination ui
0711:                uiMode_ = getProject().getProperty("vainstall.destination.ui");
0712:                if (uiMode_ == null) {
0713:                    uiMode_ = "graphic";
0714:                }
0715:
0716:                // get information about use of bluescreen
0717:                uiBluescreen_ = getProject().getProperty(
0718:                        "vainstall.destination.ui.bluescreen");
0719:                if (uiBluescreen_ == null) {
0720:                    uiBluescreen_ = "yes";
0721:                }
0722:
0723:                // get information about bluescreen color
0724:                uiBluescreenColor_ = getProject().getProperty(
0725:                        "vainstall.destination.ui.bluescreen.colour");
0726:                if ((uiBluescreenColor_ != null)
0727:                        && (!"".equals(uiBluescreenColor_))) {
0728:                    try {
0729:                        Integer.parseInt(uiBluescreenColor_, 16);
0730:                    } catch (NumberFormatException nfe) {
0731:                        log("Note: Property 'vainstall.destination.ui.bluescreen.colour' has invalid format.");
0732:                        return false;
0733:                    }
0734:                }
0735:
0736:                // get information about the logo image
0737:                tmp = getProject()
0738:                        .getProperty("vainstall.destination.ui.image");
0739:                if (tmp == null) {
0740:                    log("Note: Property 'vainstall.destination.ui.image' = null: Will use default image.");
0741:                    image_ = IMAGE_KEY;
0742:                } else {
0743:                    image_ = tmp;
0744:                }
0745:
0746:                // get information about the installation package name
0747:                appName_ = getProject().getProperty(
0748:                        "vainstall.destination.appName");
0749:                if (appName_ == null) {
0750:                    log("Note: Property 'vainstall.destination.appName' = null.");
0751:                    return false;
0752:                }
0753:
0754:                // get information about the package version
0755:                appVersion_ = getProject().getProperty(
0756:                        "vainstall.destination.appVersion");
0757:                if (appVersion_ == null) {
0758:                    log("Note: Property 'vainstall.destination.appVersion' = null.");
0759:                    return false;
0760:                }
0761:
0762:                // get information about link section name
0763:                linkSectionName_ = getProject().getProperty(
0764:                        "vainstall.destination.linkSectionName");
0765:                if (linkSectionName_ == null) {
0766:                    log("Note: Property 'vainstall.destination.appVersion' = null : Defaulting to 'Applications'.");
0767:                    linkSectionName_ = "Applications";
0768:                }
0769:
0770:                // get information about link section icon
0771:                linkSectionIcon_ = getProject().getProperty(
0772:                        "vainstall.destination.linkSectionIcon");
0773:                if (linkSectionIcon_ == null) {
0774:                    log("Note: Property 'vainstall.destination.linkSectionIcon' = null.");
0775:                    linkSectionIcon_ = "";
0776:                }
0777:
0778:                // get information about link entry name
0779:                linkEntryName_ = getProject().getProperty(
0780:                        "vainstall.destination.linkEntryName");
0781:                if (linkEntryName_ == null) {
0782:                    log("Note: Property 'vainstall.destination.linkEntryName' = null : Defaulting to '"
0783:                            + appName_ + "'.");
0784:                    linkEntryName_ = appName_;
0785:                }
0786:
0787:                // get information about link entry icon
0788:                linkEntryIcon_ = getProject().getProperty(
0789:                        "vainstall.destination.linkEntryIcon");
0790:                if (linkEntryIcon_ == null) {
0791:                    log("Note: Property 'vainstall.destination.linkEntryIcon' = null.");
0792:                    linkEntryIcon_ = "";
0793:                }
0794:
0795:                // get information about install package class name
0796:                instClassName_ = getProject().getProperty(
0797:                        "vainstall.archive.installClassName");
0798:                if (instClassName_ == null) {
0799:                    instClassName_ = "Install_" + appName_;
0800:                }
0801:
0802:                // get information about license file
0803:                tmp = getProject().getProperty("vainstall.archive.license");
0804:                if (tmp == null) {
0805:                    log("Note: Property 'vainstall.archive.license' = null.");
0806:                    return false;
0807:                }
0808:                license_ = new File(tmp);
0809:                if ((!license_.exists()) || (!license_.canRead())) {
0810:                    log("Note: Property 'vainstall.archive.license' : Can not read "
0811:                            + license_ + ".");
0812:                    return false;
0813:                }
0814:                try {
0815:                    InputStream licenseStream = new FileInputStream(license_);
0816:                    String licenseEncoding = VAProperties.PROPERTIES
0817:                            .getProperty("vainstall.archive.license.encoding");
0818:                    if (licenseEncoding != null
0819:                            && licenseEncoding.equals("") == false) {
0820:                        try {
0821:                            InputStreamReader isrLicense = new InputStreamReader(
0822:                                    licenseStream, licenseEncoding);
0823:                        } catch (UnsupportedEncodingException exc) {
0824:                            log("Note: Unsuported encoding for license!");
0825:                            return false;
0826:                        }
0827:                    }
0828:                } catch (Exception exc) {
0829:                    log("Note: Problems reading license file!");
0830:                    return false;
0831:                }
0832:
0833:                tmp = getProject().getProperty("vainstall.license.key.support");
0834:                System.out.println("fred " + tmp);
0835:                if (tmp != null && !"".equals(tmp)) {
0836:                    licenseKeySupportClassName_ = tmp;
0837:                }
0838:                encodeKey_ = getProject().getProperty(
0839:                        "vainstall.license.key.support.encode.key");
0840:                additionalFiles_ = getProject().getProperty(
0841:                        "vainstall.additional.files");
0842:                Class cls = null;
0843:                try {
0844:                    cls = Class.forName(licenseKeySupportClassName_);
0845:                } catch (Exception ex) {
0846:                    if ((cls == null) && (additionalFiles_ != null)) {
0847:                        StringTokenizer fmi = new StringTokenizer(
0848:                                additionalFiles_, ",");
0849:                        while (fmi.hasMoreTokens()) {
0850:                            StringTokenizer fm = new StringTokenizer(fmi
0851:                                    .nextToken(), "!");
0852:                            String classFound = fm.nextToken();
0853:                            if ((classFound != null)
0854:                                    && (classFound
0855:                                            .indexOf(licenseKeySupportClassName_) > -1)) {
0856:                                try {
0857:                                    URLClassLoader urlcl = new URLClassLoader(
0858:                                            new URL[] { new File(classFound)
0859:                                                    .getParentFile().toURL() });
0860:                                    cls = urlcl
0861:                                            .loadClass(licenseKeySupportClassName_);
0862:                                } catch (Exception ex2) {
0863:                                    System.out
0864:                                            .println("License key support could not be initialized  with specific URLCLassLoader"
0865:                                                    + ex2);
0866:                                }
0867:                                break;
0868:                            }
0869:                        }
0870:                    }
0871:                }
0872:                if (cls == null) {
0873:                    throw new RuntimeException(
0874:                            "License key support could not be initialized: ");
0875:                }
0876:                try {
0877:                    System.out.println(cls.getName());
0878:                    licenseKeySupport_ = (LicenseKeySupport) cls.newInstance();
0879:                } catch (Exception ex) {
0880:                    System.err
0881:                            .println("LicenseKeySupport can't be instantiated"
0882:                                    + ex);
0883:                }
0884:
0885:                // get information about readme file
0886:                tmp = getProject().getProperty("vainstall.archive.readme");
0887:                if (tmp == null) {
0888:                    log("Note: Property 'vainstall.archive.readme' = null.");
0889:                    return false;
0890:                }
0891:                readme_ = new File(tmp);
0892:                if ((!readme_.exists()) || (!readme_.canRead())) {
0893:                    log("Note: Property 'vainstall.archive.readme' : Can not read "
0894:                            + readme_ + ".");
0895:                    return false;
0896:                }
0897:                try {
0898:                    InputStream readmeStream = new FileInputStream(readme_);
0899:                    String readmeEncoding = VAProperties.PROPERTIES
0900:                            .getProperty("vainstall.archive.readme.encoding");
0901:                    if (readmeEncoding != null
0902:                            && readmeEncoding.equals("") == false) {
0903:                        try {
0904:                            InputStreamReader isrReadme = new InputStreamReader(
0905:                                    readmeStream, readmeEncoding);
0906:                        } catch (UnsupportedEncodingException exc) {
0907:                            log("Note: Unsupported encoding for readme!");
0908:                            return false;
0909:                        }
0910:                    }
0911:                } catch (Exception exc) {
0912:                    log("Note: Problems reading readme file!");
0913:                    return false;
0914:                }
0915:
0916:                return true;
0917:            }
0918:
0919:            private File makeArchive(String filename) throws IOException {
0920:                Vector scripts = new Vector();
0921:
0922:                Vector archiveExeList = new Vector();
0923:
0924:                // extract scripts
0925:                for (int l = 0; l < javaLauncherList.size(); l++) {
0926:                    JavaLauncherArgument arg = (JavaLauncherArgument) javaLauncherList
0927:                            .elementAt(l);
0928:
0929:                    String dest = "JavaLauncher\n";
0930:                    dest += "Class=" + arg.getJavaclass() + "\n";
0931:                    dest += "ClassPath="
0932:                            + (arg.getClasspath() == null ? "" : arg
0933:                                    .getClasspath()) + "\n";
0934:                    dest += "JavaMode="
0935:                            + (arg.getJavamode() == null ? "console" : arg
0936:                                    .getJavamode()) + "\n";
0937:                    dest += "JavaArgs="
0938:                            + (arg.getJavaargs() == null ? "" : arg
0939:                                    .getJavaargs()) + "\n";
0940:                    dest += "ClassArgs="
0941:                            + (arg.getClassargs() == null ? "" : arg
0942:                                    .getClassargs()) + "\n";
0943:                    dest += "ScriptName=" + arg.getScriptname() + "\n";
0944:                    scripts.add(dest);
0945:                    archiveExeList.add("[SCRIPT]" + arg.getScriptname());
0946:                } // endfor
0947:
0948:                // create archive file
0949:                File zipFile = new File(filename);
0950:                File parent = zipFile.getParentFile();
0951:                if ((parent != null) && (!parent.canWrite()))
0952:                    throw new IOException(zipFile + " can not be written");
0953:                ZipOutputStream stream = new ZipOutputStream(
0954:                        new GZIPOutputStream(new FileOutputStream(zipFile)));
0955:                stream.setLevel(0);
0956:
0957:                addFilesetsToArchive(stream);
0958:
0959:                // close archive file
0960:                stream.close();
0961:
0962:                // write to file
0963:                ObjectOutputStream infos = new ObjectOutputStream(archiveInfos_);
0964:
0965:                infos.writeInt(archivecount_);
0966:
0967:                // add vector of scripts
0968:                infos.writeObject(scripts);
0969:
0970:                // add string of scripts filenames
0971:                infos.writeObject(archiveExeList);
0972:
0973:                infos.flush();
0974:
0975:                return zipFile;
0976:            }
0977:
0978:            private String convertToLocalPath(String entry) throws IOException {
0979:                String res = Setup.expandDirectory(entry, true, null);
0980:                if (res == null)
0981:                    throw new IOException("Invalid path: " + entry);
0982:                return res.replace('/', File.separatorChar);
0983:            }
0984:
0985:            private String convertToGenericPath(String line) {
0986:                return line.replace(File.separatorChar, '/');
0987:            }
0988:
0989:            private void generateInstallCode(File javaFile,
0990:                    String instTemplate, String classLoader) throws IOException {
0991:                PrintWriter writer = new PrintWriter(new FileWriter(javaFile));
0992:                int read = 0;
0993:                byte[] buf = new byte[128];
0994:
0995:                //    LineNumberReader reader=new LineNumberReader(new FileReader(instTemplate));
0996:                InputStream is = getClass().getResourceAsStream(
0997:                        "/" + instTemplate);
0998:                InputStreamReader isr = new InputStreamReader(is);
0999:                LineNumberReader reader = new LineNumberReader(isr);
1000:
1001:                System.out.println(VAGlobals
1002:                        .i18n("VAArchiver_GeneratingInstallClassCode"));
1003:
1004:                String line = reader.readLine();
1005:                while ((line != null)
1006:                        && (!line.startsWith("// --> InstallClassName"))) {
1007:                    writer.println(line);
1008:                    line = reader.readLine();
1009:                }
1010:                writer.println("public class " + instClassName_ + " {");
1011:                writer.println("  private static final Class installClass=new "
1012:                        + instClassName_ + "().getClass();");
1013:
1014:                line = reader.readLine();
1015:                while ((line != null)
1016:                        && (!line.startsWith("// --> ArchivingMethod"))) {
1017:                    writer.println(line);
1018:                    line = reader.readLine();
1019:                }
1020:                writer.println("  private static String ARCH_METHOD=\""
1021:                        + archMethod_ + "\";");
1022:
1023:                line = reader.readLine();
1024:                while ((line != null)
1025:                        && (!line.startsWith("// --> TargetType"))) {
1026:                    writer.println(line);
1027:                    line = reader.readLine();
1028:                }
1029:                writer.println("  private static String TARGET_TYPE=\""
1030:                        + currentTarget_ + "\";");
1031:
1032:                line = reader.readLine();
1033:                while ((line != null)
1034:                        && (!line.startsWith("// --> InstallClassOffset"))) {
1035:                    writer.println(line);
1036:                    line = reader.readLine();
1037:                }
1038:                writer.println("  private static long ICLASS_OFFSET="
1039:                        + installClassOffset_ + "L;");
1040:
1041:                line = reader.readLine();
1042:                while ((line != null)
1043:                        && (!line.startsWith("// --> InstallClassSize"))) {
1044:                    writer.println(line);
1045:                    line = reader.readLine();
1046:                }
1047:                if (installClassSize_ != archOffset_)
1048:                    writer.println("  private static long ICLASS_SIZE="
1049:                            + installClassSize_ + "L;");
1050:                else
1051:                    writer
1052:                            .println("  private static long ICLASS_SIZE=-1234543210L;");
1053:
1054:                line = reader.readLine();
1055:                while ((line != null)
1056:                        && (!line.startsWith("// --> ArchiveOffset"))) {
1057:                    writer.println(line);
1058:                    line = reader.readLine();
1059:                }
1060:                writer.println("  private static long ARCH_OFFSET="
1061:                        + archOffset_ + "L;");
1062:
1063:                line = reader.readLine();
1064:                while ((line != null) && (!line.startsWith("// --> JarSize"))) {
1065:                    writer.println(line);
1066:                    line = reader.readLine();
1067:                }
1068:                writer.println("  private static long JAR_SIZE=" + jarSize_
1069:                        + "L;");
1070:
1071:                line = reader.readLine();
1072:                while ((line != null) && (!line.startsWith("// --> UIMode"))) {
1073:                    writer.println(line);
1074:                    line = reader.readLine();
1075:                }
1076:                writer.println("  private static String UI_MODE=\"" + uiMode_
1077:                        + "\";");
1078:
1079:                line = reader.readLine();
1080:                while ((line != null)
1081:                        && (!line.startsWith("// --> UIBluescreen"))) {
1082:                    writer.println(line);
1083:                    line = reader.readLine();
1084:                }
1085:                writer.println("  private static String UI_BLUESCREEN=\""
1086:                        + uiBluescreen_ + "\";");
1087:
1088:                line = reader.readLine();
1089:                while ((line != null)
1090:                        && (!line.startsWith("// --> UIBluescreenColor"))) {
1091:                    writer.println(line);
1092:                    line = reader.readLine();
1093:                }
1094:                writer.println("  private static String UI_BLUESCREEN_COLOR=\""
1095:                        + uiBluescreenColor_ + "\";");
1096:
1097:                line = reader.readLine();
1098:                while ((line != null) && (!line.startsWith("// --> DestPath"))) {
1099:                    writer.println(line);
1100:                    line = reader.readLine();
1101:                }
1102:                writer.println("  private static String DEST_PATH=\""
1103:                        + destPath_ + "\";");
1104:
1105:                line = reader.readLine();
1106:                while ((line != null) && (!line.startsWith("// --> AppInfo"))) {
1107:                    writer.println(line);
1108:                    line = reader.readLine();
1109:                }
1110:                writer.println("  private static String APP_NAME=\"" + appName_
1111:                        + "\";");
1112:                writer.println("  private static String APP_VERSION=\""
1113:                        + appVersion_ + "\";");
1114:
1115:                line = reader.readLine();
1116:                while ((line != null) && (!line.startsWith("// --> LinkInfos"))) {
1117:                    writer.println(line);
1118:                    line = reader.readLine();
1119:                }
1120:                writer.println("  private static String LINK_SECTION_NAME=\""
1121:                        + linkSectionName_ + "\";");
1122:                writer.println("  private static String LINK_SECTION_ICON=\""
1123:                        + linkSectionIcon_ + "\";");
1124:                writer.println("  private static String LINK_ENTRY_NAME=\""
1125:                        + linkEntryName_ + "\";");
1126:                writer.println("  private static String LINK_ENTRY_ICON=\""
1127:                        + linkEntryIcon_ + "\";");
1128:
1129:                line = reader.readLine();
1130:                while ((line != null)
1131:                        && (!line.startsWith("// --> LicenseKey"))) {
1132:                    writer.println(line);
1133:                    line = reader.readLine();
1134:                }
1135:                writer
1136:                        .println("  private static String LICENSE_KEY_SUPPORT_NAME=\""
1137:                                + licenseKeySupportClassName_ + "\";");
1138:
1139:                System.out.println(VAGlobals
1140:                        .i18n("VAArchiver_AppendingClassloader"));
1141:                line = reader.readLine();
1142:                while ((line != null)
1143:                        && (!line.startsWith("// --> ClassLoader"))) {
1144:                    writer.println(line);
1145:                    line = reader.readLine();
1146:                }
1147:
1148:                InputStream isClassLoader = getClass().getResourceAsStream(
1149:                        "/" + classLoader);
1150:
1151:                System.out.println("  CLASSLOADER = " + "/" + classLoader);
1152:                writer.println("  private static String[] CL_CLASS={");
1153:                read = isClassLoader.read(buf);
1154:                while (read > 0) {
1155:                    writer.println("\"" + codeLine(buf, read) + "\",");
1156:                    read = isClassLoader.read(buf);
1157:                }
1158:                isClassLoader.close();
1159:
1160:                writer.println("  };\n}");
1161:                reader.close();
1162:                writer.close();
1163:
1164:                // HFALK
1165:                is.close();
1166:                isr.close();
1167:
1168:            }
1169:
1170:            private void generateJnlpFile(File jnlpFile) throws IOException {
1171:                PrintWriter out = new PrintWriter(new BufferedWriter(
1172:                        new OutputStreamWriter(new FileOutputStream(jnlpFile),
1173:                                "UTF-8")));
1174:
1175:                out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
1176:                out.println("<jnlp spec=\"1.0\"");
1177:                out.println("      codebase=\"" + jarCodebase_ + "\"");
1178:                out.println("      href=\"" + instClassName_ + ".jnlp\">");
1179:                out.println("  <information>");
1180:                out.println("    <title>" + appName_ + " " + appVersion_
1181:                        + " Installer</title>");
1182:                out.println("    <vendor>" + jarVendor_ + "</vendor>");
1183:                out.println("    <homepage href=\"" + jarHomepage_ + "\"/>");
1184:                out.println("    <description>Installer for " + appName_ + " "
1185:                        + appVersion_ + "</description>");
1186:                //out.println("<icon href=\"alma-jnlp.png\" width=\"128\" height=\"128\"/>");
1187:                out.println("    <offline/>");
1188:                out.println("  </information>");
1189:                out.println("  <resources>");
1190:                out.println("    <j2se version=\"1.3 1.2\"/>");
1191:                out.println("    <jar href=\"" + instClassName_ + ".jar\"/>");
1192:                out.println("  </resources>");
1193:                out.println("  <security>");
1194:                out.println("    <all-permissions/>");
1195:                out.println("  </security>");
1196:                out.println("  <application-desc main-class=\""
1197:                        + instClassName_ + "\"/>");
1198:                out.println("</jnlp>");
1199:                out.close();
1200:            }
1201:
1202:            private void generateManifestFile(File mfFile) throws IOException {
1203:                PrintWriter out = new PrintWriter(new BufferedWriter(
1204:                        new OutputStreamWriter(new FileOutputStream(mfFile),
1205:                                "UTF-8")));
1206:
1207:                out.println("Manifest-Version: 1.0");
1208:                out.println("Main-Class: " + instClassName_);
1209:                out.close();
1210:            }
1211:
1212:            private long generateUnixInstallShell(File unixShellFile,
1213:                    String instTemplate, File instClassFile) throws IOException {
1214:                FileOutputStream byteWriter = new FileOutputStream(
1215:                        unixShellFile);
1216:
1217:                InputStream is = getClass().getResourceAsStream(
1218:                        "/" + instTemplate);
1219:                InputStreamReader isr = new InputStreamReader(is);
1220:                LineNumberReader reader = new LineNumberReader(isr);
1221:                String content = "";
1222:                String installClassStartStr = "000000000000";
1223:                NumberFormat nf = NumberFormat.getInstance(Locale.US);
1224:                nf.setGroupingUsed(false);
1225:                nf.setMinimumIntegerDigits(installClassStartStr.length());
1226:                int installClassStartPos = 0;
1227:                long installClassOffset = 0;
1228:
1229:                System.out.println(VAGlobals
1230:                        .i18n("VAArchiver_GenerateInstallShell"));
1231:
1232:                String line = reader.readLine();
1233:                while ((line != null)
1234:                        && (!line.startsWith("# InstallClassStart"))) {
1235:                    content += line + "\n";
1236:                    line = reader.readLine();
1237:                }
1238:                content += "InstallClassStart=" + installClassStartStr + "\n";
1239:                installClassStartPos = content.length() - 1 - 1
1240:                        - installClassStartStr.length();
1241:
1242:                line = reader.readLine();
1243:                while ((line != null)
1244:                        && (!line.startsWith("# InstallClassSize"))) {
1245:                    content += line + "\n";
1246:                    line = reader.readLine();
1247:                }
1248:                content += new String("InstallClassSize="
1249:                        + instClassFile.length() + "\n");
1250:
1251:                line = reader.readLine();
1252:                while ((line != null)
1253:                        && (!line.startsWith("# InstallClassName"))) {
1254:                    content += line + "\n";
1255:                    line = reader.readLine();
1256:                }
1257:                content += new String("InstallClassName=" + instClassName_
1258:                        + "\n");
1259:
1260:                line = reader.readLine();
1261:                while ((line != null) && (!line.startsWith("# Install class"))) {
1262:                    content += line + "\n";
1263:                    line = reader.readLine();
1264:                }
1265:                if (line != null)
1266:                    content += line + "\n";
1267:                byteWriter.write(content.substring(0, installClassStartPos + 1)
1268:                        .getBytes());
1269:                byteWriter.write(nf.format(content.length()).getBytes());
1270:                byteWriter.write(content.substring(
1271:                        installClassStartPos + 1
1272:                                + installClassStartStr.length()).getBytes());
1273:                installClassOffset = content.length();
1274:                content = null;
1275:
1276:                FileInputStream classStream = new FileInputStream(instClassFile);
1277:                byte[] buf = new byte[2048];
1278:                int read = classStream.read(buf);
1279:                while (read > 0) {
1280:                    byteWriter.write(buf, 0, read);
1281:                    read = classStream.read(buf);
1282:                }
1283:                classStream.close();
1284:                reader.close();
1285:                byteWriter.close();
1286:                return installClassOffset;
1287:            }
1288:
1289:            private void shiftArray(byte[] array) {
1290:                for (int i = 0; i < (array.length - 1); i++)
1291:                    array[i] = array[i + 1];
1292:                array[array.length - 1] = 0;
1293:            }
1294:
1295:            private long generateNativeInstallExe(File nativeInstallFile,
1296:                    String instTemplate, File instClassFile) throws IOException {
1297:                // method: we look for the items "clname_here", "clstart_here" et "clstop_here_".
1298:                // -> We read bytes one by one, but we write them with a 12 bytes latency,
1299:                //    so we can have a 12 bytes "preview" window to test "clstart_here" or
1300:                //    "clstop_here_".
1301:                //    We replace "clname_here" with the name of the class and we end with a dot.
1302:                //    We replace "clstart_here" with the size of the template file (the class
1303:                //    is appended after it).
1304:                //    We remember the position of "clstop_here_", and we finish with the file
1305:                //    in normal mode (bulk copy). We append the class, we calculate the total
1306:                //    size in bytes, and we write it in place of "clstop_here_" (of which we
1307:                //    know the position). We then only have to write all these bytes in the
1308:                //    destination file.
1309:
1310:                //    FileInputStream reader=new FileInputStream(instTemplate);
1311:                InputStream reader = getClass().getResourceAsStream(
1312:                        "/" + instTemplate);
1313:                //    InputStreamReader reader = new InputStreamReader(is);
1314:                System.out.println("generateNativeInstallExe = /"
1315:                        + instTemplate);
1316:                System.out.println("reader length=" + reader.available());
1317:
1318:                ByteArrayOutputStream content = new ByteArrayOutputStream();
1319:                String installClassVarStr = "000000000000";
1320:                byte[] buf = new byte[installClassVarStr.length()];
1321:                NumberFormat nf = NumberFormat.getInstance(Locale.US);
1322:                nf.setGroupingUsed(false);
1323:                nf.setMinimumIntegerDigits(installClassVarStr.length());
1324:                int installClassStopPos = 0;
1325:                long installClassOffset = reader.available();
1326:                int position = 0;
1327:
1328:                System.out.println(VAGlobals
1329:                        .i18n("VAArchiver_GenerateInstallExe"));
1330:
1331:                // lecture des 12 premiers octets
1332:                reader.read(buf, 0, buf.length);
1333:                // positionnement en �criture avec retard de 12 ./. lecture
1334:                position = 1;
1335:
1336:                // on va � la recherche des trois ancres clname, clstart et clstop
1337:                for (int n = 0; n < 3; n++) {
1338:                    // buf contient la fenetre de prevision. C'est elle qu'on teste.
1339:                    while ((!new String(buf).equals("clname_here_"))
1340:                            && (!new String(buf).equals("clstart_here"))
1341:                            && (!new String(buf).equals("clstop_here_"))) {
1342:                        content.write(buf[0]);
1343:                        // on lit un octet
1344:                        int nextb = reader.read();
1345:                        position++;
1346:                        shiftArray(buf);
1347:                        // on �crit un octet
1348:                        buf[buf.length - 1] = (byte) nextb;
1349:                    }
1350:                    if (new String(buf).equals("clname_here_")) {
1351:                        System.err.println("  clname_here_ found at "
1352:                                + (position - 1));
1353:                        StringBuffer clnameBuffer = new StringBuffer(64);
1354:                        clnameBuffer.append(instClassName_);
1355:                        for (int i = clnameBuffer.length() - 1; i < 64; i++) {
1356:                            clnameBuffer.append('.');
1357:                        }
1358:                        byte[] clnameBytes = clnameBuffer.toString().getBytes();
1359:                        // on �crit le nom de la classe � la place de "clname_here"
1360:                        for (int i = 0; i < 64; i++) {
1361:                            content.write(clnameBytes[i]);
1362:                            position++;
1363:                        }
1364:                        // on saute 64 octets ("clstart_here")
1365:                        reader.skip(64 - buf.length);
1366:                        // on lit les 12 octets suivants
1367:                        reader.read(buf, 0, buf.length);
1368:                    } else if (new String(buf).equals("clstart_here")) {
1369:                        System.err.println("  clstart_here found at "
1370:                                + (position - 1));
1371:                        buf = nf.format(installClassOffset).getBytes();
1372:                        // on �crit la taille du template � la place de "clstart_here"
1373:                        for (int i = 0; i < buf.length; i++) {
1374:                            content.write(buf[i]);
1375:                            position++;
1376:                        }
1377:                        // on lit les 12 octets suivants
1378:                        reader.read(buf, 0, buf.length);
1379:                    } else if (new String(buf).equals("clstop_here_")) {
1380:                        System.err.println("  clstop_here_ found at "
1381:                                + (position - 1));
1382:                        // on a trouv� "clstop_here_": on note la position
1383:                        installClassStopPos = position - 1;
1384:                        // on �crit "clstop_here_" (on ne connait pas encore sa valeur)
1385:                        content.write(buf);
1386:                        position += 12;
1387:                        // on lit les 12 octets suivants
1388:                        reader.read(buf, 0, buf.length);
1389:                    }
1390:                }
1391:                content.write(buf);
1392:                /*
1393:                 while( (!new String(buf).equals("clstart_here")) ) {
1394:                 content.write(buf[0]);
1395:                 int nextb=reader.read();
1396:                 position++;
1397:                 shiftArray(buf);
1398:                 buf[buf.length-1]=(byte)nextb;
1399:                 }
1400:                 System.err.println("  clstart_here found at "+(position-1));
1401:                 buf=nf.format(installClassOffset).getBytes();
1402:                 // on �crit la taille du template � la place de "clstart_here"
1403:                 for(int i=0; i<buf.length; i++) {
1404:                 content.write(buf[i]);
1405:                 position++;
1406:                 }
1407:                 // on lit les 12 octets suivants
1408:                 reader.read(buf, 0, buf.length);
1409:
1410:                 while( (!new String(buf).equals("clstop_here_")) ) {
1411:                 content.write(buf[0]);
1412:                 int nextb=reader.read();
1413:                 position++;
1414:                 shiftArray(buf);
1415:                 buf[buf.length-1]=(byte)nextb;
1416:                 }
1417:                 System.err.println("  clstop_here_ found at "+(position-1));
1418:                 // on a trouv� "clstop_here_": on note la position
1419:                 installClassStopPos=position-1;
1420:                 // on �crit "clstop_here_" (on ne connait pas encore sa valeur)
1421:                 content.write(buf);
1422:                 */
1423:                // on finit la lecture/ecriture en mode normal
1424:                buf = new byte[2048];
1425:                int read = reader.read(buf);
1426:                while (read > 0) {
1427:                    content.write(buf, 0, read);
1428:                    read = reader.read(buf);
1429:                }
1430:                reader.close();
1431:
1432:                // on colle la classe
1433:                FileInputStream classStream = new FileInputStream(instClassFile);
1434:
1435:                read = classStream.read(buf);
1436:                while (read > 0) {
1437:                    content.write(buf, 0, read);
1438:                    read = classStream.read(buf);
1439:                }
1440:                classStream.close();
1441:                content.close();
1442:
1443:                // la taille totale �crite est mise � la place de "clstop_here_"
1444:                byte[] contentBytes = content.toByteArray();
1445:                installClassVarStr = nf.format(contentBytes.length);
1446:                byte[] installClassVarBytes = installClassVarStr.getBytes();
1447:                for (int i = 0; i < installClassVarBytes.length; i++) {
1448:                    contentBytes[installClassStopPos + i] = installClassVarBytes[i];
1449:                }
1450:
1451:                // on enregistre le contenu sur le fichier dest
1452:                FileOutputStream out = new FileOutputStream(nativeInstallFile);
1453:                out.write(contentBytes);
1454:                out.close();
1455:                return installClassOffset;
1456:            }
1457:
1458:            private void appendArchive(File instClass) throws IOException {
1459:                FileOutputStream out = new FileOutputStream(
1460:                        instClass.getName(), true);
1461:                FileInputStream zipStream = new FileInputStream("install.jar");
1462:                byte[] buf = new byte[2048];
1463:                int read = zipStream.read(buf);
1464:                while (read > 0) {
1465:                    out.write(buf, 0, read);
1466:                    read = zipStream.read(buf);
1467:                }
1468:                zipStream.close();
1469:                out.close();
1470:            }
1471:
1472:            private void copy(File fin, File fout) throws IOException {
1473:                FileOutputStream out = new FileOutputStream(fout);
1474:                FileInputStream in = new FileInputStream(fin);
1475:                byte[] buf = new byte[2048];
1476:                int read = in.read(buf);
1477:                while (read > 0) {
1478:                    out.write(buf, 0, read);
1479:                    read = in.read(buf);
1480:                }
1481:                in.close();
1482:                out.close();
1483:            }
1484:
1485:            private void jar(String options, File jarFile, File[] files)
1486:                    throws IOException {
1487:                Process p = null;
1488:                Vector argsv = new Vector();
1489:                argsv.add(JDK_HOME + File.separator + "bin" + File.separator
1490:                        + "jar");
1491:                if (options != null && !options.equals(""))
1492:                    argsv.add(options);
1493:                argsv.add(jarFile.getName());
1494:                for (int i = 0; i < files.length; i++)
1495:                    argsv.add(files[i].getName());
1496:                String[] args = new String[argsv.size()];
1497:                for (int i = 0; i < args.length; i++)
1498:                    args[i] = (String) argsv.get(i);
1499:                try {
1500:                    p = Runtime.getRuntime().exec(args);
1501:                    p.waitFor();
1502:                } catch (Exception rte) {
1503:                    throw new IOException(
1504:                            "Runtime exception: check if you have installed the JDK and run java from the JDK\n"
1505:                                    + "Exception message: " + rte.getMessage());
1506:                }
1507:                printCmdOutput(p, "jar");
1508:                if (p.exitValue() != 0)
1509:                    throw new RuntimeException("  abnormal exit");
1510:            }
1511:
1512:            private void jarsign(String passphrase, File jarFile, String alias)
1513:                    throws IOException {
1514:                Process p = null;
1515:                try {
1516:                    p = Runtime.getRuntime().exec(
1517:                            new String[] {
1518:                                    JDK_HOME + File.separator + "bin"
1519:                                            + File.separator + "jarsigner",
1520:                                    "-storepass", passphrase,
1521:                                    jarFile.getName(), alias });
1522:                    p.waitFor();
1523:                } catch (Exception rte) {
1524:                    throw new IOException(
1525:                            "Runtime exception: check if you have installed the JDK and run java from the JDK\n"
1526:                                    + "Exception message: " + rte.getMessage());
1527:                }
1528:                printCmdOutput(p, "jarsign");
1529:                if (p.exitValue() != 0)
1530:                    throw new RuntimeException("  abnormal exit");
1531:            }
1532:
1533:            private File compile(String javafile) throws IOException {
1534:                File classFile = null;
1535:                Process p = null;
1536:                try {
1537:                    p = Runtime.getRuntime().exec(
1538:                            new String[] {
1539:                                    JDK_HOME + File.separator + "bin"
1540:                                            + File.separator + "javac",
1541:                                    javafile });
1542:                    p.waitFor();
1543:                } catch (Exception rte) {
1544:                    throw new IOException(
1545:                            "Runtime exception: check if you have installed the JDK and run java from the JDK\n"
1546:                                    + "Exception message: " + rte.getMessage());
1547:                }
1548:                printCmdOutput(p, "javac");
1549:                if (p.exitValue() != 0)
1550:                    throw new RuntimeException("  abnormal exit");
1551:
1552:                classFile = new File(javafile.substring(0, javafile
1553:                        .lastIndexOf('.'))
1554:                        + ".class");
1555:                System.out.println("  " + classFile + " " + classFile.exists());
1556:                //if( !classFile.exists() ) throw new IOException("could not compile "+javafile);
1557:                return classFile;
1558:            }
1559:
1560:            private void printCmdOutput(Process p, String cmdName)
1561:                    throws IOException {
1562:                BufferedReader psIn = new BufferedReader(new InputStreamReader(
1563:                        p.getInputStream()));
1564:                BufferedReader psErr = new BufferedReader(
1565:                        new InputStreamReader(p.getErrorStream()));
1566:                int n = 0;
1567:                System.out.println("  --- start " + cmdName + " ---");
1568:                String inLine = psIn.readLine();
1569:                String errLine = psErr.readLine();
1570:                while ((inLine != null) || (errLine != null)) {
1571:                    if (inLine != null)
1572:                        System.out.println("  " + inLine);
1573:                    if (errLine != null)
1574:                        System.err.println("  " + errLine);
1575:                    inLine = psIn.readLine();
1576:                    errLine = psErr.readLine();
1577:                }
1578:                psIn.close();
1579:                psErr.close();
1580:                System.out.println("  --- end   " + cmdName + " ---");
1581:            }
1582:
1583:            private File makeJar(String filename, File archive, File license,
1584:                    File readme, byte[] archiveInfos) throws IOException {
1585:                File jar = new File(filename);
1586:                JarOutputStream out = new JarOutputStream(new FileOutputStream(
1587:                        jar));
1588:
1589:                // copy common files to jar file
1590:                copyInternalToJar(out, JAR_FILES_COMMON);
1591:                copyInternalToJar(out, JAR_FILES_JNIREGISTRY);
1592:                copyInternalToJar(out, JAR_FILES_JNISHORTCUT);
1593:                // text and ansi uis are always provided
1594:                copyInternalToJar(out, JAR_FILES_TEXT_UI);
1595:                copyInternalToJar(out, JAR_FILES_ANSI_UI);
1596:
1597:                if (uiMode_.equals("graphic") == true) {
1598:                    copyInternalToJar(out, JAR_FILES_GRAPHIC_UI);
1599:                }
1600:
1601:                if (uiMode_.equals("xtra") == true) {
1602:                    copyInternalToJar(out, JAR_FILES_XTRA_UI);
1603:                }
1604:
1605:                // archive infos
1606:                addToJar(out, new ByteArrayInputStream(archiveInfos),
1607:                        "com/memoire/vainstall/archive_infos",
1608:                        archiveInfos.length);
1609:
1610:                // archive.zip
1611:                addToJar(out, new FileInputStream(archive),
1612:                        "com/memoire/vainstall/archive.zip", archive.length());
1613:
1614:                // license
1615:                InputStream licenseStream = new FileInputStream(license);
1616:                String licenseEncoding = VAProperties.PROPERTIES
1617:                        .getProperty("vainstall.archive.license.encoding");
1618:                if (licenseEncoding == null
1619:                        || licenseEncoding.equals("") == true) {
1620:                    // Use default encoding
1621:                    licenseEncoding = new InputStreamReader(licenseStream)
1622:                            .getEncoding();
1623:                }
1624:                InputStreamReader isrLicense = new InputStreamReader(
1625:                        licenseStream, licenseEncoding);
1626:                addToJarEncoded(out, isrLicense,
1627:                        "com/memoire/vainstall/license.txt", license.length());
1628:
1629:                // readme
1630:                InputStream readmeStream = new FileInputStream(readme);
1631:                String readmeEncoding = VAProperties.PROPERTIES
1632:                        .getProperty("vainstall.archive.readme.encoding");
1633:                if (readmeEncoding == null || readmeEncoding.equals("") == true) {
1634:                    // Use default encoding
1635:                    readmeEncoding = new InputStreamReader(readmeStream)
1636:                            .getEncoding();
1637:                }
1638:                InputStreamReader isrReadme = new InputStreamReader(
1639:                        readmeStream, readmeEncoding);
1640:                addToJarEncoded(out, isrReadme,
1641:                        "com/memoire/vainstall/readme.txt", readme.length());
1642:
1643:                // image
1644:                InputStream invaiimage = null;
1645:                try {
1646:                    invaiimage = new FileInputStream(new File(image_));
1647:                } catch (Exception exc) {
1648:                    image_ = "/" + image_;
1649:                    invaiimage = getClass().getResourceAsStream(image_);
1650:                }
1651:                if (invaiimage == null) {
1652:                    invaiimage = getClass().getResourceAsStream(IMAGE_KEY);
1653:                    image_ = "com/memoire/vainstall/resources/banner.gif";
1654:                }
1655:                if (invaiimage != null) {
1656:                    //addToJar(out, invaiimage, image_, invaiimage.available());
1657:                    addToJar(out, invaiimage, IMAGE_KEY, invaiimage.available());
1658:                }
1659:                // vailogo
1660:                InputStream invailogo = getClass().getResourceAsStream(
1661:                        "/" + VAILOGO);
1662:                addToJar(out, invailogo, VAILOGO, invailogo.available());
1663:                invailogo.close();
1664:
1665:                // add file to control various settings like language
1666:                // should be used instead of all those parameters to the setup routine
1667:                ByteArrayOutputStream poutstream = new ByteArrayOutputStream();
1668:                installProperties.store(poutstream, VAGlobals.NAME + " "
1669:                        + VAGlobals.VERSION);
1670:                ByteArrayInputStream pinstream = new ByteArrayInputStream(
1671:                        poutstream.toByteArray());
1672:                addToJar(out, pinstream,
1673:                        "com/memoire/vainstall/resources/vainstall.properties",
1674:                        poutstream.toByteArray().length);
1675:
1676:                out.close();
1677:                return jar;
1678:            }
1679:
1680:            /**
1681:             *  Copy all files from a jar file from inside a jar file
1682:             *  to a target jar file
1683:             * @param out JarOutputStream
1684:             * @param jarSourceName String
1685:             */
1686:            private void copyInternalToJar(JarOutputStream out,
1687:                    String[] JAR_FILES) throws IOException {
1688:                for (int i = 0; i < JAR_FILES.length; i++) {
1689:
1690:                    String sourceName = JAR_FILES[i];
1691:                    if (sourceName.endsWith(".jar")) {
1692:                        copyJarFilesToJar(out, sourceName);
1693:                    } else {
1694:                        //        System.out.println("sourceName="+sourceName);
1695:                        InputStream is = getClass().getResourceAsStream(
1696:                                "/" + sourceName);
1697:                        addToJar(out, is, sourceName, is.available());
1698:                    }
1699:                } // endfor
1700:            }
1701:
1702:            /**
1703:             *  Copy all files from a jar file from inside a jar file
1704:             *  to a target jar file
1705:             * @param out JarOutputStream
1706:             * @param jarSourceName String
1707:             */
1708:            private void copyJarFilesToJar(JarOutputStream out,
1709:                    String jarSourceName) throws IOException {
1710:                byte[] buffer = new byte[2048];
1711:
1712:                InputStream isJar = getClass().getResourceAsStream(
1713:                        "/" + jarSourceName);
1714:                JarInputStream zin = new JarInputStream(isJar);
1715:
1716:                JarEntry entry = null;
1717:                while ((entry = zin.getNextJarEntry()) != null) {
1718:                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
1719:                    while (true) {
1720:                        int read = zin.read(buffer);
1721:                        if (read == -1)
1722:                            break;
1723:                        bos.write(buffer, 0, read);
1724:                    }
1725:                    ByteArrayInputStream bais = new ByteArrayInputStream(bos
1726:                            .toByteArray());
1727:                    addToJar(out, bais, entry.getName(),
1728:                            bos.toByteArray().length);
1729:                    bos.close();
1730:                    zin.closeEntry();
1731:                } // endwhile
1732:                zin.close();
1733:                isJar.close();
1734:            }
1735:
1736:            private void addToJar(JarOutputStream out, InputStream in,
1737:                    String entryName, long length) throws IOException {
1738:                byte[] buf = new byte[2048];
1739:                ZipEntry entry = new ZipEntry(entryName);
1740:                CRC32 crc = new CRC32();
1741:                entry.setSize(length);
1742:                entry.setCrc(crc.getValue());
1743:                out.putNextEntry(entry);
1744:                int read = in.read(buf);
1745:                while (read > 0) {
1746:                    crc.update(buf, 0, read);
1747:                    out.write(buf, 0, read);
1748:                    read = in.read(buf);
1749:                }
1750:                entry.setCrc(crc.getValue());
1751:                //    System.out.println("  entry = "+entry.getName()+" "+entry.getSize());
1752:                in.close();
1753:                out.closeEntry();
1754:            }
1755:
1756:            private void addToJarEncoded(JarOutputStream out,
1757:                    InputStreamReader isr, String entryName, long length)
1758:                    throws IOException {
1759:
1760:                StringBuffer buffer = new StringBuffer();
1761:
1762:                Reader reader = new BufferedReader(isr);
1763:                int ch;
1764:                while ((ch = reader.read()) > -1) {
1765:                    buffer.append((char) ch);
1766:                }
1767:                reader.close();
1768:                isr.close();
1769:
1770:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
1771:                OutputStreamWriter osw = new OutputStreamWriter(baos, "UTF8");
1772:                osw.write(buffer.toString());
1773:                osw.flush();
1774:
1775:                ByteArrayInputStream bais = new ByteArrayInputStream(baos
1776:                        .toByteArray());
1777:
1778:                addToJar(out, bais, entryName, length);
1779:            }
1780:
1781:            //  private static long
1782:            private boolean checkVaiPath(String dir) {
1783:                int index = dir.indexOf(']');
1784:                if (!dir.startsWith("["))
1785:                    return true;
1786:                if (index <= 2)
1787:                    return false;
1788:                String prefix = dir.substring(1, index).trim();
1789:                System.out.println(dir);
1790:                System.out.println(prefix);
1791:                if (("HOME".equals(prefix)) || ("PROGRAM".equals(prefix)))
1792:                    return true;
1793:                if ((prefix.length() == 2) && (prefix.endsWith(":"))
1794:                        && (Character.isLetter(prefix.charAt(0))))
1795:                    return true;
1796:                return false;
1797:            }
1798:
1799:            private String codeLine(byte[] data, int siz) {
1800:                String res = null;
1801:                byte[] convert = new byte[2 * siz];
1802:                for (int i = 0; i < siz; i++) {
1803:                    convert[2 * i] = (byte) (65 + (data[i] & 0x0F));
1804:                    convert[2 * i + 1] = (byte) (65 + (data[i] & 0xF0) / 16);
1805:                }
1806:                res = new String(convert);
1807:                return res;
1808:            }
1809:
1810:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.