From 2c71cc2afbc885ae6f4871a6af500c846bc9d246 Mon Sep 17 00:00:00 2001 From: "gyeongseok.seo" Date: Thu, 5 Jul 2012 16:07:16 +0900 Subject: [PATCH] [Title] Added Query command and Insatll command [Type] Enhancement [Module] cli [Priority] Major [Jira#] [Redmine#] 5363 [Problem] [Cause] [Solution] [TestCase] Change-Id: I7c4f1c527295e539c577f5590d94b96f5e41783f --- .../org/tizen/cli/exec/TargetDeviceSelector.java | 160 ++++++++++++++++++ .../src/org/tizen/cli/exec/WRTLauncher.java | 146 +++++++++++++++++ .../src/org/tizen/cli/exec/debug/Main.java | 181 +++++++++++++++++++++ .../src/org/tizen/cli/exec/install/Main.java | 139 ++++++++++++++++ .../src/org/tizen/cli/exec/query/Main.java | 88 ++++++++++ org.tizen.cli/src/org/tizen/cli/exec/run/Main.java | 180 ++++++++++++++++++++ .../src/org/tizen/cli/exec/uninstall/Main.java | 144 ++++++++++++++++ 7 files changed, 1038 insertions(+) create mode 100644 org.tizen.cli/src/org/tizen/cli/exec/TargetDeviceSelector.java create mode 100644 org.tizen.cli/src/org/tizen/cli/exec/WRTLauncher.java create mode 100644 org.tizen.cli/src/org/tizen/cli/exec/debug/Main.java create mode 100644 org.tizen.cli/src/org/tizen/cli/exec/install/Main.java create mode 100644 org.tizen.cli/src/org/tizen/cli/exec/query/Main.java create mode 100644 org.tizen.cli/src/org/tizen/cli/exec/run/Main.java create mode 100644 org.tizen.cli/src/org/tizen/cli/exec/uninstall/Main.java diff --git a/org.tizen.cli/src/org/tizen/cli/exec/TargetDeviceSelector.java b/org.tizen.cli/src/org/tizen/cli/exec/TargetDeviceSelector.java new file mode 100644 index 0000000..572e2c1 --- /dev/null +++ b/org.tizen.cli/src/org/tizen/cli/exec/TargetDeviceSelector.java @@ -0,0 +1,160 @@ +/* + * Web IDE - Command Line Interface + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GyeongSeok Seo + * BonYong Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package org.tizen.cli.exec; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.tizen.common.core.command.Prompter; +import org.tizen.common.core.command.prompter.Option; +import org.tizen.common.core.command.sdb.DevicesSdbCommand; +import org.tizen.common.core.command.sdb.SmartDevelopmentBridgeManager; +import org.tizen.common.util.ArrayUtil; +import org.tizen.common.util.StringUtil; +import org.tizen.sdblib.IDevice; +import org.tizen.sdblib.SmartDevelopmentBridge; + +public class +TargetDeviceSelector +{ + protected Prompter prompter; + + public TargetDeviceSelector(Prompter prompter) { + this.prompter = prompter; + } + + protected SmartDevelopmentBridgeManager createSDBManager() { + return new SmartDevelopmentBridgeManager(); + } + + protected void printDeviceList( IDevice[] devices ) { + prompter.notify( "currnet connected target List\n" ); + prompter.notify( "-----------------------------\n" ); + for( int i = 0; i < devices.length; i++ ) { + prompter.notify( (i+1) + ") " + devices[i].toString() +"\n" ); + } + } + + public IDevice[] getConnectDevices() { + SmartDevelopmentBridgeManager mgr = createSDBManager(); + return mgr.getDevices(); + } + + public boolean isDeviceConnected() { + boolean isConnected = false; + IDevice[] devices = getConnectDevices(); + if ( devices != null ) { + isConnected = true; + } + + return isConnected; + } + + public boolean isDeviceConnected( String name ) { + boolean isConnected = false; + IDevice[] devices = getConnectDevices(); + + for( int i = 0; i < devices.length; i++ ) { + if ( name.equals( devices[i].toString() ) ) { + isConnected = true; + break; + } + } + + return isConnected; + } + + public boolean isDeviceConnected( IDevice device ) { + boolean isConnected = false; + IDevice[] devices = getConnectDevices(); + + if ( ArrayUtil.contains( devices, device) ) { + isConnected = true; + } + return isConnected; + } + + public IDevice getDevice( String name ) { + IDevice device = null; + IDevice[] devices = getConnectDevices(); + for( int i = 0; i < devices.length; i++ ) { + if ( name.equals( devices[i].toString() ) ) { + device = devices[i]; + break; + } + } + return device; + } + + public IDevice selectDevice() { + IDevice selectDevice = null; + IDevice[] devices = getConnectDevices(); + + if( devices == null ) { + return selectDevice; + } + + if ( devices.length == 1 ) { + selectDevice = ArrayUtil.pickupFirst( devices ); + } else if ( devices.length > 1 ) { + Option yes = new Option( "Yes" ); + Option no = new Option( "No", true ); + + final Option option = prompter.interact( + MessageFormat.format( "device is not selected\n" + + "[{0}] device select and\n" + + "Do you want to be continue?", devices[0].toString() ), + yes, + no + ); + + if ( yes.equals(option) ) { + selectDevice = ArrayUtil.pickupFirst( devices ); + } else if ( no.equals( option ) ) { + printDeviceList( devices ); + + Option num = new Option( "Num" ); + + final Option op = prompter.interact( + "select device or cancel process\n", + num, + no + ); + + if( no.equals( op ) ) { + prompter.notify( "Process is canceled, please selected device" ); + + } else { + // TODO : Needed implement - select device using option value + } + } + } + + return selectDevice; + } +} diff --git a/org.tizen.cli/src/org/tizen/cli/exec/WRTLauncher.java b/org.tizen.cli/src/org/tizen/cli/exec/WRTLauncher.java new file mode 100644 index 0000000..e98b626 --- /dev/null +++ b/org.tizen.cli/src/org/tizen/cli/exec/WRTLauncher.java @@ -0,0 +1,146 @@ +/* +* Web IDE - Command Line Interface +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* GyeongSeok Seo +* BonYong Lee +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.cli.exec; + +import java.util.List; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.tizen.common.core.command.ExecutionContext; +import org.tizen.common.core.command.Prompter; +import org.tizen.sdblib.IDevice; + +/** + *

+ * WRTLauncher. + * + * class for simple WRT command. + * + * provide {@link ExecutionContext} for command line + *

+ * + * @author GyeongSeok Seo{@literal } (S-Core) + * @author BonYong Lee{@literal } (S-Core) + */ +public class +WRTLauncher +extends AbstractLauncher +{ + /** + *

+ * Option for select device + *

+ */ + protected static final String OPT_DEVICE = "select device"; + + /** + *

+ * Description for select device + * + * This is printed out in usage + *

+ * + * @see #OPT_DEVICE + */ + protected static final String DESC_DEVICE = "Command is performed of selected device"; + + /** + *

+ * Target device + * + * command is running in this device + *

+ */ + protected IDevice device = null; + + /** + * Get target device + * + * @return device + */ + public IDevice getDevice() { + return device; + } + + /** + * Set target device + * + * @param device + */ + public void setDevice(IDevice device) { + this.device = device; + } + + /** + * {@link Options} for usage + * + * @return defined {@link Options} + */ + @SuppressWarnings("static-access") + protected + Options + getOptions() + { + final Options opts = super.getOptions(); + opts.addOption( OptionBuilder.hasArg().withLongOpt( OPT_DEVICE ).withDescription( DESC_DEVICE ).create( OPT_DEVICE.substring( 0, 1 ) ) ); + + return opts; + } + + /* (non-Javadoc) + * @see org.tizen.cli.exec.AbstractLauncher#execute(org.apache.commons.cli.CommandLine) + */ + @Override + @SuppressWarnings("unchecked") + protected void execute(CommandLine cmdLine) throws Exception { + final Prompter prompter = getPrompter(); + final List args = cmdLine.getArgList(); + final TargetDeviceSelector deviceSelector = new TargetDeviceSelector(prompter); + logger.trace( "arguments :{}", args ); + + logger.trace("check connected devices"); + if ( !deviceSelector.isDeviceConnected() ) { + prompter.notify( "Device is not connected. Process is canceled" ); + return ; + } + + int nArgs = args.size(); + // user using device select option + if ( nArgs > 0 ) { + // user select device check + String deviceName = cmdLine.getOptionValue( OPT_DEVICE ); + logger.debug( "Device option :{}", deviceName ); + + setDevice( deviceSelector.getDevice( deviceName ) ); + } + // user not using device select option + else if ( nArgs == 0 ) { + logger.trace( "user can't use device select option" ); + setDevice( deviceSelector.selectDevice() ); + } + } +} diff --git a/org.tizen.cli/src/org/tizen/cli/exec/debug/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/debug/Main.java new file mode 100644 index 0000000..bbb6be0 --- /dev/null +++ b/org.tizen.cli/src/org/tizen/cli/exec/debug/Main.java @@ -0,0 +1,181 @@ +/* +* Web IDE - Command Line Interface +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* GyeongSeok Seo +* BonYong Lee +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.cli.exec.debug; + +import java.text.MessageFormat; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.tizen.cli.exec.WRTLauncher; +import org.tizen.common.core.command.Executor; +import org.tizen.common.core.command.Prompter; +import org.tizen.common.core.command.sdb.PushSdbCommand; +import org.tizen.common.file.FileHandler; +import org.tizen.common.file.FileHandler.Attribute; +import org.tizen.web.launch.cli.command.CheckInstallCommand; +import org.tizen.web.launch.cli.command.DebugCommand; +import org.tizen.web.launch.cli.command.InstallCommand; +import org.tizen.web.launch.cli.command.RunCommand; + +/** + * Command Line Interface for debug run widget in target + * + * @author GyeongSeok Seo{@literal } (S-Core) + * @author BonYong Lee{@literal } (S-Core) + */ +public class +Main +extends WRTLauncher +{ + /** + *

+ * Option for target widget file + *

+ */ + protected static final String OPT_WIDGETFILE = "target widget file"; + + /** + *

+ * Description for target widget file + * + * This is printed out in usage + *

+ * + * @see #OPT_WIDGETFILE + */ + protected static final String DESC_WIDGETFILE = "Command is performed of widget file install in target"; + + /** + *

+ * Option for target widget id + *

+ */ + protected static final String OPT_WIDGETID = "target widget id"; + + /** + *

+ * Description for target widget id + * + * This is printed out in usage + *

+ * + * @see #OPT_WIDGETID + */ + protected static final String DESC_WIDGETID = "Command is performed of widget id uninstall in target, widget id is user written id in config.xml"; + + /** + * Entry point for cli main + * + * @param args user input parameter + * + * @throws Exception If unhandled exception occur + */ + public static + void + main( + final String[] args + ) + throws Exception + { + final Main instance = new Main(); + instance.run( args ); + } + + /* (non-Javadoc) + * @see org.tizen.cli.exec.AbstractLauncher#execute(org.apache.commons.cli.CommandLine) + */ + @Override + protected + void + execute( + final CommandLine cmdLine + ) + throws Exception + { + super.execute( cmdLine ); + + final Prompter prompter = getPrompter(); + final FileHandler fileHandler = getFileHandler(); + final Executor exec = getExecutor(); + + // device not connect then exit + if ( getDevice() == null ) { + prompter.notify( "Process is stoped, please select connect device" ); + return ; + } + + // local widget file path control + String localWidgetFileName = cmdLine.getOptionValue( OPT_WIDGETFILE ); + String localWidgetFilePath = (String)fileHandler.get( localWidgetFileName, Attribute.PATH ); + + // core operation + InstallCommand install_command = new InstallCommand(); + install_command.setDevice( getDevice() ); + String remotePath = install_command.getRemotePath(); + + PushSdbCommand push_command = new PushSdbCommand( localWidgetFilePath, remotePath ); + push_command.setDevice( getDevice() ); + + + // widget push + exec.execute( push_command ); + + // widget install + exec.execute( install_command ); + + // install check + String widgetID = cmdLine.getOptionValue( OPT_WIDGETID ); + CheckInstallCommand install_check_command = new CheckInstallCommand( widgetID ); + exec.execute( install_check_command ); + if ( !install_check_command.isInstalled() ) { + prompter.notify( + MessageFormat.format( "Process is stoped, [{0}] widget is not installed", widgetID ) + ); + return ; + } + + // widget debug run + DebugCommand run_command = new DebugCommand( widgetID ); + exec.execute( run_command ); + } + + /* (non-Javadoc) + * @see org.tizen.cli.exec.AbstractLauncher#getOptions() + */ + @Override + @SuppressWarnings("static-access") + protected + Options + getOptions() + { + final Options opts = super.getOptions(); + opts.addOption( OptionBuilder.hasArg().isRequired().withLongOpt( OPT_WIDGETFILE ).withDescription( DESC_WIDGETFILE ).create( OPT_WIDGETFILE.substring( 0, 1 ) ) ); + opts.addOption( OptionBuilder.hasArg().isRequired().withLongOpt( OPT_WIDGETID ).withDescription( DESC_WIDGETID ).create( OPT_WIDGETID.substring( 0, 1 ) ) ); + + return opts; + } +} diff --git a/org.tizen.cli/src/org/tizen/cli/exec/install/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/install/Main.java new file mode 100644 index 0000000..8688384 --- /dev/null +++ b/org.tizen.cli/src/org/tizen/cli/exec/install/Main.java @@ -0,0 +1,139 @@ +/* +* Web IDE - Command Line Interface +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* GyeongSeok Seo +* BonYong Lee +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.cli.exec.install; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; + +import org.tizen.cli.exec.WRTLauncher; +import org.tizen.common.core.command.Prompter; +import org.tizen.common.core.command.sdb.PushSdbCommand; +import org.tizen.common.file.FileHandler; +import org.tizen.common.file.FileHandler.Attribute; +import org.tizen.web.launch.cli.command.InstallCommand; + +/** + * Command Line Interface for install widget in target + * + * @author GyeongSeok Seo{@literal } (S-Core) + * @author BonYong Lee{@literal } (S-Core) + */ +public class +Main +extends WRTLauncher +{ + /** + *

+ * Option for target widget file + *

+ */ + protected static final String OPT_WIDGETFILE = "target widget file"; + + /** + *

+ * Description for target widget file + * + * This is printed out in usage + *

+ * + * @see #OPT_WIDGETFILE + */ + protected static final String DESC_WIDGETFILE = "Command is performed of widget file install in target"; + + /** + * Entry point for cli main + * + * @param args user input parameter + * + * @throws Exception If unhandled exception occur + */ + public static + void + main( + final String[] args + ) + throws Exception + { + final Main instance = new Main(); + instance.run( args ); + } + + /* (non-Javadoc) + * @see org.tizen.cli.exec.AbstractLauncher#execute(org.apache.commons.cli.CommandLine) + */ + @Override + protected + void + execute( + final CommandLine cmdLine + ) + throws Exception + { + super.execute( cmdLine ); + + final Prompter prompter = getPrompter(); + final FileHandler fileHandler = getFileHandler(); + + // device not connect then exit + if ( getDevice() == null ) { + prompter.notify( "Process is stoped, please select connect device" ); + return ; + } + + // local widget file path control + String localWidgetFileName = cmdLine.getOptionValue( OPT_WIDGETFILE ); + String localWidgetFilePath = (String)fileHandler.get( localWidgetFileName, Attribute.PATH ); + + // core operation + InstallCommand install_command = new InstallCommand(); + install_command.setDevice( getDevice() ); + String remotePath = install_command.getRemotePath(); + + PushSdbCommand push_command = new PushSdbCommand( localWidgetFilePath, remotePath ); + push_command.setDevice( getDevice() ); + + // widget push + getExecutor().execute( push_command ); + // widget install + getExecutor().execute( install_command ); + } + + /* (non-Javadoc) + * @see org.tizen.cli.exec.AbstractLauncher#getOptions() + */ + @Override + @SuppressWarnings("static-access") + protected + Options + getOptions() + { + final Options opts = super.getOptions(); + opts.addOption( OptionBuilder.hasArg().isRequired().withLongOpt( OPT_WIDGETFILE ).withDescription( DESC_WIDGETFILE ).create( OPT_WIDGETFILE.substring( 0, 1 ) ) ); + + return opts; + } +} diff --git a/org.tizen.cli/src/org/tizen/cli/exec/query/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/query/Main.java new file mode 100644 index 0000000..0c85455 --- /dev/null +++ b/org.tizen.cli/src/org/tizen/cli/exec/query/Main.java @@ -0,0 +1,88 @@ +/* +* Web IDE - Command Line Interface +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* GyeongSeok Seo +* BonYong Lee +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.cli.exec.query; + +import org.apache.commons.cli.CommandLine; + +import org.tizen.cli.exec.WRTLauncher; +import org.tizen.common.core.command.Prompter; +import org.tizen.web.launch.cli.command.QueryCommand; + +/** + * Command Line Interface for show widget list in target's installed + * + * @author GyeongSeok Seo{@literal } (S-Core) + * @author BonYong Lee{@literal } (S-Core) + */ +public class +Main +extends WRTLauncher +{ + /** + * Entry point for cli main + * + * @param args user input parameter + * + * @throws Exception If unhandled exception occur + */ + public static + void + main( + final String[] args + ) + throws Exception + { + final Main instance = new Main(); + instance.run( args ); + } + + /* (non-Javadoc) + * @see org.tizen.cli.exec.AbstractLauncher#execute(org.apache.commons.cli.CommandLine) + */ + @Override + protected + void + execute( + final CommandLine cmdLine + ) + throws Exception + { + super.execute( cmdLine ); + + final Prompter prompter = getPrompter(); + + // device not connect then exit + if ( getDevice() == null ) { + prompter.notify( "Process is stoped, please select connect device" ); + return ; + } + + // core operation + QueryCommand command = new QueryCommand(); + command.setDevice( getDevice() ); + getExecutor().execute( command ); + } +} diff --git a/org.tizen.cli/src/org/tizen/cli/exec/run/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/run/Main.java new file mode 100644 index 0000000..c0d9f32 --- /dev/null +++ b/org.tizen.cli/src/org/tizen/cli/exec/run/Main.java @@ -0,0 +1,180 @@ +/* +* Web IDE - Command Line Interface +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* GyeongSeok Seo +* BonYong Lee +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.cli.exec.run; + +import java.text.MessageFormat; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.tizen.cli.exec.WRTLauncher; +import org.tizen.common.core.command.Executor; +import org.tizen.common.core.command.Prompter; +import org.tizen.common.core.command.sdb.PushSdbCommand; +import org.tizen.common.file.FileHandler; +import org.tizen.common.file.FileHandler.Attribute; +import org.tizen.web.launch.cli.command.CheckInstallCommand; +import org.tizen.web.launch.cli.command.InstallCommand; +import org.tizen.web.launch.cli.command.RunCommand; + +/** + * Command Line Interface for run widget in target + * + * @author GyeongSeok Seo{@literal } (S-Core) + * @author BonYong Lee{@literal } (S-Core) + */ +public class +Main +extends WRTLauncher +{ + /** + *

+ * Option for target widget file + *

+ */ + protected static final String OPT_WIDGETFILE = "target widget file"; + + /** + *

+ * Description for target widget file + * + * This is printed out in usage + *

+ * + * @see #OPT_WIDGETFILE + */ + protected static final String DESC_WIDGETFILE = "Command is performed of widget file install in target"; + + /** + *

+ * Option for target widget id + *

+ */ + protected static final String OPT_WIDGETID = "target widget id"; + + /** + *

+ * Description for target widget id + * + * This is printed out in usage + *

+ * + * @see #OPT_WIDGETID + */ + protected static final String DESC_WIDGETID = "Command is performed of widget id uninstall in target, widget id is user written id in config.xml"; + + /** + * Entry point for cli main + * + * @param args user input parameter + * + * @throws Exception If unhandled exception occur + */ + public static + void + main( + final String[] args + ) + throws Exception + { + final Main instance = new Main(); + instance.run( args ); + } + + /* (non-Javadoc) + * @see org.tizen.cli.exec.AbstractLauncher#execute(org.apache.commons.cli.CommandLine) + */ + @Override + protected + void + execute( + final CommandLine cmdLine + ) + throws Exception + { + super.execute( cmdLine ); + + final Prompter prompter = getPrompter(); + final FileHandler fileHandler = getFileHandler(); + final Executor exec = getExecutor(); + + // device not connect then exit + if ( getDevice() == null ) { + prompter.notify( "Process is stoped, please select connect device" ); + return ; + } + + // local widget file path control + String localWidgetFileName = cmdLine.getOptionValue( OPT_WIDGETFILE ); + String localWidgetFilePath = (String)fileHandler.get( localWidgetFileName, Attribute.PATH ); + + // core operation + InstallCommand install_command = new InstallCommand(); + install_command.setDevice( getDevice() ); + String remotePath = install_command.getRemotePath(); + + PushSdbCommand push_command = new PushSdbCommand( localWidgetFilePath, remotePath ); + push_command.setDevice( getDevice() ); + + + // widget push + exec.execute( push_command ); + + // widget install + exec.execute( install_command ); + + // install check + String widgetID = cmdLine.getOptionValue( OPT_WIDGETID ); + CheckInstallCommand install_check_command = new CheckInstallCommand( widgetID ); + exec.execute( install_check_command ); + if ( !install_check_command.isInstalled() ) { + prompter.notify( + MessageFormat.format( "Process is stoped, [{0}] widget is not installed", widgetID ) + ); + return ; + } + + // widget run + RunCommand run_command = new RunCommand( widgetID ); + exec.execute( run_command ); + } + + /* (non-Javadoc) + * @see org.tizen.cli.exec.AbstractLauncher#getOptions() + */ + @Override + @SuppressWarnings("static-access") + protected + Options + getOptions() + { + final Options opts = super.getOptions(); + opts.addOption( OptionBuilder.hasArg().isRequired().withLongOpt( OPT_WIDGETFILE ).withDescription( DESC_WIDGETFILE ).create( OPT_WIDGETFILE.substring( 0, 1 ) ) ); + opts.addOption( OptionBuilder.hasArg().isRequired().withLongOpt( OPT_WIDGETID ).withDescription( DESC_WIDGETID ).create( OPT_WIDGETID.substring( 0, 1 ) ) ); + + return opts; + } +} diff --git a/org.tizen.cli/src/org/tizen/cli/exec/uninstall/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/uninstall/Main.java new file mode 100644 index 0000000..349fa16 --- /dev/null +++ b/org.tizen.cli/src/org/tizen/cli/exec/uninstall/Main.java @@ -0,0 +1,144 @@ +/* +* Web IDE - Command Line Interface +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* GyeongSeok Seo +* BonYong Lee +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.cli.exec.uninstall; + +import java.text.MessageFormat; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.tizen.cli.exec.WRTLauncher; +import org.tizen.common.core.command.Executor; +import org.tizen.common.core.command.Prompter; +import org.tizen.web.launch.cli.command.CheckInstallCommand; +import org.tizen.web.launch.cli.command.KillCommand; +import org.tizen.web.launch.cli.command.UninstallCommand; + +/** + * Command Line Interface for uninstall widget in target + * + * @author GyeongSeok Seo{@literal } (S-Core) + * @author BonYong Lee{@literal } (S-Core) + */ +public class +Main +extends WRTLauncher +{ + /** + *

+ * Option for target widget id + *

+ */ + protected static final String OPT_WIDGETID = "target widget id"; + + /** + *

+ * Description for target widget id + * + * This is printed out in usage + *

+ * + * @see #OPT_WIDGETID + */ + protected static final String DESC_WIDGETID = "Command is performed of widget id uninstall in target, widget id is user written id in config.xml"; + + /** + * Entry point for cli main + * + * @param args user input parameter + * + * @throws Exception If unhandled exception occur + */ + public static + void + main( + final String[] args + ) + throws Exception + { + final Main instance = new Main(); + instance.run( args ); + } + + /* (non-Javadoc) + * @see org.tizen.cli.exec.AbstractLauncher#execute(org.apache.commons.cli.CommandLine) + */ + @Override + protected + void + execute( + final CommandLine cmdLine + ) + throws Exception + { + super.execute( cmdLine ); + + final Prompter prompter = getPrompter(); + final Executor exec = getExecutor(); + + // device not connect then exit + if ( getDevice() == null ) { + prompter.notify( "Process is stoped, please select connect device" ); + return ; + } + + // core operation + String widgetID = cmdLine.getOptionValue( OPT_WIDGETID ); + + // install check + CheckInstallCommand install_check_command = new CheckInstallCommand( widgetID ); + exec.execute( install_check_command ); + if ( !install_check_command.isInstalled() ) { + prompter.notify( + MessageFormat.format( "Process is stoped, [{0}] widget is not installed", widgetID ) + ); + return ; + } + + // kill + KillCommand kill_command = new KillCommand( widgetID ); + exec.execute( kill_command ); + + // uninstall + UninstallCommand uninstall_command = new UninstallCommand( widgetID ); + exec.execute( uninstall_command ); + } + + /* (non-Javadoc) + * @see org.tizen.cli.exec.AbstractLauncher#getOptions() + */ + @Override + @SuppressWarnings("static-access") + protected + Options + getOptions() + { + final Options opts = super.getOptions(); + opts.addOption( OptionBuilder.hasArg().isRequired().withLongOpt( OPT_WIDGETID ).withDescription( DESC_WIDGETID ).create( OPT_WIDGETID.substring( 0, 1 ) ) ); + + return opts; + } +} -- 2.7.4