From 2fb98e04eeb258e59d46bd59d44b4fdea54ed3cb Mon Sep 17 00:00:00 2001 From: Heongseok Heo Date: Wed, 30 Oct 2013 19:29:19 +0900 Subject: [PATCH] [Title]Add buildWeb Module and modify related classes [Desc.] Create BuildWebAppModule class for seperating build web module with CLI. Add Test cases for build web. Signed-off-by: Heongseok Heo Change-Id: Ia222632c3e7af577b5ccfa816c8c1508f775f753 --- .../src/org/tizen/core/ide/BuildWebAppModule.java | 396 +++++++++++++++ .../src/org/tizen/core/ide/BuildWebParameter.java | 111 +++++ .../src/org/tizen/ncli/ide/shell/AbstractCLI.java | 26 +- .../src/org/tizen/ncli/ide/shell/BuildWebCLI.java | 6 +- .../ncli/ide/subcommands/AbstractSubCommand.java | 8 +- .../ncli/ide/subcommands/BuildWebCLICommand.java | 529 +++++---------------- .../ide/subcommands/BuildWebCLICommandData.java | 84 ---- .../org/tizen/core/ide/BuildWebAppModuleTest.java | 139 ++++++ .../subcommands/BuildWebCLICommandCallTest.java | 215 +++++---- .../ide/subcommands/BuildWebCLICommandTest.java | 107 +++-- .../ncli/ide/subcommands/ConfigCommandTest.java | 85 ++-- 11 files changed, 999 insertions(+), 707 deletions(-) create mode 100644 org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebAppModule.java create mode 100644 org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebParameter.java delete mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandData.java create mode 100644 org.tizen.ncli.ide/test/src/org/tizen/core/ide/BuildWebAppModuleTest.java 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 new file mode 100644 index 0000000..e51f7d6 --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebAppModule.java @@ -0,0 +1,396 @@ +/* + * IDE + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyeongseok Heo + * Kangho Kim + * + * 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.core.ide; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.FactoryWithArgument; +import org.tizen.common.builder.BuildProcess; +import org.tizen.common.builder.Builder; +import org.tizen.common.builder.Resource; +import org.tizen.common.builder.ResourceLayer; +import org.tizen.common.builder.core.CopyBuilder; +import org.tizen.common.builder.exception.BuildException; +import org.tizen.common.file.FileHandler; +import org.tizen.common.file.Filter; +import org.tizen.common.file.SimpleFileFilter; +import org.tizen.common.file.StandardFileHandler; +import org.tizen.common.file.VirtualFileHandler; +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.web.builder.CssMinifyBuilder; +import org.tizen.web.builder.HybridAppCLIBuilder; +import org.tizen.web.builder.JSMinifyBuilder; +import org.tizen.web.builder.UIFWBuilder; + +/** + * This class has a main role of build web application. + *

+ * This class make out build result by parameters for build.
+ * Independent with IDE or CLI + * + * @author Harry Hyeongseok Heo{@literal } (S-core) + * + * + */ +public class BuildWebAppModule { + private Logger log = LoggerFactory.getLogger(getClass()); + private BuildWebParameter data; + private String cwd; + private String output = ".buildResult"; + private SimpleFileFilter filter = new SimpleFileFilter(true); + public FactoryWithArgument filterFactory = new WildCardFilterFactory(); + public List excludes = new ArrayList(); + private String[] DEFAULT_EXCLUDES = { + ".build/*", + ".project", + ".settings/*", + ".sdk_delta.info", "*.wgt" + }; + + public BuildWebAppModule() { + // TODO Auto-generated constructor stub + } + /** + * @param cwd + * the cwd to set + */ + public void setCwd(String cwd) { + this.cwd = cwd; + } + + /** + * @param data the data to set + */ + public void setData(BuildWebParameter data) { + this.data = data; + } + + public BuildWebAppModule(BuildWebParameter data, String cwd, String output, SimpleFileFilter filter, + FactoryWithArgument filterFactory, List excludes) { + this.data = data; + this.cwd = cwd; + this.output = output; + this.filter = filter; + this.filterFactory = filterFactory; + this.excludes = excludes; + } + + + + public void buildResources() throws IOException, BuildException, Exception { + BuildProcess buildProcess = new BuildProcess(); + + if( isPrerequisiteSatisfy()) { + // Set output + if( null != data && null != data.getOutputName()) { + this.output = cwd+File.separator+data.getOutputName(); + }else { + this.output = cwd+File.separator+this.output; + } + // If output path exist, the path will be recreated. + deleteOutput(); + // Set default exclude resources + addDefaultExclude(); + + // Set start layer + FileHandler fh = new StandardFileHandler(); + fh.setCurrentWorkingDirectory(cwd); + ResourceLayer startLayer = new ResourceLayer("Initial Resource Layer", fh); + + log.debug("=== OUTPUT === {}", this.output); + // Get resource list for build + Resource[] resources = null; + resources = getBuildResources(startLayer); + log.trace("==!! Get Build Resources !!=="); + if (null != resources) { + log.trace("Total resource count: {}", resources.length); + // Generate web builders to build process + } + + generateAllBuilders(buildProcess, startLayer); + + if (buildProcess.getLastBuilder() != null) { + log.debug("start build process"); + buildProcess.build(resources); + + // check succeeding status. + checkHybridStructure(buildProcess); + } + }else { + throw new BuildException(null); + } + Assert.notNull(cwd,"Current Working Directory should not be NULL."); + } + + private void deleteOutput() { + if(FileUtil.isExist(output)) { + FileUtil.recursiveDelete(new File(output)); + } + } + private void addDefaultExclude() { + if( null != data && null != data.getExcludeList()) { + for (String defaultExclude : DEFAULT_EXCLUDES) { + log.trace("add exclude:{}",defaultExclude); + data.getExcludeList().add(defaultExclude); + } + } + } + /** + * Check pre-requisite for executing build + * + * @return + */ + private boolean isPrerequisiteSatisfy() { + return null != cwd && !"".equals(cwd.trim()) ; + } + + /** + * get resource list + * + * @param cwd + * root path located resources. It means working path. means current path. + * @param relativeSrcDir + * relative directory including resources. + * @param layer + * {@link ResourceLayer} about resource + * @throws IOException + */ + private List getResources(String cwd, String relativeSrcDir, ResourceLayer layer) throws IOException { + List resources = new ArrayList(); + List files = null; + String absoluteDir = cwd + File.separator + relativeSrcDir; + files = FileUtil.findFiles(new File(absoluteDir), ".*", true); + + for (File file : files) { + String fileRelativePath = FilenameUtil.getRelativePath(cwd, file.getCanonicalPath()); + + if (!FilenameUtil.equals(file.getCanonicalPath(), this.cwd) && !this.filter.accept(cwd, fileRelativePath)) { + log.debug("Ignore {}", fileRelativePath); + continue; + } + + log.debug("resource path : {}", fileRelativePath); + Resource resource = new Resource(layer, fileRelativePath); + + resources.add(resource); + } + return resources; + } + + /** + * Get resource list for build. + * + * @param cmdLine + * @param layer + * parent layer + * @param includes + * Include resource list. If you want to add all resources located in input path, set this parameter to + * null. If you set this parameter, another resources will not be added to list. + * @param data + * .excludes Exclude resource list. If you want to exclude resources, set this parameter using regular + * expression. It should be set regular expression about file element. + * @return + * @throws IOException + */ + private Resource[] getBuildResources(ResourceLayer layer) throws IOException { + List resources = new ArrayList(); + // setIncludes(includes); + setExcludes(data.getExcludeList()); + log.trace("CWD:{}",cwd); + String cwd = layer.getFileHandler().getCurrentWorkingDirectory(); + resources.addAll(getResources(cwd, FilenameUtil.getRelativePath(cwd, cwd), layer)); + + // reference project + /* + * if (cmdLine.hasOption(OPT_NAME_REFERENCE_PROJECT)) { FileHandler refFh = new StandardFileHandler(); + * ResourceLayer referenceLayer = new ResourceLayer(HybridAppCLIBuilder.RESOURCE_LAYER_REFERENCE_NAME , refFh); + * layer.setParent(referenceLayer); String refPath = + * convertPath(cmdLine.getOptionValue(OPT_NAME_REFERENCE_PROJECT)); refFh.setCurrentWorkingDirectory(refPath); + * + * resources.addAll(getResources(refPath , FilenameUtil.getRelativePath(refPath, refPath) , referenceLayer)); } + */ + + return resources.toArray(new Resource[resources.size()]); + } + + /** + * Generate builders to {@link BuildProcess}. + * + * @param buildProcess + * @param parentLayer + * @throws IOException + */ + public void generateAllBuilders(BuildProcess buildProcess, ResourceLayer parentLayer) throws IOException { + + FileHandler fh = new VirtualFileHandler(); + fh.setCurrentWorkingDirectory(parentLayer.getFileHandler().getCurrentWorkingDirectory()); + if (null != this.data && this.data.isExcludeUIFW()) { + addUIFWBuilder(true, true, buildProcess, getLastResourceLayer(buildProcess, parentLayer), fh); + } + if (null != this.data && this.data.hasReference()) { + addHybridBuilder(buildProcess, getLastResourceLayer(buildProcess, parentLayer), fh); + } + if (null != this.data && this.data.isOptimize()) { + addOptimizingBuilders(buildProcess, getLastResourceLayer(buildProcess, parentLayer), fh); + } + addLastbuilder(buildProcess, getLastResourceLayer(buildProcess, parentLayer)); + } + + /** + * Add optimizing builders to buildProcess. + * + * @param buildProcess + * @param parentLayer + */ + private void addOptimizingBuilders(BuildProcess buildProcess, ResourceLayer parentLayer, FileHandler fh) { + if (buildProcess == null) { + return; + } + + // add js minify builder + ResourceLayer jsMinLayer = new ResourceLayer(JSMinifyBuilder.RESOURCE_LAYER_NAME, parentLayer, fh); + JSMinifyBuilder jsMin = new JSMinifyBuilder(jsMinLayer); + buildProcess.addBuilder(jsMin); + + // add css minify builder + ResourceLayer cssMinLayer = new ResourceLayer(CssMinifyBuilder.RESOURCE_LAYER_NAME, jsMinLayer, fh); + CssMinifyBuilder cssMin = new CssMinifyBuilder(cssMinLayer); + buildProcess.addBuilder(cssMin); + } + + /** + * Add hybrid builder to buildProcess. It will be used to build including reference project. + * + * @param cmdLine + * @param buildProcess + * @param lastLayer + * @throws IOException + */ + private void addHybridBuilder(BuildProcess buildProcess, ResourceLayer lastLayer, FileHandler fh) + throws IOException { + ResourceLayer layer = new ResourceLayer(HybridAppCLIBuilder.RESOURCE_LAYER_NAME, lastLayer, fh); + + String refPath = ""; // TODO add HybridOption! convertPath(cmdLine.getOptionValue(OPT_NAME_REFERENCE_PROJECT)); + + HybridAppCLIBuilder hybridAppBuilder = new HybridAppCLIBuilder(layer, refPath); + buildProcess.addBuilder(hybridAppBuilder); + } + + /** + * get last resource layer located in buildProcess. + * + * @param buildProcess + * @param defaultLayer + * @return + */ + private ResourceLayer getLastResourceLayer(BuildProcess buildProcess, ResourceLayer defaultLayer) { + ResourceLayer lastLayer = buildProcess.getLastResourceLayer(); + return (lastLayer != null) ? lastLayer : defaultLayer; + } + + /** + * Add UI framework builder to buildProcess. + * + * @param isExclude + * If set true, Tizen web UI framework library will be excluded output path. Application will be used + * target's Tizen web UI framework library. + * @param useMin + * If 'isExclude' parameter set true and this parameter set true, application will be used target's + * minified Tizen web UI framework library. Or, application will be used target's original Tizen web UI + * framework library. + * @param buildProcess + * @param parentLayer + */ + private void addUIFWBuilder(boolean isExclude, boolean useMin, BuildProcess buildProcess, + ResourceLayer parentLayer, FileHandler fh) { + ResourceLayer layer = new ResourceLayer(UIFWBuilder.RESOURCE_LAYER_NAME, parentLayer, fh); + UIFWBuilder uifwBuilder = new UIFWBuilder(isExclude, layer); + uifwBuilder.setUseMin(useMin); + + buildProcess.addBuilder(uifwBuilder); + } + + /** + * Add builder that write resources to file system to buildProcess. + * + * @param buildProcess + * @param parentLayer + */ + private void addLastbuilder(BuildProcess buildProcess, ResourceLayer parentLayer) { + // add file output builder + FileHandler fh = new StandardFileHandler(); + fh.setCurrentWorkingDirectory(parentLayer.getFileHandler().getCurrentWorkingDirectory()); + ResourceLayer toFSLayer = new ResourceLayer(CopyBuilder.RESOURCE_LAYER_NAME, parentLayer, fh); + CopyBuilder toFSBuilder = new CopyBuilder(FilenameUtil.getRelativePath(this.cwd, this.output), toFSLayer); + buildProcess.addBuilder(toFSBuilder); + } + + /** + * Check whether this process have no problem. If have problems, BuildException will be occurred. + * + * @param buildProcess + * @throws BuildException + */ + protected void checkHybridStructure(BuildProcess buildProcess) throws Exception { + // Check hybrid structure. If a manifest file and a binary file are not found, this is a failure. + try { + Builder builder = buildProcess.getBuilder(HybridAppCLIBuilder.RESOURCE_LAYER_NAME); + if (builder != null) { + HybridAppCLIBuilder hybridBuilder = (HybridAppCLIBuilder) builder; + if (!hybridBuilder.isManifestFound()) { + throw new IOException(HybridAppCLIBuilder.ERROR_MANIFEST_NOT_FOUND); + } + if (!hybridBuilder.isBinaryFound()) { + throw new IOException(HybridAppCLIBuilder.ERROR_BINARY_NOT_FOUND); + } + } + } catch (IOException e) { + throw new Exception(e); + } + + // TODO Notification ?? getPrompter().notify( MessageFormat.format( SUCCEED_MSG, this.output ) ); + } + + /** + * Set excluding resource list + * @param excludes + */ + private void setExcludes(List excludes) { +// filter.clearExcludes(); + if (null != excludes) { + for (final String exclude : excludes) { + filter.addExcludes(filterFactory.create(exclude)); + } + } + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..501f40f --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/core/ide/BuildWebParameter.java @@ -0,0 +1,111 @@ +/* + * IDE + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyeongseok Heo + * Kangho Kim + * + * 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.core.ide; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +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(); + private String outputName; + private File workingDir; + private File[] refs; + + public BuildWebParameter() { + } + + public boolean isOptimize() { + return optimize; + } + + public void setOptimize(boolean optimize) { + this.optimize = optimize; + } + + public boolean isExcludeUIFW() { + return excludeUIFW; + } + + public void setExcludeUIFW(boolean excludeUIFW) { + this.excludeUIFW = excludeUIFW; + } + + public List getExcludeList() { + return excludeList; + } + + public void setExcludeList(List excludeList) { + this.excludeList = excludeList; + } + + public String getOutputName() { + return outputName; + } + + public void setOutputName(String outputName) { + this.outputName = outputName; + } + + public void setWorkingDir(File workingDir) { + this.workingDir = workingDir; + + } + /** + * @return the workingDir + */ + public File getWorkingDir() { + return workingDir; + } + + public void setReferences(File... refs) { + this.refs = refs; + } + + public boolean hasReference() { + if (null != this.refs && this.refs.length > 0) { + return true; + } else { + return false; + } + } + + public List getReferences() { + if( hasReference()) { + return Arrays.asList(this.refs); + } + return null; + } +} \ No newline at end of file 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 7cea7e3..d1f653a 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 @@ -35,37 +35,27 @@ import org.slf4j.LoggerFactory; /** * Implemented common function of CLI options + * * @author Harry Hyeongseok Heo{@literal } (S-core) */ public abstract class AbstractCLI { - protected Logger log = LoggerFactory.getLogger(getClass()); - - @Option(name="--" , metaVar="target path" , usage="Specify where is the root path for the command") - public File targetPath; - + protected Logger log = LoggerFactory.getLogger(getClass()); + + @Option(name = "--", metaVar = "working directory", usage = "Specify where is the base directory for the command") + public File workingDir; + protected PrintWriter output = new PrintWriter(System.out);; - + public final void execute(String[] args) { parseArgument(args); execute(); } - + /** * @param args */ private void parseArgument(String[] args) { log.trace("Could not use parsing argument again!"); -// log.trace("parseArgument..."); -// CmdLineParser parser = new CmdLineParser(this); -// -// try { -// parser.parseArgument(args); -// } catch (CmdLineException e) { -// e.printStackTrace(); -// System.err.println("Error occurred during parsing the arguments."); -// System.exit(1); -// } } - public abstract void execute(); } 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 2b794ea..6f6430c 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 @@ -6,8 +6,8 @@ import java.util.List; import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.tizen.core.ide.BuildWebParameter; import org.tizen.ncli.ide.subcommands.BuildWebCLICommand; -import org.tizen.ncli.ide.subcommands.BuildWebCLICommandData; public class BuildWebCLI extends AbstractCLI{ @@ -37,9 +37,9 @@ public class BuildWebCLI extends AbstractCLI{ command.setOutputName(outputName); command.setExcludeUIFW(excludeUIFW); command.setExcludeList(excludeList); - command.setTargetPath(targetPath); + command.setWorkingDir(workingDir); - BuildWebCLICommandData commandData = command.runCommand(); + 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/subcommands/AbstractSubCommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/AbstractSubCommand.java index 71a1afc..6eaaa97 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/AbstractSubCommand.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/AbstractSubCommand.java @@ -44,13 +44,13 @@ import org.tizen.ncli.ide.exec.NewCommandLineExecutor; */ abstract public class AbstractSubCommand { protected final Logger log = LoggerFactory.getLogger( getClass() ); - protected File targetPath; + protected File workingDir; /** - * @param targetPath the targetPath to set + * @param workingDir the workingDir to set */ - public void setTargetPath(File targetPath) { - this.targetPath = targetPath; + public void setWorkingDir(File targetPath) { + this.workingDir = targetPath; } /** 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 8f898c7..52e3779 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 @@ -29,456 +29,181 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.tizen.common.FactoryWithArgument; import org.tizen.common.builder.BuildProcess; import org.tizen.common.builder.Builder; import org.tizen.common.builder.Resource; import org.tizen.common.builder.ResourceLayer; -import org.tizen.common.builder.core.CopyBuilder; import org.tizen.common.builder.exception.BuildException; import org.tizen.common.file.FileHandler; -import org.tizen.common.file.Filter; import org.tizen.common.file.SimpleFileFilter; import org.tizen.common.file.StandardFileHandler; -import org.tizen.common.file.VirtualFileHandler; import org.tizen.common.file.FileHandler.Attribute; import org.tizen.common.file.filter.WildCardFilter; import org.tizen.common.file.filter.WildCardFilterFactory; -import org.tizen.common.util.FileUtil; -import org.tizen.common.util.FilenameUtil; import org.tizen.common.util.OSChecker; import org.tizen.common.util.StringUtil; -import org.tizen.web.builder.CssMinifyBuilder; +import org.tizen.core.ide.BuildWebAppModule; +import org.tizen.core.ide.BuildWebParameter; +import org.tizen.ncli.ide.shell.BuildWebCLI; import org.tizen.web.builder.HybridAppCLIBuilder; -import org.tizen.web.builder.JSMinifyBuilder; -import org.tizen.web.builder.UIFWBuilder; import org.tizen.web.builder.exception.MinifyException; import org.tizen.web.common.WebConstant; /** + * This class has a role of intermediate with {@link BuildWebCLI}} and {@link BuildWebAppModule}
+ * * @author Harry Hyeongseok Heo{@literal } (S-core) - * @param - * + * @param + * * */ -public class BuildWebCLICommand extends AbstractSubCommand { - - - private BuildWebCLICommandData data = new BuildWebCLICommandData(); - //the current working directory that build process is executed - private String cwd = "."; - //the result directory name - private String output = ".buildResult"; - private SimpleFileFilter filter = new SimpleFileFilter(true); - private FactoryWithArgument filterFactory = new WildCardFilterFactory(); - // file filter. If you want to exclude a directory, append '/*' - private static final String[] DEFAULT_EXCLUDES = {".build"+File.separator+"*" - , ".project" - , ".settings" + File.separator + "*" - , ".sdk_delta.info" - , "*.wgt"}; - // excluding file list - private List excludes = new ArrayList(); - - /** - * Make build result from the targetPath to the outputPath.
- * If there is no targetPath specified , it will assume that current working directory as - * Build-web is executed with sequence like below.
- *

- *

  • Get the resources
  • - *
  • - * - *

    - */ - @Override - protected BuildWebCLICommandData call() { - log.trace("BuildWeb command started ..."); - initExcludes(); - if (log.isTraceEnabled()) { - log.trace("BuildData: {}", data); - } - if (null != this.targetPath) { - // set CurrentWorkingDirectory (cwd) absolute path - String canonicalPath = null; - try { - canonicalPath = this.targetPath.getCanonicalPath(); - cwd = this.targetPath.getCanonicalPath(); - log.trace("canonicalPath:{}", canonicalPath); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - // TODO implement build process with BuildProcess - - - try { - // set output path (absolute) - if( !StringUtil.isEmpty(data.getOutputName())) { - this.output = convertPath(data.getOutputName()); - } else { - this.output = cwd+File.separator+this.output; - } - - // 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\ +public class BuildWebCLICommand extends AbstractSubCommand { - BuildProcess buildProcess = new BuildProcess(); + // file filter. If you want to exclude a directory, append '/*' + private static final String[] DEFAULT_EXCLUDES = { ".build" + File.separator + "*", ".project", + ".settings" + File.separator + "*", ".sdk_delta.info", "*.wgt" }; + // private BuildWebAppModule webAppBuild = new BuildWebAppModule(new BuildWebParameter(), ".", ".buildResult", new + // SimpleFileFilter(true), new WildCardFilterFactory(), new ArrayList()); + private BuildWebAppModule buildWebAppModule = new BuildWebAppModule(); + private BuildWebParameter webAppBuildData = new BuildWebParameter(); - // Set start layer - FileHandler fh = new StandardFileHandler(); - fh.setCurrentWorkingDirectory(cwd); - ResourceLayer startLayer = new ResourceLayer("Initial Resource Layer", - fh); - - log.debug("=== OUTPUT === {}",this.output); - log.trace("TEST OUTPUT:"+this.output); - // Get resource list for build - Resource[] resources = null; - resources = getBuildResources(startLayer); - log.trace("==!! Get Build Resources !!=="); - if (null != resources) { - log.trace("Total resource count: {}", resources.length); - - // Generate web builders to build process - } - - generateAllBuilders(buildProcess, startLayer); - - if (buildProcess.getLastBuilder() != null) { - log.debug("start build process"); - buildProcess.build(resources); - - // check succeeding status. - checkProcessComplete(buildProcess); - } - - } 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) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - - return data; - } - - /** - * get resource list - * @param cwd root path located resources. It means working path. means current path. - * @param relativeSrcDir relative directory including resources. - * @param layer {@link ResourceLayer} about resource - * @throws IOException - */ - private List getResources(String cwd, String relativeSrcDir, ResourceLayer layer) throws IOException { - List resources = new ArrayList(); - List files = null; - String absoluteDir = cwd+ File.separator + relativeSrcDir; - files = FileUtil.findFiles(new File(absoluteDir), ".*", true); - - for (File file : files) { - String fileRelativePath = FilenameUtil.getRelativePath(cwd, file.getCanonicalPath()); - - if (!FilenameUtil.equals(file.getCanonicalPath(), this.cwd) - && !filter.accept(cwd, fileRelativePath)) { - log.debug("Ignore {}", fileRelativePath); - continue; - } - - log.debug("resource path : {}", fileRelativePath); - Resource resource = new Resource(layer, fileRelativePath); - - resources.add(resource); - } - return resources; - } - - /** - * Get resource list for build. - * @param cmdLine - * @param layer parent layer - * @param includes Include resource list. If you want to add all resources located in input path, set this parameter to null. - * If you set this parameter, another resources will not be added to list. - * @param excludes Exclude resource list. If you want to exclude resources, set this parameter using regular expression. - * It should be set regular expression about file element. - * @return - * @throws IOException - */ - private Resource[] getBuildResources( ResourceLayer layer ) throws IOException { - List resources = new ArrayList(); -// setIncludes(includes); -// setExcludes(excludes); - - String cwd = layer.getFileHandler().getCurrentWorkingDirectory(); - resources.addAll(getResources(cwd - , FilenameUtil.getRelativePath(cwd, cwd) - , layer)); - - //reference project - /*if (cmdLine.hasOption(OPT_NAME_REFERENCE_PROJECT)) { - FileHandler refFh = new StandardFileHandler(); - ResourceLayer referenceLayer = new ResourceLayer(HybridAppCLIBuilder.RESOURCE_LAYER_REFERENCE_NAME - , refFh); - layer.setParent(referenceLayer); - String refPath = convertPath(cmdLine.getOptionValue(OPT_NAME_REFERENCE_PROJECT)); - refFh.setCurrentWorkingDirectory(refPath); - - resources.addAll(getResources(refPath - , FilenameUtil.getRelativePath(refPath, refPath) - , referenceLayer)); - }*/ - - return resources.toArray(new Resource[resources.size()]); - } - - /** - * Generate builders to {@link BuildProcess}. - * @param buildProcess - * @param parentLayer - * @throws IOException + * With the {@link BuildWebParameter} , calling {@link BuildWebAppModule} to make out build result.
    + * Below files or directories would be excluded by default.
    + *
  • .build/*
  • + *
  • .project
  • + *
  • .settings/*
  • + *
  • .sdk_delta.info
  • + *
  • *.wgt
  • */ - public void generateAllBuilders( BuildProcess buildProcess - , ResourceLayer parentLayer) throws IOException { - - FileHandler fh = new VirtualFileHandler(); - fh.setCurrentWorkingDirectory(parentLayer.getFileHandler().getCurrentWorkingDirectory()); - - if (data.isExcludeUIFW()) { - addUIFWBuilder(true ,true - , buildProcess - , getLastResourceLayer(buildProcess, parentLayer) - , fh); + @Override + protected BuildWebParameter call() { + log.trace("BuildWeb command started ..."); + initExcludes(); + if (log.isTraceEnabled()) { + log.trace("BuildData: {}", webAppBuildData); } - - if (data.hasReference()) { - addHybridBuilder( buildProcess - , getLastResourceLayer(buildProcess, parentLayer) - , fh); + if (null != webAppBuildData.getWorkingDir()) { + // set CurrentWorkingDirectory (cwd) absolute path + String canonicalPath = null; + try { + canonicalPath = this.workingDir.getCanonicalPath(); + buildWebAppModule.setCwd(canonicalPath); + log.trace("canonicalPath:{}", canonicalPath); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } - if (data.isOptimize()) { - addOptimizingBuilders(buildProcess - , getLastResourceLayer(buildProcess, parentLayer) - , fh); - } + // TODO implement build process with BuildProcess - addLastbuilder(buildProcess, getLastResourceLayer(buildProcess, parentLayer)); - } - - - /** - * Add optimizing builders to buildProcess. - * @param buildProcess - * @param parentLayer - */ - private void addOptimizingBuilders(BuildProcess buildProcess, ResourceLayer parentLayer, FileHandler fh) { - if (buildProcess == null) { - return; + 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.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) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); } - // add js minify builder - ResourceLayer jsMinLayer = new ResourceLayer(JSMinifyBuilder.RESOURCE_LAYER_NAME - , parentLayer - , fh); - JSMinifyBuilder jsMin = new JSMinifyBuilder(jsMinLayer); - buildProcess.addBuilder(jsMin); - - // add css minify builder - ResourceLayer cssMinLayer = new ResourceLayer(CssMinifyBuilder.RESOURCE_LAYER_NAME - , jsMinLayer - , fh); - CssMinifyBuilder cssMin = new CssMinifyBuilder(cssMinLayer); - buildProcess.addBuilder(cssMin); - } - - /** - * Add hybrid builder to buildProcess. It will be used to build including reference project. - * @param cmdLine - * @param buildProcess - * @param lastLayer - * @throws IOException - */ - private void addHybridBuilder(BuildProcess buildProcess, ResourceLayer lastLayer, FileHandler fh) throws IOException { - ResourceLayer layer = new ResourceLayer(HybridAppCLIBuilder.RESOURCE_LAYER_NAME - , lastLayer - , fh); - - String refPath = ""; //TODO add HybridOption! convertPath(cmdLine.getOptionValue(OPT_NAME_REFERENCE_PROJECT)); - - HybridAppCLIBuilder hybridAppBuilder = new HybridAppCLIBuilder( layer, refPath ); - buildProcess.addBuilder(hybridAppBuilder); - } - - /** - * get last resource layer located in buildProcess. - * @param buildProcess - * @param defaultLayer - * @return - */ - private ResourceLayer getLastResourceLayer(BuildProcess buildProcess, ResourceLayer defaultLayer) { - ResourceLayer lastLayer = buildProcess.getLastResourceLayer(); - return (lastLayer != null) ? lastLayer : defaultLayer; + return webAppBuildData; } /** - * Add UI framework builder to buildProcess. - * @param isExclude If set true, Tizen web UI framework library will be excluded output path. - * Application will be used target's Tizen web UI framework library. - * @param useMin If 'isExclude' parameter set true and this parameter set true, - * application will be used target's minified Tizen web UI framework library. - * Or, application will be used target's original Tizen web UI framework library. - * @param buildProcess - * @param parentLayer - */ - private void addUIFWBuilder(boolean isExclude, boolean useMin, BuildProcess buildProcess, - ResourceLayer parentLayer, FileHandler fh) { - ResourceLayer layer = new ResourceLayer(UIFWBuilder.RESOURCE_LAYER_NAME - , parentLayer - , fh); - UIFWBuilder uifwBuilder = new UIFWBuilder(isExclude, layer); - uifwBuilder.setUseMin(useMin); - - buildProcess.addBuilder(uifwBuilder); - } - - /** - * Add builder that write resources to file system to buildProcess. - * @param buildProcess - * @param parentLayer - */ - private void addLastbuilder(BuildProcess buildProcess, ResourceLayer parentLayer) { - // add file output builder - FileHandler fh = new StandardFileHandler(); - fh.setCurrentWorkingDirectory(parentLayer.getFileHandler().getCurrentWorkingDirectory()); - ResourceLayer toFSLayer = new ResourceLayer(CopyBuilder.RESOURCE_LAYER_NAME - , parentLayer - , fh); - CopyBuilder toFSBuilder = new CopyBuilder(FilenameUtil.getRelativePath(cwd, output), toFSLayer); - buildProcess.addBuilder(toFSBuilder); - } - - /** - * Check whether this process have no problem. - * If have problems, BuildException will be occurred. + * Convert path to canonical path + * + * @param path + * relative or abstract path * - * @param buildProcess - * @throws BuildException + * @return canonical path + * + * @throws IOException + * If file system deny request */ - protected void checkProcessComplete(BuildProcess buildProcess) throws Exception { - // Check hybrid structure. If a manifest file and a binary file are not found, this is a failure. - try { - Builder builder = buildProcess.getBuilder( HybridAppCLIBuilder.RESOURCE_LAYER_NAME ); - if ( builder != null ) { - HybridAppCLIBuilder hybridBuilder = (HybridAppCLIBuilder) builder; - if ( ! hybridBuilder.isManifestFound() ) { - throw new IOException( HybridAppCLIBuilder.ERROR_MANIFEST_NOT_FOUND ); - } - if ( ! hybridBuilder.isBinaryFound() ) { - throw new IOException( HybridAppCLIBuilder.ERROR_BINARY_NOT_FOUND ); - } - } - } catch( IOException e ) { - throw new Exception( e ); + protected String convertPath(final String path) throws IOException { + String target = path; + if ((!OSChecker.isWindows()) && target.startsWith("~" + File.separator)) { + target = path.replaceFirst("~", System.getProperty("user.home")); } - - //TODO Notification ?? getPrompter().notify( MessageFormat.format( SUCCEED_MSG, this.output ) ); + final FileHandler fileHandler = new StandardFileHandler(); + return (String) fileHandler.get(target, Attribute.PATH); } - - /** - * Convert path to canonical path - * - * @param path relative or abstract path - * - * @return canonical path - * - * @throws IOException If file system deny request - */ - protected - String - convertPath( - final String path - ) - throws IOException - { - String target = path; - if ((!OSChecker.isWindows()) - && target.startsWith("~"+File.separator)) { - target = path.replaceFirst("~", System.getProperty("user.home")); - } - final FileHandler fileHandler = new StandardFileHandler(); - return (String) fileHandler.get( target, Attribute.PATH ); - } - + private void initExcludes() { - this.excludes.clear(); + this.buildWebAppModule.excludes.clear(); +//FIXME +// for (String exclude : DEFAULT_EXCLUDES) { +// this.webAppBuild.excludes.add(exclude); +// webAppBuild.filter.addExcludes(webAppBuild.filterFactory.create(exclude)); +// } +// +// List excludeList = webAppBuildData.getExcludeList(); +// for (String exclude : excludeList) { +// this.webAppBuild.excludes.add(exclude); +// webAppBuild.filter.addExcludes(webAppBuild.filterFactory.create(exclude)); +// } +// +// if (webAppBuildData.isExcludeUIFW()) { +// this.webAppBuild.excludes.add(WebConstant.TIZEN_WEB_UI_FRAMWORK_LIBRARY_DIRECTORY + File.separator + "*"); +// webAppBuild.filter.addExcludes(webAppBuild.filterFactory +// .create(WebConstant.TIZEN_WEB_UI_FRAMWORK_LIBRARY_DIRECTORY + File.separator + "*")); +// } + } - for (String exclude : DEFAULT_EXCLUDES) { - this.excludes.add(exclude); - filter.addExcludes(filterFactory.create(exclude)); - } + // ======================================================== END - List excludeList = data.getExcludeList(); - for (String exclude : excludeList) { - this.excludes.add(exclude); - filter.addExcludes(filterFactory.create(exclude)); - } + private void printOptions() { + // TODO Auto-generated method stub - if (data.isExcludeUIFW()) { - this.excludes.add(WebConstant.TIZEN_WEB_UI_FRAMWORK_LIBRARY_DIRECTORY+File.separator+"*"); - filter.addExcludes(filterFactory.create(WebConstant.TIZEN_WEB_UI_FRAMWORK_LIBRARY_DIRECTORY+File.separator+"*")); - } } - - - - - - //======================================================== END - private void printOptions() { - // TODO Auto-generated method stub - - } + public void setOptimize(boolean optimize) { + this.webAppBuildData.setOptimize(optimize); + } - public void setOptimize(boolean optimize) { - this.data.setOptimize(optimize); - } + public void setOutputName(String outputName) { + this.webAppBuildData.setOutputName(outputName); + } - public void setOutputName(String outputName) { - this.data.setOutputName(outputName); - } + public void setExcludeUIFW(boolean excludeUIFW) { + this.webAppBuildData.setExcludeUIFW(excludeUIFW); + } - public void setExcludeUIFW(boolean excludeUIFW) { - this.data.setExcludeUIFW(excludeUIFW); - } + public void setExcludeList(List excludeList) { + this.webAppBuildData.setExcludeList(excludeList); + } - public void setExcludeList(List excludeList) { - this.data.setExcludeList(excludeList); - } - - @Override - public void setTargetPath(File targetPath) { - this.data.setTargetPath(targetPath); - } + @Override + public void setWorkingDir(File targetPath) { + super.setWorkingDir(targetPath); + this.webAppBuildData.setWorkingDir(targetPath); + } - public void setReferences(File...refs) { - this.data.setReferences(refs); - } + public void setReferences(File... refs) { + this.webAppBuildData.setReferences(refs); + } } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandData.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandData.java deleted file mode 100644 index 78e97e0..0000000 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandData.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.tizen.ncli.ide.subcommands; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -public class BuildWebCLICommandData { - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("BuildWebCLICommandData [optimize="); - builder.append(optimize); - builder.append(", excludeUIFW="); - builder.append(excludeUIFW); - builder.append(", excludeList="); - builder.append(excludeList); - builder.append(", outputName="); - builder.append(outputName); - builder.append(", targetPath="); - builder.append(targetPath); - builder.append("]"); - return builder.toString(); - } - - private boolean optimize; - private boolean excludeUIFW; - private List excludeList = new ArrayList(); - private String outputName; - private File targetPath; - private File[] refs; - - public BuildWebCLICommandData() { - } - - public boolean isOptimize() { - return optimize; - } - - public void setOptimize(boolean optimize) { - this.optimize = optimize; - } - - public boolean isExcludeUIFW() { - return excludeUIFW; - } - - public void setExcludeUIFW(boolean excludeUIFW) { - this.excludeUIFW = excludeUIFW; - } - - public List getExcludeList() { - return excludeList; - } - - public void setExcludeList(List excludeList) { - this.excludeList = excludeList; - } - - public String getOutputName() { - return outputName; - } - - public void setOutputName(String outputName) { - this.outputName = outputName; - } - - public void setTargetPath(File targetPath) { - this.targetPath = targetPath; - - } - - public void setReferences(File...refs) { - this.refs = refs; - } - - public boolean hasReference() { - if( null != this.refs && this.refs.length > 0) { - return true; - }else { - return false; - } - } -} \ No newline at end of file diff --git a/org.tizen.ncli.ide/test/src/org/tizen/core/ide/BuildWebAppModuleTest.java b/org.tizen.ncli.ide/test/src/org/tizen/core/ide/BuildWebAppModuleTest.java new file mode 100644 index 0000000..244939e --- /dev/null +++ b/org.tizen.ncli.ide/test/src/org/tizen/core/ide/BuildWebAppModuleTest.java @@ -0,0 +1,139 @@ +/* + * IDE + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyeongseok Heo + * Kangho Kim + * + * 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.core.ide; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.common.builder.exception.BuildException; +import org.tizen.common.util.FileUtil; + +/** + * Test Case for {@link BuildWebAppModule} + * @author Harry Hyeongseok Heo{@literal } (S-core) + * + * + */ +public class BuildWebAppModuleTest { + private static final String TEST_PROJECT = "test/resources/testProject"; + + private Logger log = LoggerFactory.getLogger(getClass()); + + private String output = ".buildResult"; + + private File cwdFile; + + /** + * Test method for {@link org.tizen.core.ide.BuildWebAppModule#setCwd(java.lang.String)}. + */ + @Ignore + @Test + public void testSetCwd() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.tizen.core.ide.BuildWebAppModule#setOutput(java.lang.String)}. + */ + @Ignore + @Test + public void testSetOutput() { + fail("Not yet implemented"); + } + /** + * Test method for {@link org.tizen.core.ide.BuildWebAppModule#setExcludes(java.util.List)}. + */ + @Ignore + @Test + public void testSetExcludes() { + fail("Not yet implemented"); + } + + @Before + public void checkBeforeTest() { + cwdFile = new File(TEST_PROJECT); + log.trace("cwd:{}",cwdFile.getAbsolutePath()); + log.trace("Exist? {}",cwdFile.exists()); + //In case of out of container test , the test will be ignored. + Assume.assumeTrue(cwdFile.exists()); + } + + /** + * Test method for {@link org.tizen.core.ide.BuildWebAppModule#buildResources()}. + */ + @Test + public void test_buildResources_exclude() { + BuildWebAppModule testObject = new BuildWebAppModule(); + testObject.setCwd(cwdFile.getAbsolutePath()); + + // Setting build parameters + List excludes = new ArrayList(); + excludes.add("section1.html"); + BuildWebParameter buildParameter = new BuildWebParameter(); + buildParameter.setExcludeList(excludes); + testObject.setData(buildParameter); + + try { + // Test method call + testObject.buildResources(); + + // Assertion + File excludeFile = new File(TEST_PROJECT + File.separator + output + File.separator + "section1.html"); + assertFalse(excludeFile.exists()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (BuildException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + fail(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + @After + public void tearDown() { + File outputDir = new File(TEST_PROJECT+File.separator+output); + if( outputDir.exists()) { + FileUtil.recursiveDelete(outputDir); + } + } + +} diff --git a/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandCallTest.java b/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandCallTest.java index a838c33..a77a7be 100644 --- a/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandCallTest.java +++ b/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandCallTest.java @@ -1,98 +1,117 @@ -/* - * IDE - * - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * Hyeongseok Heo - * Kangho Kim - * - * 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.ncli.ide.subcommands; - -import static org.junit.Assert.*; - -import java.io.File; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.tizen.common.util.FileUtil; -import org.tizen.ncli.ide.core.config.TizenCLIConfigProvider; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.powermock.api.mockito.PowerMockito.doAnswer; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.spy; -import static org.powermock.api.mockito.PowerMockito.when; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.whenNew; - -/** - * Test main logic of {@link BuildWebCLICommand#call()} - * @author Harry Hyeongseok Heo{@literal } (S-core) - * - * - */ -@PowerMockIgnore({ "org.apache.log4j.*", "org.slf4j.Logger" }) -@RunWith(PowerMockRunner.class) -public class BuildWebCLICommandCallTest { - - @BeforeClass - public static void setUpOnlyOnce() { - } - - /** - * Test method for {@link org.tizen.ncli.ide.subcommands.BuildWebCLICommand#call()}. - * Test with testProject if build output is correct as expected. - */ - @Test - public void testCall() { - File testProject = mock(File.class); - - - BuildWebCLICommand command = new BuildWebCLICommand(); - command.setTargetPath(testProject); - command.setOutputName("test/resources/testProject/testBuildOutput"); - command.setOptimize(true); - command.setExcludeUIFW(true); - - BuildWebCLICommandData buildData = command.runCommand(); - assertNotNull(buildData); - -// File outputFolder = buildData.getResult(); - - - } - -// @AfterClass - public static void tearDownOnlyOnce() { - File testProject = mock(File.class); - - if( null != testProject && testProject.exists()) { - - FileUtil.recursiveDelete(testProject); - } - } - -} +/* + * IDE + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyeongseok Heo + * Kangho Kim + * + * 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.ncli.ide.subcommands; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.tizen.common.util.FileUtil; +import org.tizen.core.ide.BuildWebParameter; +import org.tizen.ncli.ide.core.config.TizenCLIConfigProvider; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.powermock.api.mockito.PowerMockito.doAnswer; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.spy; +import static org.powermock.api.mockito.PowerMockito.when; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.whenNew; + +/** + * Test main logic of {@link BuildWebCLICommand#call()} + * + * @author Harry Hyeongseok Heo{@literal } (S-core) + * + * + */ +@PowerMockIgnore({ "org.apache.log4j.*", "org.slf4j.Logger" }) +@RunWith(PowerMockRunner.class) +public class BuildWebCLICommandCallTest { + + @BeforeClass + public static void setUpOnlyOnce() { + } + + /** + * Test method for {@link org.tizen.ncli.ide.subcommands.BuildWebCLICommand#call()}. Test with testProject if build + * output is correct as expected. + * @throws Exception + */ + @Ignore + @Test + public void testCall() throws Exception { + // Prepare for test + File workingProject = mock(File.class); + whenNew(File.class).withArguments("/testProject").thenReturn(workingProject); + when(workingProject.getCanonicalPath()).thenReturn("/testProject"); + when(workingProject.isDirectory()).thenReturn(Boolean.TRUE); + when(workingProject.exists()).thenReturn(Boolean.TRUE); + when(workingProject.canRead()).thenReturn(Boolean.TRUE); + + + + workingProject = new File("/testProject"); + + BuildWebCLICommand command = new BuildWebCLICommand(); + command.setWorkingDir(workingProject); + command.setOutputName("testBuildOutput"); + command.setOptimize(true); + command.setExcludeUIFW(true); + + + + // Execute test method + BuildWebParameter buildData = command.runCommand(); + + // Assertion the result + assertNotNull(buildData); + + // File outputFolder = buildData.getResult(); + + } + + // @AfterClass + public static void tearDownOnlyOnce() { + File testProject = mock(File.class); + + if (null != testProject && testProject.exists()) { + + FileUtil.recursiveDelete(testProject); + } + } + +} diff --git a/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandTest.java b/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandTest.java index d609bc5..f16b6ea 100644 --- a/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandTest.java +++ b/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/BuildWebCLICommandTest.java @@ -31,72 +31,71 @@ import java.util.ArrayList; import java.util.List; import org.junit.Test; +import org.tizen.core.ide.BuildWebParameter; /** * Test basic method of {@link BuildWebCLICommand} * * @author Harry Hyeongseok Heo{@literal } (S-core) - * + * * */ public class BuildWebCLICommandTest { - + /** + * Test method for {@link org.tizen.ncli.ide.subcommands.BuildWebCLICommand#setOptimize(boolean)}. + */ + @Test + public void testSetOptimize() { + BuildWebCLICommand command = new BuildWebCLICommand(); + command.setOptimize(false); + + BuildWebParameter buildData = command.runCommand(); + assertNotNull(buildData); + assertEquals(false, buildData.isOptimize()); + + } + + /** + * Test method for {@link org.tizen.ncli.ide.subcommands.BuildWebCLICommand#setOutputName(java.lang.String)}. + */ + @Test + public void testSetOutputName() { + BuildWebCLICommand command = new BuildWebCLICommand(); + command.setOutputName("TestBuildResult"); + + BuildWebParameter buildData = command.runCommand(); + assertNotNull(buildData); + assertEquals("TestBuildResult", buildData.getOutputName()); + } + + /** + * Test method for {@link org.tizen.ncli.ide.subcommands.BuildWebCLICommand#setExcludeUIFW(boolean)}. + */ + @Test + public void testSetExcludeUIFW() { + BuildWebCLICommand command = new BuildWebCLICommand(); + command.setExcludeUIFW(true); - /** - * Test method for {@link org.tizen.ncli.ide.subcommands.BuildWebCLICommand#setOptimize(boolean)}. - */ - @Test - public void testSetOptimize() { - BuildWebCLICommand command = new BuildWebCLICommand(); - command.setOptimize(false); - - BuildWebCLICommandData buildData = command.runCommand(); - assertNotNull(buildData); - assertEquals(false, buildData.isOptimize()); - - } + BuildWebParameter buildData = command.runCommand(); + assertNotNull(buildData); + assertEquals(true, buildData.isExcludeUIFW()); + } - /** - * Test method for {@link org.tizen.ncli.ide.subcommands.BuildWebCLICommand#setOutputName(java.lang.String)}. - */ - @Test - public void testSetOutputName() { - BuildWebCLICommand command = new BuildWebCLICommand(); - command.setOutputName("TestBuildResult"); - - BuildWebCLICommandData buildData = command.runCommand(); - assertNotNull(buildData); - assertEquals("TestBuildResult", buildData.getOutputName()); - } + /** + * Test method for {@link org.tizen.ncli.ide.subcommands.BuildWebCLICommand#setExcludeList(java.util.List)}. + */ + @Test + public void testSetExcludeList() { + BuildWebCLICommand command = new BuildWebCLICommand(); + List excludeList = new ArrayList(); + excludeList.add(".git"); - /** - * Test method for {@link org.tizen.ncli.ide.subcommands.BuildWebCLICommand#setExcludeUIFW(boolean)}. - */ - @Test - public void testSetExcludeUIFW() { - BuildWebCLICommand command = new BuildWebCLICommand(); - command.setExcludeUIFW(true); - - BuildWebCLICommandData buildData = command.runCommand(); - assertNotNull(buildData); - assertEquals(true, buildData.isExcludeUIFW()); - } + command.setExcludeList(excludeList); - /** - * Test method for {@link org.tizen.ncli.ide.subcommands.BuildWebCLICommand#setExcludeList(java.util.List)}. - */ - @Test - public void testSetExcludeList() { - BuildWebCLICommand command = new BuildWebCLICommand(); - List excludeList = new ArrayList(); - excludeList.add(".git"); - - command.setExcludeList(excludeList); - - BuildWebCLICommandData buildData = command.runCommand(); - assertNotNull(buildData); - assertEquals(".git", buildData.getExcludeList().get(0)); - } + BuildWebParameter buildData = command.runCommand(); + assertNotNull(buildData); + assertEquals(".git", buildData.getExcludeList().get(0)); + } } diff --git a/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/ConfigCommandTest.java b/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/ConfigCommandTest.java index 7546cc2..07447c8 100644 --- a/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/ConfigCommandTest.java +++ b/org.tizen.ncli.ide/test/src/org/tizen/ncli/ide/subcommands/ConfigCommandTest.java @@ -58,76 +58,73 @@ import org.tizen.ncli.ide.core.config.TizenCLIConfigProvider; * Test class for {@link ConfigCLICommand}
    * * In this class , setting global or local configuration is tested. + * * @author Harry Hyeongseok Heo{@literal } (S-core) * */ @PowerMockIgnore({ "org.apache.log4j.*", "org.slf4j.Logger" }) @RunWith(PowerMockRunner.class) @PrepareForTest(NCLIConfigLoader.class) -public class ConfigCommandTest extends CommonCLISubCommandTest{ - - @Before - public void setUp(){ - - - } - - @PrepareForTest({NCLIConfigLoader.class,ConfigCLICommand.class}) +public class ConfigCommandTest extends CommonCLISubCommandTest { + + @Before + public void setUp() { + + } + + @PrepareForTest({ NCLIConfigLoader.class, ConfigCLICommand.class }) @Test public void test_setLocalConfig() throws Exception { - - File testFile = mock(File.class); - whenNew(File.class).withAnyArguments().thenReturn(testFile); - when(testFile.getName()).thenReturn(".tizen-cli-config"); - when(testFile.getPath()).thenReturn("/tizen-sdk/tools/.tizen-cli-config"); - when(testFile.exists()).thenReturn(true); - when(testFile.canWrite()).thenReturn(true); - - FileOutputStream mockFileOutputStream = mock(FileOutputStream.class); - whenNew(FileOutputStream.class).withAnyArguments().thenReturn(mockFileOutputStream); - - //Mocking NCLIConfigLoader - mockStatic(NCLIConfigLoader.class); - when(NCLIConfigLoader.getLocalConfigFile()).thenReturn(testFile); - when(NCLIConfigLoader.loadLocalConf()).thenReturn(testLocalProp); - - - - ConfigCLICommand configCmd = new ConfigCLICommand(); - - configCmd.setConfig("local.key.test", "this is LOCAL test value"); - //method for test + + File testFile = mock(File.class); + whenNew(File.class).withAnyArguments().thenReturn(testFile); + when(testFile.getName()).thenReturn(".tizen-cli-config"); + when(testFile.getPath()).thenReturn("/tizen-sdk/tools/.tizen-cli-config"); + when(testFile.exists()).thenReturn(true); + when(testFile.canWrite()).thenReturn(true); + + FileOutputStream mockFileOutputStream = mock(FileOutputStream.class); + whenNew(FileOutputStream.class).withAnyArguments().thenReturn(mockFileOutputStream); + + // Mocking NCLIConfigLoader + mockStatic(NCLIConfigLoader.class); + when(NCLIConfigLoader.getLocalConfigFile()).thenReturn(testFile); + when(NCLIConfigLoader.loadLocalConf()).thenReturn(testLocalProp); + + ConfigCLICommand configCmd = new ConfigCLICommand(); + + configCmd.setConfig("local.key.test", "this is LOCAL test value"); + // method for test Configuration cliConfig = configCmd.call(); assertEquals("this is LOCAL test value", cliConfig.getLocalValue("local.key.test")); - - + } - - @PrepareForTest({NCLIConfigLoader.class , ConfigCLICommand.class}) + + @PrepareForTest({ NCLIConfigLoader.class, ConfigCLICommand.class }) @Test public void test_setGlobalConfig() throws Exception { - File testFile = mock(File.class); + File testFile = mock(File.class); whenNew(File.class).withAnyArguments().thenReturn(testFile); when(testFile.getName()).thenReturn(".tizen-cli-config"); when(testFile.getPath()).thenReturn("/home/user/.tizen-cli-config"); when(testFile.exists()).thenReturn(true); when(testFile.canWrite()).thenReturn(true); - + FileOutputStream mockFileOutputStream = mock(FileOutputStream.class); whenNew(FileOutputStream.class).withAnyArguments().thenReturn(mockFileOutputStream); - - //Mocking NCLIConfigLoader + + // Mocking NCLIConfigLoader mockStatic(NCLIConfigLoader.class); when(NCLIConfigLoader.getGlobalConfigFile()).thenReturn(testFile); when(NCLIConfigLoader.loadGlobalConf()).thenReturn(testGlobalProp); - + ConfigCLICommand configCmd = new ConfigCLICommand(); - + configCmd.setConfig("global.key.test", "this is GLOBAL test value"); configCmd.setGlobal(true); - //method for test - Configuration cliConfig = configCmd.call(); - assertEquals("this is GLOBAL test value", cliConfig.getGlobalValue("global.key.test")); + // method for test + Configuration cliConfig = configCmd.call(); + assertEquals("this is GLOBAL test value", cliConfig.getGlobalValue("global.key.test")); } } -- 2.7.4