From: Taeyoung Son Date: Fri, 23 May 2014 07:26:44 +0000 (+0900) Subject: BUILD: Refactored old cli about web build X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F74%2F21574%2F1;p=sdk%2Ftools%2Fcli.git BUILD: Refactored old cli about web build Refactored old cli about web build Change-Id: I263bb8d02d3c4fd9179c1ed54d11735a7752c6e7 Signed-off-by: Taeyoung Son --- diff --git a/org.tizen.cli/src/org/tizen/cli/exec/web/build/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/web/build/Main.java index c5afc84..a3a5752 100755 --- a/org.tizen.cli/src/org/tizen/cli/exec/web/build/Main.java +++ b/org.tizen.cli/src/org/tizen/cli/exec/web/build/Main.java @@ -39,23 +39,23 @@ import org.tizen.cli.exec.Help; import org.tizen.cli.exec.pack.CLIMultiPackager; 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.IBuilder; import org.tizen.common.builder.ResourceLayer; import org.tizen.common.builder.core.CopyBuilder; import org.tizen.common.core.command.CommandCancelException; import org.tizen.common.file.FileHandler; import org.tizen.common.file.FileHandler.Attribute; import org.tizen.common.file.Filter; +import org.tizen.common.file.IResource; +import org.tizen.common.file.Resource; 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.FileUtil; import org.tizen.common.util.FilenameUtil; -import org.tizen.web.builder.CssMinifyBuilder; +import org.tizen.web.builder.BuilderFactory; 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; @@ -113,12 +113,7 @@ extends AbstractLauncher protected static final String RESOURCE_LAYER_END = "end"; // file filter. If you want to exclude a directory, append '/*' - private static final String[] DEFAULT_EXCLUDES = {".build/*" - , ".project" - , ".settings/*" - , ".sdk_delta.info" - , "*.wgt" - , ".buildResult/*"}; + private static final String[] DEFAULT_EXCLUDES = WebConstant.DEFAULT_EXCLUDING_RESOURCES; // excluding file list private List excludes = new ArrayList(); @@ -185,16 +180,14 @@ extends AbstractLauncher // Set start layer FileHandler fh = new StandardFileHandler(); fh.setCurrentWorkingDirectory(cwd); - ResourceLayer startLayer = new ResourceLayer(RESOURCE_LAYER_START, fh); // Get resource list for build - Resource[] resources = getBuildResources(cmdLine - , startLayer + IResource[] resources = getBuildResources(cmdLine , null , excludes.toArray(new String[excludes.size()])); // Generate web builders to build process - generateAllBuilders(cmdLine, buildProcess, startLayer); + generateAllBuilders(cmdLine, buildProcess); if (buildProcess.getLastBuilder() != null) { logger.debug("start build process"); @@ -325,7 +318,7 @@ extends AbstractLauncher protected void checkProcessComplete(BuildProcess buildProcess) throws BuildException { // 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 ); + IBuilder builder = buildProcess.getBuilder(HybridAppCLIBuilder.class); if ( builder != null ) { HybridAppCLIBuilder hybridBuilder = (HybridAppCLIBuilder) builder; if ( ! hybridBuilder.isManifestFound() ) { @@ -341,7 +334,7 @@ extends AbstractLauncher getPrompter().notify( MessageFormat.format( SUCCEED_MSG, this.output ) ); } - + private void initExcludes(CommandLine cmdLine) { this.excludes.clear(); @@ -349,6 +342,15 @@ extends AbstractLauncher this.excludes.add(exclude); } + if (isExcludeUIFW(cmdLine)) { + this.excludes.add(WebConstant.TIZEN_WEB_UI_FRAMWORK_LIBRARY_DIRECTORY); + this.excludes.add(WebConstant.TIZEN_WEB_UI_FRAMWORK_LIBRARY_DIRECTORY+"/*"); + } + + String[] cwdFragments = FilenameUtil.getCanonicalFragments(cwd); + + this.excludes.add(cwdFragments[cwdFragments.length-1]+".wgt"); + if (cmdLine.hasOption(OPT_NAME_EXCLUDE)) { String[] excludes = cmdLine.getOptionValues(OPT_NAME_EXCLUDE); for (String exclude : excludes) { @@ -369,17 +371,15 @@ extends AbstractLauncher * @throws IOException */ public void generateAllBuilders(CommandLine cmdLine - , BuildProcess buildProcess - , ResourceLayer parentLayer) throws IOException { + , BuildProcess buildProcess) throws IOException { FileHandler fh = new VirtualFileHandler(); - fh.setCurrentWorkingDirectory(parentLayer.getFileHandler().getCurrentWorkingDirectory()); + fh.setCurrentWorkingDirectory(cwd); if (isExcludeUIFW(cmdLine)) { addUIFWBuilder(true , cmdLine.hasOption(OPT_NAME_EXCLUDE_UI_FRAMEWORK_USEMIN) , buildProcess - , getLastResourceLayer(buildProcess, parentLayer) , fh); } @@ -387,17 +387,15 @@ extends AbstractLauncher if (hasReference) { addHybridBuilder( cmdLine , buildProcess - , getLastResourceLayer(buildProcess, parentLayer) , fh); } if (cmdLine.hasOption(OPT_NAME_OPTIMIZE)) { addOptimizingBuilders(buildProcess - , getLastResourceLayer(buildProcess, parentLayer) , fh); } - addLastbuilder(buildProcess, getLastResourceLayer(buildProcess, parentLayer)); + addLastbuilder(buildProcess); } /** @@ -421,10 +419,7 @@ extends AbstractLauncher * @param lastLayer * @throws IOException */ - private void addHybridBuilder(CommandLine cmdLine, BuildProcess buildProcess, ResourceLayer lastLayer, FileHandler fh) throws IOException { - ResourceLayer layer = new ResourceLayer(HybridAppCLIBuilder.RESOURCE_LAYER_NAME - , lastLayer - , fh); + private void addHybridBuilder(CommandLine cmdLine, BuildProcess buildProcess, FileHandler fh) throws IOException { String refPath = null; String[] refProjects = getReferenceProjects(); if ((refProjects != null) @@ -434,19 +429,8 @@ extends AbstractLauncher refPath = 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; + HybridAppCLIBuilder hybridAppBuilder = new HybridAppCLIBuilder(fh, cwd, refPath); + buildProcess.addBuilders(hybridAppBuilder); } /** @@ -459,31 +443,21 @@ extends AbstractLauncher * @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); + private void addUIFWBuilder(boolean isExclude, boolean useMin, BuildProcess buildProcess, FileHandler fh) { + UIFWBuilder uifwBuilder = new UIFWBuilder(isExclude, fh); uifwBuilder.setUseMin(useMin); - buildProcess.addBuilder(uifwBuilder); + buildProcess.addBuilders(uifwBuilder); } /** * Add builder that write resources to file system to buildProcess. * @param buildProcess - * @param parentLayer */ - private void addLastbuilder(BuildProcess buildProcess, ResourceLayer parentLayer) { + private void addLastbuilder(BuildProcess buildProcess) { // 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); + CopyBuilder toFSBuilder = new CopyBuilder(output); + buildProcess.addBuilders(toFSBuilder); } /** @@ -497,24 +471,17 @@ extends AbstractLauncher * @return * @throws IOException */ - private Resource[] getBuildResources(CommandLine cmdLine - , ResourceLayer layer + private IResource[] getBuildResources(CommandLine cmdLine , String[] includes , String[] excludes) throws IOException { - List resources = new ArrayList(); + List resources = new ArrayList(); setIncludes(includes); setExcludes(excludes); - String cwd = layer.getFileHandler().getCurrentWorkingDirectory(); - resources.addAll(getResources(cwd - , FilenameUtil.getRelativePath(cwd, cwd) - , layer)); + resources.addAll(getResources(cwd, FilenameUtil.getRelativePath(cwd, cwd))); 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 refRootPath = null; String[] refProjects = getReferenceProjects(); if ((refProjects != null) @@ -526,11 +493,10 @@ extends AbstractLauncher refFh.setCurrentWorkingDirectory(refRootPath); resources.addAll(getResources(refRootPath - , FilenameUtil.getRelativePath(refRootPath, refRootPath) - , referenceLayer)); + , FilenameUtil.getRelativePath(refRootPath, refRootPath))); } - return resources.toArray(new Resource[resources.size()]); + return resources.toArray(new IResource[0]); } /** @@ -540,11 +506,12 @@ extends AbstractLauncher * @param layer {@link ResourceLayer} about resource * @throws IOException */ - private List getResources(String cwd, String relativeSrcDir, ResourceLayer layer) throws IOException { - List resources = new ArrayList(); + private List getResources(String cwd, String relativeSrcDir) throws IOException { + List resources = new ArrayList(); List files = null; - String absoluteDir = cwd+ File.separator + relativeSrcDir; + String absoluteDir = FileUtil.appendPath(cwd, relativeSrcDir); files = FileUtil.findFiles(new File(absoluteDir), ".*", true); + FileHandler fh = new StandardFileHandler(cwd); for (File file : files) { String fileRelativePath = FilenameUtil.getRelativePath(cwd, file.getCanonicalPath()); @@ -556,7 +523,7 @@ extends AbstractLauncher } logger.debug("resource path : {}", fileRelativePath); - Resource resource = new Resource(layer, fileRelativePath); + IResource resource = new Resource(fh, fileRelativePath); resources.add(resource); } @@ -594,24 +561,12 @@ extends AbstractLauncher * @param buildProcess * @param parentLayer */ - private void addOptimizingBuilders(BuildProcess buildProcess, ResourceLayer parentLayer, FileHandler fh) { + private void addOptimizingBuilders(BuildProcess buildProcess, 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); + buildProcess.addBuilders(BuilderFactory.generateCompressBuilders(fh.getCurrentWorkingDirectory())); } @Override