From: Bonyong.lee
Date: Tue, 3 Jul 2012 04:39:57 +0000 (+0100)
Subject: [Title] Merge cli branch
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=55cd833d33cf8d61702291b6e7c8ea25a96add79;p=sdk%2Ftools%2Fcli.git
[Title] Merge cli branch
[Type] Enhancement
[Module] Sub
[Priority] Minor
[CQ#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]
---
diff --git a/.gitignore b/.gitignore
index e69de29..fd9ed35 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1,11 @@
+#binary files
+build_result
+bin
+*.class
+common-eplugin_*.tar.gz
+common-eplugin_*_*.zip
+common-eplugin.package.linux
+common-eplugin.package.windows
+#log files
+.log
+
diff --git a/org.tizen.cli/.classpath b/org.tizen.cli/.classpath
new file mode 100644
index 0000000..c879acc
--- /dev/null
+++ b/org.tizen.cli/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/org.tizen.cli/.project b/org.tizen.cli/.project
new file mode 100644
index 0000000..16a12da
--- /dev/null
+++ b/org.tizen.cli/.project
@@ -0,0 +1,28 @@
+
+
+ org.tizen.cli
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/org.tizen.cli/.settings/org.eclipse.jdt.core.prefs b/org.tizen.cli/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..c328be6
--- /dev/null
+++ b/org.tizen.cli/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Thu Jun 07 10:18:19 KST 2012
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/org.tizen.cli/.settings/org.eclipse.pde.core.prefs b/org.tizen.cli/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 0000000..d778992
--- /dev/null
+++ b/org.tizen.cli/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,4 @@
+#Thu Jun 07 10:18:19 KST 2012
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/org.tizen.cli/META-INF/MANIFEST.MF b/org.tizen.cli/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..985a308
--- /dev/null
+++ b/org.tizen.cli/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Command Line Interface
+Bundle-SymbolicName: org.tizen.cli;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: Samsung
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.tizen.common,
+ org.tizen.web.common,
+ org.tizen.web.sign
+Bundle-ClassPath: .,
+ lib/ant.jar,
+ lib/commons-cli-1.2.jar
diff --git a/org.tizen.cli/build.properties b/org.tizen.cli/build.properties
new file mode 100644
index 0000000..45e04ba
--- /dev/null
+++ b/org.tizen.cli/build.properties
@@ -0,0 +1,11 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ lib/ant.jar,\
+ lib/commons-cli-1.2.jar
+source.lib/commons-cli-1.2.jar =
+jars.compile.order = .,\
+ lib/commons-cli-1.2.jar,\
+ lib/ant.jar
+source.lib/ant.jar =
diff --git a/org.tizen.cli/doc/shell/sign b/org.tizen.cli/doc/shell/sign
new file mode 100644
index 0000000..0563925
--- /dev/null
+++ b/org.tizen.cli/doc/shell/sign
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+MAIN=org.tizen.cli.exec.sign.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/doc/shell/wgt b/org.tizen.cli/doc/shell/wgt
new file mode 100644
index 0000000..93b141f
--- /dev/null
+++ b/org.tizen.cli/doc/shell/wgt
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+MAIN=org.tizen.cli.exec.wgt.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"
+ARGS=`echo "$@"`
+EXEC="java -cp $CLASSPATH $OPT $MAIN $ARGS"
+
+if [ -n "$OPT_TRACE" ]
+then
+ echo "Command :$EXEC"
+fi
+
+$EXEC
diff --git a/org.tizen.cli/lib/ant.jar b/org.tizen.cli/lib/ant.jar
new file mode 100644
index 0000000..b3a94df
Binary files /dev/null and b/org.tizen.cli/lib/ant.jar differ
diff --git a/org.tizen.cli/lib/commons-cli-1.2.jar b/org.tizen.cli/lib/commons-cli-1.2.jar
new file mode 100644
index 0000000..ce4b9ff
Binary files /dev/null and b/org.tizen.cli/lib/commons-cli-1.2.jar differ
diff --git a/org.tizen.cli/src/org/tizen/cli/exec/AbstractLauncher.java b/org.tizen.cli/src/org/tizen/cli/exec/AbstractLauncher.java
new file mode 100644
index 0000000..9096f5a
--- /dev/null
+++ b/org.tizen.cli/src/org/tizen/cli/exec/AbstractLauncher.java
@@ -0,0 +1,522 @@
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * 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 static org.tizen.common.util.StringUtil.nvl;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.common.core.command.ExecutionContext;
+import org.tizen.common.core.command.Executor;
+import org.tizen.common.core.command.Prompter;
+import org.tizen.common.core.command.policy.PolicyRegistry;
+import org.tizen.common.file.FileHandler;
+import org.tizen.common.file.FileHandler.Attribute;
+import org.tizen.common.file.StandardFileHandler;
+import org.tizen.common.util.MapUtil;
+
+/**
+ *
+ * AbstractLauncher.
+ *
+ * abstract class for simple command.
+ *
+ * provide {@link ExecutionContext} for command line
+ *
+ *
+ * @author BonYong Lee{@literal } (S-Core)
+ */
+abstract public class
+AbstractLauncher
+{
+ /**
+ * Program name property key
+ */
+ protected static final String PROP_PRG = "cli.name";
+
+ /**
+ *
+ * Option for help text
+ *
+ */
+ protected static final String OPT_HELP = "help";
+
+ /**
+ *
+ * Description for help option
+ *
+ * This is printed out in usage
+ *
+ *
+ * @see #OPT_HELP
+ */
+ protected static final String DESC_HELP = "print out this page";
+
+ /**
+ *
+ * Option for log level
+ *
+ * This option is shared in shell
+ *
+ */
+ protected static final String OPT_LOG = "log";
+
+ /**
+ *
+ * Description for log level option
+ *
+ * This is printed out in usage
+ *
+ *
+ * @see #OPT_LOG
+ */
+ protected static final String DESC_LOG = "specify log level( ex - error, warn, info, debug, trace, none )";
+
+ /**
+ *
+ * Option for no output
+ *
+ */
+ protected static final String OPT_QUIET = "quiet";
+
+ /**
+ *
+ * Description for no output option
+ *
+ * This is printed out in usage
+ *
+ *
+ * @see #OPT_QUIET
+ */
+ protected static final String DESC_QUIET = "execute silently";
+
+ /**
+ *
+ * Property key for command line parameter parser
+ *
+ */
+ protected static final String PROP_PARSER = "tizen.cli.parser";
+
+ /**
+ *
+ * logger for this object
+ *
+ */
+ protected final Logger logger = LoggerFactory.getLogger( getClass() );
+
+ /**
+ *
+ * optional flag to be specified by user
+ *
+ * flag is formatted in POSIX style in default
+ *
+ */
+ protected CommandLine cmd;
+
+ /**
+ * {@link Executor} for Command Line Interface
+ */
+ protected Executor executor;
+
+ /**
+ * Convert path
to canonical path
+ *
+ * @param path relative or abstract path
+ *
+ * @return canonical path
+ *
+ * @throws IOException If file system deny request
+ */
+ protected
+ String
+ convertPath(
+ final String path
+ )
+ throws IOException
+ {
+ final FileHandler fileHandler = getFileHandler();
+ return (String) fileHandler.get( path, Attribute.PATH );
+ }
+
+ /**
+ * return execution command for usage
+ *
+ * @return execution command
+ */
+ protected String getSyntax()
+ {
+ return nvl( System.getProperty( PROP_PRG ), "java " + getClass().getName() );
+ }
+
+ /**
+ * {@link Options} for usage
+ *
+ * @return defined {@link Options}
+ */
+ @SuppressWarnings("static-access")
+ protected
+ Options
+ getOptions()
+ {
+ final Options options = new Options();
+
+ options.addOption( OptionBuilder.withLongOpt( OPT_HELP ).withDescription( DESC_HELP ).create( OPT_HELP.substring( 0, 1 ) ) );
+ options.addOption( OptionBuilder.hasArg().withLongOpt( OPT_LOG ).withDescription( DESC_LOG ).create( OPT_LOG.substring( 0, 1 ) ) );
+ options.addOption( OptionBuilder.withLongOpt( OPT_QUIET ).withDescription( DESC_QUIET ).create( OPT_QUIET.substring( 0, 1 ) ) );
+
+ return options;
+ }
+
+ /**
+ * Print out usage
+ *
+ * @return usage string
+ */
+ protected
+ String
+ printHelp()
+ {
+ final HelpFormatter formatter = new HelpFormatter();
+
+ final StringWriter writer = new StringWriter();
+
+ final PrintWriter stream = new PrintWriter( writer );
+
+ formatter.printHelp(
+ stream,
+ formatter.getWidth(),
+ getSyntax(),
+ null,
+ getOptions(),
+ formatter.getLeftPadding(),
+ formatter.getDescPadding(),
+ null,
+ false
+ );
+
+ final String help = writer.toString();
+
+ getPrompter().error( help );
+
+ return help;
+ }
+
+
+ /**
+ * Entry method for execution
+ *
+ * @param args command line argument
+ *
+ * @throws Exception If unhandled exception occured
+ */
+ public void
+ run(
+ final String... args
+ )
+ throws Exception
+ {
+ executor = new CommandLineExecutor(
+ new ConsolePrompter( System.out, new InputStreamReader( System.in ) )
+ );
+ if ( logger.isTraceEnabled() )
+ {
+ logger.trace( "System properties :\n{}", MapUtil.toString( System.getProperties() ) );
+ }
+
+
+ try
+ {
+ this.cmd = parse( args );
+
+ if ( cmd.hasOption( OPT_QUIET ) )
+ {
+ executor = new CommandLineExecutor(
+ new ConsolePrompter( new PrintStream( new OutputStream() {
+ public void write(int b) throws IOException {
+ }
+ } ), new InputStreamReader( System.in ) )
+ );
+
+ }
+
+ if ( cmd.hasOption( OPT_HELP ) )
+ {
+ printHelp();
+ return ;
+ }
+
+ execute( cmd );
+ }
+ catch ( final ParseException e )
+ {
+ printHelp();
+ }
+ catch ( final Exception e )
+ {
+ handleException( e );
+ }
+ }
+
+ /**
+ * Handle uncaught exception
+ *
+ * @param e uncaught exception
+ */
+ protected
+ void
+ handleException(
+ final Exception e
+ )
+ {
+ logger.error( "Command stop because of exception", e );
+
+ Throwable iter = e;
+ while ( null != iter )
+ {
+ final String localMessage = iter.getLocalizedMessage();
+ if ( null != localMessage )
+ {
+ logger.error( localMessage );
+ return ;
+ }
+
+ final String message = iter.getMessage();
+ if ( null != message )
+ {
+ logger.error( message );
+ return ;
+ }
+ iter = iter.getCause();
+ }
+
+ }
+
+ /**
+ * Parse arguments args
with {@link CommandLineParser}
+ *
+ * @param args arguments to parse
+ *
+ * @return {@link CommandLine} to be parsed
+ *
+ * @throws InstantiationException If custom parser is invalid
+ * @throws IllegalAccessException If custom parser is invalid
+ * @throws ParseException If arguements is invalid
+ */
+ protected
+ CommandLine
+ parse(
+ final String... args
+ )
+ throws InstantiationException, IllegalAccessException, ParseException
+ {
+ final CommandLineParser parser = getParser();
+
+ final Options options = getOptions();
+
+ final CommandLine cmdLine = parser.parse( options, args );
+
+ return cmdLine;
+ }
+
+ /**
+ * Return default parser {@link Class}
+ *
+ * @return {@link Class} for default parser
+ */
+ protected
+ static
+ Class>
+ getDefaultParserClass()
+ {
+ return PosixParser.class;
+ }
+
+ /**
+ * Return parser along user selection.
+ *
+ * The selection is specified JVM system properties
+ *
+ * Support two built-in parser
+ *
+ * POSIX style - tar -zxvf foo.tar.gz
+ * GNU style - du --human-readable --max-depth=1
+ *
+ *
+ * if you want use custom parser, specify class name
+ *
+ * @return {@link CommandLineParser} to parse
+ *
+ * @throws InstantiationException If custom parser can't be instantiated
+ * @throws IllegalAccessException If custom parser's constructor is NOT accessible
+ *
+ * @see #PROP_PARSER
+ * @see CommandLineParser
+ */
+ protected
+ CommandLineParser
+ getParser()
+ throws InstantiationException, IllegalAccessException {
+ final String parserName = System.getProperty( PROP_PARSER );
+ logger.trace( "Parser name :{}", parserName );
+ Class> parserClazz = getDefaultParserClass();
+ try {
+ if ( null != parserName )
+ {
+ parserClazz = Class.forName( parserName );
+ }
+ }
+ catch ( final ClassNotFoundException e )
+ {
+ if ( "posix".equalsIgnoreCase( parserName ) )
+ { // tar -zxvf foo.tar.gz
+ parserClazz = PosixParser.class;
+ }
+ else if ( "gnu".equalsIgnoreCase( parserName ) )
+ {
+ parserClazz = GnuParser.class;
+ }
+ else
+ {
+ logger.warn( "Invalid argument parser :" + parserName );
+ }
+ }
+
+ logger.trace( "Parser class :{}", parserClazz );
+
+ return (CommandLineParser) parserClazz.newInstance();
+ }
+
+ /**
+ * Return managed command line arguments
+ *
+ * @return managed arguments
+ *
+ * @see CommandLine
+ */
+ protected
+ CommandLine
+ getCommandLine()
+ {
+ return this.cmd;
+ }
+
+ /**
+ * Return defined executor for command
+ *
+ * @return {@link ExecutionContext} to use
+ */
+ protected
+ Executor
+ getExecutor()
+ {
+ if ( null == executor )
+ {
+ this.executor = new Executor();
+ }
+
+ return executor;
+ }
+
+ /**
+ * Return {@link ExecutionContext} in cli
+ *
+ * @return {@link ExecutionContext}
+ */
+ protected
+ ExecutionContext
+ getExecutionContext()
+ {
+ return getExecutor().getContext();
+ }
+
+ /**
+ * Return {@link PolicyRegistry} in cli
+ *
+ * @return {@link PolicyRegistry}
+ */
+ protected
+ PolicyRegistry
+ getPolicy()
+ {
+ return getExecutionContext().getPolicyRegistry();
+ }
+
+ /**
+ * Return {@link FileHandler} in cli
+ *
+ * @return {@link FileHandler}
+ *
+ * @see #getExecutionContext()
+ * @see StandardFileHandler
+ */
+ protected
+ FileHandler
+ getFileHandler()
+ {
+ return getExecutionContext().getFileHandler();
+ }
+
+ /**
+ * Return {@link Prompter} in cli
+ *
+ * @return {@link Prompter}
+ *
+ * @see #getExecutionContext()
+ */
+ protected
+ Prompter
+ getPrompter()
+ {
+ return getExecutionContext().getPrompter();
+ }
+
+ /**
+ * Execute command
+ *
+ * Implement execution of command
+ *
+ * @param cmdLine arguments
+ *
+ * @throws Exception If Unhandled exception occured
+ */
+ abstract protected void execute( CommandLine cmdLine ) throws Exception;
+
+
+}
diff --git a/org.tizen.cli/src/org/tizen/cli/exec/CommandLineExecutor.java b/org.tizen.cli/src/org/tizen/cli/exec/CommandLineExecutor.java
new file mode 100644
index 0000000..d839bb0
--- /dev/null
+++ b/org.tizen.cli/src/org/tizen/cli/exec/CommandLineExecutor.java
@@ -0,0 +1,130 @@
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * 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 org.tizen.common.Factory;
+import org.tizen.common.core.command.ExecutionContext;
+import org.tizen.common.core.command.Executor;
+import org.tizen.common.core.command.Prompter;
+import org.tizen.common.core.command.policy.PolicyRegistry;
+import org.tizen.common.file.FileHandler;
+import org.tizen.common.file.StandardFileHandler;
+
+/**
+ *
+ * CommandLineExecutor.
+ *
+ * {@link Executor} for commaand line interface
+ *
+ *
+ * @author BonYong Lee{@literal } (S-Core)
+ */
+public class
+CommandLineExecutor
+extends Executor
+{
+
+ /**
+ * Contructor with prompter
+ *
+ * @param prompter {@link Prompter}
+ */
+ public
+ CommandLineExecutor(
+ final Prompter prompter
+ )
+ {
+ super(
+ new Factory() {
+
+ /**
+ * {@link FileHandler} for Command Line Interface
+ */
+ protected FileHandler fileHandler = new StandardFileHandler();
+
+
+ /**
+ *
+ * {@link PolicyRegistry} for Command Line Interface
+ *
+ */
+ protected Factory factory = new PolicyRegistryFactory();
+
+ /**
+ * Create and return {@link PolicyRegistry}
+ *
+ * @return {@link PolicyRegistry} to be created
+ */
+ protected
+ PolicyRegistry
+ getRegistry()
+ {
+ return factory.create();
+ }
+
+ /**
+ * {@link ExecutionContext} for Command Line Interface
+ */
+ protected
+ final
+ ExecutionContext context = new ExecutionContext(
+ getRegistry(),
+ prompter,
+ fileHandler
+ );
+
+ /* (non-Javadoc)
+ * @see org.tizen.common.core.command.ExecutionContextFactory#create()
+ */
+ @Override
+ public
+ ExecutionContext
+ create()
+ {
+ return context;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public
+ String
+ toString()
+ {
+ return MessageFormat.format(
+ "Policy :{0}, Prompter :{1}, File Handler :{2}",
+ context.getPolicyRegistry(),
+ context.getPrompter(),
+ context.getFileHandler()
+ );
+ };
+ }
+ );
+ }
+
+}
diff --git a/org.tizen.cli/src/org/tizen/cli/exec/ConsolePrompter.java b/org.tizen.cli/src/org/tizen/cli/exec/ConsolePrompter.java
new file mode 100644
index 0000000..7be1719
--- /dev/null
+++ b/org.tizen.cli/src/org/tizen/cli/exec/ConsolePrompter.java
@@ -0,0 +1,227 @@
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * 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 static org.tizen.common.util.StringUtil.isEmpty;
+import static org.tizen.common.util.StringUtil.trim;
+
+import java.io.BufferedReader;
+import java.io.Console;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+
+import org.tizen.common.core.command.Prompter;
+import org.tizen.common.core.command.prompter.AbstractPrompter;
+import org.tizen.common.core.command.prompter.Option;
+import org.tizen.common.util.ArrayUtil;
+import org.tizen.common.util.Assert;
+import org.tizen.common.util.CollectionUtil;
+
+/**
+ *
+ * ConsolePrompter.
+ *
+ * {@link Prompter} for command line interface
+ *
+ * Print out using {@link PrintStream} and Read input from console( including standard input )
+ *
+ *
+ * @author BonYong Lee{@literal } (S-Core)
+ */
+public class
+ConsolePrompter
+extends AbstractPrompter
+implements Prompter
+{
+ /**
+ * {@link PrintStream} for output
+ */
+ protected final PrintStream out;
+
+ /**
+ * {@link BufferedReader} for input
+ */
+ protected final BufferedReader reader;
+
+ /**
+ * Flag about cancellation
+ */
+ protected boolean bCancel = false;
+
+ /**
+ * Constructor with {@link PrintStream} and {@link Reader}
+ *
+ * @param out {@link PrintStream} for output
+ * @param reader {@link Reader} for input
+ */
+ public
+ ConsolePrompter(
+ final PrintStream out,
+ final Reader reader
+ )
+ {
+ Assert.notNull( out );
+ this.out = out;
+ this.reader = new BufferedReader( reader );
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.common.core.command.Prompter#interact(java.lang.String, int, org.tizen.common.core.command.prompter.Option[])
+ */
+ @Override
+ public
+ Option
+ interact(
+ final String question,
+ final Option... options
+ )
+ {
+ final HashSet reducedOptions = new LinkedHashSet ();
+ Option defaultOption = null;
+ final ArrayList optionNames = new ArrayList();
+ for ( final Option option : options )
+ {
+ if ( reducedOptions.contains( option ) )
+ {
+ throw new IllegalArgumentException( "Question can't have duplicated choice(s) :" + option );
+ }
+ optionNames.add( option.getName() );
+ reducedOptions.add( option );
+ if ( option.isDefault() )
+ {
+ if ( null != defaultOption )
+ {
+ throw new IllegalArgumentException(
+ "Question must have only one default choice"
+ );
+ }
+
+ defaultOption = option;
+ }
+ }
+
+ String choice = null;
+ try
+ {
+ while ( true )
+ {
+ printQuestion( question, options );
+
+ choice = reader.readLine();
+ if ( isEmpty( choice ) )
+ {
+ return defaultOption;
+ }
+ for ( final Option option : options )
+ {
+ if ( option.isMatch( choice ) )
+ {
+ return option;
+ }
+ }
+ }
+ } catch ( final IOException e )
+ {
+ throw new IllegalStateException( e );
+ }
+ }
+
+ /**
+ * Print out question and options for choice
+ *
+ * @param question message to print
+ * @param options options to suggest
+ */
+ protected
+ void
+ printQuestion(
+ final String question,
+ final Option... options
+ )
+ {
+ out.print( question );
+ if ( !ArrayUtil.isEmpty( options ) )
+ {
+ out.print( "( " );
+ out.print( CollectionUtil.concatenate( options, " / " ) );
+ out.print( " )" );
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.common.core.command.Prompter#notify(java.lang.String, java.lang.Object[])
+ */
+ @Override
+ public
+ void
+ notify(
+ final String message
+ )
+ {
+ out.println( message );
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.common.core.command.Prompter#cancel()
+ */
+ @Override
+ synchronized public void cancel()
+ {
+ bCancel = true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.common.core.command.Prompter#password(java.lang.String)
+ */
+ @Override
+ public
+ char[] password(
+ final String message
+ )
+ {
+ out.print( trim( message ) );
+ out.print( " " );
+ Console console = System.console();
+ return console.readPassword();
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.common.core.command.Prompter#error(java.lang.String, java.lang.Object[])
+ */
+ @Override
+ public
+ void
+ error(
+ final String message
+ )
+ {
+ out.println( message );
+ }
+
+}
diff --git a/org.tizen.cli/src/org/tizen/cli/exec/PolicyRegistryFactory.java b/org.tizen.cli/src/org/tizen/cli/exec/PolicyRegistryFactory.java
new file mode 100644
index 0000000..11efdb3
--- /dev/null
+++ b/org.tizen.cli/src/org/tizen/cli/exec/PolicyRegistryFactory.java
@@ -0,0 +1,127 @@
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * 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 static org.tizen.common.core.command.Policy.EXCEPTION_UNHANDLED;
+import static org.tizen.common.core.command.Policy.EXIST_OUT_FILE;
+import static org.tizen.common.core.command.Policy.NONEXIST_IN_FILE;
+
+import java.lang.Thread.UncaughtExceptionHandler;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.common.Factory;
+import org.tizen.common.core.command.Policy;
+import org.tizen.common.core.command.policy.AbstractPolicy;
+import org.tizen.common.core.command.policy.FilePolicy;
+import org.tizen.common.core.command.policy.MessagePolicy;
+import org.tizen.common.core.command.policy.PolicyRegistry;
+
+/**
+ *
+ * PolicyRegistryFactory.
+ *
+ * {@link Factory} to provide {@link PolicyRegistry}
+ *
+ *
+ *
+ * @author BonYong Lee{@literal } (S-Core)
+ */
+public class
+PolicyRegistryFactory
+implements Factory
+{
+ /**
+ * Logger for this instance
+ */
+ protected final Logger logger =
+ LoggerFactory.getLogger( PolicyRegistryFactory.class );
+
+ /**
+ *
+ * CLIPolicy.
+ *
+ * {@link Policy} when command line interface
+ *
+ *
+ * @author BonYong Lee{@literal } (S-Core)
+ *
+ * @see PolicyRegistry, {@link Policy}
+ */
+ class CLIPolicy
+ extends AbstractPolicy
+ {
+ /**
+ *
+ * Constructor with name
+ *
+ *
+ * @param name policy name
+ */
+ public CLIPolicy( final String name )
+ {
+ super( name );
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.common.Adaptable#adapt(java.lang.Class)
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public
+ T
+ adapt(
+ final Class clazz
+ )
+ {
+ if ( clazz.isAssignableFrom( FilePolicy.class ) )
+ {
+ return (T) FilePolicy.STOP_PROCESS;
+ }
+ else if ( clazz.isAssignableFrom( MessagePolicy.class) )
+ {
+ return (T) MessagePolicy.PROMPTER;
+ }
+ return null;
+ }
+
+ }
+ /* (non-Javadoc)
+ * @see org.tizen.common.Factory#create()
+ */
+ @Override
+ public
+ PolicyRegistry
+ create()
+ {
+ final PolicyRegistry registry = new PolicyRegistry();
+
+ registry.register( new CLIPolicy( EXIST_OUT_FILE ) );
+ registry.register( new CLIPolicy( NONEXIST_IN_FILE ) );
+
+ return registry;
+ }
+
+}
diff --git a/org.tizen.cli/src/org/tizen/cli/exec/sign/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/sign/Main.java
new file mode 100644
index 0000000..cc37814
--- /dev/null
+++ b/org.tizen.cli/src/org/tizen/cli/exec/sign/Main.java
@@ -0,0 +1,315 @@
+/*
+* Web IDE - Command Line Interface
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* 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.sign;
+
+import static org.tizen.common.util.FilenameUtil.addTailingPath;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+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.cli.exec.AbstractLauncher;
+import org.tizen.common.core.command.Prompter;
+import org.tizen.common.core.command.prompter.Option;
+import org.tizen.common.file.FileHandler;
+import org.tizen.common.file.FileHandler.Attribute;
+import org.tizen.common.util.CollectionUtil;
+import org.tizen.web.sign.command.ReadSigningProfileFileCommand;
+import org.tizen.web.sign.command.SignCommand;
+
+/**
+ * Command Line Interface for creation of signature file
+ *
+ * @author BonYong Lee{@literal } (S-Core)
+ */
+public class
+Main
+extends AbstractLauncher
+{
+
+ /**
+ *
+ * Option for include file pattern
+ *
+ */
+ protected static final String OPT_INCLUDE = "include";
+
+ /**
+ *
+ * Description for include file pattern option
+ *
+ * This is printed out in usage
+ *
+ *
+ * @see #OPT_INCLUDE
+ */
+ protected static final String DESC_INCLUDE = "file name pattern to include";
+
+ /**
+ *
+ * Option for exclude file pattern
+ *
+ */
+ protected static final String OPT_EXCLUDE = "exclude";
+
+ /**
+ *
+ * Description for exclude file pattern option
+ *
+ * This is printed out in usage
+ *
+ *
+ * @see #OPT_EXCLUDE
+ */
+ protected static final String DESC_EXCLUDE = "file name pattern to exclude";
+
+ /**
+ *
+ * Option for no check of validation
+ *
+ */
+ protected static final String OPT_NOCHECK = "nocheck";
+
+ /**
+ *
+ * Description for no check option
+ *
+ * This is printed out in usage
+ *
+ *
+ * @see #OPT_NOCHECK
+ */
+ protected static final String DESC_NOCHECK = "skip validation check";
+
+ /**
+ *
+ * Option for profile with/without profiles file
+ *
+ * Examples are following
+ *
+ * test:/opt/profiles.xml
+ * test - equals to test#${HOME}/.tizen/profiles.xml
+ *
+ *
+ */
+ protected static final String OPT_PROFILE = "profile";
+
+ /**
+ *
+ * Description for profile option
+ *
+ * This is printed out in usage
+ *
+ *
+ * @see #OPT_PROFILE
+ */
+ protected static final String DESC_PROFILE = "specify profile name with or without profile file( example - test, test:/opt/profile.xml )";
+
+ /**
+ *
+ * separator between profile name and profile file path
+ *
+ *
+ * @see #OPT_PROFILE
+ */
+ protected static final int SEPARATOR_PROFILE = ':';
+
+ /**
+ * 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#getOptions()
+ */
+ @Override
+ @SuppressWarnings("static-access")
+ protected Options getOptions() {
+ final Options opts = super.getOptions();
+
+ opts.addOption( OptionBuilder.withLongOpt( OPT_NOCHECK ).withDescription( DESC_NOCHECK ).create( OPT_NOCHECK.substring( 0, 1 ) ) );
+ opts.addOption( OptionBuilder.hasArg().withLongOpt( OPT_INCLUDE ).withDescription( DESC_INCLUDE ).create( OPT_INCLUDE.substring( 0, 1 ) ) );
+ opts.addOption( OptionBuilder.hasArg().withLongOpt( OPT_EXCLUDE ).withDescription( DESC_EXCLUDE ).create( OPT_EXCLUDE.substring( 0, 1 ) ) );
+
+ opts.addOption( OptionBuilder.hasArg().isRequired().withLongOpt( OPT_PROFILE ).withDescription( DESC_PROFILE ).create( OPT_PROFILE.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(
+ final CommandLine cmdLine
+ )
+ throws Exception
+ {
+ final List args = cmdLine.getArgList();
+ logger.trace( "arguments :{}", args );
+
+ int nArgs = args.size();
+
+ String baseDir = convertPath( "." );
+ if ( 0 < nArgs )
+ {
+ baseDir = convertPath( args.get( 0 ) );
+ }
+ logger.debug( "Base directory :{}", baseDir );
+
+ final String[] includes = cmdLine.getOptionValues( OPT_INCLUDE );
+ logger.debug( "Includes :{}", CollectionUtil.toString( includes ) );
+
+ String[] excludes = cmdLine.getOptionValues( OPT_EXCLUDE );
+ if ( null == includes && null == excludes )
+ {
+ excludes = getDefaultExcludes();
+ }
+
+ if ( !cmdLine.hasOption( OPT_NOCHECK ) )
+ {
+ logger.trace( "Check input" );
+ if ( !isValidRoot( baseDir ) )
+ {
+ logger.trace( "Base directory is not valid root" );
+ Option yes = new Option( "Yes" );
+ Option no = new Option( "No", true );
+
+ final Prompter prompter = getPrompter();
+
+ final Option option = prompter.interact(
+ MessageFormat.format( ".projet file doesn''t exist in [{0}]\nDo you want to be continue?", baseDir ),
+ yes,
+ no
+ );
+
+ if ( no.equals( option ) )
+ {
+ prompter.notify( "Process is canceled" );
+ return ;
+ }
+ }
+ }
+
+ String profileName = cmdLine.getOptionValue( OPT_PROFILE );
+ logger.debug( "Profile option :{}", profileName );
+
+ String profilesFilePath = null;
+
+ final int index = profileName.indexOf( SEPARATOR_PROFILE );
+ if ( index < 0 )
+ {
+ profilesFilePath = System.getProperty( "user.home" ) + "/.tizen/profiles.xml";
+ }
+ else
+ {
+ profilesFilePath = profileName.substring( index + 1 );
+ profileName = profileName.substring( 0, index );
+ }
+
+ logger.debug( "Profile name :{}", profileName );
+ logger.debug( "Profiles file path :{}", profilesFilePath );
+
+ final ReadSigningProfileFileCommand readProfile = new ReadSigningProfileFileCommand( profilesFilePath, profileName );
+ getExecutor().execute( readProfile );
+ logger.info( "Profiles file[{}] is read", profilesFilePath );
+
+ if ( readProfile.getProfileItems().isEmpty() )
+ {
+ getPrompter().error( "No Signing profile[" + profileName + "] item in " + profilesFilePath );
+ return ;
+ }
+
+ final SignCommand command = new SignCommand( baseDir, profileName, readProfile.getProfileItems() );
+ getExecutor().execute( command );
+ }
+
+ /**
+ * Check if path
is Tizen web project root
+ *
+ * @param path directory path to check
+ *
+ * @return true
if path
is Tize web project root
+ *
+ * @throws IOException If path
's sub files can't be accessed
+ */
+ protected
+ boolean
+ isValidRoot(
+ final String path
+ )
+ throws IOException
+ {
+ final FileHandler fileHandler = getFileHandler();
+ if ( !fileHandler.is( addTailingPath( path, ".project" ), Attribute.EXISTS ) )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Return default excludes file patterns
+ *
+ * @return default excludes file patterns
+ */
+ protected
+ String[] getDefaultExcludes()
+ {
+ return new String[] { ".*", "signature*.xml" };
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.cli.exec.AbstractLauncher#getSyntax()
+ */
+ @Override
+ protected
+ String
+ getSyntax()
+ {
+ return super.getSyntax() + " [option]... [name] [source]";
+ }
+
+}
diff --git a/org.tizen.cli/src/org/tizen/cli/exec/wgt/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/wgt/Main.java
new file mode 100644
index 0000000..6701f4e
--- /dev/null
+++ b/org.tizen.cli/src/org/tizen/cli/exec/wgt/Main.java
@@ -0,0 +1,333 @@
+/*
+* Web IDE - Command Line Interface
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* 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.wgt;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.MessageFormat;
+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.cli.exec.AbstractLauncher;
+import org.tizen.common.core.command.Executor;
+import org.tizen.common.core.command.Prompter;
+import org.tizen.common.core.command.prompter.Option;
+import org.tizen.common.core.command.zip.ZipCommand;
+import org.tizen.common.file.FileHandler;
+import org.tizen.common.file.FileHandler.Attribute;
+import org.tizen.common.util.CollectionUtil;
+import org.tizen.common.util.FilenameUtil;
+import org.tizen.web.common.WebConstant;
+
+/**
+ * Command Line Interface for creation of wgt file
+ *
+ * @author BonYong Lee{@literal } (S-Core)
+ */
+public class
+Main
+extends AbstractLauncher
+{
+
+ /**
+ *
+ * Option for include file pattern
+ *
+ */
+ protected static final String OPT_INCLUDE = "include";
+
+ /**
+ *
+ * Description for include file pattern option
+ *
+ * It is printed out in usage
+ *
+ */
+ protected static final String DESC_INCLUDE = "file name pattern to include";
+
+ /**
+ *
+ * Option for exclude file pattern
+ *
+ */
+ protected static final String OPT_EXCLUDE = "exclude";
+
+ /**
+ *
+ * Description for exclude file pattern option
+ *
+ * It is printed out in usage
+ *
+ */
+ protected static final String DESC_EXCLUDE = "file name pattern to exclude";
+
+ /**
+ *
+ * Option for no check of validation
+ *
+ */
+ protected static final String OPT_NOCHECK = "nocheck";
+
+ /**
+ *
+ * Description for no check option
+ *
+ * It is printed out in usage
+ *
+ */
+ protected static final String DESC_NOCHECK = "skip validation check";
+
+ /**
+ *
+ * Option for over-writing of output file
+ *
+ */
+ protected static final String OPT_OVERWRITE = "overwrite";
+
+ /**
+ *
+ * Description for overwrite option
+ *
+ * It is printed out in usage
+ *
+ */
+ protected static final String DESC_OVERWRITE = "overwrite output file if it exists";
+
+ /**
+ * 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#getOptions()
+ */
+ @Override
+ @SuppressWarnings("static-access")
+ protected
+ Options
+ getOptions()
+ {
+ final Options opts = super.getOptions();
+
+ opts.addOption( OptionBuilder.withLongOpt( OPT_OVERWRITE ).withDescription( DESC_OVERWRITE ).create( OPT_OVERWRITE.substring( 0, 1 ) ) );
+ opts.addOption( OptionBuilder.withLongOpt( OPT_NOCHECK ).withDescription( DESC_NOCHECK ).create( OPT_NOCHECK.substring( 0, 1 ) ) );
+ opts.addOption( OptionBuilder.hasArg().withLongOpt( OPT_INCLUDE ).withDescription( DESC_INCLUDE ).create( OPT_INCLUDE.substring( 0, 1 ) ) );
+ opts.addOption( OptionBuilder.hasArg().withLongOpt( OPT_EXCLUDE ).withDescription( DESC_EXCLUDE ).create( OPT_EXCLUDE.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(
+ final CommandLine cmdLine
+ )
+ throws Exception
+ {
+ final List args = cmdLine.getArgList();
+ logger.trace( "arguments :{}", args );
+
+ int nArgs = args.size();
+
+ final File cwd = new File( "." ).getCanonicalFile();
+
+ String wgtPath = cwd.getName() + "." + WebConstant.WIDGET_FILE_EXTENSION;
+ if ( 0 < nArgs )
+ {
+ wgtPath = convertPath( args.get( 0 ) );
+ }
+ logger.debug( "Widget path :{}", wgtPath );
+
+ String baseDir = convertPath( "." );
+ if ( 1 < nArgs )
+ {
+ baseDir = convertPath( args.get( 1 ) );
+ }
+ logger.debug( "Base directory :{}", baseDir );
+
+ final String[] includes = cmdLine.getOptionValues( OPT_INCLUDE );
+ logger.debug( "Includes :{}", CollectionUtil.toString( includes ) );
+
+ String[] excludes = cmdLine.getOptionValues( OPT_EXCLUDE );
+ if ( null == includes && null == excludes )
+ {
+ excludes = getDefaultExcludes();
+ }
+
+ logger.debug( "Excludes :{}", CollectionUtil.toString( excludes ) );
+
+ if ( !cmdLine.hasOption( OPT_NOCHECK ) )
+ {
+ logger.trace( "Check input" );
+ if ( !exists( baseDir ) )
+ {
+ logger.trace( "Base directory does exist" );
+ final Prompter prompter = getPrompter();
+
+ prompter.notify( "Base directory path is wrong :" + baseDir );
+ return ;
+
+ }
+ else if ( !isValidRoot( baseDir ) )
+ {
+ logger.trace( "Base directory is not valid root" );
+ final Option yes = new Option( "Yes" );
+ final Option no = new Option( "No", true );
+
+ final Prompter prompter = getPrompter();
+
+ final Option option = prompter.interact(
+ MessageFormat.format( ".projet file doesn''t exist in [{0}]\nDo you want to be continue?", baseDir ),
+ yes,
+ no
+ );
+
+ if ( no.equals( option ) )
+ {
+ prompter.notify( "Process is canceled" );
+ return ;
+ }
+ }
+ }
+
+ if ( cmdLine.hasOption( OPT_OVERWRITE ) )
+ {
+ getFileHandler().removeFile( wgtPath );
+ logger.info( "Old wgt file deleted" );
+ }
+
+ zipFiles( wgtPath, baseDir, includes, excludes );
+ }
+
+ /**
+ * Check if path
exists
+ *
+ * @param path file path
+ *
+ * @return true
if path
exists
+ *
+ * @throws IOException If path
can't be accessed
+ */
+ protected
+ boolean
+ exists(
+ final String path
+ )
+ throws IOException
+ {
+ return getFileHandler().is( path, Attribute.EXISTS );
+ }
+
+ /**
+ * Check if path
is Tizen web project root
+ *
+ * @param path directory path to check
+ *
+ * @return true
if path
is Tize web project root
+ * @throws IOException If path
's sub files can't be accessed
+ */
+ protected
+ boolean
+ isValidRoot(
+ final String path
+ )
+ throws IOException
+ {
+ final FileHandler fileHandler = getFileHandler();
+ final String projectFilePath = FilenameUtil.addTailingPath( path, ".project" );
+ return fileHandler.is( projectFilePath, Attribute.EXISTS );
+ }
+
+
+ /**
+ * Return default excludes file patterns
+ *
+ * @return default excludes file patterns
+ */
+ protected
+ String[] getDefaultExcludes()
+ {
+ return new String[] { ".*", "*.wgt" };
+ }
+
+
+ /**
+ * Archive baseDir
to wgtPath
+ *
+ * including includes
and excluding excludes
+ *
+ * @param wgtPath wgt file path
+ * @param baseDir directory to root
+ * @param includes includes file pattern
+ * @param excludes excludes filee pattern
+ */
+ protected
+ void
+ zipFiles(
+ final String wgtPath,
+ final String baseDir,
+ final String[] includes,
+ final String[] excludes
+ )
+ {
+ final ZipCommand command = new ZipCommand( baseDir, wgtPath );
+ command.setIncludes( includes );
+ command.setExcludes( excludes );
+
+ final Executor executor = getExecutor();
+ executor.execute( command );
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.cli.exec.AbstractLauncher#getSyntax()
+ */
+ @Override
+ protected
+ String
+ getSyntax()
+ {
+ return super.getSyntax() + " [option]... name source";
+ }
+}
diff --git a/org.tizen.cli/test/src/org/tizen/cli/exec/AbstractLauncherTest.java b/org.tizen.cli/test/src/org/tizen/cli/exec/AbstractLauncherTest.java
new file mode 100644
index 0000000..0cbeb1e
--- /dev/null
+++ b/org.tizen.cli/test/src/org/tizen/cli/exec/AbstractLauncherTest.java
@@ -0,0 +1,281 @@
+/*
+* Command Line Interface
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* 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 static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.tizen.common.core.command.Executor;
+import org.tizen.common.core.command.prompter.NopPrompter;
+
+
+/**
+ * AbstractLauncherTest
+ *
+ * Test case for {@link AbstractLauncher}
+ *
+ * @author BonYong Lee{@literal } (S-Core)
+ *
+ * @see AbstractLauncher
+ */
+public class
+AbstractLauncherTest
+{
+ /**
+ * Spi class for {@link AbstractLauncher}
+ */
+ public class
+ LauncherSpi
+ extends AbstractLauncher
+ {
+ /**
+ * Flag to be executed
+ */
+ public boolean bExecute = false;
+
+ /**
+ * Default constructor
+ */
+ public LauncherSpi() {
+ executor = new CommandLineExecutor( new NopPrompter() );
+ }
+
+ /* (non-Javadoc)
+ * @see org.tizen.cli.exec.AbstractLauncher#execute(org.apache.commons.cli.CommandLine)
+ */
+ @Override
+ protected void execute(CommandLine cmdLine) throws Exception {
+ bExecute = true;
+ }
+ }
+
+ /**
+ * custom parser
+ */
+ public static class
+ CustomParser
+ implements CommandLineParser
+ {
+ /* (non-Javadoc)
+ * @see org.apache.commons.cli.CommandLineParser#parse(org.apache.commons.cli.Options, java.lang.String[], boolean)
+ */
+ @Override
+ public CommandLine parse(Options arg0, String[] arg1, boolean arg2)
+ throws ParseException {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.cli.CommandLineParser#parse(org.apache.commons.cli.Options, java.lang.String[])
+ */
+ @Override
+ public CommandLine parse(Options arg0, String[] arg1) throws ParseException {
+ return null;
+ }
+ };
+
+ /**
+ * Test target
+ */
+ protected LauncherSpi launcher = null;
+
+ /**
+ * Old parser property
+ */
+ protected String old = null;
+
+ /**
+ * Prepare test target
+ */
+ @Before
+ public void setUp()
+ {
+ old = System.getProperty( AbstractLauncher.PROP_PARSER );
+ launcher = new LauncherSpi() {
+
+ };
+ }
+
+ /**
+ * Clean up test setting
+ */
+ @After
+ public void tearDown()
+ {
+ if ( null == old )
+ {
+ System.getProperties().remove( AbstractLauncher.PROP_PARSER );
+ }
+ else
+ {
+ System.setProperty( AbstractLauncher.PROP_PARSER, old );
+ }
+ }
+
+ /**
+ * Test {@link AbstractLauncher#getSyntax()}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see AbstractLauncher#getSyntax()
+ */
+ @Test
+ public
+ void
+ test_getSyntax()
+ throws Exception
+ {
+ assertNotNull( launcher.getSyntax() );
+ }
+
+
+ /**
+ * Test {@link AbstractLauncher#getOptions()}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see AbstractLauncher#getOptions()
+ */
+ @Test
+ public
+ void
+ test_getOptions()
+ throws Exception
+ {
+ assertNotNull( launcher.getOptions() );
+ }
+
+ /**
+ * Test {@link AbstractLauncher#printHelp()}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see AbstractLauncher#printHelp()
+ */
+ @Test
+ public
+ void
+ test_printHelp()
+ throws Exception
+ {
+ assertNotNull( launcher.printHelp() );
+ }
+
+ /**
+ * Test {@link AbstractLauncher#run(String...)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see AbstractLauncher#run(String...)
+ */
+ @Test
+ public
+ void
+ test_run()
+ throws Exception
+ {
+ assertNull( launcher.getCommandLine() );
+ launcher.run();
+ assertTrue( launcher.bExecute );
+ }
+
+ /**
+ * Test {@link AbstractLauncher#getParser()}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see AbstractLauncher#getParser()
+ */
+ @Test
+ public
+ void
+ test_getParser()
+ throws Exception
+ {
+ assertTrue( AbstractLauncher.getDefaultParserClass().isInstance( launcher.getParser() ) );
+ String old = System.getProperty( AbstractLauncher.PROP_PARSER );
+ System.setProperty( AbstractLauncher.PROP_PARSER, "gnu" );
+ assertTrue( GnuParser.class.isInstance( launcher.getParser() ) );
+ System.setProperty( AbstractLauncher.PROP_PARSER, "posix" );
+ assertTrue( PosixParser.class.isInstance( launcher.getParser() ) );
+ System.setProperty( AbstractLauncher.PROP_PARSER, "wrong" );
+ assertTrue( AbstractLauncher.getDefaultParserClass().isInstance( launcher.getParser() ) );
+ CommandLineParser parser = new CustomParser();
+ System.setProperty( AbstractLauncher.PROP_PARSER, parser.getClass().getName() );
+ assertTrue( CustomParser.class.isInstance( launcher.getParser() ) );
+
+ if ( null != old )
+ {
+ System.setProperty( AbstractLauncher.PROP_PARSER, old );
+ }
+ }
+
+ /**
+ * Test {@link AbstractLauncher#getCommandLine()}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see AbstractLauncher#getCommandLine()
+ */
+ @Test
+ public
+ void
+ test_getCommandLine()
+ throws Exception
+ {
+ assertNull( launcher.getCommandLine() );
+ launcher.run();
+ assertNotNull( launcher.getCommandLine() );
+ }
+
+
+ /**
+ * Test {@link AbstractLauncher#getExecutor()}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see AbstractLauncher#getExecutor()
+ */
+ @Test
+ public
+ void
+ test_getExecutor()
+ throws Exception
+ {
+ final Executor executor = launcher.getExecutor();
+ assertNotNull( executor );
+ }
+
+}
diff --git a/org.tizen.cli/test/src/org/tizen/cli/exec/AbstractMainTest.java b/org.tizen.cli/test/src/org/tizen/cli/exec/AbstractMainTest.java
new file mode 100644
index 0000000..6d282d1
--- /dev/null
+++ b/org.tizen.cli/test/src/org/tizen/cli/exec/AbstractMainTest.java
@@ -0,0 +1,87 @@
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * 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 org.junit.After;
+import org.junit.Before;
+import org.tizen.common.Factory;
+import org.tizen.common.core.command.ExecutionContext;
+import org.tizen.common.core.command.Executor;
+import org.tizen.common.core.command.policy.PolicyRegistry;
+import org.tizen.common.core.command.prompter.NopPrompter;
+import org.tizen.common.file.FileHandler;
+import org.tizen.common.file.VirtualFileHandler;
+
+/**
+ * AbstractMainTest
+ *
+ * Abstract class of test case for Main
+ *
+ * @author BonYong Lee{@literal } (S-Core)
+ */
+public class
+AbstractMainTest
+{
+
+
+ /**
+ * Stub object for {@link FileHandler}
+ */
+ protected VirtualFileHandler fileHandler;
+
+ /**
+ * {@link Executor} to provide test environment
+ */
+ protected Executor executor;
+
+ /**
+ * Set up test
+ */
+ @Before
+ public void setUp()
+ {
+
+ fileHandler = new VirtualFileHandler();
+
+ executor = new Executor( new Factory() {
+ public ExecutionContext create() {
+ return new ExecutionContext( new PolicyRegistry(), new NopPrompter(), fileHandler );
+ }
+ } );
+ }
+
+ /**
+ * Tear down test
+ */
+ @After
+ public void tearDown()
+ {
+ executor = null;
+ fileHandler = null;
+ }
+
+
+
+}
diff --git a/org.tizen.cli/test/src/org/tizen/cli/exec/sign/MainTest.java b/org.tizen.cli/test/src/org/tizen/cli/exec/sign/MainTest.java
new file mode 100644
index 0000000..9f94ddd
--- /dev/null
+++ b/org.tizen.cli/test/src/org/tizen/cli/exec/sign/MainTest.java
@@ -0,0 +1,139 @@
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * 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.sign;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.PosixParser;
+import org.apache.commons.cli.UnrecognizedOptionException;
+import org.junit.Test;
+import org.tizen.cli.exec.AbstractMainTest;
+import org.tizen.common.core.command.Executor;
+
+
+/**
+ * MainTest
+ *
+ * Test case for {@link Main}
+ *
+ * @author BonYong Lee{@literal } (S-Core)
+ *
+ * @see Main
+ */
+public class
+MainTest
+extends AbstractMainTest
+{
+ /**
+ * Test {@link Main#getOptions()}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see Main#getOptions()}
+ */
+ @Test
+ public void test_getOptions() throws Exception {
+
+ Main main = new Main();
+ final Options opts = main.getOptions();
+ final PosixParser parser = new PosixParser();
+
+ parser.parse( opts, new String[] {
+ "-help", "-quiet", "-profile", "test:/test/profiles.xml"
+ } );
+ parser.parse( opts, new String[] {
+ "--help", "--quiet", "--profile", "test:/test/profiles.xml"
+ } );
+
+ parser.parse( opts, new String[] {
+ "-h", "-q", "-p", "test:/test/profiles.xml"
+ } );
+
+
+ try {
+ parser.parse( opts, new String[] {
+ "-verbose", "-quiet"
+ } );
+ fail();
+ } catch ( final UnrecognizedOptionException e ) {
+ }
+
+ {
+ final CommandLine cmd = parser.parse( opts, new String[] { "--exclude", "hello", "--log=trace", "--exclude", "message2", "--profile", "test:/test/prfiles.xml" } );
+ final String[] args = cmd.getOptionValues( Main.OPT_EXCLUDE );
+ assertEquals( 2, args.length );
+ assertEquals( "hello", args[0] );
+ assertEquals( "message2", args[1] );
+ final String[] shortArgs = cmd.getOptionValues( "e" );
+ assertEquals( 2, shortArgs.length );
+ assertEquals( "hello", shortArgs[0] );
+ assertEquals( "message2", shortArgs[1] );
+ }
+
+ {
+ final CommandLine cmd = parser.parse( opts, new String[] { "--log=debug", "-p", "test:/test/prfiles.xml" } );
+ final String[] args = cmd.getOptionValues( Main.OPT_EXCLUDE );
+ assertNull( args );
+ }
+ }
+
+ /**
+ * Test {@link Main#run(String...)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see Main#run(String...)}
+ */
+ @Test
+ public
+ void
+ test_run()
+ throws Exception
+ {
+ final AtomicBoolean result = new AtomicBoolean( false );
+
+ final Main main = new Main()
+ {
+ protected Executor getExecutor() {
+ return MainTest.this.executor;
+ }
+
+ protected void execute( final CommandLine cmdLine ) throws Exception {
+ result.set( true );
+ }
+ };
+
+ main.run( "-p", "test" );
+ assertTrue( result.get() );
+ }
+
+}
diff --git a/org.tizen.cli/test/src/org/tizen/cli/exec/wgt/MainTest.java b/org.tizen.cli/test/src/org/tizen/cli/exec/wgt/MainTest.java
new file mode 100644
index 0000000..4900ad5
--- /dev/null
+++ b/org.tizen.cli/test/src/org/tizen/cli/exec/wgt/MainTest.java
@@ -0,0 +1,228 @@
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * 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.wgt;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.tizen.common.util.ArrayUtil.isEmpty;
+import static org.tizen.common.util.ArrayUtil.size;
+import static org.tizen.common.util.IOUtil.getBytes;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.PosixParser;
+import org.apache.commons.cli.UnrecognizedOptionException;
+import org.junit.Test;
+import org.tizen.cli.exec.AbstractMainTest;
+import org.tizen.common.core.command.Executor;
+import org.tizen.common.file.FileHandler.Attribute;
+
+/**
+ * MainTest
+ *
+ * Test case for {@link Main}
+ *
+ * @author BonYong Lee{@literal } (S-Core)
+ *
+ * @see Main
+ */
+public class
+MainTest
+extends AbstractMainTest
+{
+
+ /**
+ * Test {@link Main#zipFiles(String, String, String[], String[])}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see Main#zipFiles(String, String, String[], String[])}
+ */
+ @Test
+ public
+ void
+ test_zipFiles()
+ throws Exception
+ {
+
+ fileHandler.makeDirectory( "/test" );
+ fileHandler.write( "/test/b.txt", "This is test message" );
+
+ final Main main = new Main() {
+ protected Executor getExecutor() {
+ return MainTest.this.executor;
+ }
+ };
+
+ main.zipFiles( "/test.zip", "/test", null, null );
+
+ assertTrue( 0 < size( getBytes( fileHandler.read( "/test.zip" ) ) ) );
+
+ }
+
+ /**
+ * Test {@link Main#run(String...)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see Main#run(String...)}
+ */
+ @Test
+ public
+ void
+ test_run()
+ throws Exception
+ {
+ final AtomicBoolean result = new AtomicBoolean( false );
+
+ final Main main = new Main()
+ {
+ protected void execute(CommandLine cmdLine) throws Exception {
+ result.set( true );
+ };
+ };
+
+ main.run();
+ assertTrue( result.get() );
+ }
+
+ /**
+ * Test {@link Main#execute(CommandLine)}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see Main#execute(CommandLine)}
+ */
+ @Test
+ public
+ void
+ test_execute()
+ throws Exception
+ {
+ fileHandler.makeDirectory( "/test" );
+ fileHandler.write( "/test/b.txt", "This is test message" );
+
+ final Main main = new Main()
+ {
+ protected Executor getExecutor()
+ {
+ return MainTest.this.executor;
+ }
+ };
+
+ final PosixParser parser = new PosixParser();
+
+ main.execute( parser.parse( main.getOptions(), new String[] {
+ "-help", "-quiet"
+ } ) );
+ assertFalse( fileHandler.is( "/test.wgt", Attribute.EXISTS ) );
+
+ main.execute( parser.parse( main.getOptions(), new String[] {
+ "test.wgt", "test"
+ } ) );
+ assertFalse( fileHandler.is( "/test.wgt", Attribute.EXISTS ) );
+
+ main.execute( parser.parse( main.getOptions(), new String[] {
+ "--nocheck", "test.wgt", "test"
+ } ) );
+ assertTrue( fileHandler.is( "/test.wgt", Attribute.EXISTS ) );
+ assertTrue( 0 < size( getBytes( fileHandler.read( "/test.wgt" ) ) ) );
+ main.execute( parser.parse( main.getOptions(), new String[] {
+ "-i", "*.html"
+ } ) );
+ }
+
+ /**
+ * Test {@link Main#getOptions()}
+ *
+ * @throws Exception in case of failure in test
+ *
+ * @see Main#getOptions()}
+ */
+ @Test
+ public void test_getOptions() throws Exception {
+
+ Main main = new Main();
+ final Options opts = main.getOptions();
+ final PosixParser parser = new PosixParser();
+
+ parser.parse( opts, new String[] {
+ "-help", "-quiet"
+ } );
+
+
+ try {
+ parser.parse( opts, new String[] {
+ "-verbose", "-quiet", "-aaa"
+ } );
+ fail();
+ } catch ( final UnrecognizedOptionException e ) {
+ }
+
+ {
+ final CommandLine cmd = parser.parse( opts, new String[] { "--exclude", "hello", "--log=trace", "--exclude", "message2" } );
+ final String[] args = cmd.getOptionValues( Main.OPT_EXCLUDE );
+ assertArrayEquals( new String[] { "hello", "message2" }, args );
+ final String[] shortArgs = cmd.getOptionValues( "e" );
+ assertArrayEquals( new String[] { "hello", "message2" }, shortArgs );
+ }
+
+ {
+ final CommandLine cmd = parser.parse( opts, new String[] { "--log=debug" } );
+ final String[] args = cmd.getOptionValues( Main.OPT_EXCLUDE );
+ assertNull( args );
+ }
+
+ {
+ final CommandLine cmd = parser.parse( opts, new String[] { "--include", "*.html" } );
+ final String[] args = cmd.getArgs();
+ assertTrue( isEmpty( args ) );
+ assertArrayEquals( new String[] { "*.html" }, cmd.getOptionValues( Main.OPT_INCLUDE ) );
+ }
+ }
+
+
+ @Test
+ public void test_printHelp() throws Exception
+ {
+ final Main testTarget = new Main() {
+ @Override
+ protected void handleException( Exception e )
+ {
+ throw new IllegalStateException( e );
+ }
+ };
+ testTarget.run( "--help" );
+
+
+ }
+
+
+}