001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU General
007: * Public License Version 2 only ("GPL") or the Common Development and Distribution
008: * License("CDDL") (collectively, the "License"). You may not use this file except in
009: * compliance with the License. You can obtain a copy of the License at
010: * http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
011: * License for the specific language governing permissions and limitations under the
012: * License. When distributing the software, include this License Header Notice in
013: * each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Sun
014: * designates this particular file as subject to the "Classpath" exception as
015: * provided by Sun in the GPL Version 2 section of the License file that
016: * accompanied this code. If applicable, add the following below the License Header,
017: * with the fields enclosed by brackets [] replaced by your own identifying
018: * information: "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Contributor(s):
021: *
022: * The Original Software is NetBeans. The Initial Developer of the Original Software
023: * is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
024: * Rights Reserved.
025: *
026: * If you wish your version of this file to be governed by only the CDDL or only the
027: * GPL Version 2, indicate your decision by adding "[Contributor] elects to include
028: * this software in this distribution under the [CDDL or GPL Version 2] license." If
029: * you do not indicate a single choice of license, a recipient has the option to
030: * distribute your version of this file under either the CDDL, the GPL Version 2 or
031: * to extend the choice of license to its licensees as provided above. However, if
032: * you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then
033: * the option applies only if the new code is made subject to such option by the
034: * copyright holder.
035: */
036:
037: package org.netbeans.installer.utils.system.launchers.impl;
038:
039: import java.io.File;
040: import java.io.IOException;
041: import java.util.ArrayList;
042: import java.util.Arrays;
043: import java.util.List;
044: import org.netbeans.installer.utils.FileUtils;
045: import org.netbeans.installer.utils.LogManager;
046: import org.netbeans.installer.utils.StringUtils;
047: import org.netbeans.installer.utils.SystemUtils;
048: import org.netbeans.installer.utils.applications.JavaUtils;
049: import org.netbeans.installer.utils.helper.JavaCompatibleProperties;
050: import org.netbeans.installer.utils.system.launchers.LauncherProperties;
051: import org.netbeans.installer.utils.system.launchers.LauncherResource;
052: import org.netbeans.installer.utils.progress.Progress;
053:
054: /**
055: *
056: * @author Dmitry Lipin
057: */
058: public class JarLauncher extends CommonLauncher {
059: public static final String MIN_JAVA_VERSION_DEFAULT = "1.5";
060:
061: public JarLauncher(LauncherProperties props) {
062: super (props);
063: }
064:
065: public void initialize() throws IOException {
066: checkBundledJars();
067: checkOutputFileName();
068: checkCompatibleJava();
069: }
070:
071: public File create(Progress progress) throws IOException {
072: LogManager.log("Create Jar launcher... ");
073: File out = null;
074: for (LauncherResource file : jars) {
075: if (file.isBundled()) {
076: // TODO
077: // think about what should we do if we have more than 2 files for bundling...
078: File jarFile = new File(file.getPath());
079: if (jarFile.getCanonicalPath().equals(
080: outputFile.getCanonicalPath())) {
081: out = jarFile;
082: } else {
083: out = outputFile;
084: FileUtils.copyFile(jarFile, out);
085: }
086: break;
087: }
088: }
089: if (out != null) {
090: for (LauncherResource file : jars) {
091: if (!file.isBundled()) {
092: File jarFile = new File(file.getPath());
093: if (jarFile.getCanonicalPath().equals(
094: outputFile.getCanonicalPath())) {
095: out = jarFile;
096: } else {
097: out = outputFile;
098: //FileUtils.copyFile(jarFile, out);
099: }
100: break;
101: }
102: }
103: }
104: return out;
105: }
106:
107: public String getExtension() {
108: return FileUtils.JAR_EXTENSION;
109: }
110:
111: protected String getI18NResourcePrefix() {
112: return null;
113: }
114:
115: public String[] getExecutionCommand() {
116: File javaLocation = null;
117: for (LauncherResource java : jvms) {
118: switch (java.getPathType()) {
119: case ABSOLUTE:
120: javaLocation = new File(java.getPath());
121: break;
122: case RELATIVE_USERHOME:
123: javaLocation = new File(SystemUtils
124: .getUserHomeDirectory(), java.getPath());
125: break;
126: case RELATIVE_LAUNCHER_PARENT:
127: javaLocation = new File(outputFile.getParentFile(),
128: java.getPath());
129: break;
130: default:
131: break; // other is nonsense for jar launcher
132: }
133: if (javaLocation != null) {
134: // TODO
135: // check java compatibility here and find necessary JVM on the system
136: for (JavaCompatibleProperties javaCompat : compatibleJava) {
137: }
138: break;
139: }
140: }
141: List<String> commandList = new ArrayList<String>();
142: commandList.add(JavaUtils.getExecutableW(javaLocation)
143: .getAbsolutePath());
144: commandList.add("-cp");
145: String classpath = StringUtils.EMPTY_STRING;
146: for (LauncherResource jar : jars) {
147: switch (jar.getPathType()) {
148: case RELATIVE_JAVAHOME:
149: classpath += new File(javaLocation, jar.getPath())
150: + SystemUtils.getPathSeparator();
151: break;
152: case ABSOLUTE:
153: classpath += new File(jar.getPath())
154: + SystemUtils.getPathSeparator();
155: break;
156: case RELATIVE_USERHOME:
157: classpath += new File(SystemUtils
158: .getUserHomeDirectory(), jar.getPath())
159: + SystemUtils.getPathSeparator();
160: break;
161: case RELATIVE_LAUNCHER_PARENT:
162: classpath += new File(outputFile.getParentFile(), jar
163: .getPath())
164: + SystemUtils.getPathSeparator();
165: break;
166: default:
167: break;
168: }
169: }
170: commandList.add(classpath);
171: commandList.addAll(jvmArguments);
172: commandList.add(mainClass);
173: commandList.addAll(appArguments);
174: return commandList.toArray(new String[commandList.size()]);
175: }
176:
177: public List<JavaCompatibleProperties> getDefaultCompatibleJava() {
178: List<JavaCompatibleProperties> list = new ArrayList<JavaCompatibleProperties>();
179: list.add(new JavaCompatibleProperties(MIN_JAVA_VERSION_DEFAULT,
180: null, null, null, null));
181: return list;
182: }
183:
184: }
|