From 7c202d6f5e48f5a62df2a327f63c30b6ecc44b8e Mon Sep 17 00:00:00 2001 From: "hyeongseok.heo" Date: Thu, 12 Dec 2013 18:14:53 +0900 Subject: [PATCH] CLI : Fix build-web bug Fix bug with using option '--' (working directory) in build-web CLI module Add start and finish log message in AbstractCLI Add method for getting real working path Change-Id: If67c283303382ffb166262fbd2301eb1a112a1e3 Signed-off-by: hyeongseok.heo --- .../src/org/tizen/core/ide/BuildWebAppModule.java | 4 +- .../src/org/tizen/core/ide/BuildWebParameter.java | 4 +- .../src/org/tizen/ncli/core/CommandLineParser.java | 39 ++++++++----- .../tizen/ncli/core/TizenSubCommandHandler.java | 2 +- .../src/org/tizen/ncli/ide/CLIConstant.java | 1 + .../src/org/tizen/ncli/ide/shell/AbstractCLI.java | 67 +++++++++++++++++++++- .../src/org/tizen/ncli/ide/shell/BuildWebCLI.java | 15 +++-- .../src/org/tizen/ncli/ide/shell/ConfigCLI.java | 3 + .../src/org/tizen/ncli/ide/shell/Main.java | 47 ++++++++------- .../ncli/ide/subcommands/BuildWebCLICommand.java | 10 ++-- 10 files changed, 136 insertions(+), 56 deletions(-) diff --git a/org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebAppModule.java b/org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebAppModule.java index d34cb50..8d155b8 100644 --- a/org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebAppModule.java +++ b/org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebAppModule.java @@ -47,6 +47,7 @@ import org.tizen.common.file.filter.WildCardFilterFactory; import org.tizen.common.util.Assert; import org.tizen.common.util.FileUtil; import org.tizen.common.util.FilenameUtil; +import org.tizen.ncli.ide.CLIConstant; import org.tizen.web.builder.CssMinifyBuilder; import org.tizen.web.builder.HybridAppCLIBuilder; import org.tizen.web.builder.JSMinifyBuilder; @@ -63,7 +64,7 @@ public class BuildWebAppModule { private BuildWebParameter data; private String cwd; - private String output = ".buildResult"; + private String output = CLIConstant.DEFAULT_BUILD_OUTPUT; private SimpleFileFilter filter = new SimpleFileFilter(true); public FactoryWithArgument filterFactory = new WildCardFilterFactory(); public List excludes = new ArrayList(); @@ -127,6 +128,7 @@ public class BuildWebAppModule { } else { this.output = cwd + File.separator + this.output; } + data.setOutputName(this.output); // If output path exist, the path will be recreated. deleteOutput(); 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 dbdafed..5eb6bb4 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 @@ -29,6 +29,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.tizen.ncli.ide.CLIConstant; + /** * Class for representing parameter of Web Build * @@ -40,7 +42,7 @@ public class BuildWebParameter { private boolean optimize; private boolean excludeUIFW; private List excludeList = new ArrayList(); - private String outputName; + private String outputName = CLIConstant.DEFAULT_BUILD_OUTPUT; private File workingDir; private File[] refs; diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/core/CommandLineParser.java b/org.tizen.ncli.ide/src/org/tizen/ncli/core/CommandLineParser.java index 84d1950..b87cef1 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/core/CommandLineParser.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/core/CommandLineParser.java @@ -147,21 +147,8 @@ public class CommandLineParser extends CmdLineParser { SubCommand[] subCommandArray = subCommands.value(); for (int i = 0; i < subCommandArray.length; i++) { SubCommand subCommand = subCommandArray[i]; - TizenSubCommand annotation = subCommand.impl().getClass().getAnnotation(TizenSubCommand.class); - log.trace("SubCommand:{}", subCommand.name()); - String subCmdName = subCommand.name(); - CommandInfo cmdInfo = null; - if (null != annotation) { - subCmdName = (null == annotation.name()) ? subCommand.name() : annotation.name(); - cmdInfo = new CommandInfo((Class) subCommand.impl(), subCmdName, - annotation.usage(), annotation.common()); - log.trace("SubCommandData:" + subCmdName + "\t{}\t{}", annotation.usage(), annotation.common()); - } else { - cmdInfo = new CommandInfo((Class) subCommand.impl(), subCmdName, "", - false); - log.trace("SubCommandData w/o annotation:{}", subCommandArray[i].name()); - } - SubCommandData.put(subCmdName, cmdInfo); + CommandInfo cmdInfo = parseTizenSubCommand(subCommand); + SubCommandData.put(cmdInfo.getCommandName(), cmdInfo); if (null != findTreeNode) { findTreeNode.addChild(cmdInfo); } @@ -171,4 +158,26 @@ public class CommandLineParser extends CmdLineParser { } } + /** + * @param subCommand + * @return + */ + private CommandInfo parseTizenSubCommand(SubCommand subCommand) { + TizenSubCommand annotation = subCommand.impl().getClass().getAnnotation(TizenSubCommand.class); + log.trace("SubCommand:{}", subCommand.name()); + String subCmdName = subCommand.name(); + CommandInfo cmdInfo = null; + if (null != annotation) { + subCmdName = (null == annotation.name()) ? subCommand.name() : annotation.name(); + cmdInfo = new CommandInfo((Class) subCommand.impl(), subCmdName, + annotation.usage(), annotation.common()); + log.trace("SubCommandData:" + subCmdName + "\t{}\t{}", annotation.usage(), annotation.common()); + } else { + cmdInfo = new CommandInfo((Class) subCommand.impl(), subCmdName, "", + false); + log.trace("SubCommandData w/o annotation:{}", subCommand.name()); + } + return cmdInfo; + } + } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/core/TizenSubCommandHandler.java b/org.tizen.ncli.ide/src/org/tizen/ncli/core/TizenSubCommandHandler.java index 23d39c4..3da2d9c 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/core/TizenSubCommandHandler.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/core/TizenSubCommandHandler.java @@ -114,7 +114,7 @@ public class TizenSubCommandHandler extends OptionHandler { @Override public String getDefaultMetaVariable() { - return "CMD ARGS..."; + return ""; } public SubCommands getSubcommand() { diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/CLIConstant.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/CLIConstant.java index c541d2e..3eee66f 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/CLIConstant.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/CLIConstant.java @@ -36,6 +36,7 @@ public class CLIConstant { public static final String TIZEN_CLI_LOCAL_KEY = "TIZEN.CLI.LOCAL";//Preference key public static final String CLI_HOME = System.getenv("CLI_HOME"); + public static final String DEFAULT_BUILD_OUTPUT = ".buildResult"; public static String NATIVE_PKG_EXT = TizenPlatformConstants.PKGTYPE_TPK.toLowerCase(); public static String WEB_PKG_EXT = TizenPlatformConstants.PKGTYPE_WGT.toLowerCase(); diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java index a0cc824..0a907f3 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/AbstractCLI.java @@ -37,8 +37,12 @@ import org.apache.commons.lang3.time.StopWatch; import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.tizen.common.util.OSChecker; import org.tizen.common.util.StringUtil; +import org.tizen.ncli.core.CommandInfo; import org.tizen.ncli.core.CommandLineParser; +import org.tizen.ncli.core.SubCommandData; +import org.tizen.ncli.core.TizenSubCommand; /** * Implemented common function of CLI options @@ -49,7 +53,7 @@ public abstract class AbstractCLI { protected Logger log = LoggerFactory.getLogger(getClass()); protected final Logger progressLog = LoggerFactory.getLogger("NCLI_PROGRESS"); - @Option(name = "--", metaVar = "working directory", usage = "Specify where is the base directory for the command") + @Option(name = "--", metaVar = "working directory", usage = "Specify where the base directory is for the command") public File workingDir; @Option(hidden=true,name = "--current-workspace-path", metaVar = "current workspace path", usage = "Specify where is the root path for the command as a default") @@ -62,19 +66,51 @@ public abstract class AbstractCLI { public abstract void execute(); private StopWatch stopWatch = new StopWatch(); + + private File realWorkingPath; + + /** + * Set to false , if sub command do not need to print out start and finish message + */ + protected boolean isLoggingStartFinish = true; /** * @param cmdParser */ public void execute(final CommandLineParser cmdParser) { this.cmdParser = cmdParser; + printStarted(); stopWatch.start(); - execute(); - stopWatch.stop(); + printFinished(); + } + + private void printStarted() { + if( !isLoggingStartFinish) return; + progressLog.info("-----------------------------------------------------"); + progressLog.info("Starting {}", getCurrCmdName()); + progressLog.info("-----------------------------------------------------"); + } + + private void printFinished() { + if( !isLoggingStartFinish) return; + progressLog.info("-----------------------------------------------------"); + progressLog.info("Finished {}", getCurrCmdName()); + progressLog.info("-----------------------------------------------------"); } + private String getCurrCmdName() { + CommandInfo currentCmdInfo = SubCommandData.get("CURRENT_CMD"); + String commandName = "Tizen Command"; + if( null != currentCmdInfo && null != currentCmdInfo.getSubCmdImpl()) { + if ( null != currentCmdInfo.getCommandName()) { + commandName = currentCmdInfo.getCommandName(); + } + } + + return commandName; + } /** * Print execution time as form of "Total time: {hours}:{minutes}:{seconds}.{milliseconds}" */ @@ -91,4 +127,29 @@ public abstract class AbstractCLI { public boolean needPrintTime() { return false; } + + /** + * Getting working directory path to execute command. + *

+ * Convert relative path string './ ' and tilde character '~/' to absolute path.
+ * Tilde character is converted only in Linux or Mac.
+ * Recommend to use {@link File#getCanonicalPath()} with return value + * @return File real current working path + */ + protected File getRealWorkingPath() { + if( null == workingDir) { + return currentWorkspacePath; + } else { + File retFile = null; + if( null != workingDir.getPath() && workingDir.getPath().startsWith(".") ) { + retFile = new File(currentWorkspacePath,workingDir.getPath()); + }else if( !OSChecker.isWindows() && + null != workingDir.getPath() && + workingDir.getPath().startsWith("~")) { + String tempPath = workingDir.getPath().replaceFirst("~", System.getProperty("user.home")); + retFile = new File(tempPath); + } + return retFile; + } + } } 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 072fc53..4703e9b 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 @@ -35,6 +35,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.core.ide.BuildWebParameter; import org.tizen.core.ide.TextProgressMonitor; +import org.tizen.ncli.core.TizenSubCommand; import org.tizen.ncli.ide.subcommands.BuildWebCLICommand; /** @@ -42,6 +43,7 @@ import org.tizen.ncli.ide.subcommands.BuildWebCLICommand; * * @author Harry Hyeongseok Heo {@literal } (S-core) */ +@TizenSubCommand(name="build-web" , usage="Make a build output directory for web application.") public class BuildWebCLI extends AbstractCLI { private Logger log = LoggerFactory.getLogger(getClass()); @@ -57,17 +59,12 @@ public class BuildWebCLI extends AbstractCLI { @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(); + log.trace("getRealWorkingPath:{}",getRealWorkingPath()); - if( null == workingDir && null != currentWorkspacePath) { - workingDir = currentWorkspacePath; - }else { - workingDir = cwd; - } if(null != outputName) { command.setOutputName(outputName); } @@ -76,10 +73,12 @@ public class BuildWebCLI extends AbstractCLI { } command.setOptimize(optimize); command.setExcludeUIFW(excludeUIFW); - command.setWorkingDir(workingDir); + command.setWorkingDir(getRealWorkingPath()); command.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))); BuildWebParameter commandData = command.runCommand(); + + progressLog.info("Output path:{}",commandData.getOutputName()); } @Override diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ConfigCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ConfigCLI.java index dbc0a28..c387724 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ConfigCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ConfigCLI.java @@ -78,6 +78,9 @@ public class ConfigCLI extends AbstractCLI{ @Option (name="-g" , aliases="--global", usage="Setting global Tizen CLI config" , depends= {}) public boolean global; + public ConfigCLI() { + this.isLoggingStartFinish = false; + } public void execute() { log.trace("Execute configCLI..."); 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 568277f..0e93e77 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 @@ -77,32 +77,35 @@ public class Main { cmdParser.setUsageWidth(120); cmdParser.parseArgument(args); } catch (CmdLineException e) { - if (args.length == 0 || helpOpt) { - printDefaultCommandUsage(errorWriter); - } else if (args.length == 3) { - String command = args[0]; - log.trace("{}", command); - if (null == SubCommandData.get(command)) { - errorWriter.println(MessageFormat.format("{0}", e.getMessage())); + try { + if (args.length == 0 || helpOpt) { printDefaultCommandUsage(errorWriter); - } else { - printSubCommandOrArgUsage(command, errorWriter); - } + } else if (args.length == 3) { + String command = args[0]; + log.trace("{}", command); + if (null == SubCommandData.get(command)) { + errorWriter.println(MessageFormat.format("{0}", e.getMessage())); + printDefaultCommandUsage(errorWriter); + } else { + printSubCommandOrArgUsage(command, errorWriter); + } - } else if (args.length > 3) { - errorWriter.println(); - errorWriter.println(TizenCLIMessages.INVALID_ARG); - errorWriter.println(MessageFormat.format("Error: {0}", e.getMessage())); - errorWriter.println(); - CommandInfo currentCmdInfo = SubCommandData.get("CURRENT_CMD"); - if (null != currentCmdInfo) { - // FIXME ResourceBundle needed. - log.trace("command:{}", currentCmdInfo.getCommandName()); - currentCmdInfo.getCmdLineParser().printUsage(errorWriter, null); + } else if (args.length > 3) { + errorWriter.println(); + errorWriter.println(MessageFormat.format("Error: {0}", e.getMessage())); + errorWriter.println(); + CommandInfo currentCmdInfo = SubCommandData.get("CURRENT_CMD"); + if (null != currentCmdInfo) { + // FIXME ResourceBundle needed. + log.trace("command:{}", currentCmdInfo.getCommandName()); + currentCmdInfo.getCmdLineParser().printUsage(errorWriter, null); + } } + }finally { + errorWriter.flush(); + System.exit(1); } - errorWriter.flush(); - System.exit(1); + } try { 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 aadf8ff..ebfff82 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 @@ -76,9 +76,7 @@ public class BuildWebCLICommand extends AbstractSubCommand { */ @Override protected BuildWebParameter call() { - progressLog.info("-----------------------------------------------------"); - progressLog.info("Starting Tizen project build:"); - progressLog.info("-----------------------------------------------------"); + initExcludes(); if (log.isTraceEnabled()) { @@ -91,6 +89,8 @@ public class BuildWebCLICommand extends AbstractSubCommand { canonicalPath = this.workingDir.getCanonicalPath(); buildWebAppModule.setCwd(canonicalPath); log.trace("canonicalPath:{}", canonicalPath); + log.trace("absolutPath:{}", this.workingDir.getAbsolutePath()); + log.trace("path:{}",this.workingDir.getPath()); } catch (IOException e) { progressLog.error("Error occurred during setting current work path!"); log.error("Error occurred during setting current work path!\n{}",e.getMessage()); @@ -104,12 +104,12 @@ public class BuildWebCLICommand extends AbstractSubCommand { buildWebAppModule.buildResources(); } catch (IOException e) { - e.printStackTrace(); + log.error(e.getMessage()); } catch (BuildException e) { progressLog.error("Error occured during build!\n\t{}",e.getMessage()); return webAppBuildData; } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage()); } progressLog.info("\nBUILD SUCCESSFUL\n"); return webAppBuildData; -- 2.7.4