From: Taeyoung Son Date: Mon, 6 May 2013 06:45:58 +0000 (+0900) Subject: [Title] added minify fuction to web-package command. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b2cc57bca1c7dea90a54524661c3c335525c2003;p=sdk%2Ftools%2Fcli.git [Title] added minify fuction to web-package command. [Desc.] [Issue] Change-Id: I2437049148ecbd0baa72109a6d06c99b33e19552 --- diff --git a/.gitignore b/.gitignore index fd9ed35..a18a8b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,20 @@ +#library files +lib +native-lib + #binary files +dist/ +build build_result bin *.class -common-eplugin_*.tar.gz -common-eplugin_*_*.zip -common-eplugin.package.linux -common-eplugin.package.windows +web-cli_*.tar.gz +native-cli_*.tar.gz +web-cli_*_*.zip +native-cli_*_*.zip +web-cli.package.linux +native-cli.package.windows +*.package.* #log files .log diff --git a/org.tizen.cli/META-INF/MANIFEST.MF b/org.tizen.cli/META-INF/MANIFEST.MF index 7106b22..e973423 100755 --- a/org.tizen.cli/META-INF/MANIFEST.MF +++ b/org.tizen.cli/META-INF/MANIFEST.MF @@ -16,7 +16,8 @@ Require-Bundle: org.tizen.web.common, Bundle-ClassPath: ., lib/ant.jar, lib/commons-cli-1.2.jar -Import-Package: org.tizen.nativecommon, +Import-Package: org.tizen.common.builder, + org.tizen.nativecommon, org.tizen.nativecommon.build, org.tizen.nativecommon.exception, org.tizen.nativecommon.templateengine, @@ -26,4 +27,5 @@ Import-Package: org.tizen.nativecommon, org.tizen.nativecommon.templateengine.model, org.tizen.nativecommon.templateengine.process, org.tizen.nativecommon.templateengine.util, - org.tizen.nativecpp.misc.core + org.tizen.nativecpp.misc.core, + org.tizen.web.builder diff --git a/org.tizen.cli/src/org/tizen/cli/exec/wgt/Main.java b/org.tizen.cli/src/org/tizen/cli/exec/wgt/Main.java index 5802572..7538c9d 100755 --- a/org.tizen.cli/src/org/tizen/cli/exec/wgt/Main.java +++ b/org.tizen.cli/src/org/tizen/cli/exec/wgt/Main.java @@ -24,26 +24,30 @@ */ package org.tizen.cli.exec.wgt; +import static org.tizen.cli.exec.LaunchOptionConstants.DESC_EXCLUDE; +import static org.tizen.cli.exec.LaunchOptionConstants.DESC_INCLUDE; +import static org.tizen.cli.exec.LaunchOptionConstants.DESC_NOCHECK; +import static org.tizen.cli.exec.LaunchOptionConstants.DESC_OVERWRITE; +import static org.tizen.cli.exec.LaunchOptionConstants.OPT_EXCLUDE; +import static org.tizen.cli.exec.LaunchOptionConstants.OPT_INCLUDE; +import static org.tizen.cli.exec.LaunchOptionConstants.OPT_NOCHECK; +import static org.tizen.cli.exec.LaunchOptionConstants.OPT_OVERWRITE; + import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.List; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; - -import static org.tizen.cli.exec.LaunchOptionConstants.OPT_NOCHECK; -import static org.tizen.cli.exec.LaunchOptionConstants.DESC_NOCHECK; -import static org.tizen.cli.exec.LaunchOptionConstants.OPT_INCLUDE; -import static org.tizen.cli.exec.LaunchOptionConstants.DESC_INCLUDE; -import static org.tizen.cli.exec.LaunchOptionConstants.OPT_EXCLUDE; -import static org.tizen.cli.exec.LaunchOptionConstants.DESC_EXCLUDE; -import static org.tizen.cli.exec.LaunchOptionConstants.OPT_OVERWRITE; -import static org.tizen.cli.exec.LaunchOptionConstants.DESC_OVERWRITE; - import org.tizen.cli.exec.AbstractLauncher; import org.tizen.cli.exec.Help; +import org.tizen.common.builder.BuildProcess; +import org.tizen.common.builder.Resource; +import org.tizen.common.builder.ResourceLayer; import org.tizen.common.core.command.Executor; import org.tizen.common.core.command.Prompter; import org.tizen.common.core.command.prompter.ChoiceOption; @@ -51,8 +55,11 @@ import org.tizen.common.core.command.prompter.Option; import org.tizen.common.core.command.zip.ZipCommand; import org.tizen.common.file.FileHandler; import org.tizen.common.file.FileHandler.Attribute; +import org.tizen.common.file.VirtualFileHandler; import org.tizen.common.util.CollectionUtil; +import org.tizen.common.util.FileUtil; import org.tizen.common.util.FilenameUtil; +import org.tizen.web.builder.JavaScriptMinifier; import org.tizen.web.common.WebConstant; /** @@ -64,6 +71,17 @@ public class Main extends AbstractLauncher { + private static final String OPT_NAME_MINIFY = "minify"; + private static final String OPT_DESC_MINIFY = "Minify resources(js | css)"; + + //for build framework(org.tizen.common.builder) + protected static final String RESOURCE_LAYER_MINIFY = "minify"; + protected static final String RESOURCE_LAYER_MINIFY_JS = RESOURCE_LAYER_MINIFY+".js"; + protected static final String RESOURCE_LAYER_START = "start"; + protected static final String RESOURCE_LAYER_OPTIMIZE = "optimize"; + protected static final String RESOURCE_LAYER_END = "end"; + + /** * Entry point for cli main * @@ -98,6 +116,7 @@ extends AbstractLauncher opts.addOption( OptionBuilder.hasArg().withLongOpt( OPT_INCLUDE ).withDescription( DESC_INCLUDE ).create( OPT_INCLUDE.substring( 0, 1 ) ) ); opts.addOption( OptionBuilder.hasArg().withLongOpt( OPT_EXCLUDE ).withDescription( DESC_EXCLUDE ).create( OPT_EXCLUDE.substring( 0, 1 ) ) ); + opts.addOption( OptionBuilder.hasArg().withLongOpt( OPT_NAME_MINIFY ).withDescription( OPT_DESC_MINIFY ).create( OPT_NAME_MINIFY.substring( 0, 1 ) ) ); return opts; } @@ -116,7 +135,7 @@ extends AbstractLauncher final List args = cmdLine.getArgList(); logger.trace( "arguments :{}", args ); - int nArgs = args.size(); + int nArgs = args.size(); final File cwd = new File( "." ).getCanonicalFile(); @@ -181,12 +200,94 @@ extends AbstractLauncher if ( cmdLine.hasOption( OPT_OVERWRITE ) ) { - getFileHandler().removeFile( wgtPath ); - logger.info( "Old wgt file deleted" ); + if (exists(wgtPath)) { + getFileHandler().removeFile( wgtPath ); + logger.info( "Old wgt file deleted" ); + } else { + logger.info( "Old wgt file does not exist" ); + } + } else if (exists(wgtPath)) { + getPrompter().notify("Widget already exist."); + return; } - zipFiles( wgtPath, baseDir, includes, excludes ); - } + BuildProcess buildProcess = new BuildProcess(); + + ResourceLayer startLayer = new ResourceLayer("start", new VirtualFileHandler()); + addBuilders(cmdLine, buildProcess, startLayer); + + Resource[] resources = getResources(baseDir, startLayer, includes, excludes); + if (buildProcess.getLastBuilder() != null) { + logger.debug("start build process"); + buildProcess.build(resources); + } + zipFiles(wgtPath, baseDir, resources, includes, excludes); + } + + private Resource[] getResources(String baseDir, ResourceLayer resourceLayer, String[] includes, String[] excludes) throws IOException { + List files = FileUtil.findFiles(new File(baseDir), ".*", true); + List resources = new ArrayList(); + FileHandler fh = resourceLayer.getFileHandler(); + for (File file : files) { + Resource resource = new Resource(resourceLayer, file.getPath()); + + String dir = null; + if (file.isFile()) { + dir = file.getParent(); + } else { + dir = file.getPath(); + } + + if (fh instanceof VirtualFileHandler) { + ((VirtualFileHandler) fh).makeDirectory(dir, true); + } + + resource.setContents(new FileInputStream(file)); + resources.add(resource); + } + return resources.toArray(new Resource[resources.size()]); + } + + /** + * Archive baseDir to wgtPath including + * includes and excluding excludes + * + * @param wgtPath wgt file path + * @param baseDir directory to root + * @param includes includes file pattern + * @param excludes excludes file pattern + */ + private void zipFiles(final String wgtPath, final String baseDir, final Resource[] resources, final String[] includes, final String[] excludes) { + final ZipCommand command = new ZipCommand(baseDir, resources, wgtPath); + command.setIncludes(includes); + command.setExcludes(excludes); + + final Executor executor = getExecutor(); + executor.execute(command); + } + + private void addBuilders(CommandLine cmdLine, BuildProcess buildProcess, ResourceLayer parentLayer ) { + if (buildProcess == null | cmdLine == null) { + return; + } + /* + * 1. optimization builder + */ + String[] mins = cmdLine.getOptionValues(OPT_NAME_MINIFY); + if (mins != null) { + ResourceLayer optimizeLayer = new ResourceLayer(RESOURCE_LAYER_OPTIMIZE, parentLayer, parentLayer.getFileHandler()); + ResourceLayer minifyLayer = new ResourceLayer(RESOURCE_LAYER_MINIFY, optimizeLayer, parentLayer.getFileHandler()); + for (String minify : mins) { + if ("js".equals(minify)||"javascript".equals(minify)) { + ResourceLayer jsMinLayer = new ResourceLayer(RESOURCE_LAYER_MINIFY_JS, minifyLayer,parentLayer.getFileHandler()); + JavaScriptMinifier jsMin = new JavaScriptMinifier(jsMinLayer); + buildProcess.addBuilder(jsMin); + } else if ("css".equals(minify)) { + throw new UnsupportedOperationException("css minification could not support yet."); + } + } + } + } /** * Check if path exists @@ -227,7 +328,6 @@ extends AbstractLauncher return fileHandler.is( projectFilePath, Attribute.EXISTS ); } - /** * Return default excludes file patterns * @@ -239,7 +339,6 @@ extends AbstractLauncher return new String[] { ".*", "*.wgt" }; } - /** * Archive baseDir to wgtPath * @@ -248,7 +347,7 @@ extends AbstractLauncher * @param wgtPath wgt file path * @param baseDir directory to root * @param includes includes file pattern - * @param excludes excludes filee pattern + * @param excludes excludes file pattern */ protected void @@ -259,12 +358,7 @@ extends AbstractLauncher final String[] excludes ) { - final ZipCommand command = new ZipCommand( baseDir, wgtPath ); - command.setIncludes( includes ); - command.setExcludes( excludes ); - - final Executor executor = getExecutor(); - executor.execute( command ); + zipFiles(wgtPath, baseDir, null, includes, excludes); } /* (non-Javadoc) diff --git a/package/build.ubuntu-64 b/package/build.linux similarity index 67% rename from package/build.ubuntu-64 rename to package/build.linux index a50cc04..245a05f 100755 --- a/package/build.ubuntu-64 +++ b/package/build.linux @@ -36,64 +36,55 @@ native_build() { exit 1 ;; esac - LIB_SRC=`find ${ROOTDIR} -name "org.tizen.common_*" | head -1` - cp ${LIB_SRC} ${NATIVE_LIB} - jar -xvf $SRC ${NATIVE_LIB} - - LIB_SRC=`find ${ROOTDIR} -name "org.tizen.common.sign_*" | head -1` - cp ${LIB_SRC} ${NATIVE_LIB} - jar -xvf $SRC ${NATIVE_LIB} - - LIB_SRC=`find ${ROOTDIR} -name "org.tizen.nativecommon_*" | head -1` - cp ${LIB_SRC} ${NATIVE_LIB} - jar -xvf $SRC ${NATIVE_LIB} - - LIB_SRC=`find ${ROOTDIR} -name "org.tizen.nativecpp.misc_*" | head -1` - cp ${LIB_SRC} ${NATIVE_LIB} - jar -xvf $SRC ${NATIVE_LIB} + INCLUDING_LIB_SRC_LIST=" + org.tizen.common_* + org.tizen.common.sign_* + org.tizen.nativecommon_* + org.tizen.nativecpp.misc_* + " + for SRC in ${INCLUDING_LIB_SRC_LIST} + do + TARGET=`find $ROOTDIR -name "${SRC}" | head -1` + cp ${TARGET} $LIB + jar -xvf ${TARGET} lib + done } build() { echo $LIB mkdir -p $LIB - SRC=`find $ROOTDIR -name "org.eclipse.osgi_*" | head -1` - cp $SRC $LIB - - SRC=`find $ROOTDIR -name "org.tizen.common_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.common.sign_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.common.verrari_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.common.verrari.realm_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.common.sdblib_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.web.common_*" | head -1` - cp $SRC $LIB - - SRC=`find $ROOTDIR -name "org.tizen.web.zimlaunch_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.web.project.wizard_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - SRC=`find $ROOTDIR -name "org.tizen.web.sign_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib + SRC_LIST=" + org.eclipse.osgi_* + org.tizen.web.common_* + " + + for SRC in ${SRC_LIST} + do + TARGET=`find $ROOTDIR -name "${SRC}" | head -1` + cp ${TARGET} $LIB + done + + INCLUDING_LIB_SRC_LIST=" + org.tizen.common_* + org.tizen.common.builder_* + org.tizen.common.sign_* + org.tizen.common.verrari_* + org.tizen.common.verrari.realm_* + org.tizen.common.sdblib_* + org.tizen.web.builder_* + org.tizen.web.zimlaunch_* + org.tizen.web.project.wizard_* + org.tizen.web.sign_* + " + + for SRC in ${INCLUDING_LIB_SRC_LIST} + do + TARGET=`find $ROOTDIR -name "${SRC}" | head -1` + cp ${TARGET} $LIB + jar -xvf ${TARGET} lib + done cp $PROJECT_HOME/lib/*.jar $LIB diff --git a/package/build.ubuntu-32 b/package/build.ubuntu-32 deleted file mode 100755 index 3c72cf8..0000000 --- a/package/build.ubuntu-32 +++ /dev/null @@ -1,185 +0,0 @@ -#!/bin/sh -xe - -PROJECT_HOME="org.tizen.cli" -BUILD=build -PLATFORM=$TARGET_OS -TARGET=package/web-cli.package.$PLATFORM/data/tools/ide -NATIVE_TARGET=package/native-cli.package.$PLATFORM/data/tools/ide - -LIB=$SRCDIR/lib -NATIVE_LIB=${SRCDIR}/native-lib - -# clean -clean() -{ - echo "$SRCDIR" - rm -rf dist lib package/web-cli.package.linux - rm -rf ${NATIVE_LIB} package/native-cli.package.${TARGET_OS} -} - -# build -native_build() { - mkdir -p ${NATIVE_LIB} - mkdir -p ${NATIVE_TARGET}/bin - - case ${TARGET_OS} in - ubuntu-32|ubuntu-64|macos-64) - SIGN_BIN=`find ${ROOTDIR} -name "native-signing" | head -1` - cp ${SIGN_BIN} ${NATIVE_TARGET}/bin - ;; - windows-32|windows-64) - SIGN_BIN=`find ${ROOTDIR} -name "native-signing.bat" | head -1` - cp ${SIGN_BIN} ${NATIVE_TARGET}/bin - ;; - *) - echo "${TARGET_OS} is not support yet." - exit 1 - ;; - esac - LIB_SRC=`find ${ROOTDIR} -name "org.tizen.common_*" | head -1` - cp ${LIB_SRC} ${NATIVE_LIB} - jar -xvf $SRC ${NATIVE_LIB} - - LIB_SRC=`find ${ROOTDIR} -name "org.tizen.common.sign_*" | head -1` - cp ${LIB_SRC} ${NATIVE_LIB} - jar -xvf $SRC ${NATIVE_LIB} - - LIB_SRC=`find ${ROOTDIR} -name "org.tizen.nativecommon_*" | head -1` - cp ${LIB_SRC} ${NATIVE_LIB} - jar -xvf $SRC ${NATIVE_LIB} - - LIB_SRC=`find ${ROOTDIR} -name "org.tizen.nativecpp.misc_*" | head -1` - cp ${LIB_SRC} ${NATIVE_LIB} - jar -xvf $SRC ${NATIVE_LIB} - -} -build() -{ - echo $LIB - mkdir -p $LIB - SRC=`find $ROOTDIR -name "org.eclipse.osgi_*" | head -1` - cp $SRC $LIB - - SRC=`find $ROOTDIR -name "org.tizen.common_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.common.sign_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.common.verrari_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.common.verrari.realm_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.common.sdblib_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.web.common_*" | head -1` - cp $SRC $LIB - - SRC=`find $ROOTDIR -name "org.tizen.web.zimlaunch_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.web.project.wizard_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - SRC=`find $ROOTDIR -name "org.tizen.web.sign_*" | head -1` - cp $SRC $LIB - jar -xvf $SRC lib - - cp $PROJECT_HOME/lib/*.jar $LIB - - mkdir -p $BUILD - cp -r $PROJECT_HOME/src/* $BUILD - - # native-cli build - native_build - - ant - -} - - -# install -native_install() { - - mkdir -p ${NATIVE_TARGET}/lib - - # copy command - case ${TARGET_OS} in - ubuntu-32|ubuntu-64|macos-64) - cp -rf ${SRCDIR}/${PROJECT_HOME}/doc/install/native_bin/* ${NATIVE_TARGET}/bin - rm ${NATIVE_TARGET}/bin/*.bat - ;; - windows-32|windows-64) - cp -rf ${SRCDIR}/${PROJECT_HOME}/doc/install/native_bin/*.bat ${NATIVE_TARGET}/bin - ;; - *) - echo "${TARGET_OS} is not support yet." - exit 1 - ;; - esac - cp -rf ${NATIVE_LIB}/* ${NATIVE_TARGET}/lib || true - cp ${SRCDIR}/dist/*.jar ${NATIVE_TARGET}/lib || true - cp -rf ${SRCDIR}/package/addingFiles/template ${NATIVE_TARGET}/ || true - -dependency_jars="CertificateGenerator.jar -HashSign.jar -commons-cli-*.jar -log4j-*.jar -slf4j-api-*.jar -slf4j-log4j*.jar -xmlsec-*.jar -" - for i in ${dependency_jars} - do - cp -rf ${LIB}/${i} ${NATIVE_TARGET}/lib - done - -} - - - -install() -{ - mkdir -p $TARGET/lib - - # copy command - case ${TARGET_OS} in - ubuntu-32|ubuntu-64|macos-64) - cp -r $PROJECT_HOME/doc/install/bin_ $TARGET/bin || true - rm $TARGET/bin/*.bat - ;; - windows-32|windows-64) - mkdir -p $TARGET/bin - cp -r $PROJECT_HOME/doc/install/bin_/*.bat $TARGET/bin || true - ;; - *) - echo "${TARGET_OS} is not support yet." - exit 1 - ;; - esac - - cp -r $PROJECT_HOME/doc/install/conf $TARGET/conf || true - cp -r $PROJECT_HOME/doc/install/sample $TARGET/sample || true - cp -r $PROJECT_HOME/doc/install/realm $TARGET/realm || true - cp -r $PROJECT_HOME/doc/install/document/* $TARGET || true - cp -r $LIB/* $TARGET/lib || true - cp dist/*.jar $TARGET/lib || true - # native-cli install - native_install -} - -[ "$1" = "clean" ] && clean -[ "$1" = "build" ] && build -[ "$1" = "install" ] && install - -echo "success"