⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pkgpackagegenerator.java

📁 jdic,显著提高swing性能的插件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is * subject to license terms. *  * This program is free software; you can redistribute it and/or modify * it under the terms of the Lesser GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */  package org.jdesktop.jdic.packager.impl;import java.io.File;import java.io.FileWriter;import java.io.BufferedWriter;import java.io.InputStreamReader;import java.io.BufferedReader;import java.io.IOException;import java.net.URL;import java.net.MalformedURLException;  /** * Concrete implementation of interface PackageGenerator for pkg packages  * generating on Solaris. * <pre> * The steps to create installable packages are briefly as below: *   1. Create "pkginfo" file at the location for the package information files. *   2. Create "copyright" file at the location for the package information files.  *   3. Create "checkinstall" file at the location for the package information files.  *   4. Create "postinstall" file at the location for the package information files. *   5. Create "postremove" file at the location for the package information files. *   6. Generate 'prototype' file using command 'pkgproto' with the jnlp file,  *      jnlp resource files, and the created information files including "pkginfo", *      "postinstall" and "postremove". *   7. Generate an installable package using command 'pkgmk', with the created prototype file,  *      created information files, the given jnlp file, and JNLP referenced resource files. * </pre> */public class PkgPackageGenerator implements PackageGenerator {    // Information files used to generate installable packages in pkg format.    // These files are generated during the packaging process, and will be    // deleted automatically after the process finishes.    private static final String FILE_NAME_PKGINFO = "pkginfo";    private static final String FILE_NAME_COPYRIGHT = "copyright";    private static final String FILE_NAME_CHECKINSTALL = "checkinstall";        private static final String FILE_NAME_POSTINSTALL = "postinstall";    private static final String FILE_NAME_POSTREMOVE = "postremove";    private static final String FILE_NAME_PROTOTYPE = "prototype";        // Required information files to generate a package.    File pkginfoFile = null;    File copyrightFile = null;    File checkinstallFile = null;    File postinstallFile = null;    File postremoveFile = null;    File prototypeFile = null;        // Location of the generated JNLP package information files.    private static String pkgInfoFileLocation = null;    // Temporarily created directory for JNLP resource files.    private static String tmpResourcePath = null;    // Temporarily created directory for copyright/license files.    private static String tmpCopyrightPath = null;        /**     * Runs a shell command and return the output string.     */    private String runShellCommand(String[] commandStrs) {        BufferedReader br = null;        try {                  Process proc = Runtime.getRuntime().exec(commandStrs);            // Output messages.             br = new BufferedReader(new InputStreamReader(proc.getInputStream()));            String oneLine = null;            if ((oneLine = br.readLine()) != null) {                 // ONLY return the first line of the output.                return oneLine;            } else {                return null;            }        } catch (IOException e) {            // If there are exceptions, just return null.            return null;        } finally {            // No matter what happens, always close streams already opened.             if (br != null) {                try {                    br.close();                } catch (IOException e) {                }            }        }            }    /**     * Creates a new file with the given absolute file path. If it already exists,      * remove it first.     */    private void createFileIgnoreExistance(File absFilePath) throws IOException {        // Check if the given file already exists. If it is, delete it first.        if (absFilePath.exists()) {            boolean deleteSucceed = absFilePath.delete();            if (!deleteSucceed) {                throw new IOException("Failed to remove already existed file: " + absFilePath);            }        }                boolean createSucceed = absFilePath.createNewFile();        if (!createSucceed) {            throw new IOException("Failed to create new file: " + absFilePath);        }    }       /**     * Deletes the temporarily created files and directories.     */    private void deleteTempFiles() throws IOException {        if (pkginfoFile != null) pkginfoFile.delete();        if (checkinstallFile != null) checkinstallFile.delete();        if (postinstallFile != null) postinstallFile.delete();        if (postremoveFile != null) postremoveFile.delete();        if (prototypeFile != null) prototypeFile.delete();        if (tmpResourcePath != null) {            FileOperUtility.deleteDirTree(new File(tmpResourcePath));        }        if (tmpCopyrightPath != null) {            FileOperUtility.deleteDirTree(new File(tmpCopyrightPath));                    }    }    /*     * Creates pkginfo file by extract the info fields in English locale.     */    private void createFilePkginfo(JnlpPackageInfo pkgInfo) throws IOException {        String packageName = pkgInfo.getPackageName();        String vendor = pkgInfo.getLocalizedJnlpInfo("en", JnlpConstants.JNLP_FIELD_VENDOR);        String productInfo = pkgInfo.getLocalizedJnlpInfo("en", JnlpConstants.JNLP_FIELD_TITLE);        String installationPath = pkgInfo.getUniqueTmpDirPath();        String versionNum = pkgInfo.getVersion();        String releaseNum = pkgInfo.getRelease();        // Version string is like: 1.0,RELEASE 1        String versionStr = versionNum + ",RELEASE " + releaseNum;        // Create file pkginfo. If it already exists, delete it first.        pkginfoFile = new File(pkgInfoFileLocation, FILE_NAME_PKGINFO);        createFileIgnoreExistance(pkginfoFile);                // Write the package information into the pkginfo file:        BufferedWriter mBufferWriter = null;        try {            mBufferWriter = new BufferedWriter(new FileWriter(pkginfoFile));            mBufferWriter.write("PKG=" + packageName + "\n");            mBufferWriter.write("NAME=" + productInfo + "\n");            mBufferWriter.write("ARCH=sparc" + "\n");            mBufferWriter.write("CATEGORY=system" + "\n");            mBufferWriter.write("VERSION=" + versionStr + "\n");            mBufferWriter.write("BASEDIR=" + installationPath + "\n");            mBufferWriter.write("PSTAMP=" + vendor + "\n");            mBufferWriter.write("CLASSES=none" + "\n");        } catch (IOException e) {            throw new IOException ("Failed to write into file: " + pkginfoFile);        } finally {            // No matter what happens, always close streams already opened.             if (mBufferWriter != null) {                try {                    mBufferWriter.close();                } catch (IOException e) {                }            }        }    }    /*     * Creates checkinstall file.     */    private void createFileCheckinstall() throws IOException {        // If it already exists, delete it first.        checkinstallFile = new File(pkgInfoFileLocation, FILE_NAME_CHECKINSTALL);        createFileIgnoreExistance(checkinstallFile);        // Write the Javaws version check script into the postremove file:        BufferedWriter mBufferWriter = null;        try {            mBufferWriter = new BufferedWriter(new FileWriter(checkinstallFile));            String[] javawsCheckScript = JnlpUtility.javawsCheckScript();             for (int lineNum = 0; lineNum < javawsCheckScript.length; lineNum++ ) {                mBufferWriter.write(javawsCheckScript[lineNum] + "\n");            }            /* Append below lines, which are only needed on Solaris, not on Linux:                  cat >$1 <<EOB                  JAVAWS_PATH=${JAVAWS_PATH}                  EOB                  exit 0             */                        mBufferWriter.write("cat >$1 <<EOB" + "\n");                        mBufferWriter.write("JAVAWS_PATH=${JAVAWS_PATH}" + "\n");            mBufferWriter.write("EOB" + "\n");            mBufferWriter.write("exit 0" + "\n");                   } catch (IOException e) {            throw new IOException ("Failed to write info into file: " + checkinstallFile);        } finally {            // No matter what happens, always close streams already opened.             if (mBufferWriter != null) {                try {                    mBufferWriter.close();                } catch (IOException e) {                }            }        }    }            /*     * Creates postinstall file.     */    private void createFilePostinstall(JnlpPackageInfo pkgInfo) throws IOException {        String installationPath = pkgInfo.getUniqueTmpDirPath();        String jnlpFileName = pkgInfo.getJnlpFileName();        boolean shortcutEnabled = pkgInfo.getShortcutEnabled();        boolean associationEnabled = pkgInfo.getAssociationEnabled();        boolean sysCacheEnabled = pkgInfo.getSystemCacheEnabled() ;                // Create file postinstall. If it already exists, delete it first.        postinstallFile = new File(pkgInfoFileLocation, FILE_NAME_POSTINSTALL);        createFileIgnoreExistance(postinstallFile);                // Write the below info into the postinstall file:        //   # Launch javaws using below command:        //   $JAVAWS_PATH -silent -system -import -codebase <codebase> <local location of jnlp file>        //   exit 0        BufferedWriter mBufferWriter = null;        try {            mBufferWriter = new BufferedWriter(new FileWriter(postinstallFile));            mBufferWriter.write("# Launch javaws using below command:" + "\n");            mBufferWriter.write("\n");                        // Convert the installation path to url style, which will be used by javaws as codebase.            File instFile = new File(installationPath);            URL codebase = instFile.toURL();            String jnlpFileLocation = null;            if (installationPath.endsWith(File.separator)) {                            jnlpFileLocation = installationPath + jnlpFileName;            } else {                jnlpFileLocation = installationPath + File.separator + jnlpFileName;            }            String javawsCommand = "$JAVAWS_PATH ";            if (sysCacheEnabled) {                javawsCommand += "-system ";                            }             javawsCommand += "-silent ";            if (shortcutEnabled) {                javawsCommand += "-shortcut ";            }            if (associationEnabled) {                javawsCommand += "-association ";            }            javawsCommand += "-import -codebase " + codebase + " " + jnlpFileLocation + "\n";                       mBufferWriter.write(javawsCommand);                        mBufferWriter.write("\n");            mBufferWriter.write("exit 0" + "\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -