From c833c7b1de813777a278b0c44700fff818631e6f Mon Sep 17 00:00:00 2001 From: Heongseok Heo Date: Thu, 7 Nov 2013 16:43:04 +0900 Subject: [PATCH] NCLI:BUILD-WEB: Fix some bug with argument. 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 --- .../src/org/tizen/core/ide/BuildWebParameter.java | 9 ++- .../src/org/tizen/ncli/ide/shell/BuildWebCLI.java | 73 ++++++++++++---------- .../src/org/tizen/ncli/ide/shell/Main.java | 3 +- .../ncli/ide/subcommands/BuildWebCLICommand.java | 21 +------ .../org/tizen/ncli/ide/shell/BuildWebCLITest.java | 18 +++++- 5 files changed, 64 insertions(+), 60 deletions(-) diff --git a/org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebParameter.java b/org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebParameter.java index 501f40f..78e92aa 100644 --- a/org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebParameter.java +++ b/org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebParameter.java @@ -31,12 +31,12 @@ import java.util.List; /** * Class for representing parameter of Web Build + * * @author Harry Hyeongseok Heo{@literal } (S-core) * */ public class BuildWebParameter { - private boolean optimize; private boolean excludeUIFW; private List excludeList = new ArrayList(); @@ -68,7 +68,9 @@ public class BuildWebParameter { } public void setExcludeList(List 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 getReferences() { - if( hasReference()) { + if (hasReference()) { return Arrays.asList(this.refs); } return null; diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildWebCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildWebCLI.java index 6f6430c..b11314f 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildWebCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildWebCLI.java @@ -4,47 +4,54 @@ import java.io.File; import java.util.List; import org.kohsuke.args4j.Option; +import org.kohsuke.args4j.spi.StringOptionHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.core.ide.BuildWebParameter; import org.tizen.ncli.ide.subcommands.BuildWebCLICommand; - -public class BuildWebCLI extends AbstractCLI{ +public class BuildWebCLI extends AbstractCLI { private Logger log = LoggerFactory.getLogger(getClass()); - - @Option(name="-opt" , aliases= {"--optimize"}, usage="Optimize option" ) - private boolean optimize; - - @Option(name="--output" , usage="Specify output directory name") - private String outputName; - - @Option(name="-euf" , aliases= {"--exclude-uifw"} , usage="") - private boolean excludeUIFW; - - @Option(name="-e" , aliases= {"--exclude"} , usage="") - private List excludeList; - + + @Option(name = "-opt", aliases = { "--optimize" }, usage = "Optimize option") + public boolean optimize; + + @Option(name = "-out", aliases = {"--output"} ,handler=StringOptionHandler.class, usage = "Specify output directory name") + public String outputName; + + @Option(name = "-euf", aliases = { "--exclude-uifw" }, usage = "Specify whether exclude tizen web ui f/w or not.") + public boolean excludeUIFW; + + @Option(name = "-e", aliases = { "--exclude" }, usage = "Specify exclude file list.") + public List excludeList; + private File cwd = new File("."); - - - public void execute() { - log.trace("Execute BuildWebCLI..."); - - BuildWebCLICommand command = new BuildWebCLICommand(); - - command.setOptimize(optimize); - command.setOutputName(outputName); - command.setExcludeUIFW(excludeUIFW); - command.setExcludeList(excludeList); - command.setWorkingDir(workingDir); - - BuildWebParameter commandData = command.runCommand(); - - output.println("Build web project succeeded!"); - output.println(commandData); + + public void execute() { + log.trace("Execute BuildWebCLI..."); + + BuildWebCLICommand command = new BuildWebCLICommand(); + if( null == workingDir && null != currentWorkspacePath) { + workingDir = new File(currentWorkspacePath); + }else { + workingDir = cwd; + } + if(null != outputName) { + command.setOutputName(outputName); + } + if( null != excludeList) { + command.setExcludeList(excludeList); + } + command.setOptimize(optimize); + command.setExcludeUIFW(excludeUIFW); + command.setWorkingDir(workingDir); + + BuildWebParameter commandData = command.runCommand(); + + output.println("Build web project succeeded!"); + output.println(commandData); + } - } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java index 3877b78..5a7cccb 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java @@ -57,12 +57,11 @@ public class Main { } } catch (CmdLineException e) { - // TODO Handle CLI exception cmdParser.printUsage(System.out); e.printStackTrace(); } catch (Exception e) { // TODO: handle exception - cmdParser.printUsage(System.out); +// cmdParser.printUsage(System.out); e.printStackTrace(); } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommand.java index 52e3779..b05048f 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommand.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommand.java @@ -99,28 +99,9 @@ public class BuildWebCLICommand extends AbstractSubCommand { // TODO implement build process with BuildProcess try { - // set output path (absolute) - if (!StringUtil.isEmpty(webAppBuildData.getOutputName())) { -// this.buildWebAppModule.setOutput(convertPath(webAppBuildData.getOutputName())); - } - - // If output path exist, the path will be recreated. - // Set exclude file list - - // Set start layer - // Get resource list for build - // Generate web builders to build process\ - + buildWebAppModule.setData(webAppBuildData); buildWebAppModule.buildResources(); - } catch (MinifyException e) { - StringBuffer msg = new StringBuffer(); - msg.append("Optimization failed.\n"); - msg.append("Error: " + e.getPath() + "(" + e.getLineNumber() + "): " + e.getLineSource() + "\n"); - msg.append("Cause: " + e.getMessage() + "\n"); - // TODO print out Exception message - // getPrompter().notify(msg.toString()); - e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (BuildException e) { diff --git a/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/shell/BuildWebCLITest.java b/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/shell/BuildWebCLITest.java index 32e9b96..745b99d 100644 --- a/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/shell/BuildWebCLITest.java +++ b/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/shell/BuildWebCLITest.java @@ -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 } (S-core) @@ -35,10 +36,23 @@ import org.junit.Test; */ public class BuildWebCLITest extends Args4JTestBase { - + + + @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(); } -- 2.7.4