+#binary files
+build_result
+bin
+*.class
+common-eplugin_*.tar.gz
+common-eplugin_*_*.zip
+common-eplugin.package.linux
+common-eplugin.package.windows
+#log files
+.log
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="test/src"/>
+ <classpathentry kind="lib" path="lib/ant.jar"/>
+ <classpathentry kind="lib" path="lib/commons-cli-1.2.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.tizen.cli</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#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
--- /dev/null
+#Thu Jun 07 10:18:19 KST 2012
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
--- /dev/null
+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
--- /dev/null
+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 =
--- /dev/null
+#!/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
--- /dev/null
+#!/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
--- /dev/null
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * BonYong Lee <bonyong.lee@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;
+
+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;
+
+/**
+ * <p>
+ * AbstractLauncher.
+ *
+ * abstract class for simple command.
+ *
+ * provide {@link ExecutionContext} for command line
+ * </p>
+ *
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ */
+abstract public class
+AbstractLauncher
+{
+ /**
+ * Program name property key
+ */
+ protected static final String PROP_PRG = "cli.name";
+
+ /**
+ * <p>
+ * Option for help text
+ * </p>
+ */
+ protected static final String OPT_HELP = "help";
+
+ /**
+ * <p>
+ * Description for help option
+ *
+ * This is printed out in usage
+ * </p>
+ *
+ * @see #OPT_HELP
+ */
+ protected static final String DESC_HELP = "print out this page";
+
+ /**
+ * <p>
+ * Option for log level
+ *
+ * This option is shared in shell
+ * </p>
+ */
+ protected static final String OPT_LOG = "log";
+
+ /**
+ * <p>
+ * Description for log level option
+ *
+ * This is printed out in usage
+ * </p>
+ *
+ * @see #OPT_LOG
+ */
+ protected static final String DESC_LOG = "specify log level( ex - error, warn, info, debug, trace, none )";
+
+ /**
+ * <p>
+ * Option for no output
+ * </p>
+ */
+ protected static final String OPT_QUIET = "quiet";
+
+ /**
+ * <p>
+ * Description for no output option
+ *
+ * This is printed out in usage
+ * </p>
+ *
+ * @see #OPT_QUIET
+ */
+ protected static final String DESC_QUIET = "execute silently";
+
+ /**
+ * <p>
+ * Property key for command line parameter parser
+ * </p>
+ */
+ protected static final String PROP_PARSER = "tizen.cli.parser";
+
+ /**
+ * <p>
+ * logger for this object
+ * </p>
+ */
+ protected final Logger logger = LoggerFactory.getLogger( getClass() );
+
+ /**
+ * <p>
+ * optional flag to be specified by user
+ *
+ * flag is formatted in POSIX style in default
+ * </p>
+ */
+ protected CommandLine cmd;
+
+ /**
+ * {@link Executor} for Command Line Interface
+ */
+ protected Executor executor;
+
+ /**
+ * Convert <code>path</code> 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 <code>args</code> 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
+ * <ul>
+ * <li>POSIX style - tar -zxvf foo.tar.gz</li>
+ * <li>GNU style - du --human-readable --max-depth=1</li>
+ * </ul>
+ *
+ * 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;
+
+
+}
--- /dev/null
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * BonYong Lee <bonyong.lee@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;
+
+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;
+
+/**
+ * <p>
+ * CommandLineExecutor.
+ *
+ * {@link Executor} for commaand line interface
+ * </p>
+ *
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ */
+public class
+CommandLineExecutor
+extends Executor
+{
+
+ /**
+ * Contructor with prompter
+ *
+ * @param prompter {@link Prompter}
+ */
+ public
+ CommandLineExecutor(
+ final Prompter prompter
+ )
+ {
+ super(
+ new Factory<ExecutionContext>() {
+
+ /**
+ * {@link FileHandler} for Command Line Interface
+ */
+ protected FileHandler fileHandler = new StandardFileHandler();
+
+
+ /**
+ * <p>
+ * {@link PolicyRegistry} for Command Line Interface
+ * </p>
+ */
+ protected Factory<PolicyRegistry> 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()
+ );
+ };
+ }
+ );
+ }
+
+}
--- /dev/null
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * BonYong Lee <bonyong.lee@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;
+
+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;
+
+/**
+ * <p>
+ * ConsolePrompter.
+ *
+ * {@link Prompter} for command line interface
+ *
+ * Print out using {@link PrintStream} and Read input from console( including standard input )
+ * </p>
+ *
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (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<Option> reducedOptions = new LinkedHashSet<Option>();
+ Option defaultOption = null;
+ final ArrayList<String> optionNames = new ArrayList<String>();
+ 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 );
+ }
+
+}
--- /dev/null
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * BonYong Lee <bonyong.lee@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;
+
+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;
+
+/**
+ * <p>
+ * PolicyRegistryFactory.
+ *
+ * {@link Factory} to provide {@link PolicyRegistry}
+ *
+ * </p>
+ *
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ */
+public class
+PolicyRegistryFactory
+implements Factory<PolicyRegistry>
+{
+ /**
+ * Logger for this instance
+ */
+ protected final Logger logger =
+ LoggerFactory.getLogger( PolicyRegistryFactory.class );
+
+ /**
+ * <p>
+ * CLIPolicy.
+ *
+ * {@link Policy} when command line interface
+ * </p>
+ *
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)
+ *
+ * @see PolicyRegistry, {@link Policy}
+ */
+ class CLIPolicy
+ extends AbstractPolicy
+ {
+ /**
+ * <p>
+ * Constructor with <code>name</code>
+ * </p>
+ *
+ * @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>
+ T
+ adapt(
+ final Class<T> 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;
+ }
+
+}
--- /dev/null
+/*
+* Web IDE - Command Line Interface
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* BonYong Lee <bonyong.lee@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.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 <bonyong.lee@samsung.com>} (S-Core)
+ */
+public class
+Main
+extends AbstractLauncher
+{
+
+ /**
+ * <p>
+ * Option for include file pattern
+ * </p>
+ */
+ protected static final String OPT_INCLUDE = "include";
+
+ /**
+ * <p>
+ * Description for include file pattern option
+ *
+ * This is printed out in usage
+ * </p>
+ *
+ * @see #OPT_INCLUDE
+ */
+ protected static final String DESC_INCLUDE = "file name pattern to include";
+
+ /**
+ * <p>
+ * Option for exclude file pattern
+ * </p>
+ */
+ protected static final String OPT_EXCLUDE = "exclude";
+
+ /**
+ * <p>
+ * Description for exclude file pattern option
+ *
+ * This is printed out in usage
+ * </p>
+ *
+ * @see #OPT_EXCLUDE
+ */
+ protected static final String DESC_EXCLUDE = "file name pattern to exclude";
+
+ /**
+ * <p>
+ * Option for no check of validation
+ * </p>
+ */
+ protected static final String OPT_NOCHECK = "nocheck";
+
+ /**
+ * <p>
+ * Description for no check option
+ *
+ * This is printed out in usage
+ * </p>
+ *
+ * @see #OPT_NOCHECK
+ */
+ protected static final String DESC_NOCHECK = "skip validation check";
+
+ /**
+ * <p>
+ * Option for profile with/without profiles file
+ *
+ * Examples are following
+ * <ul>
+ * <li>test:/opt/profiles.xml</li>
+ * <li>test - equals to test#${HOME}/.tizen/profiles.xml</li>
+ * </ul>
+ * </p>
+ */
+ protected static final String OPT_PROFILE = "profile";
+
+ /**
+ * <p>
+ * Description for profile option
+ *
+ * This is printed out in usage
+ * </p>
+ *
+ * @see #OPT_PROFILE
+ */
+ protected static final String DESC_PROFILE = "specify profile name with or without profile file( example - test, test:/opt/profile.xml )";
+
+ /**
+ * <p>
+ * separator between profile name and profile file path
+ * </p>
+ *
+ * @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<String> 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 <code>path</code> is Tizen web project root
+ *
+ * @param path directory path to check
+ *
+ * @return <code>true</code> if <code>path</code> is Tize web project root
+ *
+ * @throws IOException If <code>path</code>'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]";
+ }
+
+}
--- /dev/null
+/*
+* Web IDE - Command Line Interface
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* BonYong Lee <bonyong.lee@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.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 <bonyong.lee@samsung.com>} (S-Core)
+ */
+public class
+Main
+extends AbstractLauncher
+{
+
+ /**
+ * <p>
+ * Option for include file pattern
+ * </p>
+ */
+ protected static final String OPT_INCLUDE = "include";
+
+ /**
+ * <p>
+ * Description for include file pattern option
+ *
+ * It is printed out in usage
+ * </p>
+ */
+ protected static final String DESC_INCLUDE = "file name pattern to include";
+
+ /**
+ * <p>
+ * Option for exclude file pattern
+ * </p>
+ */
+ protected static final String OPT_EXCLUDE = "exclude";
+
+ /**
+ * <p>
+ * Description for exclude file pattern option
+ *
+ * It is printed out in usage
+ * </p>
+ */
+ protected static final String DESC_EXCLUDE = "file name pattern to exclude";
+
+ /**
+ * <p>
+ * Option for no check of validation
+ * </p>
+ */
+ protected static final String OPT_NOCHECK = "nocheck";
+
+ /**
+ * <p>
+ * Description for no check option
+ *
+ * It is printed out in usage
+ * </p>
+ */
+ protected static final String DESC_NOCHECK = "skip validation check";
+
+ /**
+ * <p>
+ * Option for over-writing of output file
+ * </p>
+ */
+ protected static final String OPT_OVERWRITE = "overwrite";
+
+ /**
+ * <p>
+ * Description for overwrite option
+ *
+ * It is printed out in usage
+ * </p>
+ */
+ 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<String> 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 <code>path</code> exists
+ *
+ * @param path file path
+ *
+ * @return <code>true</code> if <code>path</code> exists
+ *
+ * @throws IOException If <code>path</code> can't be accessed
+ */
+ protected
+ boolean
+ exists(
+ final String path
+ )
+ throws IOException
+ {
+ return getFileHandler().is( path, Attribute.EXISTS );
+ }
+
+ /**
+ * Check if <code>path</code> is Tizen web project root
+ *
+ * @param path directory path to check
+ *
+ * @return <code>true</code> if <code>path</code> is Tize web project root
+ * @throws IOException If <code>path</code>'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 <code>baseDir</code> to <code>wgtPath</code>
+ *
+ * including <code>includes</code> and excluding <code>excludes</code>
+ *
+ * @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";
+ }
+}
--- /dev/null
+/*
+* Command Line Interface
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* BonYong Lee <bonyong.lee@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;
+
+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 <bonyong.lee@samsung.com>} (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 );
+ }
+
+}
--- /dev/null
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * BonYong Lee <bonyong.lee@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;
+
+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 <bonyong.lee@samsung.com>} (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<ExecutionContext>() {
+ public ExecutionContext create() {
+ return new ExecutionContext( new PolicyRegistry(), new NopPrompter(), fileHandler );
+ }
+ } );
+ }
+
+ /**
+ * Tear down test
+ */
+ @After
+ public void tearDown()
+ {
+ executor = null;
+ fileHandler = null;
+ }
+
+
+
+}
--- /dev/null
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * BonYong Lee <bonyong.lee@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.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 <bonyong.lee@samsung.com>} (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() );
+ }
+
+}
--- /dev/null
+/*
+ * Web IDE - Command Line Interface
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * BonYong Lee <bonyong.lee@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.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 <bonyong.lee@samsung.com>} (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" );
+
+
+ }
+
+
+}