NCLI:BUILD-WEB: Fix some bug with argument. 83/11883/1
authorHeongseok Heo <hyeongseok.heo@samsung.com>
Thu, 7 Nov 2013 07:43:04 +0000 (16:43 +0900)
committerHeongseok Heo <hyeongseok.heo@samsung.com>
Thu, 7 Nov 2013 07:43:04 +0000 (16:43 +0900)
Fix bug in case of submitting illegal argument or null argument from the
user input.
Modify to use currentWorkspacePath if there is no workingDir argument.

Change-Id: Ib9cda26016ac18591197eb9ec04ccffb68229770
Signed-off-by: Heongseok Heo <hyeongseok.heo@samsung.com>
org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebParameter.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildWebCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommand.java
org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/shell/BuildWebCLITest.java

index 501f40f..78e92aa 100644 (file)
@@ -31,12 +31,12 @@ import java.util.List;
 
 /**
  * Class for representing parameter of Web Build
+ * 
  * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
  * 
  */
 public class BuildWebParameter {
 
-
     private boolean optimize;
     private boolean excludeUIFW;
     private List<String> excludeList = new ArrayList<String>();
@@ -68,7 +68,9 @@ public class BuildWebParameter {
     }
 
     public void setExcludeList(List<String> excludeList) {
-        this.excludeList = excludeList;
+        if( null != excludeList) {
+            this.excludeList = excludeList;
+        }
     }
 
     public String getOutputName() {
@@ -83,6 +85,7 @@ public class BuildWebParameter {
         this.workingDir = workingDir;
 
     }
+
     /**
      * @return the workingDir
      */
@@ -103,7 +106,7 @@ public class BuildWebParameter {
     }
 
     public List<File> getReferences() {
-        ifhasReference()) {
+        if (hasReference()) {
             return Arrays.asList(this.refs);
         }
         return null;
index 6f6430c..b11314f 100644 (file)
@@ -4,47 +4,54 @@ import java.io.File;
 import java.util.List;\r
 \r
 import org.kohsuke.args4j.Option;\r
+import org.kohsuke.args4j.spi.StringOptionHandler;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 import org.tizen.core.ide.BuildWebParameter;\r
 import org.tizen.ncli.ide.subcommands.BuildWebCLICommand;\r
 \r
-\r
-public class BuildWebCLI extends AbstractCLI{\r
+public class BuildWebCLI extends AbstractCLI {\r
     private Logger log = LoggerFactory.getLogger(getClass());\r
-    \r
-    @Option(name="-opt" , aliases= {"--optimize"}, usage="Optimize option" )\r
-    private boolean optimize;\r
-    \r
-    @Option(name="--output" , usage="Specify output directory name")\r
-    private String outputName;\r
-    \r
-    @Option(name="-euf" , aliases= {"--exclude-uifw"} , usage="")\r
-    private boolean excludeUIFW;\r
-    \r
-    @Option(name="-e" , aliases= {"--exclude"} , usage="")\r
-    private List<String> excludeList;\r
-    \r
+\r
+    @Option(name = "-opt", aliases = { "--optimize" }, usage = "Optimize option")\r
+    public boolean optimize;\r
+\r
+    @Option(name = "-out", aliases = {"--output"} ,handler=StringOptionHandler.class, usage = "Specify output directory name")\r
+    public String outputName;\r
+\r
+    @Option(name = "-euf", aliases = { "--exclude-uifw" }, usage = "Specify whether exclude tizen web ui f/w or not.")\r
+    public boolean excludeUIFW;\r
+\r
+    @Option(name = "-e", aliases = { "--exclude" }, usage = "Specify exclude file list.")\r
+    public List<String> excludeList;\r
+\r
     private File cwd = new File(".");\r
-    \r
-    \r
-    public  void execute() {\r
-       log.trace("Execute BuildWebCLI...");\r
-       \r
-       BuildWebCLICommand command = new BuildWebCLICommand();\r
-       \r
-       command.setOptimize(optimize);\r
-       command.setOutputName(outputName);\r
-       command.setExcludeUIFW(excludeUIFW);\r
-       command.setExcludeList(excludeList);\r
-       command.setWorkingDir(workingDir);\r
-       \r
-       BuildWebParameter commandData = command.runCommand();\r
-       \r
-       output.println("Build web project succeeded!");\r
-       output.println(commandData);\r
+\r
+    public void execute() {\r
+        log.trace("Execute BuildWebCLI...");\r
+\r
+        BuildWebCLICommand command = new BuildWebCLICommand();\r
         \r
+        if( null == workingDir && null != currentWorkspacePath) {\r
+            workingDir = new File(currentWorkspacePath);\r
+        }else {\r
+            workingDir = cwd;\r
+        }\r
+        if(null != outputName) {\r
+            command.setOutputName(outputName);\r
+        }\r
+        if( null != excludeList) {\r
+            command.setExcludeList(excludeList);\r
+        }\r
+        command.setOptimize(optimize);\r
+        command.setExcludeUIFW(excludeUIFW);\r
+        command.setWorkingDir(workingDir);\r
+\r
+        BuildWebParameter commandData = command.runCommand();\r
+\r
+        output.println("Build web project succeeded!");\r
+        output.println(commandData);\r
+\r
     }\r
-    \r
 \r
 }\r
index 3877b78..5a7cccb 100644 (file)
@@ -57,12 +57,11 @@ public class Main {
             }\r
 \r
         } catch (CmdLineException e) {\r
-            // TODO Handle CLI exception\r
             cmdParser.printUsage(System.out);\r
             e.printStackTrace();\r
         } catch (Exception e) {\r
             // TODO: handle exception\r
-            cmdParser.printUsage(System.out);\r
+//            cmdParser.printUsage(System.out);\r
             e.printStackTrace();\r
         }\r
 \r
index 52e3779..b05048f 100644 (file)
@@ -99,28 +99,9 @@ public class BuildWebCLICommand extends AbstractSubCommand<BuildWebParameter> {
         // TODO implement build process with BuildProcess\r
 \r
         try {\r
-            // set output path (absolute)\r
-            if (!StringUtil.isEmpty(webAppBuildData.getOutputName())) {\r
-//                this.buildWebAppModule.setOutput(convertPath(webAppBuildData.getOutputName()));\r
-            } \r
-\r
-            // If output path exist, the path will be recreated.\r
-            // Set exclude file list\r
-\r
-            // Set start layer\r
-            // Get resource list for build\r
-            // Generate web builders to build process\\r
-\r
+            buildWebAppModule.setData(webAppBuildData);\r
             buildWebAppModule.buildResources();\r
 \r
-        } catch (MinifyException e) {\r
-            StringBuffer msg = new StringBuffer();\r
-            msg.append("Optimization failed.\n");\r
-            msg.append("Error: " + e.getPath() + "(" + e.getLineNumber() + "): " + e.getLineSource() + "\n");\r
-            msg.append("Cause: " + e.getMessage() + "\n");\r
-            // TODO print out Exception message\r
-            // getPrompter().notify(msg.toString());\r
-            e.printStackTrace();\r
         } catch (IOException e) {\r
             e.printStackTrace();\r
         } catch (BuildException e) {\r
index 32e9b96..745b99d 100644 (file)
@@ -27,6 +27,7 @@ package org.tizen.ncli.ide.shell;
 import static org.junit.Assert.*;
 
 import org.junit.Test;
+import org.kohsuke.args4j.CmdLineException;
 
 /**
  * @author Harry Hyeongseok Heo{@literal <hyeongseok.heo@samsung.com>} (S-core)
@@ -35,10 +36,23 @@ import org.junit.Test;
  */
 public class BuildWebCLITest extends Args4JTestBase<BuildWebCLI> {
 
-
+    
+    
+    @Test
+    public void test_build_basic() {
+        BuildWebCLI testObject = getTestObject();
+        String [] args = {"--output", "buildOutput"};
+        try {
+            parser.parseArgument(args);
+        } catch (CmdLineException e) {
+            e.printStackTrace();
+            fail(e.getMessage());
+        }
+        log.trace("test_build_basic..");
+    }
+    
     @Override
     public BuildWebCLI getTestObject() {
-        // TODO Auto-generated method stub
         return new BuildWebCLI();
     }