[Title] Implement CLI multipackager
authorho.namkoong <ho.namkoong@samsung.com>
Tue, 19 Mar 2013 12:30:30 +0000 (21:30 +0900)
committerho.namkoong <ho.namkoong@samsung.com>
Tue, 19 Mar 2013 14:14:35 +0000 (23:14 +0900)
[Type]
[Module]
[Priority]
[Jira#]
[Redmine#] 8635
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: Ie4f432970139513fb36b130a368a791d7f068456

org.tizen.cli/META-INF/MANIFEST.MF
org.tizen.cli/src/org/tizen/cli/exec/ConsolePrompter.java
org.tizen.cli/src/org/tizen/cli/exec/PolicyRegistryFactory.java
org.tizen.cli/src/org/tizen/cli/exec/pack/CLIMultiPackager.java [new file with mode: 0644]
org.tizen.cli/src/org/tizen/cli/exec/pack/NativeMain.java [new file with mode: 0644]

index 32792f4..d93511f 100755 (executable)
@@ -17,10 +17,13 @@ Bundle-ClassPath: .,
  lib/ant.jar,
  lib/commons-cli-1.2.jar
 Import-Package: org.tizen.nativecommon,
+ org.tizen.nativecommon.build,
  org.tizen.nativecommon.exception,
  org.tizen.nativecommon.templateengine,
  org.tizen.nativecommon.templateengine.build,
  org.tizen.nativecommon.templateengine.build.model,
  org.tizen.nativecommon.templateengine.model,
  org.tizen.nativecommon.templateengine.process,
- org.tizen.nativecommon.templateengine.util
+ org.tizen.nativecommon.templateengine.util,
+ org.tizen.nativecpp.misc.core,
+ org.tizen.nativecpp.uibuilder.launcher.xml
index 471bc91..b3a0979 100755 (executable)
@@ -165,10 +165,27 @@ implements Prompter
                final Option... options
        )
        {
-               out.print( question );
+               out.print( getFullQuestion(question, options) );
        }
        
-       /* (non-Javadoc)
+       private char[] getFullQuestion(String question, Option[] options) {
+           
+           StringBuffer buffer = new StringBuffer();
+           buffer.append(question + "\n");
+           
+           for(Option option: options) {
+               if(option instanceof ChoiceOption) {
+                   ChoiceOption choiceOption = (ChoiceOption) option;
+                   buffer.append(String.format("%s: (%s), ", choiceOption.getName(), choiceOption.getShortName()));
+               }
+           }
+           
+           buffer.append("?");
+           
+        return buffer.toString().toCharArray();
+    }
+
+    /* (non-Javadoc)
         * @see org.tizen.common.core.command.Prompter#notify(java.lang.String, java.lang.Object[])
         */
        @Override
index 3fd56d2..8f70b31 100755 (executable)
@@ -34,7 +34,9 @@ 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.OptionPolicy;
 import org.tizen.common.core.command.policy.PolicyRegistry;
+import org.tizen.common.core.command.prompter.FileHandlingOption;
 
 /**
  * <p>
@@ -118,6 +120,16 @@ implements Factory<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;
        }
 
diff --git a/org.tizen.cli/src/org/tizen/cli/exec/pack/CLIMultiPackager.java b/org.tizen.cli/src/org/tizen/cli/exec/pack/CLIMultiPackager.java
new file mode 100644 (file)
index 0000000..c1cbe81
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+* Native IDE - Command Line Interface
+*
+* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Ho Namkoong <ho.namkoong@samsung.com>
+* BonYong Lee <bonyong.lee@samsung.com>
+* Kangho Kim <kh5325.kim@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.pack;
+
+import java.io.File;
+
+import org.tizen.common.core.command.Executor;
+import org.tizen.nativecommon.IXMLStore;
+import org.tizen.nativecommon.build.AbstractMultiPackager;
+import org.tizen.nativecpp.misc.core.NewAppXmlStore;
+import org.tizen.nativecpp.uibuilder.launcher.xml.ManifestXmlFile;
+
+public class CLIMultiPackager extends AbstractMultiPackager{
+
+    private static final String BIN_FOLDER_NAME = "CommandLineBuild";
+    private String rootPrjPath;
+    private String[] refPrjPath;
+    
+    
+    CLIMultiPackager(String rootPrjPath, String[] refPrjPath, Executor executor) {
+        super(executor);
+        this.rootPrjPath = rootPrjPath;
+        this.refPrjPath = refPrjPath;
+    }
+    
+    @Override
+    protected String getBinaryFolder() {
+        return BIN_FOLDER_NAME;
+    }
+
+    @Override
+    protected void buildPrjs() throws Exception {
+        // TODO do later
+    }
+
+    @Override
+    protected String[] getRefPrjPaths() {
+        return refPrjPath;
+    }
+
+    @Override
+    protected String getRootPrjPath() {
+        return rootPrjPath;
+    }
+
+    @Override
+    protected boolean validateMultiPackage() {
+        File manifestFile = new File(rootPrjPath, ManifestXmlFile.MANIFEST_XML_FILE_NAME);
+        if(manifestFile.exists() || (refPrjPath != null && refPrjPath.length > 0)) {
+            return true;
+        }
+        
+        return false;
+    }
+
+    @Override
+    protected IXMLStore getIXmlStore() throws Exception {
+        return new NewAppXmlStore();
+    }
+    
+}
diff --git a/org.tizen.cli/src/org/tizen/cli/exec/pack/NativeMain.java b/org.tizen.cli/src/org/tizen/cli/exec/pack/NativeMain.java
new file mode 100644 (file)
index 0000000..297b5b4
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+* Native IDE - Command Line Interface
+*
+* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Ho Namkoong <ho.namkoong@samsung.com>
+* BonYong Lee <bonyong.lee@samsung.com>
+* Kangho Kim <kh5325.kim@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.pack;
+
+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.application.InstallPathConfig;
+import org.tizen.common.core.command.CommandCancelException;
+import org.tizen.common.util.FileUtil;
+import org.tizen.common.util.StringUtil;
+
+public class NativeMain extends AbstractLauncher{
+
+    private boolean printHelp = false;
+    private CommandLine cmdLine;
+
+    private static final String USAGE_PACK = "usage: native-packaging --sign-author-key <path> --sign-author-pwd <passwd> [OPTIONS]\nPackage a project\n\n";
+    
+    private static final String PATH_SBI = FileUtil.appendPath(InstallPathConfig.getSDKPath(), "tools/smart-build-interface/bin");
+    private static final String CMD_CLI_NATIVE_PACK = FileUtil.appendPath(PATH_SBI, "sbi_pack");
+    
+    private static final String OPTION_TARGET = "target";
+    private static final String OPTION_SIGN_AK = "sign-author-key";
+    private static final String OPTION_SIGN_APWD = "sign-author-pwd";
+    private static final String OPTION_SIGN_DK = "sign-dist2-key";
+    private static final String OPTION_SIGN_DPWD = "sign-dist2-pwd";
+    private static final String OPTION_SIGN_DCA = "sign-dist2-ca";
+    private static final String OPTION_SIGN_DROOT = "sign-dist2-root";
+    private static final String OPTION_REF_PROJECTS = "ref-prj";
+    
+    private static final String DESC_TARGET = "Specify target. Emulator or device.";
+    private static final String DESC_SIGN_AK = "Specify author p12 file path.";
+    private static final String DESC_SIGN_APWD = "Specify author certificate password.";
+    private static final String DESC_SIGN_DK = "Specify distributor2 p12 file path.";
+    private static final String DESC_SIGN_DPWD = "Specify distributor2 password.";
+    private static final String DESC_SIGN_DCA = "Specify distributor2 CA path.";
+    private static final String DESC_SIGN_DROOT = "Specify distributor2 root certicate path";
+    private static final String DESC_REF_PROJECTS = "Specify paths of referenced projects. Paths can be seperator by ','";
+    
+    private static final String[] OPTION_REMAINING = {
+        "sign_cert_dir", "sign_dist1_key", "sign_dist1_pwd", "sign_dist1_ca"
+    };
+
+    public static void main(String[] args) throws Exception {
+        
+        final NativeMain instance = new NativeMain();
+        
+        if(args.length == 0) {
+            instance.printHelp = true;
+        }
+        
+        instance.run( args );
+    }
+
+    @Override
+    protected void execute(CommandLine cmdLine) throws Exception {
+        
+        if(printHelp) {
+            printHelp();
+            return;
+        }
+        
+        this.cmdLine = cmdLine;
+        
+        logger.trace("get user input");
+        
+        String rowRefPrjs = this.cmdLine.getOptionValue(OPTION_REF_PROJECTS);
+        String[] refPrjPaths = rowRefPrjs.split(",");
+        
+        if(StringUtil.isEmpty(this.cmdLine.getOptionValue(OPTION_SIGN_AK)) ||
+                StringUtil.isEmpty(this.cmdLine.getOptionValue(OPTION_SIGN_APWD))) {
+            logger.error(String.format("--%s and --%s are mandatory options.", OPTION_SIGN_AK, OPTION_SIGN_APWD));
+            return;
+        }
+        
+        CLIMultiPackager packager = new CLIMultiPackager("../", refPrjPaths, getExecutor());
+        
+        try {
+            packager.doMultiPreProcess();
+        }
+        catch (CommandCancelException e) {
+            packager.removeMutilAppResources();
+            logger.error("Packaging canceld");
+        }
+        
+        StringBuffer option = new StringBuffer();
+        appendOption(option, OPTION_TARGET);
+        appendOption(option, OPTION_SIGN_AK);
+        appendOption(option, OPTION_SIGN_APWD);
+        appendOption(option, OPTION_SIGN_DK);
+        appendOption(option, OPTION_SIGN_DPWD);
+        appendOption(option, OPTION_SIGN_DCA);
+        appendOption(option, OPTION_SIGN_DROOT);
+        
+        appendRemaningOptions(option);
+        
+        String command = CMD_CLI_NATIVE_PACK + option.toString();
+        
+        Runtime.getRuntime().exec(command);
+//        p.wait();
+    
+    }
+
+    private void appendRemaningOptions(StringBuffer option) {
+        for(String remaningOption: OPTION_REMAINING) {
+            option.append(String.format(" --%s \" \"", remaningOption));
+        }
+    }
+
+    private void appendOption(StringBuffer option, String optionTarget) {
+        String optionValue = cmdLine.getOptionValue(optionTarget);
+        if(!StringUtil.isEmpty(optionValue)) {
+            option.append(String.format(" --%s \"%s\"", optionTarget, optionValue));
+        }
+    }
+
+    @Override
+    protected String printHelp() {
+        StringBuffer helpBuffer = new StringBuffer();
+        helpBuffer.append(USAGE_PACK);
+        helpBuffer.append(getHelp().getHelp());
+        String helpStr = helpBuffer.toString();
+        getPrompter().error(helpStr);
+        return helpStr;
+    }
+    
+    @SuppressWarnings("static-access")
+    @Override
+    protected Options getOptions() {
+        Options result = super.getOptions();
+        result.addOption(OptionBuilder.hasArg().withLongOpt(OPTION_TARGET).withDescription(DESC_TARGET).create("t"));
+        result.addOption(OptionBuilder.hasArg().withLongOpt(OPTION_SIGN_AK).withDescription(DESC_SIGN_AK).create("ak"));
+        result.addOption(OptionBuilder.hasArg().withLongOpt(OPTION_SIGN_APWD).withDescription(DESC_SIGN_APWD).create("ap"));
+        result.addOption(OptionBuilder.hasArg().withLongOpt(OPTION_SIGN_DK).withDescription(DESC_SIGN_DK).create("dk"));
+        result.addOption(OptionBuilder.hasArg().withLongOpt(OPTION_SIGN_DPWD).withDescription(DESC_SIGN_DPWD).create("dp"));
+        result.addOption(OptionBuilder.hasArg().withLongOpt(OPTION_SIGN_DCA).withDescription(DESC_SIGN_DCA).create("dc"));
+        result.addOption(OptionBuilder.hasArg().withLongOpt(OPTION_SIGN_DROOT).withDescription(DESC_SIGN_DROOT).create("dr"));
+        result.addOption(OptionBuilder.hasArg().withLongOpt(OPTION_REF_PROJECTS).withDescription(DESC_REF_PROJECTS).create("rp"));
+        
+        return result;
+    }
+    
+}