[Title] cli: sync the renewaled secure profile models
authorJihoon Song <jihoon80.song@samsung.com>
Sat, 22 Jun 2013 10:29:34 +0000 (19:29 +0900)
committerJihoon Song <jihoon80.song@samsung.com>
Sun, 23 Jun 2013 12:01:00 +0000 (21:01 +0900)
[Desc.]
[Issue]

Change-Id: I9ee04363cd219bd13b82fbc4b721b65bc2f3fe1e

org.tizen.cli/src/org/tizen/cli/exec/sign/Main.java

index ea2c4ff..1f087c1 100644 (file)
@@ -29,7 +29,6 @@ import static org.tizen.common.util.ObjectUtil.nvl;
 
 import java.io.IOException;
 import java.text.MessageFormat;
-import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.cli.CommandLine;
@@ -51,8 +50,7 @@ import org.tizen.common.file.FileHandler;
 import org.tizen.common.file.FileHandler.Attribute;
 import org.tizen.common.sign.command.ReadSigningProfileFileCommand;
 import org.tizen.common.sign.command.SignCommand;
-import org.tizen.common.sign.preferences.SigningProfileItem;
-import org.tizen.common.sign.util.SigningProfileUtil;
+import org.tizen.common.sign.preferences.SigningProfile;
 import org.tizen.common.util.FilenameUtil;
 
 
