📄 jnlp2package.java
字号:
/* Check EnableSystemCache property. */ systemCacheEnabled = getBoolProperty( JnlpConstants.PROPERTY_NAME_ENABLESYSTEMCACHE); pkgInfo.setSystemCacheEnabled(systemCacheEnabled); return pkgInfo; } /** * Checks if the file argument is valid. * @param filePath The given file path argument. * @param argName The name of the argument. * @param isNullable true if the argument could be set as null. * @return The valid file argument. * @throws IOException If fails to get the valid file. */ private static String getValidFileArgument( String filePath, String argName, boolean isNullable) throws IOException { if (filePath == null) { //filePaht argument is null if (isNullable) { //null argument acceptable return null; } else { //null argument not acceptable throw new IllegalArgumentException(argName + " could not be null."); } } else { //filePath argument is not null File theFile = new File(filePath); theFile = theFile.getCanonicalFile(); if (theFile.canRead()) { //The file is readable return theFile.getPath(); } else { throw new IllegalArgumentException( "The given " + argName + " is not valid: " + filePath); } } } /** * Checks if the resource files referenced in the jnlp file in valid. * @param pkgInfo The jnlpPackageInfo instance. * @throws IOException If failed during the checking process. */ private static void checkResourcePathArgument(JnlpPackageInfo pkgInfo) throws IOException { String resourceDirName = System.getProperty( JnlpConstants.PROPERTY_NAME_RESOURCEDIR); String jnlpFileName = pkgInfo.getJnlpFilePath(); File jnlpFile = new File(jnlpFileName); if (resourceDirName == null) { String jnlpFileParentDir = jnlpFile.getParent(); resourceDirName = getValidFileArgument( jnlpFileParentDir, "resource dir", false); } else { resourceDirName = getValidFileArgument( resourceDirName, "resource dir", false); } File resourceDirFile = new File(resourceDirName); // Check if all of the absolute referenced file paths exist. Iterator refIter = pkgInfo.getJnlpRefFilePaths(); while (refIter.hasNext()) { String oneRefFilePath = (String) refIter.next(); if (oneRefFilePath != null) { File oneAbsFilePath = new File(resourceDirFile, oneRefFilePath); // Check if the file is a valid file and is readable. if (!FileOperUtility.isFileReadable(oneAbsFilePath)) { throw new IllegalArgumentException( "Cann't read resource file: " + oneRefFilePath + " from resource path: " + resourceDirFile.toString()); } } } pkgInfo.setResourcePath(resourceDirName); } /** * Get the package name property from command line option. * @param pkgInfo The JnlpPackageInfo instance. * @throws IOException If failed to get the packagename property. */ private static void checkPackageNameArgument(JnlpPackageInfo pkgInfo) throws IOException { String packageName = System.getProperty( JnlpConstants.PROPERTY_NAME_PACKAGENAME); if (packageName == null) { // No package name is set, then use the jnlp file name by default. File jnlpFile = new File(pkgInfo.getJnlpFilePath()); packageName = FileOperUtility.getFileNameWithoutExt(jnlpFile); if (packageName == null) { throw new IllegalArgumentException( "The given jnlp file name is not a valid package name."); } } else { // User specified the packagename argument // Check if the user input is valid File packageFile = new File(packageName); if (packageFile.isDirectory()) { throw new IllegalArgumentException( "The given jnlp file name is not a valid package name."); } } pkgInfo.setPackageName(packageName); } /** * Gets the raw MSI template file path from command line option. * @param pkgInfo The JnlpPakcageInfo instance. * @throws IOException If failed to get the raw MSI template path. */ private static void checkMSSDKPathArgument(JnlpPackageInfo pkgInfo) throws IOException { String osName = System.getProperty("os.name").toLowerCase(); String msSDKPath = null; String rawMsiFilePath = null; if (osName.startsWith(JnlpConstants.OS_WINDOWS)) { msSDKPath = System.getProperty( JnlpConstants.PROPERTY_NAME_MS_SDK_PATH); msSDKPath = getValidFileArgument( msSDKPath, "MS SDK Path", false); msSDKPath = msSDKPath + (msSDKPath.endsWith(File.separator) ? "" : File.separator); rawMsiFilePath = msSDKPath + JnlpConstants.HIERACHY_TO_RAW_MSI; rawMsiFilePath = getValidFileArgument( rawMsiFilePath, "raw MSI file path", false); } pkgInfo.setMSSDKDirPath(msSDKPath); pkgInfo.setRawMsiFilePath(rawMsiFilePath); } /** * Checks if the output directory is valid. * @param pkgInfo The JnlpPackageInfo instance. * @throws IOException If failed during the checking process. */ private static void checkOutputDirNameArgument(JnlpPackageInfo pkgInfo) throws IOException { String outputDirName = System.getProperty( JnlpConstants.PROPERTY_NAME_OUTPUTDIR); if (outputDirName == null) { outputDirName = "." + File.separator; } outputDirName = getValidFileArgument(outputDirName, "output dir", false); //Make sure output dir ends with file separator. if (!outputDirName.endsWith(File.separator)) { outputDirName += File.separator; } File outputDirFile = new File(outputDirName); // Check if the directory already exists. if (outputDirFile.isDirectory()) { if (!outputDirFile.canWrite()) { throw new IllegalArgumentException( "The given package path is not writable: " + outputDirFile); } else { pkgInfo.setOutputDirPath(outputDirName); } } else { //The given outputDirFile exists and is not a directory! throw new IllegalArgumentException( "The given output dir is not valid: " + outputDirFile); } } /** * Invoke the concrete platform relevant implementation to generate the * package. * @param args The given arguments. * @throws IOException If failed to generate the dest package. */ public static void generatePackage(String[] args) throws IOException { // Check if the given jnlp file path is an URL. If it it, retrieve the // file locally. boolean isHttpJnlp = false; String tempDirName = null; // Parse and check the command line arguments. JnlpPackageInfo jnlpPkgInfo = null; jnlpPkgInfo = parseArguments(args); // Generate the installable package with the given package info. PackageGenerator pkgGenerator = PackageGeneratorFactory.newInstance(); pkgGenerator.generatePackage(jnlpPkgInfo); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -