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
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * DeviceAnywhereDeploymentPlugin.java
044: *
045: */
046:
047: package org.netbeans.modules.deployment.deviceanywhere;
048:
049: import java.awt.Component;
050: import java.util.Collections;
051: import java.util.HashMap;
052: import java.util.Map;
053: import org.netbeans.api.mobility.project.ui.customizer.ProjectProperties;
054: import org.openide.util.NbBundle;
055: import org.netbeans.spi.mobility.deployment.DeploymentPlugin;
056: import org.netbeans.spi.mobility.project.ui.customizer.CustomizerPanel;
057: import org.netbeans.spi.project.support.ant.EditableProperties;
058: import org.netbeans.spi.project.support.ant.PropertyUtils;
059:
060: /**
061: *
062: * @author Petr Suchomel
063: */
064: public class DeviceAnywhereDeploymentPlugin implements
065: DeploymentPlugin, CustomizerPanel {
066:
067: static final String PROP_DEVICE = "deployment.deviceanywhere.device"; //NOI18N
068: static final String PROP_AVAILABLE_DEVICES = "deployment.deviceanywhere.availabledevices"; //NOI18N
069: static final String PROP_USERID = "deployment.deviceanywhere.userid"; //NOI18N
070: static final String PROP_PASSWORD = "deployment.deviceanywhere.password"; //NOI18N
071: static final String PROP_CAREER = "deployment.deviceanywhere.career"; //NOI18N
072:
073: final Map<String, Object> propertyDefValues;
074: final Map<String, Object> globalPropertyDefValues;
075:
076: private ProjectProperties props;
077: private String configuration;
078:
079: private PropertyEvaluator evaluator = new PropertyEvaluator();
080:
081: /**
082: * Creates a new instance of DeviceAnywhereDeploymentPlugin
083: */
084: public DeviceAnywhereDeploymentPlugin() {
085: HashMap<String, Object> m = new HashMap<String, Object>();
086: m.put(PROP_USERID, "");//NOI18N
087: m.put(PROP_PASSWORD, "");//NOI18N
088: globalPropertyDefValues = Collections.unmodifiableMap(m);
089: m = new HashMap<String, Object>();
090: m.put(PROP_DEVICE, "");//NOI18N
091: m.put(PROP_CAREER, "");//NOI18N
092: m.put(PROP_AVAILABLE_DEVICES, "");//NOI18N
093: propertyDefValues = Collections.unmodifiableMap(m);
094: }
095:
096: public String getAntScriptLocation() {
097: return "modules/scr/deploy-deviceanywhere-impl.xml"; // NOI18N
098: }
099:
100: public String getDeploymentMethodName() {
101: return "DeviceAnywhere"; // NOI18N
102: }
103:
104: public String getDeploymentMethodDisplayName() {
105: return NbBundle.getMessage(
106: DeviceAnywhereDeploymentPlugin.class,
107: "LBL_DeviceAnywhereTypeName"); //NOI18N
108: }
109:
110: public Component createProjectCustomizerPanel() {
111: return new DeviceAnywhereCustomizerPanel(evaluator);
112: }
113:
114: public Map<String, Object> getProjectPropertyDefaultValues() {
115: return propertyDefValues;
116: }
117:
118: public Map<String, Object> getGlobalPropertyDefaultValues() {
119: return globalPropertyDefValues;
120: }
121:
122: public Component createGlobalCustomizerPanel() {
123: return new DeviceAnywhereGlobalCustomizerPanel();
124: }
125:
126: public void initValues(ProjectProperties props, String configuration) {
127: this .props = props;
128: this .configuration = configuration;
129: }
130:
131: class PropertyEvaluator {
132: String evaluateProperty(String propertyName) {
133: assert props != null : "Project Properties can not be null!"; //NOI18N
134: if (configuration == null)
135: return (String) props.get(propertyName);
136: String value = (String) props.get("configs."
137: + configuration + "." + propertyName); // NOI18N
138: return value != null ? value : evaluateProperty(
139: propertyName, null);
140: }
141:
142: private String evaluateProperty(String propertyName,
143: String configuration) {
144: //deployment.instance
145: if (configuration == null)
146: return (String) props.get(propertyName);
147: String value = (String) props.get("configs."
148: + configuration + "." + propertyName); // NOI18N
149: return value != null ? value : evaluateProperty(
150: propertyName, null);
151: }
152:
153: String evaluateGlobalProperty(String propertyName,
154: String instanceName) {
155: EditableProperties ep = PropertyUtils.getGlobalProperties();
156: String prefix = "deployments.DeviceAnywhere.";
157: String evaluatedPropertyName = prefix
158: + ((instanceName == null) ? "default"
159: : instanceName) + '.' + propertyName; //NOI18N
160: String value = ep.getProperty(evaluatedPropertyName); // NOI18N
161: return value != null ? value : evaluateGlobalProperty(
162: propertyName, null);
163: }
164: }
165: }
|