@@ -65,226 +63,224 @@ public class
 Main
 extends AbstractLauncher
 {
-       
-       /**
-        * <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( ex - test, test:/opt/profile.xml )";
-
-       /**
-        * <p>
-        * separator between profile name and profile file path 
-        * </p>
-        * 
-        * @see #OPT_PROFILE
-        */
-       protected static final int SEPARATOR_PROFILE = ':';
-       
-       
-       /**
-        * <p>
-        * JVM property key for default profile path
-        * </p>
-        */
-       protected static final String PROP_CLI_HOME = "cli.home";
-       
-       /**
-        * <p>
-        * OS environment variable key for default profile path
-        * </p>
-        */
-       protected static final String ENV_CLI_HOME = "CLI_HOME";
-       
-       /**
-        * <p>
-        * default profile file's name
-        * </p>
-        */
-       protected static final String DEFAULT_PROFILE_NAME = "profiles.xml";
-       
-       /**
-        * 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().withLongOpt( OPT_PROFILE ).withDescription( DESC_PROFILE ).create( OPT_PROFILE.substring( 0, 1 ) ) );
-               opts.addOption( OptionBuilder.withLongOpt( OPT_DEVELOP ).withDescription( DESC_DEVELOP_PROFILE ).create( OPT_DEVELOP.substring( 0, 1 ) ) );
-               
-               return opts;
-       }
+    
+    /**
+     * <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( ex - test, test:/opt/profile.xml )";
 
-       /* (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
-       {
+    /**
+     * <p>
+     * separator between profile name and profile file path 
+     * </p>
+     * 
+     * @see #OPT_PROFILE
+     */
+    protected static final int SEPARATOR_PROFILE = ':';
+    
+    
+    /**
+     * <p>
+     * JVM property key for default profile path
+     * </p>
+     */
+    protected static final String PROP_CLI_HOME = "cli.home";
+    
+    /**
+     * <p>
+     * OS environment variable key for default profile path
+     * </p>
+     */
+    protected static final String ENV_CLI_HOME = "CLI_HOME";
+    
+    /**
+     * <p>
+     * default profile file's name
+     * </p>
+     */
+    protected static final String DEFAULT_PROFILE_NAME = "profiles.xml";
+    
+    /**
+     * 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().withLongOpt( OPT_PROFILE ).withDescription( DESC_PROFILE ).create( OPT_PROFILE.substring( 0, 1 ) ) );
+        opts.addOption( OptionBuilder.withLongOpt( OPT_DEVELOP ).withDescription( DESC_DEVELOP_PROFILE ).create( OPT_DEVELOP.substring( 0, 1 ) ) );
+        
+        return opts;
+    }
 
-           String profileName = cmdLine.getOptionValue( OPT_PROFILE );
-           logger.debug( "Profile option :{}", profileName );
-           if ( null == profileName )
-           {
-               throw new ParseException( "profile option is requred" );
-           }
+    /* (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 );
+        String profileName = cmdLine.getOptionValue( OPT_PROFILE );
+        logger.debug( "Profile option :{}", profileName );
+        if ( null == profileName )
+        {
+            throw new ParseException( "profile option is requred" );
+        }
 
-//             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();
-//             }
-               
-               String[] excludes = getDefaultExcludes();
-               
-               if ( !cmdLine.hasOption( OPT_NOCHECK ) )
-               {
-                       logger.trace( "Check input" );
-                       if ( !isValidRoot( baseDir ) )
-                       {
-                               logger.trace( "Base directory is not valid root" );
-                               ChoiceOption yes = new ChoiceOption( "Yes" );
-                               ChoiceOption no = new ChoiceOption( "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 profilesFilePath = null;
-               
-               final int index = profileName.indexOf( SEPARATOR_PROFILE );
-               if ( index < 0 )
-               {
-                       profilesFilePath = getDefaultProfilesFilePath();
-               }
-               else
-               {
-                       profilesFilePath = profileName.substring( index + 1 );
-                       profileName = profileName.substring( 0, index );
-               }
-               
-               logger.debug( "Profile name :{}", profileName );
-               logger.debug( "Profiles file path :{}", profilesFilePath );
-               if ( null == profilesFilePath )
-               {
-                   getExecutionContext().getPrompter().error( "Profiles file not found. Try to specify profiles path using -p option or environment variable cli.home" );
-                   return ;
-               }
-               
-               List<SigningProfileItem> profileItems = new ArrayList<SigningProfileItem>();
-               
-               if ( cmdLine.hasOption( OPT_DEVELOP ) ) {
-               // Always add a developer certificate first because must be "signature1.xml"
-               profileItems.add( SigningProfileUtil.createDeveloperItem() );
-               }
-               
-               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 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 );
 
-               profileItems.addAll( readProfile.getProfileItems() );
-               
-               final SignCommand command = new SignCommand( baseDir, profileName, profileItems );
-               command.setIncludes( null );
-               command.setExcludes( excludes );
-               getExecutor().execute( command );
-       }
+//        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();
+//        }
+        
+        String[] excludes = getDefaultExcludes();
+        
+        if ( !cmdLine.hasOption( OPT_NOCHECK ) )
+        {
+            logger.trace( "Check input" );
+            if ( !isValidRoot( baseDir ) )
+            {
+                logger.trace( "Base directory is not valid root" );
+                ChoiceOption yes = new ChoiceOption( "Yes" );
+                ChoiceOption no = new ChoiceOption( "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 profilesFilePath = null;
+        
+        final int index = profileName.indexOf( SEPARATOR_PROFILE );
+        if ( index < 0 )
+        {
+            profilesFilePath = getDefaultProfilesFilePath();
+        }
+        else
+        {
+            profilesFilePath = profileName.substring( index + 1 );
+            profileName = profileName.substring( 0, index );
+        }
+        
+        logger.debug( "Profile name :{}", profileName );
+        logger.debug( "Profiles file path :{}", profilesFilePath );
+        if ( null == profilesFilePath )
+        {
+            getExecutionContext().getPrompter().error( "Profiles file not found. Try to specify profiles path using -p option or environment variable cli.home" );
+            return ;
+        }
+        profilesFilePath = convertPath( profilesFilePath );
+        
+        final ReadSigningProfileFileCommand readProfile = new ReadSigningProfileFileCommand( profilesFilePath, profileName );
+        getExecutor().execute( readProfile );
+        logger.info( "Profiles file[{}] is read", profilesFilePath );
+        
+        SigningProfile profile = readProfile.getProfile();
+        if ( profile == null )
+        {
+            getPrompter().error( "No Signing profile( " + profileName + " ) item in " + profilesFilePath );
+            return ;
+        }
+        
+        if ( cmdLine.hasOption( OPT_DEVELOP ) ) {
+            // Always add a developer certificate first because must be "signature1.xml"
+            profile.createProfileItemForDeveloper();
+        }
+        
+        final SignCommand command = new SignCommand( baseDir, profile );
+        command.setIncludes( null );
+        command.setExcludes( excludes );
+        getExecutor().execute( command );
+    }
 
-       /**
-        * Return default profiles.xml's path
-        
-        * default profile path is specified by jvm propertyes naming "cli.home"
-        
-        * or os environment variable "CLI_HOME"
-        
-        * @return default profiles path
-        */
-       protected
-       String
-       getDefaultProfilesFilePath()
+    /**
+     * Return default profiles.xml's path
+     * 
+     * default profile path is specified by jvm propertyes naming "cli.home"
+     * 
+     * or os environment variable "CLI_HOME"
+     * 
+     * @return default profiles path
+     */
+    protected
+    String
+    getDefaultProfilesFilePath()
     {
-           
+        
         final String cliHome =
         nvl( System.getProperty( PROP_CLI_HOME ), System.getenv( ENV_CLI_HOME ) );
         
@@ -297,61 +293,61 @@ extends AbstractLauncher
     }
 
     /**
-        * 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;
-       }
+     * 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" };
-       }
+    /**
+     * 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#createHelp()
-        */
-       @Override
-       protected Help createHelp() {
-               Help help = super.createHelp();
+    /* (non-Javadoc)
+     * @see org.tizen.cli.exec.AbstractLauncher#createHelp()
+     */
+    @Override
+    protected Help createHelp() {
+        Help help = super.createHelp();
 
-               help.setSyntax( help.getSyntax() + getSyntax() );
-               return help;
-       }
+        help.setSyntax( help.getSyntax() + getSyntax() );
+        return help;
+    }
 
-       /* (non-Javadoc)
-        * @see org.tizen.cli.exec.AbstractLauncher#getSyntax()
-        */
-       @Override
-       protected
-       String
-       getSyntax()
-       {
-               return  " [options]";
-       }
+    /* (non-Javadoc)
+     * @see org.tizen.cli.exec.AbstractLauncher#getSyntax()
+     */
+    @Override
+    protected
+    String
+    getSyntax()
+    {
+        return  " [options]";
+    }
 
 }