Skip to content
This repository was archived by the owner on Nov 25, 2022. It is now read-only.

Commit 2802317

Browse files
committed
Fix build process and merge internal updates.
1 parent 8bcc7be commit 2802317

26 files changed

+347
-141
lines changed

client_side_only_impl/vsaq_main.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ vsaq.Qpage.prototype.updateStorage_ = function(data) {
159159
var newStorageData = null;
160160
var storageData = this.readStorage_();
161161
if (storageData) {
162-
storageData = JSON.parse(storageData);
162+
storageData = /** @type {Object|null} */ (JSON.parse(storageData));
163163
goog.object.extend(storageData, data);
164164
newStorageData = goog.json.serialize(storageData);
165165
} else {
@@ -259,7 +259,7 @@ vsaq.Qpage.prototype.loadExtensionThenQuestionnaire = function(
259259
text = vsaq.utils.vsaqonToJson(text);
260260
var extension = {};
261261
try {
262-
extension = JSON.parse(text);
262+
extension = /** @type {Object|null} */ (JSON.parse(text));
263263
} catch (err) {
264264
alert('Loading the extension failed. It does not appear to be ' +
265265
'valid json');
@@ -297,7 +297,7 @@ vsaq.Qpage.prototype.loadQuestionnaire = function(opt_path, opt_extension) {
297297
text = vsaq.utils.vsaqonToJson(text);
298298
var template = {};
299299
try {
300-
template = JSON.parse(text);
300+
template = /** @type {Object|null} */ (JSON.parse(text));
301301
} catch (err) {
302302
alert('Loading the template failed. It does not appear to be ' +
303303
'valid json');
@@ -328,7 +328,7 @@ vsaq.Qpage.prototype.loadQuestionnaire = function(opt_path, opt_extension) {
328328

329329
this.questionnaire.listen(
330330
goog.events.EventType.CHANGE, goog.bind(function(e) {
331-
goog.structs.forEach(e.changedValues, function(val, key) {
331+
goog.object.forEach(e.changedValues, function(val, key) {
332332
this.changes[key] = val;
333333
}, this);
334334
if (goog.structs.getCount(this.changes) > 0) {

compiler.flags

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
--jscomp_error=checkVars
88
--jscomp_error=const
99
--jscomp_error=constantProperty
10-
--jscomp_error=deprecated
10+
--jscomp_warning=deprecated
1111
--jscomp_error=duplicate
1212
--jscomp_error=duplicateMessage
1313
--jscomp_error=es5Strict
@@ -24,8 +24,6 @@
2424
--jscomp_error=unknownDefines
2525
--jscomp_error=uselessCode
2626
--jscomp_error=visibility
27-
--externs=third_party/closure-compiler/contrib/externs/chrome_extensions.js
2827
--only_closure_dependencies
2928
--manage_closure_dependencies
30-
--js third_party/closure-library/closure/goog/deps.js
3129
--js build/deps.js

do.sh

+19-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#
1818

1919
PYTHON_CMD="python"
20-
JSCOMPILE_CMD="java -jar third_party/closure-compiler/build/compiler.jar --flagfile=compiler.flags"
20+
JSCOMPILE_CMD="java -jar third_party/closure-compiler/target/closure-compiler-1.0-SNAPSHOT.jar --flagfile=compiler.flags"
2121
CKSUM_CMD="cksum" # chosen because it's available on most Linux/OS X installations
2222
BUILD_DIR="build"
2323
BUILD_TPL_DIR="$BUILD_DIR/templates"
@@ -35,10 +35,9 @@ vsaq_assert_dependencies() {
3535
fi
3636
# Check if required files are present.
3737
files=(third_party/closure-library \
38-
third_party/closure-templates-compiler \
39-
third_party/closure-stylesheets/build/closure-stylesheets.jar \
40-
third_party/closure-compiler/build/compiler.jar \
41-
third_party/closure-compiler/contrib/externs/chrome_extensions.js \
38+
third_party/closure-templates/target \
39+
third_party/closure-stylesheets/target/closure-stylesheets-1.5.0-SNAPSHOT-jar-with-dependencies.jar \
40+
third_party/closure-compiler/target/closure-compiler-1.0-SNAPSHOT.jar \
4241
)
4342
for var in "${files[@]}"
4443
do
@@ -62,13 +61,16 @@ vsaq_build_templates() {
6261
set -e
6362
mkdir -p "$BUILD_TPL_DIR"
6463
rm -rf "$BUILD_TPL_DIR/*"
64+
mkdir "$BUILD_TPL_DIR/proto"
65+
# Compile safe html type proto to JS
66+
third_party/protoc/bin/protoc --js_out $BUILD_TPL_DIR/proto \
67+
./third_party/safe-html-types/proto/src/main/protobuf/webutil/html/types/html.proto
6568
# Compile soy templates
6669
echo "Compiling Soy templates..."
6770
rm -f "$BUILD_TPL_DIR/cksum"
6871
vsaq_get_file_cksum '*.soy' > "$BUILD_TPL_DIR/cksum"
69-
find "vsaq" -name '*.soy' -exec java -jar third_party/closure-templates-compiler/SoyToJsSrcCompiler.jar \
70-
--shouldProvideRequireSoyNamespaces --shouldGenerateJsdoc --shouldDeclareTopLevelNamespaces --srcs {} \
71-
--outputPathFormat "$BUILD_TPL_DIR/{INPUT_DIRECTORY}{INPUT_FILE_NAME}.js" \;
72+
find "vsaq" -name '*.soy' -exec java -jar third_party/closure-templates/target/soy-2018-03-14-SoyToJsSrcCompiler.jar \
73+
--srcs {} --outputPathFormat "$BUILD_TPL_DIR/{INPUT_DIRECTORY}{INPUT_FILE_NAME}.js" \;
7274
echo "Done."
7375
}
7476

@@ -110,9 +112,10 @@ vsaq_build_closure_lib_() {
110112
SRC_DIRS=( \
111113
vsaq \
112114
client_side_only_impl \
115+
third_party/closure-templates/target \
113116
third_party/closure-library/closure/goog \
114117
third_party/closure-library/third_party/closure/goog \
115-
third_party/closure-templates-compiler )
118+
third_party/protoc/protobuf-3.5.1/js/binary )
116119
if [ -d "$3" ]; then
117120
SRC_DIRS+=("$3")
118121
fi
@@ -122,13 +125,16 @@ vsaq_build_closure_lib_() {
122125
jscompile_vsaq+=" --js='$var/**.js' --js='!$var/**_test.js' --js='!$var/**_perf.js'"
123126
done
124127
jscompile_vsaq+=" --js='!third_party/closure-library/closure/goog/demos/**.js'"
128+
jscompile_vsaq+=" --js='!third_party/closure-templates/javascript/examples/**.js'"
125129
if [ "$4" == "debug" ]; then
126130
jscompile_vsaq+=" --debug --formatting=PRETTY_PRINT -O WHITESPACE_ONLY"
127131
elif [ "$4" == "optimized" ]; then
128132
jscompile_vsaq+=" -O ADVANCED"
129133
fi
134+
cmd="$jscompile_vsaq --closure_entry_point "$ENTRY_POINT" --js_output_file "$FNAME""
135+
echo $cmd
130136
echo -n "."
131-
$jscompile_vsaq --closure_entry_point "$ENTRY_POINT" --js_output_file "$FNAME"
137+
$cmd
132138
}
133139

134140
vsaq_build_jsmodule() {
@@ -161,7 +167,7 @@ vsaq_build() {
161167

162168
BUILD_DIR_STATIC="$BUILD_DIR/static"
163169
mkdir -p "$BUILD_DIR_STATIC"
164-
csscompile_vsaq="java -jar third_party/closure-stylesheets/build/closure-stylesheets.jar --allowed-non-standard-function color-stop"
170+
csscompile_vsaq="java -jar third_party/closure-stylesheets/target/closure-stylesheets-1.5.0-SNAPSHOT-jar-with-dependencies.jar --allowed-non-standard-function color-stop"
165171
echo "Compiling CSS files..."
166172
$csscompile_vsaq "vsaq/static/vsaq_base.css" "vsaq/static/vsaq.css" > "$BUILD_DIR_STATIC/vsaq.css"
167173
echo "Copying remaining static files..."
@@ -203,7 +209,7 @@ vsaq_generate_jsdeps() {
203209
$PYTHON_CMD third_party/closure-library/closure/bin/build/depswriter.py \
204210
--root_with_prefix="build/templates/ build/templates/" \
205211
--root_with_prefix="vsaq/ vsaq/" \
206-
--root_with_prefix="third_party/closure-templates-compiler/ third_party/closure-templates-compiler/" \
212+
--root_with_prefix="third_party/closure-templates/javascript third_party/closure-templates/javascript/" \
207213
> "$BUILD_DIR/deps.js"
208214
}
209215

@@ -215,7 +221,7 @@ vsaq_run() {
215221
$PYTHON_CMD third_party/closure-library/closure/bin/build/depswriter.py \
216222
--root_with_prefix="build/templates/ ../../../build/templates/" \
217223
--root_with_prefix="vsaq/ ../vsaq/" \
218-
--root_with_prefix="third_party/closure-templates-compiler/ ../../../../third_party/closure-templates-compiler/" \
224+
--root_with_prefix="third_party/closure-templates/javascript/ ../../../../third_party/closure-templates/javascript/" \
219225
> "$BUILD_DIR/deps-runfiles.js"
220226

221227
rm -f "$BUILD_DIR/all_tests.js"

download-libs.sh

+49-16
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,24 @@
1919
export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
2020
THIRD_PARTY_DIRECTORY="third_party"
2121

22+
23+
24+
type unzip >/dev/null 2>&1 || {
25+
echo >&2 "Unzip is required to build VSAQ dependencies."
26+
exit 1
27+
}
28+
type wget >/dev/null 2>&1 || {
29+
echo >&2 "Wget is required to build VSAQ dependencies."
30+
exit 1
31+
}
2232
type ant >/dev/null 2>&1 || {
2333
echo >&2 "Ant is required to build VSAQ dependencies."
2434
exit 1
2535
}
36+
type mvn >/dev/null 2>&1 || {
37+
echo >&2 "Apache Maven is required to build VSAQ dependencies."
38+
exit 1
39+
}
2640
type javac >/dev/null 2>&1 || {
2741
echo >&2 "Java compiler is required to build VSAQ dependencies."
2842
exit 1
@@ -52,6 +66,7 @@ if [ ! -d .git ]; then
5266
rm -rf $THIRD_PARTY_DIRECTORY/closure-library
5367
rm -rf $THIRD_PARTY_DIRECTORY/closure-stylesheets
5468
rm -rf $THIRD_PARTY_DIRECTORY/js-dossier
69+
rm -rf $THIRD_PARTY_DIRECTORY/closure-templates
5570
fi
5671

5772
if [ ! -d $THIRD_PARTY_DIRECTORY ]; then
@@ -62,54 +77,72 @@ cd $THIRD_PARTY_DIRECTORY
6277
git submodule add -f https://github.com/google/closure-compiler closure-compiler
6378
git submodule add -f https://github.com/google/closure-library closure-library
6479
git submodule add -f https://github.com/google/closure-stylesheets closure-stylesheets
80+
git submodule add -f https://github.com/google/closure-templates closure-templates
6581
git submodule add -f https://github.com/jleyba/js-dossier js-dossier
82+
git submodule add -f https://github.com/google/safe-html-types safe-html-types
6683

6784
git submodule init
6885
git submodule update
6986

7087
# Pin submodules to particular commits
7188
cd closure-compiler
72-
git checkout -b 59b42c9fc8fc752b3ff3aabe04ad89a96f9a7bf7 59b42c9fc8fc752b3ff3aabe04ad89a96f9a7bf7
89+
git checkout -b 0441c526dc7ed322034d4f708062c00802184e8f 0441c526dc7ed322034d4f708062c00802184e8f
7390
cd ..
7491
cd closure-library
75-
git checkout -b dc369cde87d7ef6dfb46d3b873f872ebee7d07cd dc369cde87d7ef6dfb46d3b873f872ebee7d07cd
92+
git checkout -b 26de3253e443d36f64c2ea380faee879dfcf1c54 26de3253e443d36f64c2ea380faee879dfcf1c54
7693
cd ..
7794
cd js-dossier
78-
git checkout -b 6f2d09ee26925b7417f9f6bd1547dffe700ab60f 6f2d09ee26925b7417f9f6bd1547dffe700ab60f
95+
git checkout -b e6e55806ea97a4fcf4157661ee809eb8b48fe848 e6e55806ea97a4fcf4157661ee809eb8b48fe848
96+
cd ..
97+
cd closure-templates
98+
git checkout -b 17dad0f13db94ca43a2e4c436658682a0403ced1 17dad0f13db94ca43a2e4c436658682a0403ced1
99+
cd ..
100+
cd safe-html-types
101+
git checkout -b 8507735457ea41a37dfa027fb176d49d5783c4ba 8507735457ea41a37dfa027fb176d49d5783c4ba
79102
cd ..
80103

81104
# build closure compiler
82105
if [ ! -f closure-compiler/build/compiler.jar ] && [ -d closure-compiler ]; then
83106
cd closure-compiler
84-
ant clean
85-
ant jar
107+
# ant clean
108+
# ant jar
109+
mvn -DskipTests -pl externs/pom.xml,pom-main.xml,pom-main-shaded.xml
86110
cd ..
87111
fi
88112

89-
# checkout closure templates compiler
90-
if [ ! -d closure-templates-compiler ]; then
91-
curl https://dl.google.com/closure-templates/closure-templates-for-javascript-latest.zip -O
92-
unzip closure-templates-for-javascript-latest.zip -d closure-templates-compiler
93-
rm closure-templates-for-javascript-latest.zip
113+
# build closure templates compiler
114+
if [ -d closure-templates ] && [ ! -d closure-templates/target ]; then
115+
cd closure-templates
116+
mvn -DskipTests package
117+
cd ..
94118
fi
95119

96120
# build css compiler
97-
if [ ! -f closure-stylesheets/build/closure-stylesheets.jar ]; then
121+
if [ ! -f closure-stylesheets/target/closure-stylesheets-1.5.0-SNAPSHOT-jar-with-dependencies.jar ]; then
98122
cd closure-stylesheets
99-
ant
123+
mvn compile assembly:single
100124
cd ..
101125
fi
102126

103127
if [ -f chrome_extensions.js ]; then
104128
rm -f chrome_extensions.js
105129
fi
106130

131+
mkdir protoc; cd protoc
132+
wget https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip
133+
unzip protoc-3.5.1-linux-x86_64.zip
134+
rm protoc-3.5.1-linux-x86_64.zip
135+
wget https://github.com/google/protobuf/releases/download/v3.5.1/protobuf-js-3.5.1.zip
136+
unzip protobuf-js-3.5.1.zip
137+
rm protobuf-js-3.5.1.zip
138+
cd ..
139+
107140
# Temporary fix
108141
# Soy file bundled with the compiler does not compile with strict settings:
109142
# lib/closure-templates-compiler/soyutils_usegoog.js:1762: ERROR - element JS_STR_CHARS does not exist on this enum
110-
cd closure-templates-compiler
111-
echo $PWD
112-
curl https://raw.githubusercontent.com/google/closure-templates/0cbc8543c34d3f7727dd83a2d1938672f16d5c20/javascript/soyutils_usegoog.js -O
113-
cd ..
143+
#cd closure-templates/javascript
144+
#echo $PWD
145+
#curl https://raw.githubusercontent.com/google/closure-templates/0cbc8543c34d3f7727dd83a2d1938672f16d5c20/javascript/soyutils_usegoog.js -O
146+
#cd ../..
114147

115148
cd ..

vsaq/static/qpage_base.js

-15
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ goog.require('goog.events.EventType');
2828
goog.require('goog.structs');
2929
goog.require('goog.ui.Tooltip');
3030
goog.require('vsaq.Questionnaire');
31-
goog.require('vsaq.utils');
3231

3332

3433

@@ -52,10 +51,6 @@ vsaq.QpageBase = function() {
5251
goog.dom.createDom(goog.dom.TagName.SPAN);
5352
this.questionnaire.setReadOnlyMode(this.isReadOnly);
5453

55-
vsaq.utils.initClickables({
56-
'eh-edit': goog.bind(this.makeEditable, this)
57-
});
58-
5954
goog.events.listen(window, [goog.events.EventType.BEFOREUNLOAD],
6055
function() {
6156
if (vsaq.qpageObject_ && vsaq.qpageObject_.unsavedChanges())
@@ -122,16 +117,6 @@ vsaq.QpageBase.prototype.isReadOnly;
122117
vsaq.QpageBase.prototype.statusIndicator;
123118

124119

125-
/**
126-
* Make questionnaire editable.
127-
*/
128-
vsaq.QpageBase.prototype.makeEditable = function() {
129-
this.isReadOnly = false;
130-
this.questionnaire.setReadOnlyMode(this.isReadOnly);
131-
this.questionnaire.render();
132-
};
133-
134-
135120
/**
136121
* Attempts to keep track of updates that were done to the current
137122
* questionnaire.

vsaq/static/questionnaire/blockitems.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ goog.require('vsaq.questionnaire.templates');
4343
* for the item to be visible to the user.
4444
* @param {?string} caption The caption of the block.
4545
* @param {?string=} opt_auth The needed authorization to get an item displayed.
46-
* The auth param on {@code vsaq.questionnaire.items.BlockItem} only
46+
* The auth param on `vsaq.questionnaire.items.BlockItem` only
4747
* prevents that items are displayed to the user (hidden by display=none).
4848
* @param {?string=} opt_className Name of a CSS class to add to the block.
4949
* @extends {vsaq.questionnaire.items.ContainerItem}

vsaq/static/questionnaire/boxitem.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ goog.require('vsaq.questionnaire.utils');
4949
* @param {number=} opt_maxlength HTML maxlength attribute value for the input
5050
* field. See {@link
5151
* https://html.spec.whatwg.org/multipage/forms.html#attr-fe-maxlength}
52+
* @param {string=} opt_auth If "readonly", this ValueItem cannot be modified.
5253
* @extends {vsaq.questionnaire.items.ValueItem}
5354
* @constructor
5455
*/
5556
vsaq.questionnaire.items.BoxItem = function(id, conditions, caption,
5657
opt_placeholder, opt_inputPattern, opt_inputTitle, opt_isRequired,
57-
opt_maxlength) {
58+
opt_maxlength, opt_auth) {
5859
goog.base(this, id, conditions, caption, opt_placeholder, opt_inputPattern,
59-
opt_inputTitle, opt_isRequired, opt_maxlength);
60+
opt_inputTitle, opt_isRequired, opt_maxlength, opt_auth);
6061

6162
/**
6263
* The text area where the user can provide an answer.
@@ -122,13 +123,14 @@ vsaq.questionnaire.items.BoxItem.parse = function(questionStack) {
122123

123124
return new vsaq.questionnaire.items.BoxItem(item.id, item.cond, item.text,
124125
item.placeholder, item.inputPattern, item.inputTitle, item.required,
125-
item.maxlength);
126+
item.maxlength, item.auth);
126127
};
127128

128129

129130
/** @inheritDoc */
130131
vsaq.questionnaire.items.BoxItem.prototype.setReadOnly = function(readOnly) {
131-
this.textArea_.readOnly = readOnly;
132+
// if item marked readonly, always keep it readonly
133+
this.textArea_.readOnly = this.auth == 'readonly' ? true : readOnly;
132134
};
133135

134136

vsaq/static/questionnaire/boxitem_test.js

+18
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,22 @@ function testBoxItemParse() {
8888
assertEquals('placeholder', box.placeholder);
8989
assertTrue(box.required);
9090
assertEquals(0, testStack.length);
91+
assertTrue(box.auth != 'readonly');
92+
93+
testStack = [{
94+
'type': 'box',
95+
'text': CAPTION,
96+
'id': ID,
97+
'required' : true,
98+
'placeholder': 'placeholder',
99+
'auth': 'readonly'
100+
}];
101+
box = vsaq.questionnaire.items.BoxItem.parse(testStack);
102+
assert(box instanceof vsaq.questionnaire.items.BoxItem);
103+
assertEquals(ID, box.id);
104+
assertEquals(CAPTION, box.text);
105+
assertEquals('placeholder', box.placeholder);
106+
assertTrue(box.required);
107+
assertEquals(0, testStack.length);
108+
assertEquals('readonly', box.auth);
91109
}

0 commit comments

Comments
 (0)