[Title] fixed some bugs
authorJihoon Song <jihoon80.song@samsung.com>
Mon, 24 Jun 2013 08:57:43 +0000 (17:57 +0900)
committerJihoon Song <jihoon80.song@samsung.com>
Mon, 24 Jun 2013 08:57:43 +0000 (17:57 +0900)
[Desc.]
[Issue]

Change-Id: I58d687ae3f81c6664700d3979102dc3904904bb9

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

index fbb8d0f..853cca2 100644 (file)
@@ -42,6 +42,8 @@ import org.apache.commons.cli.ParseException;
 
 import static org.tizen.cli.exec.LaunchOptionConstants.OPT_NOCHECK;
 import static org.tizen.cli.exec.LaunchOptionConstants.DESC_NOCHECK;
+import static org.tizen.cli.exec.LaunchOptionConstants.OPT_DEVELOP;
+import static org.tizen.cli.exec.LaunchOptionConstants.DESC_DEVELOP_PROFILE;
 
 import org.tizen.cli.exec.AbstractLauncher;
 import org.tizen.cli.exec.Help;
@@ -156,7 +158,7 @@ extends AbstractLauncher
 //        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 ) ) );
+        opts.addOption( OptionBuilder.withLongOpt( OPT_DEVELOP ).withDescription( DESC_DEVELOP_PROFILE ).create( OPT_DEVELOP.substring( 0, 1 ) ) );
         
         return opts;
     }
@@ -251,39 +253,13 @@ extends AbstractLauncher
         }
         profilesFilePath = convertPath( profilesFilePath );
         
-        SigningProfileContainer container = new SigningProfileContainer() {
-            @Override
-            protected void preprocessForItemLoad(SigningProfile profile,
-                    String version) {
-                // remove automatically insert dist1 for CLI
-            }
-        };
-        InputStream in = getFileHandler().read( profilesFilePath );
-        try {
-            String version = container.readProfileXML( in );
-            if ( version == null ) {
-                getPrompter().error( "Cannot load profiles in " + profilesFilePath );
-                return;
-            }
-            
-            // if old version
-            if ( StringUtil.isEmpty( version ) ) {
-                getPrompter().notify( "Old version profile detected. Converting this automatically." );
-                
-                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-                container.writeProfileXML( outStream );
-                InputStream inForOut = new ByteArrayInputStream( outStream.toByteArray() );
-                
-                try {
-                    getFileHandler().write( profilesFilePath, inForOut );
-                } finally {
-                    tryClose( in );
-                }
-            }
-        } finally {
-            IOUtil.tryClose( in );
+        // preload profile XML for convert
+        boolean bSuccess = tryConvert( cmdLine, profilesFilePath );
+        if ( ! bSuccess ) {
+            return;
         }
         
+        // read a selected profile from XML
         final ReadSigningProfileFileCommand readProfile = new ReadSigningProfileFileCommand( profilesFilePath, profileName );
         getExecutor().execute( readProfile );
         logger.info( "Profiles file[{}] is read", profilesFilePath );
@@ -295,6 +271,7 @@ extends AbstractLauncher
             return ;
         }
         
+        // notify items of selected profile
         for ( int i = 0; i < SigningProfile.MAX_DISTRIBUTOR; i++ ) {
             SigningProfileItem item = profile.getProfileItem( i );
             String keyLocation = item.getKeyLocation();
@@ -304,18 +281,63 @@ extends AbstractLauncher
             }
         }
         
-        // deprecated --develop option
-//        if ( cmdLine.hasOption( OPT_DEVELOP ) ) {
-//            // Always add a developer certificate first because must be "signature1.xml"
-//            profile.createProfileItemForDeveloper();
-//        }
+        if ( cmdLine.hasOption( OPT_DEVELOP ) ) {
+            // Always add a developer certificate first because must be "signature1.xml"
+            profile.createProfileItemForDeveloper();
+        }
         
+        // sign
         final SignCommand command = new SignCommand( baseDir, profile );
         command.setIncludes( null );
         command.setExcludes( excludes );
         getExecutor().execute( command );
     }
 
+    protected boolean tryConvert(final CommandLine cmdLine, String profilesFilePath) throws IOException {
+        SigningProfileContainer container = null;
+        
+        // preload profile XML for convert
+        if ( cmdLine.hasOption( OPT_DEVELOP ) ) {
+            container = new SigningProfileContainer();
+        } else {
+            container = new SigningProfileContainer() {
+                @Override
+                protected void preprocessForItemLoad(SigningProfile profile,
+                        String version) {
+                    // remove automatically insert dist1 for CLI
+                }
+            };
+        }
+        InputStream in = getFileHandler().read( profilesFilePath );
+        
+        try {
+            String version = container.readProfileXML( in );
+            if ( version == null ) {
+                getPrompter().error( "Cannot load profiles in " + profilesFilePath );
+                return false;
+            }
+            
+            // if old version, rewrite to new version.
+            if ( StringUtil.isEmpty( version ) ) {
+                getPrompter().notify( "Old version profile detected. Converting this automatically." );
+                
+                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+                container.writeProfileXML( outStream );
+                InputStream inForOut = new ByteArrayInputStream( outStream.toByteArray() );
+                
+                try {
+                    getFileHandler().write( profilesFilePath, inForOut );
+                } finally {
+                    tryClose( inForOut );
+                }
+            }
+        } finally {
+            IOUtil.tryClose( in );
+        }
+        
+        return true;
+    }
+    
     /**
      * Return default profiles.xml's path
      *