[Title] Added CLI command - project generation.
authorgyeongseok.seo <gyeongseok.seo@samsung.com>
Fri, 17 Aug 2012 10:55:55 +0000 (19:55 +0900)
committergyeongseok.seo <gyeongseok.seo@samsung.com>
Fri, 17 Aug 2012 10:55:55 +0000 (19:55 +0900)
[Type] Enhancement
[Module] cli
[Priority] Major
[Jira#]
[Redmine#] 6364
[Problem]
[Cause]
[Solution]
[TestCase] cli

Change-Id: Ia871b76a4e9b0034b7ae0e1a54233a82ecc77336

org.tizen.cli/META-INF/MANIFEST.MF
org.tizen.cli/doc/install/bin_/web-gen [new file with mode: 0755]
org.tizen.cli/src/org/tizen/cli/exec/gen/Main.java [new file with mode: 0644]

index a045d36..9903541 100644 (file)
@@ -7,7 +7,8 @@ Bundle-Vendor: Samsung
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Require-Bundle: org.tizen.web.common,
  org.tizen.web.sign,
- org.tizen.web.launch
+ org.tizen.web.launch,
+ org.tizen.web.project.wizard
 Bundle-ClassPath: .,
  lib/ant.jar,
  lib/commons-cli-1.2.jar
diff --git a/org.tizen.cli/doc/install/bin_/web-gen b/org.tizen.cli/doc/install/bin_/web-gen
new file mode 100755 (executable)
index 0000000..b63a8a4
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+MAIN=org.tizen.cli.exec.gen.Main
+
+SCRIPT="$0"
+
+while [ -h "$SCRIPT" ] ; do
+    ls=`ls -ld "$SCRIPT"`
+
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        SCRIPT="$link"
+    else
+        SCRIPT=`dirname "$SCRIPT"`/"$link"
+    fi
+done
+
+DIR_BIN=`dirname $SCRIPT`
+DIR_HOME=$DIR_BIN/..
+DIR_LIB=$DIR_HOME/lib
+DIR_CONFIG=$DIR_HOME/conf
+
+JARS=`find $DIR_LIB -name "*.jar"`
+
+JAR=""
+for JAR_FILE in $JARS; do
+    JAR=$JAR:$JAR_FILE
+done
+
+CLASSPATH=$DIR_CONFIG:$JAR
+
+OPT_LOGGING="-Dlog4j.configuration=log4j.xml"
+OPT_PRG_NAME="-Dcli.name=$SCRIPT"
+
+READ_ARG="n"
+
+OPT_TRACE=
+
+for WORD in $@; do
+        if [ "y" = "$READ_ARG" ]
+        then
+                OPT_LOGGING="-Dlog4j.configuration=log4j-${WORD}.xml"
+                if [ "$WORD" = "trace" ]
+                then
+                        OPT_TRACE="-Dlog4j.debug=true"
+                fi
+                READ_ARG="n"
+        fi
+        case $WORD in
+        "--log" | "-l" )
+        READ_ARG="y"
+        ;;
+        esac
+done
+
+OPT="$OPT_TRACE $OPT_LOGGING $OPT_PRG_NAME"
+
+EXEC="java -cp $CLASSPATH $OPT $MAIN $@"
+
+if [ -n "$OPT_TRACE" ]
+then
+        echo "Command :$EXEC"
+fi
+
+$EXEC
diff --git a/org.tizen.cli/src/org/tizen/cli/exec/gen/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/gen/Main.java
new file mode 100644 (file)
index 0000000..f4e65ed
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+* Web IDE - Command Line Interface
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* GyeongSeok Seo <gyeongseok.seo@samsung.com>
+* Jihoon Song <jihoon80.song@samsung.com>
+* BonYong Lee <bonyong.lee@samsung.com>
+* Hyeongseok Heo <hyeongseok.heo@samsung.com>
+* 
+* 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.gen;
+
+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.AbstractLauncher;
+import org.tizen.common.core.command.Prompter;
+import org.tizen.common.core.command.prompter.ChoiceOption;
+import org.tizen.common.core.command.prompter.Option;
+import org.tizen.common.util.ObjectUtil;
+import org.tizen.web.project.wizard.cli.command.ProjectGenCommand;
+
+/**
+ * Command Line Interface for install widget in target
+ * 
+ * @author GyeongSeok Seo{@literal <gyeongseok.seo@samsung.com>} (S-Core)
+ * @author Jihoon Song{@literal <jihoon80.song@samsung.com>} (S-Core)
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ * @author Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-Core)
+ */
+public class
+Main
+extends AbstractLauncher {
+
+       /**
+        * <p>
+        * Option for project name
+        * </p>
+        */
+       protected static final String OPT_NAME = "name";
+
+       /**
+        * <p>
+        * Description for project name
+        * 
+        * This is printed out in usage
+        * </p>
+        * 
+        * @see #OPT_WIDGETFILE
+        */
+       protected static final String DESC_NAME = "generation project name";
+
+       /**
+        * <p>
+        * Option for project name
+        * </p>
+        */
+       protected static final String OPT_PATH = "path";
+
+       /**
+        * <p>
+        * Description for project name
+        * 
+        * This is printed out in usage
+        * </p>
+        * 
+        * @see #OPT_WIDGETFILE
+        */
+       protected static final String DESC_PATH = "generation project path";
+
+       /**
+        * 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 );
+       }
+
+       @Override
+       protected
+       void
+       execute(
+               CommandLine cmdLine
+       )
+       throws Exception
+       {
+               final Prompter prompter = getPrompter();
+
+               logger.trace( "create ProjectGenCommand instance" );
+               ProjectGenCommand command = new ProjectGenCommand();
+
+               logger.trace( "get user input options" );
+               String name = cmdLine.getOptionValue( OPT_NAME );
+               String path = cmdLine.getOptionValue( OPT_PATH );
+
+               logger.trace( "set user input options" );
+               command.setProjectName( name );
+               command.setTargetPath( path );
+
+               logger.trace( "check destination directory" );
+               String destDir = command.getDestDir();
+               if ( command.isDirectoryExists( destDir ) ) {
+                       ChoiceOption yes = new ChoiceOption( "Yes" );
+                       ChoiceOption no = new ChoiceOption( "No", true );
+
+                       final Option option = prompter.interact(
+                               MessageFormat.format( "{0} is already exist\nDo you want to be overwrite and continue?", destDir ),
+                               yes,
+                               no
+                       );
+
+                       if ( no.equals( option ) )
+                       {
+                               prompter.notify( "Process is canceled" );
+                               return ;
+                       }
+               }
+
+               logger.trace( "execute project gen command" );
+               getExecutor().execute( command );
+
+               logger.trace( "check excute result" );
+               String result = command.getResult();
+               if ( ObjectUtil.equals("success", result) ) {
+                       command.printInfo(prompter);
+               }
+               prompter.notify( result );
+       }
+
+       /* (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().withLongOpt( OPT_NAME ).withDescription( DESC_NAME ).create( OPT_NAME.substring( 0, 1 ) ) );
+               opts.addOption( OptionBuilder.hasArg().withLongOpt( OPT_PATH ).withDescription( DESC_PATH ).create( OPT_PATH.substring( 0, 1 ) ) );
+               return opts;
+       }
+}