Skip to content

Commit

Permalink
Replace existing zip implementation with jszip v2.4.0
Browse files Browse the repository at this point in the history
jszip has a much cleaner API than the existing RawDeflate version. In
addition, jszip supports creation of a compressed output stream.

As it's non-trivial to make jszip behave with closure compiler, a second
concat-only step has been added during compilation to include 3rd party
dependencies.

Fixes webodf#21.
  • Loading branch information
peitschie committed Sep 15, 2014
1 parent 3b22a30 commit 10e914b
Show file tree
Hide file tree
Showing 13 changed files with 9,194 additions and 3,871 deletions.
8 changes: 4 additions & 4 deletions programs/docnosis/docnosis.js
Expand Up @@ -182,19 +182,19 @@ function UnpackJob() {
}
return str;
}
function loadZipEntries(input, position, callback) {
function loadZipEntries(input, zip, position, callback) {
if (position >= input.file.entries.length) {
return callback();
}
var e = input.file.entries[position];
e.load(function (err, data) {
zip.load(e.filename, function (err, data) {
if (err) {
input.errors.unpackErrors.push(err);
}
e.error = err;
e.data = data;
window.setTimeout(function () {
loadZipEntries(input, position + 1, callback);
loadZipEntries(input, zip, position + 1, callback);
}, 0);
});
}
Expand All @@ -206,7 +206,7 @@ function UnpackJob() {
callback();
} else {
input.file.entries = zip.getEntries();
loadZipEntries(input, 0, callback);
loadZipEntries(input, zip, 0, callback);
}
});
}
Expand Down
59 changes: 46 additions & 13 deletions webodf/CMakeLists.txt
Expand Up @@ -73,8 +73,6 @@ add_custom_target(webodf.css.js-target DEPENDS webodf.css.js)
# option to help keep the length of the compilation command as small as possible.
file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/cc-noTestFiles.txt "--warning_level VERBOSE --jscomp_error accessControls --jscomp_error ambiguousFunctionDecl --jscomp_error checkEventfulObjectDisposal --jscomp_error checkRegExp --jscomp_error checkStructDictInheritance --jscomp_error checkTypes --jscomp_error checkVars --jscomp_error const --jscomp_error constantProperty --jscomp_error deprecated --jscomp_error duplicateMessage --jscomp_error es3 --jscomp_error es5Strict --jscomp_error externsValidation --jscomp_error fileoverviewTags --jscomp_error globalThis --jscomp_error invalidCasts --jscomp_error misplacedTypeAnnotation --jscomp_error missingProperties --jscomp_error missingProvide --jscomp_error missingRequire --jscomp_error missingReturn --jscomp_off nonStandardJsDocs --jscomp_error suspiciousCode --jscomp_error strictModuleDepCheck --jscomp_error typeInvalidation --jscomp_error undefinedNames --jscomp_error undefinedVars --jscomp_error unknownDefines --jscomp_error uselessCode --jscomp_error visibility --summary_detail_level 3")

file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/cc-noTestFiles.txt " --js ${HEADERCOMPILED_FILE}")

