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.List;
043: import org.netbeans.installer.utils.ErrorManager;
044: import org.netbeans.installer.utils.FileProxy;
045: import org.netbeans.installer.utils.ResourceUtils;
046: import org.netbeans.installer.utils.StringUtils;
047: import org.netbeans.installer.utils.exceptions.DownloadException;
048: import org.netbeans.installer.utils.helper.JavaCompatibleProperties;
049: import org.netbeans.installer.utils.system.launchers.LauncherProperties;
050: import org.netbeans.installer.utils.system.launchers.LauncherResource;
051:
052: /**
053: *
054: * @author Dmitry Lipin
055: */
056: public class CommandLauncher extends ShLauncher {
057: private static final String COMMAND_EXT = ".command"; //NOI18N
058:
059: public static final String JAVA_APPLICATION_ICON_PROPERTY = "nbi.java.application.icon"; //NOI18N
060:
061: public static final String JAVA_APPLICATION_NAME_LAUNCHER_PROPERTY = "nlu.java.application.name.macosx"; //NOI18N
062:
063: public static final String JAVA_APPLICATION_ICON_DEFAULT_URI = FileProxy.RESOURCE_SCHEME_PREFIX
064: + "org/netbeans/installer/utils/system/launchers/impl/dockicon.icns";
065:
066: public static final String NOTSET_DOCK_ICON_PROPERTY = "nbi.not.set.dock.icon";
067: public static final String NOTSET_DOCK_NAME_PROPERTY = "nbi.not.set.dock.name";
068:
069: public static final String XDOCK_ICON_PROPERTY_NAME = "-Xdock:icon";//NOI18N
070: public static final String XDOCK_NAME_PROPERTY_NAME = "-Xdock:name";//NOI18N
071:
072: private static final String[] JAVA_MACOSX_LOCATION = {
073: "/Library/Java", // NOI18N
074: "/System/Library/Frameworks/JavaVM.framework/Versions/1.5", // NOI18N
075: "/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0", // NOI18N
076: "/System/Library/Frameworks/JavaVM.framework/Versions/1.6", // NOI18N
077: "/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0", // NOI18N
078: "/System/Library/Frameworks/JavaVM.framework/Versions/" // NOI18N
079: };
080: // the 1.5.0_02 is the first fcs release of J2SE5 for MacOSX according to
081: // http://developer.apple.com/releasenotes/Java/Java50RN/index.html
082: public static final String MIN_JAVA_VERSION_MACOSX = "1.5.0_02";
083:
084: public CommandLauncher(LauncherProperties props) {
085: super (props);
086: }
087:
088: @Override
089: protected String[] getCommonSystemJavaLocations() {
090: return JAVA_MACOSX_LOCATION;
091: }
092:
093: @Override
094: public String getExtension() {
095: return COMMAND_EXT;
096: }
097:
098: @Override
099: public List<JavaCompatibleProperties> getDefaultCompatibleJava() {
100: List<JavaCompatibleProperties> list = new ArrayList<JavaCompatibleProperties>();
101: list.add(new JavaCompatibleProperties(MIN_JAVA_VERSION_MACOSX,
102: null, null, null, null));
103: return list;
104: }
105:
106: @Override
107: public void initialize() throws IOException {
108: super .initialize();
109: boolean setDockIcon = true;
110: boolean setDockName = true;
111: for (String s : jvmArguments) {
112: if (s.contains(XDOCK_NAME_PROPERTY_NAME)) {
113: setDockName = false;
114: }
115: if (s.contains(XDOCK_ICON_PROPERTY_NAME)) {
116: setDockIcon = false;
117: }
118: }
119:
120: if (setDockIcon
121: && !Boolean.getBoolean(NOTSET_DOCK_ICON_PROPERTY)) {
122: File iconFile = null;
123: String uri = System
124: .getProperty(JAVA_APPLICATION_ICON_PROPERTY);
125: if (uri == null) {
126: uri = JAVA_APPLICATION_ICON_DEFAULT_URI;
127: }
128:
129: try {
130: iconFile = FileProxy.getInstance().getFile(uri, true);
131: LauncherResource iconResource = new LauncherResource(
132: iconFile);
133: jvmArguments.add(XDOCK_ICON_PROPERTY_NAME
134: + StringUtils.EQUAL
135: + iconResource.getAbsolutePath());
136: otherResources.add(iconResource);
137: } catch (DownloadException e) {
138: ErrorManager.notify(ResourceUtils.getString(
139: CommandLauncher.class,
140: ERROR_CANNOT_GET_ICON_KEY, uri), e);
141: }
142: }
143: if (setDockName
144: && !Boolean.getBoolean(NOTSET_DOCK_NAME_PROPERTY)) {
145: jvmArguments.add(XDOCK_NAME_PROPERTY_NAME
146: + StringUtils.EQUAL + "$P{"
147: + JAVA_APPLICATION_NAME_LAUNCHER_PROPERTY + "}");
148: }
149: }
150:
151: private static final String ERROR_CANNOT_GET_ICON_KEY = "CdL.error.cannot.get.icon";//NOI18N
152: }
|