CLI: Add an uncaught exception handling policy 39/11739/2
authorJihoon Song <jihoon80.song@samsung.com>
Mon, 4 Nov 2013 07:21:09 +0000 (16:21 +0900)
committerJihoon Song <jihoon80.song@samsung.com>
Mon, 4 Nov 2013 08:01:47 +0000 (17:01 +0900)
'web-signing' module doesn't stop process when exception occurred.
This cause is that CLI policy don't have an uncaught exception handler.
So, this policy is added.

Change-Id: I03021e09a3285b802b94d0fd636b923f7624cc5c
Signed-off-by: Jihoon Song <jihoon80.song@samsung.com>
org.tizen.cli/src/org/tizen/cli/exec/PolicyRegistryFactory.java
org.tizen.cli/src/org/tizen/cli/exec/sign/Main.java

index 8f70b31..d3c2e24 100644 (file)
@@ -26,6 +26,7 @@ package org.tizen.cli.exec;
 
 import static org.tizen.common.core.command.Policy.EXIST_OUT_FILE;
 import static org.tizen.common.core.command.Policy.NONEXIST_IN_FILE;
+import static org.tizen.common.core.command.Policy.EXCEPTION_UNHANDLED;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -36,6 +37,7 @@ import org.tizen.common.core.command.policy.FilePolicy;
 import org.tizen.common.core.command.policy.MessagePolicy;
 import org.tizen.common.core.command.policy.OptionPolicy;
 import org.tizen.common.core.command.policy.PolicyRegistry;
+import org.tizen.common.core.command.policy.UncaughtExceptionHandlingPolicy;
 import org.tizen.common.core.command.prompter.FileHandlingOption;
 
 /**
@@ -52,85 +54,90 @@ 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 );
-               }
+   /**
+    * 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.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;
+         }
+         else if ( clazz.isAssignableFrom( UncaughtExceptionHandlingPolicy.class ) )
+         {
+             return (T) UncaughtExceptionHandlingPolicy.INSTANCE;
+         }
+         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 ) );
-               
-               CLIPolicy existFileWhenCopy = new CLIPolicy(Policy.EXIST_FILE_WHEN_COPY) {
-                       
-                       @SuppressWarnings("unchecked")
-                       @Override
-                       public <T> T adapt(Class<T> clazz) {
-                               return (T)(new OptionPolicy(FileHandlingOption.OVERWRITE, FileHandlingOption.IGNORE, FileHandlingOption.OVERWRITE_ALL, FileHandlingOption.IGNORE_ALL, FileHandlingOption.CANCEL));
-                       }
-               };
-               
-               registry.register(existFileWhenCopy);
-               return registry;
-       }
+   }
+   /* (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 ) );
+      registry.register( new CLIPolicy( EXCEPTION_UNHANDLED ) );
+      
+      CLIPolicy existFileWhenCopy = new CLIPolicy(Policy.EXIST_FILE_WHEN_COPY) {
+         
+         @SuppressWarnings("unchecked")
+         @Override
+         public <T> T adapt(Class<T> clazz) {
+            return (T)(new OptionPolicy(FileHandlingOption.OVERWRITE, FileHandlingOption.IGNORE, FileHandlingOption.OVERWRITE_ALL, FileHandlingOption.IGNORE_ALL, FileHandlingOption.CANCEL));
+         }
+      };
+      
+      registry.register(existFileWhenCopy);
+      return registry;
+   }
 
 }
index c57f384..59f41f1 100644 (file)
@@ -249,6 +249,7 @@ extends AbstractLauncher
         if ( null == profilesFilePath )
         {
             getExecutionContext().getPrompter().error( "Profiles file not found. Try to specify profiles path using -p option or environment variable cli.home" );
+            exit( 1 );
             return ;
         }
         profilesFilePath = convertPath( profilesFilePath );
@@ -256,6 +257,7 @@ extends AbstractLauncher
         // preload profile XML for convert
         boolean bSuccess = tryConvert( cmdLine, profilesFilePath );
         if ( ! bSuccess ) {
+            exit( 1 );
             return;
         }
         
@@ -268,6 +270,7 @@ extends AbstractLauncher
         if ( profile == null )
         {
             getPrompter().error( "No Signing profile( " + profileName + " ) item in " + profilesFilePath );
+            exit( 1 );
             return ;
         }