foreach(JSFILE ${LIBJSFILES})
if (IS_ABSOLUTE ${JSFILE})
file (APPEND ${CMAKE_CURRENT_BINARY_DIR}/cc-noTestFiles.txt " --js ${JSFILE}")
Expand Down Expand Up @@ -105,14 +103,17 @@ set(SHARED_CLOSURE_ARGS -XX:+TieredCompilation -jar ${CLOSURE_JAR})
add_custom_command(
OUTPUT simplecompiled.js
COMMAND ${Java_JAVA_EXECUTABLE}
ARGS ${SHARED_CLOSURE_ARGS} --flagfile ${CMAKE_CURRENT_BINARY_DIR}/cc-withTestFiles.txt
ARGS ${SHARED_CLOSURE_ARGS}
--js ${HEADERCOMPILED_FILE}
--flagfile ${CMAKE_CURRENT_BINARY_DIR}/cc-withTestFiles.txt
--js ${CMAKE_CURRENT_SOURCE_DIR}/lib/externs/*.js
--compilation_level WHITESPACE_ONLY
--formatting PRETTY_PRINT
--js_output_file simplecompiled.js-
# in WHITESPACE_ONLY mode, it is not possible to define IS_COMPILED_CODE
# so the value for IS_COMPILED_CODE is set by find and replace in the code
COMMAND ${CMAKE_COMMAND} -DFILENAME:STRING="${CMAKE_CURRENT_BINARY_DIR}/simplecompiled.js" -P ${CMAKE_CURRENT_SOURCE_DIR}/tools/set_IS_COMPILED_CODE.cmake
DEPENDS ClosureCompiler ${LIBJSFILES} ${TESTJSFILES}
DEPENDS ClosureCompiler ${LIBJSFILES} ${TESTJSFILES} ${HEADERCOMPILED_FILE}
${CMAKE_CURRENT_BINARY_DIR}/webodf.css.js
)
add_custom_target(simplecompiled.js-target DEPENDS simplecompiled.js)
Expand All @@ -127,50 +128,82 @@ add_custom_target(simplecompiled.js-target DEPENDS simplecompiled.js)
add_custom_command(
OUTPUT compiled.js
COMMAND ${Java_JAVA_EXECUTABLE}
ARGS ${SHARED_CLOSURE_ARGS} --flagfile ${CMAKE_CURRENT_BINARY_DIR}/cc-withTestFiles.txt
ARGS ${SHARED_CLOSURE_ARGS}
--js ${HEADERCOMPILED_FILE}
--flagfile ${CMAKE_CURRENT_BINARY_DIR}/cc-withTestFiles.txt
--define IS_COMPILED_CODE=true
--compilation_level ADVANCED_OPTIMIZATIONS
--formatting PRETTY_PRINT
--externs ${CMAKE_CURRENT_SOURCE_DIR}/tools/externs.js
--externs ${CMAKE_CURRENT_SOURCE_DIR}/externs/*.js
--js_output_file compiled.js-
COMMAND ${CMAKE_COMMAND} ARGS -E rename compiled.js- compiled.js
DEPENDS ClosureCompiler ${LIBJSFILES} ${TESTJSFILES} tools/externs.js
webodf.css.js-target
webodf.css.js-target ${HEADERCOMPILED_FILE}
)
add_custom_target(compiled.js-target DEPENDS compiled.js)

# Compile the optimized production version of WebODF.
add_custom_command(
OUTPUT webodf.js
OUTPUT webodf-compiled.js
COMMAND ${Java_JAVA_EXECUTABLE}
ARGS ${SHARED_CLOSURE_ARGS} --flagfile ${CMAKE_CURRENT_BINARY_DIR}/cc-noTestFiles.txt
--jscomp_error reportUnknownTypes
--define IS_COMPILED_CODE=true
--compilation_level SIMPLE_OPTIMIZATIONS
--externs ${CMAKE_CURRENT_SOURCE_DIR}/tools/externs.js
--externs ${CMAKE_CURRENT_SOURCE_DIR}/externs/*.js
--js_output_file webodf-compiled.js-
COMMAND ${CMAKE_COMMAND} ARGS -E rename webodf-compiled.js- webodf-compiled.js
DEPENDS ClosureCompiler ${LIBJSFILES} tools/externs.js
webodf.css.js-target
)
# Include non-Closure Compiler compatible libraries with no further recompilation
add_custom_command(
OUTPUT webodf.js
COMMAND ${Java_JAVA_EXECUTABLE}
ARGS ${SHARED_CLOSURE_ARGS}
--js ${HEADERCOMPILED_FILE}
--js webodf-compiled.js
--js ${CMAKE_CURRENT_SOURCE_DIR}/lib/externs/*.js
--compilation_level WHITESPACE_ONLY
--js_output_file webodf.js-
COMMAND ${CMAKE_COMMAND} ARGS -E rename webodf.js- webodf.js
DEPENDS ClosureCompiler ${LIBJSFILES} tools/externs.js
webodf.css.js-target ${HEADERCOMPILED_FILE}
DEPENDS ClosureCompiler webodf-compiled.js ${HEADERCOMPILED_FILE}
)
add_custom_target(webodf.js-target DEPENDS webodf.js)

# Compile the debug version of WebODF. This is also published as a product.
add_custom_command(
OUTPUT webodf-debug.js
OUTPUT webodf-debug-compiled.js
COMMAND ${Java_JAVA_EXECUTABLE}
ARGS ${SHARED_CLOSURE_ARGS} --flagfile ${CMAKE_CURRENT_BINARY_DIR}/cc-noTestFiles.txt
--jscomp_error reportUnknownTypes
--define IS_COMPILED_CODE=true
--compilation_level WHITESPACE_ONLY
--formatting PRETTY_PRINT
--externs ${CMAKE_CURRENT_SOURCE_DIR}/tools/externs.js
--js_output_file webodf-debug.js-
--externs ${CMAKE_CURRENT_SOURCE_DIR}/externs/*.js
--js_output_file webodf-debug-compiled.js-
# in WHITESPACE_ONLY mode, it is not possible to define IS_COMPILED_CODE
# so the value for IS_COMPILED_CODE is set by find and replace in the code
COMMAND ${CMAKE_COMMAND} -DFILENAME:STRING="${CMAKE_CURRENT_BINARY_DIR}/webodf-debug.js" -P ${CMAKE_CURRENT_SOURCE_DIR}/tools/set_IS_COMPILED_CODE.cmake
COMMAND ${CMAKE_COMMAND} -DFILENAME:STRING="${CMAKE_CURRENT_BINARY_DIR}/webodf-debug-compiled.js" -P ${CMAKE_CURRENT_SOURCE_DIR}/tools/set_IS_COMPILED_CODE.cmake
DEPENDS ClosureCompiler ${LIBJSFILES} tools/externs.js
webodf.css.js-target ${HEADERCOMPILED_FILE}
webodf.css.js-target
)
# Include non-Closure Compiler compatible libraries with no further recompilation
add_custom_command(
OUTPUT webodf-debug.js
COMMAND ${Java_JAVA_EXECUTABLE}
ARGS ${SHARED_CLOSURE_ARGS}
--js ${HEADERCOMPILED_FILE}
--js webodf-debug-compiled.js
--js ${CMAKE_CURRENT_SOURCE_DIR}/lib/externs/*.js
--compilation_level WHITESPACE_ONLY
--formatting PRETTY_PRINT
--js_output_file webodf-debug.js-
COMMAND ${CMAKE_COMMAND} ARGS -E rename webodf-debug.js- webodf-debug.js
DEPENDS ClosureCompiler webodf-debug-compiled.js ${HEADERCOMPILED_FILE}
)
add_custom_target(webodf-debug.js-target DEPENDS webodf-debug.js)

Expand Down
79 changes: 79 additions & 0 deletions webodf/externs/JSZip.js
@@ -0,0 +1,79 @@
/**
* Copyright (C) 2010-2014 KO GmbH <copyright@kogmbh.com>
*
* @licstart
* This file is part of WebODF.
*
* WebODF is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License (GNU AGPL)
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* WebODF is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with WebODF. If not, see <http://www.gnu.org/licenses/>.
* @licend
*
* @source: http://www.webodf.org/
* @source: https://github.com/kogmbh/WebODF/
*/

/*global externs*/

/*jslint nomen: false, emptyblock: true, unparam: true */

/**
* @constructor
*/
function ZipObject() { "use strict"; }

/**
* @return {!Uint8Array}
*/
ZipObject.prototype.asUint8Array = function() { "use strict"; };

/**
* @constructor
*/
function JSZip() { "use strict"; }

/**
* @param {!string} filename
* @param {!Uint8Array=} data
* @param {*=} options
* @return {?ZipObject}
*/
JSZip.prototype.file = function(filename, data, options) { "use strict"; };

/**
* @type {!Array.<!ZipObject>}
*/
JSZip.prototype.files;

/**
* @param {*} options
* @return {*}
*/
JSZip.prototype.generate = function(options) { "use strict"; };

/**
* @param {!Uint8Array} data
* @param {*=} options
* @return {undefined}
*/
JSZip.prototype.load = function(data, options) { "use strict"; };

/**
* @param {!string} filename
* @return {undefined}
*/
JSZip.prototype.remove = function(filename) { "use strict"; };

/**
* @type {!function(new:JSZip)}
*/
externs.JSZip;
63 changes: 0 additions & 63 deletions webodf/lib/core/ByteArray.js

This file was deleted.

0 comments on commit 10e914b

Please sign in to comment.