package org.tizen.cli.command;\r
\r
import java.io.IOException;\r
-import java.net.URL;\r
+import java.util.HashMap;\r
\r
import org.tizen.cli.util.TemplateModelProvider;\r
import org.tizen.common.core.command.ExecutionContext;\r
import org.tizen.common.verrari.Realm;\r
-import org.tizen.common.verrari.RealmFactory;\r
+import org.tizen.common.verrari.Storage;\r
import org.tizen.common.verrari.Template;\r
import org.tizen.common.verrari.TemplateContext;\r
import org.tizen.common.verrari.TemplateException;\r
+import org.tizen.common.verrari.realm.StandardRealm;\r
import org.tizen.common.verrari.storage.FileStorage;\r
+import org.tizen.common.verrari.template.TemplateConstants;\r
\r
public class CreateTemplate\r
extends AbstractCommand\r
context.getPrompter().error( "One more template id required" );\r
return ;\r
}\r
- Realm realm = (Realm) context.getValue( PluginConstants.REALM );\r
- \r
- if ( null == realm )\r
- {\r
- final URL url = new URL( "file:///home/bylee/.install/tizen-cli/template/config.json" );\r
- realm = RealmFactory.getInstance().create( url );\r
- }\r
+ final Realm realm = (Realm) context.getValue( PluginConstants.REALM );\r
\r
final FileStorage storage = new FileStorage( context.getFileHandler() );\r
\r
final TemplateModelProvider models = new TemplateModelProvider( context );\r
\r
- TemplateContext.set( models );\r
+ TemplateContext.getInstance().setModelProvider( models );\r
+ \r
try\r
{\r
- for ( final String arg : args )\r
- {\r
- logger.debug( "Arg :{}", arg );\r
- final Template template = realm.getTemplate( arg );\r
- \r
- logger.debug( "Template :{}", template );\r
- \r
- template.template( models, storage );\r
- \r
- }\r
+ template( realm, args, models, storage );\r
}\r
finally\r
{\r
\r
}\r
\r
+ protected void\r
+ template(\r
+ final Realm realm,\r
+ final String[] names,\r
+ final TemplateModelProvider models,\r
+ final Storage storage\r
+ ) throws IOException, TemplateException\r
+ {\r
+ final HashMap<String, Template> ret = new HashMap<String, Template>();\r
+ \r
+ template( realm, names, models, storage, ret );\r
+ }\r
+\r
+ protected\r
+ void\r
+ template(\r
+ final Realm realm,\r
+ final String[] names,\r
+ final TemplateModelProvider models,\r
+ final Storage storage,\r
+ final HashMap<String, Template> cache\r
+ )\r
+ throws IOException, TemplateException\r
+ {\r
+ for ( final String name : names )\r
+ {\r
+ logger.trace( "Template name :{}", name );\r
+ Template template = cache.get( name );\r
+ if ( null == template )\r
+ {\r
+ logger.debug( "{} alread cached", name );\r
+ template = realm.getTemplate( name );\r
+ }\r
+ cache.put( name, template );\r
+ template.template( models, storage );\r
+ final String[] dependencies = StandardRealm.separate( template.getAttribute( TemplateConstants.ATTR_DEPENDENCY ) );\r
+ if ( null == dependencies )\r
+ {\r
+ continue;\r
+ }\r
+ \r
+ template( realm, dependencies, models, storage, cache );\r
+ }\r
+ \r
+ }\r
+\r
}\r
final SearchableRealm searchable = (SearchableRealm) realm;\r
final String keyword = args[0];\r
final Collection<AttributeContainer> templates = searchable.search(\r
- new Condition( Operation.Contains, "keyword", keyword )\r
+ new Condition( Operation.CaseInsensitiveContains, "keyword", keyword )\r
);\r
\r
if ( isEmpty( templates ) )\r
import org.apache.commons.cli.PosixParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.tizen.common.config.Preference;
+import org.tizen.common.config.provider.EnvironmentProvider;
+import org.tizen.common.config.provider.SystemPropertiesProvider;
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.UntrackedException;
import org.tizen.common.core.command.policy.PolicyRegistry;
import org.tizen.common.file.FileHandler;
import org.tizen.common.file.FileHandler.Attribute;
)
throws Exception
{
+ Preference.register( "", new EnvironmentProvider() );
+ Preference.register( "", new SystemPropertiesProvider() );
executor = new CommandLineExecutor(
new ConsolePrompter( System.out, new InputStreamReader( System.in ) )
);
}
}
- catch ( final Exception e )
+ catch ( final Throwable e )
{
handleException( e );
}
protected
void
handleException(
- final Exception e
+ final Throwable 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();
- }
+ if ( e instanceof UntrackedException )
+ {
+ getPrompter().error( e.getMessage() );
+ return ;
+ }
+ 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();
+ }
}
/**
import org.tizen.common.core.command.prompter.ChoiceOption;
import org.tizen.common.core.command.prompter.GenericOption;
import org.tizen.common.core.command.prompter.Option;
-import org.tizen.common.util.ArrayUtil;
import org.tizen.common.util.Assert;
-import org.tizen.common.util.CollectionUtil;
/**
* <p>
)
{
out.print( question );
- if ( !ArrayUtil.isEmpty( options ) )
- {
- out.print( "( " );
- out.print( CollectionUtil.concatenate( options, " / " ) );
- out.print( " )" );
- }
}
/* (non-Javadoc)
)\r
throws Exception\r
{\r
- final String urlStr = nvl( Preference.getValue( "tizen.template.realm", null ) );\r
+ String urlStr = nvl( Preference.getValue( "tizen.template.realm", cmdLine.getOptionValue( OPT_REALM ) ) );\r
logger.info( "Realm url :{}", urlStr );\r
if ( isEmpty( urlStr ) )\r
{\r
package org.tizen.cli.util;\r
\r
+import static org.tizen.common.util.ObjectUtil.nvl;\r
+import static org.tizen.common.util.StringUtil.nvl;\r
+\r
import java.util.Collection;\r
\r
import org.tizen.common.config.Preference;\r
import org.tizen.common.core.command.Prompter;\r
import org.tizen.common.core.command.prompter.GenericOption;\r
import org.tizen.common.verrari.IModelProvider;\r
+import org.tizen.common.verrari.template.StandardTemplate;\r
\r
public class\r
TemplateModelProvider\r
implements IModelProvider\r
{\r
+ protected static final Object NULL = new Object();\r
+ \r
protected final ExecutionContext context;\r
\r
+ \r
public\r
TemplateModelProvider(\r
final ExecutionContext context\r
)\r
{\r
Object obj = context.getValue( key );\r
- if ( null != obj )\r
+ if ( NULL.equals( obj ) )\r
+ {\r
+ return null;\r
+ } else if ( null != obj )\r
{\r
return obj;\r
}\r
\r
obj = inputFromUser( key );\r
\r
- this.context.setValue( key, obj );\r
+ this.context.setValue( key, nvl( obj, NULL ) );\r
\r
return obj;\r
}\r
{\r
final Prompter prompter = this.context.getPrompter();\r
final GenericOption opt = new GenericOption();\r
- \r
- prompter.interact( "Input " + key + " ?", opt );\r
+\r
+ StandardTemplate current = StandardTemplate.getCurrentTemplate();\r
+ String message = "Input " + key + " ?";\r
+ if ( null != current )\r
+ {\r
+ message = nvl( current.getMessage( key ), message );\r
+ }\r
+ prompter.interact( message, opt );\r
\r
return opt.getAnswer();\r
}\r
import org.apache.commons.cli.PosixParser;\r
import org.junit.Test;\r
import org.tizen.cli.exec.CommandLineExecutor;\r
-import org.tizen.cli.exec.sign.Main;\r
import org.tizen.common.core.command.Executor;\r
import org.tizen.common.core.command.Prompter;\r
\r
{
final Main testTarget = new Main() {
@Override
- protected void handleException( Exception e )
+ protected void handleException( Throwable e )
{
throw new IllegalStateException( e );
}