import org.tizen.common.core.command.Prompter;
import org.tizen.common.core.command.prompter.ChoiceOption;
+import org.tizen.common.core.command.prompter.GenericOption;
import org.tizen.common.core.command.prompter.Option;
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;
}
protected void printDeviceList( IDevice[] devices ) {
- prompter.notify( "-----------------------------\n" );
- prompter.notify( "currnet connected target List\n" );
- prompter.notify( "-----------------------------\n" );
+ prompter.notify( "-----------------------------" );
+ prompter.notify( "currnet connected target List" );
+ prompter.notify( "-----------------------------" );
for( int i = 0; i < devices.length; i++ ) {
- prompter.notify( (i+1) + ") " + devices[i].toString() +"\n" );
+ prompter.notify( (i+1) + ") " + devices[i].toString() );
}
}
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() ),
+ "Do you want to be continue ?", devices[0].toString() ),
yes,
no
);
} else if ( no.equals( option ) ) {
printDeviceList( devices );
- ChoiceOption num = new ChoiceOption( "Num" );
+ ChoiceOption cancel = new ChoiceOption( "Cancel", true );
+ GenericOption num = new GenericOption( "Num" );
final Option op = prompter.interact(
- "select device or cancel process\n",
- num,
- no
+ "select device or cancel process ",
+ cancel,
+ num
);
- if( no.equals( op ) ) {
+ if( cancel.equals( op ) ) {
prompter.notify( "Process is canceled, please selected device" );
-
} else {
- int index = Integer.parseInt( op.getName() );
- prompter.notify( "select : " + op.getName() );
- selectDevice = ArrayUtil.get( devices, index-1 );
- // TODO : Needed implement - select device using option value
+ String answer = ((GenericOption)op).getAnswer();
+ if ( !StringUtil.isEmpty( answer ) ) {
+ boolean isCorrect = false;
+ int index = 0;
+ try {
+ index = Integer.parseInt( answer );
+
+ // answer check
+ for ( int i = 1; i <= devices.length; i++ ) {
+ if ( index == i ) {
+ isCorrect = true;
+ break;
+ }
+ }
+ } catch (NumberFormatException e) {
+ } finally {
+ if ( isCorrect ) {
+ selectDevice = ArrayUtil.get( devices, index-1 );
+ prompter.notify( "Select Device is : " + selectDevice.toString() );
+ } else {
+ prompter.notify( "Process is canceled, please selected correct device" );
+ }
+ }
+ }
}
}
}
*/
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.common.core.command.sdb.PushSdbCommand;
import org.tizen.common.file.FileHandler;
import org.tizen.common.file.FileHandler.Attribute;
+import org.tizen.common.util.FilenameUtil;
+import org.tizen.common.util.StringUtil;
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;
+import org.tizen.web.launch.cli.command.KillCommand;
+import org.tizen.web.launch.cli.command.ModeCommnad;
/**
* Command Line Interface for debug run widget in target
// device not connect then exit
if ( getDevice() == null ) {
- prompter.notify( "Process is stoped, please select connect device" );
+ endSDB();
return ;
}
// local widget file path control
- String localWidgetFileName = cmdLine.getOptionValue( OPT_WIDGETFILE );
- String localWidgetFilePath = (String)fileHandler.get( localWidgetFileName, Attribute.PATH );
+ String inputName = cmdLine.getOptionValue( OPT_WIDGETFILE );
+ logger.trace("input file name : {} ", inputName);
+ if ( StringUtil.isEmpty( inputName ) ) {
+ prompter.notify( "widget file not selected." );
+ printHelp();
+ endSDB();
+ }
+ String widgetId = cmdLine.getOptionValue( OPT_WIDGETID );
+
+ String filePath = (String)fileHandler.get( inputName, Attribute.PATH );
+ logger.trace( "local widget file path : {}", filePath );
+
+ String fileName = FilenameUtil.getFilename( inputName );
+ logger.trace( "local widget file name : {}", fileName );
// core operation
InstallCommand install_command = new InstallCommand();
+ install_command.setWidget( fileName );
install_command.setDevice( getDevice() );
- String remotePath = install_command.getRemotePath();
+ String remotePath = install_command.getRemotePath() + fileName;
+ logger.trace( "remote widget file path : {}", remotePath );
- PushSdbCommand push_command = new PushSdbCommand( localWidgetFilePath, remotePath );
+ PushSdbCommand push_command = new PushSdbCommand( filePath, remotePath );
push_command.setDevice( getDevice() );
+ ModeCommnad mode_command = new ModeCommnad();
+ mode_command.setDevice( getDevice() );
// widget push
+ logger.trace( "push command");
exec.execute( push_command );
+ if ( "failed".equals( push_command.getResult() ) ) {
+ endSDB();
+ }
- // widget install
- exec.execute( install_command );
+ // widget mode
+ logger.trace( "mode command");
+ exec.execute( mode_command );
+ if ( mode_command.getResult().contains( "failed" ) ) {
+ endSDB();
+ }
- // 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 ;
+ if ( !StringUtil.isEmpty( widgetId ) ) {
+ logger.trace( "same widget's pre-install check and kill process" );
+ CheckInstallCommand check_install_cmd = new CheckInstallCommand( widgetId );
+ check_install_cmd.setDevice( getDevice() );
+ check_install_cmd.setPrintOption( false );
+ exec.execute( check_install_cmd );
+ if ( check_install_cmd.isInstalled() ) {
+ KillCommand kill_cmd = new KillCommand( widgetId );
+ kill_cmd.setPrintOption( false );
+ kill_cmd.setDevice( getDevice() );
+ exec.execute( kill_cmd );
+ }
}
+ // widget install
+ logger.trace( "install command");
+ exec.execute( install_command );
+
// widget debug run
- DebugCommand run_command = new DebugCommand( widgetID );
+ DebugCommand run_command = new DebugCommand( widgetId );
+ run_command.setDevice( getDevice() );
exec.execute( run_command );
+
+ endSDB();
}
/* (non-Javadoc)
*/
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.common.core.command.sdb.PushSdbCommand;
import org.tizen.common.file.FileHandler;
import org.tizen.common.file.FileHandler.Attribute;
+import org.tizen.common.util.FilenameUtil;
+import org.tizen.common.util.StringUtil;
import org.tizen.web.launch.cli.command.CheckInstallCommand;
import org.tizen.web.launch.cli.command.InstallCommand;
+import org.tizen.web.launch.cli.command.KillCommand;
+import org.tizen.web.launch.cli.command.ModeCommnad;
import org.tizen.web.launch.cli.command.RunCommand;
/**
// device not connect then exit
if ( getDevice() == null ) {
- prompter.notify( "Process is stoped, please select connect device" );
+ endSDB();
return ;
}
// local widget file path control
- String localWidgetFileName = cmdLine.getOptionValue( OPT_WIDGETFILE );
- String localWidgetFilePath = (String)fileHandler.get( localWidgetFileName, Attribute.PATH );
+ String inputName = cmdLine.getOptionValue( OPT_WIDGETFILE );
+ logger.trace("input file name : {} ", inputName);
+ if ( StringUtil.isEmpty( inputName ) ) {
+ prompter.notify( "widget file not selected." );
+ printHelp();
+ endSDB();
+ }
+ String widgetId = cmdLine.getOptionValue( OPT_WIDGETID );
+
+ String filePath = (String)fileHandler.get( inputName, Attribute.PATH );
+ logger.trace( "local widget file path : {}", filePath );
+
+ String fileName = FilenameUtil.getFilename( inputName );
+ logger.trace( "local widget file name : {}", fileName );
// core operation
InstallCommand install_command = new InstallCommand();
+ install_command.setWidget( fileName );
install_command.setDevice( getDevice() );
- String remotePath = install_command.getRemotePath();
+ String remotePath = install_command.getRemotePath() + fileName;
+ logger.trace( "remote widget file path : {}", remotePath );
- PushSdbCommand push_command = new PushSdbCommand( localWidgetFilePath, remotePath );
+ PushSdbCommand push_command = new PushSdbCommand( filePath, remotePath );
push_command.setDevice( getDevice() );
+ ModeCommnad mode_command = new ModeCommnad();
+ mode_command.setDevice( getDevice() );
// widget push
+ logger.trace( "push command");
exec.execute( push_command );
+ if ( "failed".equals( push_command.getResult() ) ) {
+ endSDB();
+ }
- // widget install
- exec.execute( install_command );
+ // widget mode
+ logger.trace( "mode command");
+ exec.execute( mode_command );
+ if ( mode_command.getResult().contains( "failed" ) ) {
+ endSDB();
+ }
- // 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 ;
+ if ( !StringUtil.isEmpty( widgetId ) ) {
+ logger.trace( "same widget's pre-install check and kill process" );
+ CheckInstallCommand check_install_cmd = new CheckInstallCommand( widgetId );
+ check_install_cmd.setDevice( getDevice() );
+ check_install_cmd.setPrintOption( false );
+ exec.execute( check_install_cmd );
+ if ( check_install_cmd.isInstalled() ) {
+ KillCommand kill_cmd = new KillCommand( widgetId );
+ kill_cmd.setPrintOption( false );
+ kill_cmd.setDevice( getDevice() );
+ exec.execute( kill_cmd );
+ }
}
+ // widget install
+ logger.trace( "install command");
+ exec.execute( install_command );
+
// widget run
- RunCommand run_command = new RunCommand( widgetID );
+ RunCommand run_command = new RunCommand( widgetId );
+ run_command.setDevice( getDevice() );
exec.execute( run_command );
+
+ endSDB();
}
/* (non-Javadoc)
import org.junit.Test;
import org.tizen.common.core.command.Prompter;
import org.tizen.common.core.command.prompter.ChoiceOption;
+import org.tizen.common.core.command.prompter.GenericOption;
import org.tizen.sdblib.IDevice;
import static org.mockito.Mockito.mock;
{
try {
testClass.printDeviceList( mockDevices );
- verify( mockPropter ).notify( "currnet connected target List\n" );
- verify( mockPropter ).notify( "1) test1\n" );
- verify( mockPropter ).notify( "2) test2\n" );
+ verify( mockPropter ).notify( "currnet connected target List" );
+ verify( mockPropter ).notify( "1) test1" );
+ verify( mockPropter ).notify( "2) test2" );
} catch (Exception e) {
fail( "devices is not null then Not throw exception" );
}
try {
testClass.printDeviceList( null );
- verify( mockPropter ).notify( "-----------------------------\n" );
- verify( mockPropter ).notify( "currnet connected target List\n" );
- verify( mockPropter ).notify( "-----------------------------\n" );
+ verify( mockPropter ).notify( "-----------------------------" );
+ verify( mockPropter ).notify( "currnet connected target List" );
+ verify( mockPropter ).notify( "-----------------------------" );
fail( "devices is null then throw exception" );
} catch (Exception e) {}
}
ChoiceOption no = new ChoiceOption( "No", true );
when( mockPropter.interact( "device is not selected\n" +
"[test1] device select and\n" +
- "Do you want to be continue?",
+ "Do you want to be continue ?",
yes,
no
)
when( mockPropter.interact( "device is not selected\n" +
"[test1] device select and\n" +
- "Do you want to be continue?",
+ "Do you want to be continue ?",
yes,
no
)
).thenReturn( no );
- ChoiceOption num = new ChoiceOption( "Num" );
+ ChoiceOption cancel = new ChoiceOption( "Cancel", true );
+ GenericOption num = new GenericOption( "Num" );
- when( mockPropter.interact( "select device or cancel process\n",
- num,
- no
+ when( mockPropter.interact( "select device or cancel process ",
+ cancel,
+ num
)
- ).thenReturn( no );
+ ).thenReturn( cancel );
assertEquals( null, testClass.selectDevice() );
verify( mockPropter ).notify( "Process is canceled, please selected device" );
}