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.wizard.components.actions;
038:
039: import java.io.File;
040: import java.io.IOException;
041: import org.netbeans.installer.product.Registry;
042: import org.netbeans.installer.utils.ErrorManager;
043: import org.netbeans.installer.utils.FileUtils;
044: import org.netbeans.installer.utils.LogManager;
045: import org.netbeans.installer.utils.ResourceUtils;
046: import org.netbeans.installer.utils.SystemUtils;
047: import org.netbeans.installer.utils.helper.Platform;
048: import org.netbeans.installer.utils.system.launchers.LauncherResource;
049: import org.netbeans.installer.utils.progress.Progress;
050: import org.netbeans.installer.utils.system.launchers.LauncherProperties;
051: import org.netbeans.installer.wizard.components.WizardAction;
052:
053: /**
054: *
055: * @author Dmitry Lipin
056: */
057: public class CreateNativeLauncherAction extends WizardAction {
058: /////////////////////////////////////////////////////////////////////////////////
059: // Constants
060: public static final String DEFAULT_TITLE = ResourceUtils.getString(
061: CreateNativeLauncherAction.class, "CNLA.title"); // NOI18N
062:
063: public static final String DEFAULT_DESCRIPTION = ResourceUtils
064: .getString(CreateNativeLauncherAction.class,
065: "CNLA.description"); // NOI18N
066: public static final String DEFAULT_ERROR_FAILED_CREATE_LAUNCHER = ResourceUtils
067: .getString(CreateNativeLauncherAction.class,
068: "CNLA.error.failed.create.launcher");//NOI18N
069: public static final String ERROR_FAILED_CREATE_LAUNCHER_PROPERTY = "error.failed.create.launcher";//NOI18N
070: public static final String BUNDLED_JVM_FILE_PROPERTY = "nbi.bundled.jvm.file";
071:
072: /////////////////////////////////////////////////////////////////////////////////
073: // Instance
074: public CreateNativeLauncherAction() {
075: setProperty(TITLE_PROPERTY, DEFAULT_TITLE);
076: setProperty(DESCRIPTION_PROPERTY, DEFAULT_DESCRIPTION);
077: setProperty(ERROR_FAILED_CREATE_LAUNCHER_PROPERTY,
078: DEFAULT_ERROR_FAILED_CREATE_LAUNCHER);
079: }
080:
081: public void execute() {
082: LogManager.logEntry("creating the native launcher");
083:
084: final String targetPath = System
085: .getProperty(Registry.CREATE_BUNDLE_PATH_PROPERTY);
086: final File targetFile = new File(targetPath);
087:
088: final Progress progress = new Progress();
089:
090: getWizardUi().setProgress(progress);
091: try {
092: final Platform platform = Registry.getInstance()
093: .getTargetPlatform();
094: final LauncherProperties properties = new LauncherProperties();
095:
096: properties
097: .addJar(new LauncherResource(new File(targetPath)));
098:
099: properties.setJvmArguments(new String[] { "-Xmx256m",
100: "-Xms64m" });
101: if (System.getProperty(BUNDLED_JVM_FILE_PROPERTY) != null) {
102: final LauncherResource jvm = new LauncherResource(
103: new File(System
104: .getProperty(BUNDLED_JVM_FILE_PROPERTY)));
105: properties.addJVM(jvm);
106: properties.getJvmArguments().add(
107: "-D" + BUNDLED_JVM_FILE_PROPERTY + "="
108: + jvm.getAbsolutePath());
109: }
110: File file = SystemUtils.createLauncher(properties,
111: platform, progress).getOutputFile();
112:
113: if (!targetFile.equals(file)) {
114: FileUtils.deleteFile(targetFile);
115: System.setProperty(
116: Registry.CREATE_BUNDLE_PATH_PROPERTY, file
117: .getPath());
118:
119: }
120: } catch (IOException e) {
121: ErrorManager.notifyError(
122: getProperty(ERROR_FAILED_CREATE_LAUNCHER_PROPERTY),
123: e);
124: }
125: LogManager.logExit("finished creating the native launcher");
126: }
127: }
|