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 the Nokia Deployment.
027: * The Initial Developer of the Original Software is Nokia Corporation.
028: * Portions created by Nokia Corporation Copyright 2005, 2007.
029: * All Rights Reserved.
030: *
031: * If you wish your version of this file to be governed by only the CDDL
032: * or only the GPL Version 2, indicate your decision by adding
033: * "[Contributor] elects to include this software in this distribution
034: * under the [CDDL or GPL Version 2] license." If you do not indicate a
035: * single choice of license, a recipient has the option to distribute
036: * your version of this file under either the CDDL, the GPL Version 2 or
037: * to extend the choice of license to its licensees as provided above.
038: * However, if you add GPL Version 2 code and therefore, elected the GPL
039: * Version 2 license, then the option applies only if the new code is
040: * made subject to such option by the copyright holder.
041: */
042:
043: package com.nokia.phone.deploy;
044:
045: import java.io.File;
046: import java.io.IOException;
047: import java.util.ArrayList;
048: import java.util.List;
049:
050: /**
051: * Main class for deployment functionality. Called from deployment script.
052: */
053: public class DeployerMain {
054:
055: /**
056: * Main method that deploys the given application to the given devices.
057: * The device list must be separated by new lines ('\n'), this is to
058: * simplify the deployment ant script.
059: */
060: public static void main(String[] args) {
061: if (args.length < 2) {
062: System.err
063: .println("usage: DeployerMain <jad file> <jar file> [list of device names to deploy to]");
064:
065: } else {
066: // Don't continue if OS is not supported
067: if (!CONA.getInstance().isOSSupportsDeployment()) {
068: System.err
069: .println("Deployment aborted, only supported on Windows operating system");
070: System.exit(0);
071: }
072:
073: // Don't continue if dll's were not found
074: if (!CONA.getInstance().isConnAPIDllFound()) {
075: System.err
076: .println("Deployment aborted, ConnAPI.dll not found.");
077: System.exit(0);
078: }
079: if (!CONA.getInstance().isConnJNIDllFound()) {
080: System.err
081: .println("Deployment aborted, ConnJNI.dll not found.");
082: System.exit(0);
083: }
084:
085: String jad = args[0];
086: String jar = args[1];
087:
088: File jadFile = new File(jad);
089: File jarFile = new File(jar);
090:
091: ArrayList<String> selectedTerminals = null;
092:
093: if (args.length > 2) {
094: String[] deviceNamesList = args[2].split("\n");
095: selectedTerminals = new java.util.ArrayList<java.lang.String>();
096: for (int i = 0; i < deviceNamesList.length; i++) {
097: String deviceName = deviceNamesList[i].trim();
098: if (!deviceName.equals("")) {
099: selectedTerminals.add(deviceName);
100: }
101: }
102: }
103:
104: Deployer deployer = new Deployer();
105:
106: // Open connection, if it doesn't work out, don't continue
107: deployer.openConnectionLayer();
108: if (!deployer.isConnected()) {
109: System.err
110: .println("Deployment aborted, connection failed.");
111: System.exit(0);
112: }
113:
114: List<String> allConnectedTerminals = deployer
115: .getTerminals();
116:
117: // If there are no terminals, don't continue
118: if (allConnectedTerminals.size() == 0) {
119: System.err
120: .println("Deployment aborted, no devices found.");
121: deployer.closeConnectionLayer();
122: System.exit(0);
123: }
124:
125: List<String> notOkTerminals = new ArrayList<String>();
126:
127: if (selectedTerminals != null) {
128:
129: // check whether the selected terminals are still connected
130: for (String terminal : selectedTerminals) {
131: if (!allConnectedTerminals.contains(terminal)) {
132: System.err
133: .println("Could not deploy. Selected terminal: "
134: + terminal
135: + " is not currently connected.");
136: notOkTerminals.add(terminal);
137: } else {
138: System.out.println("Deploying to: '" + terminal
139: + "' using "
140: + deployer.getConnectionType(terminal));
141: try {
142: boolean success = deployer.deploy(new File(
143: jad), new File(jar), terminal);
144: if (success) {
145: System.out
146: .println("Deployment succeeded!");
147: } else {
148: notOkTerminals.add(terminal);
149: }
150: } catch (IOException e) {
151: e.printStackTrace();
152: notOkTerminals.add(terminal);
153: } catch (UnsatisfiedLinkError e) {
154: e.printStackTrace();
155: notOkTerminals.add(terminal);
156: }
157: }
158: }
159: selectedTerminals.removeAll(notOkTerminals);
160: } else {
161: System.out
162: .println("Deploying to all connected terminals.");
163: notOkTerminals = deployer.deployToAllTerminals(jadFile,
164: jarFile);
165: }
166:
167: for (String notOk : notOkTerminals) {
168: System.err.println("Could not deploy to terminal: "
169: + notOk);
170: }
171:
172: System.out
173: .println("Deployment done, closing connection layer");
174:
175: deployer.closeConnectionLayer();
176: }
177: }
178: }
|