📄 sunspotdeploymentprogressui.java
字号:
/* * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is * described in this document. In particular, and without limitation, these intellectual property rights may * include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents * or pending patent applications in the U.S. and in other countries. * * U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. * standard license agreement and applicable provisions of the FAR and its supplements. * * Use is subject to license terms. * * This distribution may include materials developed by third parties. Sun, Sun Microsystems, the Sun logo and * Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. * * Copyright (c) 2006 Sun Microsystems, Inc. Tous droits r?serv?s. * * Sun Microsystems, Inc. d?tient les droits de propri?t? intellectuels relatifs ? la technologie incorpor?e dans * le produit qui est d?crit dans ce document. En particulier, et ce sans limitation, ces droits de propri?t? * intellectuelle peuvent inclure un ou plus des brevets am?ricains list?s ? l'adresse http://www.sun.com/patents * et un ou les brevets suppl?mentaires ou les applications de brevet en attente aux Etats - Unis et dans les * autres pays. * * L'utilisation est soumise aux termes du contrat de licence. * * Cette distribution peut comprendre des composants d?velopp?s par des tierces parties. * Sun, Sun Microsystems, le logo Sun et Java sont des marques de fabrique ou des marques d?pos?es de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.spot.spotworld.gui;import com.sun.spot.client.ITarget;import com.sun.spot.client.RemoteTarget;import com.sun.spot.client.SpotClientCommands;import com.sun.spot.client.SpotClientException;import com.sun.spot.client.SpotManager;import com.sun.spot.client.ui.SpotCommandDefinition;import com.sun.spot.peripheral.ota.ISpotClientConstants;import com.sun.spot.spotworld.participants.SunSPOT;import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;import org.apache.tools.ant.DefaultLogger;import org.apache.tools.ant.Project;import org.apache.tools.ant.ProjectHelper;/** * * @author randy */public class SunSPOTDeploymentProgressUI extends SunSPOTProgressUI { public void doTasksAndMonitor(final IUIObject obj, File appDir, String remoteAddress, boolean doClean, boolean doCompile, boolean doDeploy) throws FileNotFoundException, IOException{ setSunspot((SunSPOT) obj.getVirtualObject()); File buildFile = new File(appDir.toString(), "build.xml"); if (!buildFile.exists()) throw new FileNotFoundException("Can't find a build.xml file in the given directory"); final Project p = new Project(); // this is an "ant" object that does the work. p.setUserProperty("ant.file", buildFile.getAbsolutePath()); DefaultLogger consoleLogger = new DefaultLogger(); consoleLogger.setErrorPrintStream(System.err); consoleLogger.setOutputPrintStream(System.out); consoleLogger.setMessageOutputLevel(Project.MSG_INFO); p.addBuildListener(consoleLogger); p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference("ant.projectHelper", helper); helper.parse(p, buildFile); Thread cleanThread = null; Thread compileThread = null; if(doClean) { cleanThread = executeAntInBG(p, "clean", (! doCompile ) && (! doDeploy), null ); } if(doCompile) { compileThread = executeAntInBG(p, "suite", ! doDeploy, cleanThread); } if(doDeploy){ remoteDeployAndRunAppInBG(obj, appDir, remoteAddress, compileThread); } } public Thread executeAntInBG(final Project proj, final String command, final boolean disposeOnCompletion, final Thread runFirst){ Runnable r = new Runnable(){ public void run(){ if(runFirst != null) { try { runFirst.join(); } catch (InterruptedException ex) { ex.printStackTrace(); } } info("ant " + command); proj.executeTarget(command); if(disposeOnCompletion) getFrame().dispose(); } }; Thread t = new Thread(r); t.start(); return t; } public void remoteDeployAndRunAppInBG(final IUIObject obj, final File appDir, final String remoteAddress, final Thread runFirst) { Runnable r = new Runnable(){ public void run(){ if(runFirst != null) { try { runFirst.join(); } catch (InterruptedException ex) { ex.printStackTrace(); } } String keyStoreDir = System.getProperty("keyStoreDir"); String libFileDir = System.getProperty("libFileDir"); String sysBinDir = System.getProperty("sysBinDir"); final String imageFile = appDir.toString() + File.separator + "suite" + File.separator + "image"; SpotManager spotManager; try { spotManager = new SpotManager(keyStoreDir); SpotClientCommands commandRepository = new SpotClientCommands(SunSPOTDeploymentProgressUI.this, spotManager, imageFile, libFileDir, new File(sysBinDir)); initCommands(commandRepository); ITarget target = new RemoteTarget(null, remoteAddress, 26, (short) 3, SunSPOTDeploymentProgressUI.this, ISpotClientConstants.MASTER_ISOLATE_ECHO_PORT); spotManager.setTarget(target); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } try { synchronize(); ((SpotCommandDefinition) bootloaderClientCommands.get("flashapp")).process(imageFile); ((SpotCommandDefinition) bootloaderClientCommands.get("run")).process("fork"); } catch (SpotClientException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } }; Thread t = new Thread(r); t.start(); } public void remoteDeployAndRunApp(final IUIObject obj, final File appDir, final String remoteAddress, final Thread runFirst) { if(runFirst != null) { try { runFirst.join(); } catch (InterruptedException ex) { ex.printStackTrace(); } } String keyStoreDir = System.getProperty("keyStoreDir"); String libFileDir = System.getProperty("libFileDir"); String sysBinDir = System.getProperty("sysBinDir"); final String imageFile = appDir.toString() + File.separator + "suite" + File.separator + "image"; SpotManager spotManager; try { spotManager = new SpotManager(keyStoreDir); SpotClientCommands commandRepository = new SpotClientCommands(SunSPOTDeploymentProgressUI.this, spotManager, imageFile, libFileDir, new File(sysBinDir)); initCommands(commandRepository); ITarget target = new RemoteTarget(null, remoteAddress, 26, (short) 3, SunSPOTDeploymentProgressUI.this, ISpotClientConstants.MASTER_ISOLATE_ECHO_PORT); spotManager.setTarget(target); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } try { synchronize(); ((SpotCommandDefinition) bootloaderClientCommands.get("flashapp")).process(imageFile); ((SpotCommandDefinition) bootloaderClientCommands.get("run")).process("fork"); } catch (SpotClientException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -