[Title] added minify fuction to web-package command.
authorTaeyoung Son <taeyoung2.son@samsung.com>
Mon, 6 May 2013 06:45:58 +0000 (15:45 +0900)
committerTaeyoung Son <taeyoung2.son@samsung.com>
Thu, 9 May 2013 06:04:48 +0000 (15:04 +0900)
[Desc.]
[Issue]

Change-Id: I2437049148ecbd0baa72109a6d06c99b33e19552

.gitignore
org.tizen.cli/META-INF/MANIFEST.MF
org.tizen.cli/src/org/tizen/cli/exec/wgt/Main.java
package/build.linux [moved from package/build.ubuntu-64 with 67% similarity]
package/build.ubuntu-32 [deleted file]

index fd9ed35..a18a8b5 100644 (file)
@@ -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
 
index 7106b22..e973423 100755 (executable)
@@ -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
index 5802572..7538c9d 100755 (executable)
  */
 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<String> 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<File> files = FileUtil.findFiles(new File(baseDir), ".*", true);
+        List<Resource> resources = new ArrayList<Resource>();
+        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 <code>baseDir</code> to <code>wgtPath</code> including
+     * <code>includes</code> and excluding <code>excludes</code>
+     * 
+     * @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 <code>path</code> 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 <code>baseDir</code> to <code>wgtPath</code>
      * 
@@ -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)
similarity index 67%
rename from package/build.ubuntu-64
rename to package/build.linux
index a50cc04..245a05f 100755 (executable)
@@ -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 (executable)
index 3c72cf8..0000000
+++ /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"