*/
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;
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;
/**
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
*
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;
}
final List<String> args = cmdLine.getArgList();
logger.trace( "arguments :{}", args );
- int nArgs = args.size();
+ int nArgs = args.size();
final File cwd = new File( "." ).getCanonicalFile();
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
return fileHandler.is( projectFilePath, Attribute.EXISTS );
}
-
/**
* Return default excludes file patterns
*
return new String[] { ".*", "*.wgt" };
}
-
/**
* Archive <code>baseDir</code> to <code>wgtPath</code>
*
* @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
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)
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
+++ /dev/null
-#!/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"