Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • fabcat/vmap
1 result
Select Git revision
Show changes
Showing
with 8527 additions and 1 deletion
#!/usr/bin/env python
#
# Copyright 2010 The Closure Library Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Unit test for depswriter."""
__author__ = 'johnlenz@google.com (John Lenz)'
import unittest
import depswriter
class MockSource(object):
"""Mock Source file."""
def __init__(self, provides, requires):
self.provides = set(provides)
self.requires = set(requires)
self.is_goog_module = False
def __repr__(self):
return 'MockSource %s' % self.provides
class DepsWriterTestCase(unittest.TestCase):
"""Unit test for depswriter."""
def testMakeDepsFile(self):
sources = {}
sources['test.js'] = MockSource(['A'], ['B', 'C'])
deps = depswriter.MakeDepsFile(sources)
self.assertEqual(
'goog.addDependency(\'test.js\', [\'A\'], [\'B\', \'C\'], false);\n',
deps)
def testMakeDepsFileUnicode(self):
sources = {}
sources['test.js'] = MockSource([u'A'], [u'B', u'C'])
deps = depswriter.MakeDepsFile(sources)
self.assertEqual(
'goog.addDependency(\'test.js\', [\'A\'], [\'B\', \'C\'], false);\n',
deps)
if __name__ == '__main__':
unittest.main()
# Copyright 2010 The Closure Library Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utility to use the Closure Compiler CLI from Python."""
import logging
import os
import re
import subprocess
import tempfile
# Pulls just the major and minor version numbers from the first line of
# 'java -version'. Versions are in the format of [0-9]+\.[0-9]+\..* See:
# http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html
_VERSION_REGEX = re.compile(r'"([0-9]+)\.([0-9]+)')
class JsCompilerError(Exception):
"""Raised if there's an error in calling the compiler."""
pass
def _GetJavaVersionString():
"""Get the version string from the Java VM."""
return subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)
def _ParseJavaVersion(version_string):
"""Returns a 2-tuple for the current version of Java installed.
Args:
version_string: String of the Java version (e.g. '1.7.2-ea').
Returns:
The major and minor versions, as a 2-tuple (e.g. (1, 7)).
"""
match = _VERSION_REGEX.search(version_string)
if match:
version = tuple(int(x, 10) for x in match.groups())
assert len(version) == 2
return version
def _JavaSupports32BitMode():
"""Determines whether the JVM supports 32-bit mode on the platform."""
# Suppresses process output to stderr and stdout from showing up in the
# console as we're only trying to determine 32-bit JVM support.
supported = False
try:
devnull = open(os.devnull, 'wb')
return subprocess.call(['java', '-d32', '-version'],
stdout=devnull,
stderr=devnull) == 0
except IOError:
pass
else:
devnull.close()
return supported
def _GetJsCompilerArgs(compiler_jar_path, java_version, jvm_flags):
"""Assembles arguments for call to JsCompiler."""
if java_version < (1, 7):
raise JsCompilerError('Closure Compiler requires Java 1.7 or higher. '
'Please visit http://www.java.com/getjava')
args = ['java']
# Add JVM flags we believe will produce the best performance. See
# https://groups.google.com/forum/#!topic/closure-library-discuss/7w_O9-vzlj4
# Attempt 32-bit mode if available (Java 7 on Mac OS X does not support 32-bit
# mode, for example).
if _JavaSupports32BitMode():
args += ['-d32']
# Prefer the "client" VM.
args += ['-client']
# Add JVM flags, if any
if jvm_flags:
args += jvm_flags
# Add the application JAR.
args += ['-jar', compiler_jar_path]
return args
def _GetFlagFile(source_paths, compiler_flags):
"""Writes given source paths and compiler flags to a --flagfile.
The given source_paths will be written as '--js' flags and the compiler_flags
are written as-is.
Args:
source_paths: List of string js source paths.
compiler_flags: List of string compiler flags.
Returns:
The file to which the flags were written.
"""
args = []
for path in source_paths:
args += ['--js', path]
# Add compiler flags, if any.
if compiler_flags:
args += compiler_flags
flags_file = tempfile.NamedTemporaryFile(delete=False)
flags_file.write(' '.join(args))
flags_file.close()
return flags_file
def Compile(compiler_jar_path,
source_paths,
jvm_flags=None,
compiler_flags=None):
"""Prepares command-line call to Closure Compiler.
Args:
compiler_jar_path: Path to the Closure compiler .jar file.
source_paths: Source paths to build, in order.
jvm_flags: A list of additional flags to pass on to JVM.
compiler_flags: A list of additional flags to pass on to Closure Compiler.
Returns:
The compiled source, as a string, or None if compilation failed.
"""
java_version = _ParseJavaVersion(str(_GetJavaVersionString()))
args = _GetJsCompilerArgs(compiler_jar_path, java_version, jvm_flags)
# Write source path arguments to flag file for avoiding "The filename or
# extension is too long" error in big projects. See
# https://github.com/google/closure-library/pull/678
flags_file = _GetFlagFile(source_paths, compiler_flags)
args += ['--flagfile', flags_file.name]
logging.info('Compiling with the following command: %s', ' '.join(args))
try:
return subprocess.check_output(args)
except subprocess.CalledProcessError:
raise JsCompilerError('JavaScript compilation failed.')
finally:
os.remove(flags_file.name)
#!/usr/bin/env python
#
# Copyright 2013 The Closure Library Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Unit test for depstree."""
__author__ = 'nnaze@google.com (Nathan Naze)'
import os
import unittest
import jscompiler
class JsCompilerTestCase(unittest.TestCase):
"""Unit tests for jscompiler module."""
def testGetFlagFile(self):
flags_file = jscompiler._GetFlagFile(
['path/to/src1.js', 'path/to/src2.js'], ['--test_compiler_flag'])
def file_get_contents(filename):
with open(filename) as f:
content = f.read()
f.close()
return content
flags_file_content = file_get_contents(flags_file.name)
os.remove(flags_file.name)
self.assertEqual(
'--js path/to/src1.js --js path/to/src2.js --test_compiler_flag',
flags_file_content)
def testGetJsCompilerArgs(self):
original_check = jscompiler._JavaSupports32BitMode
jscompiler._JavaSupports32BitMode = lambda: False
args = jscompiler._GetJsCompilerArgs('path/to/jscompiler.jar', (1, 7),
['--test_jvm_flag'])
self.assertEqual(
['java', '-client', '--test_jvm_flag', '-jar',
'path/to/jscompiler.jar'], args)
def CheckJava15RaisesError():
jscompiler._GetJsCompilerArgs('path/to/jscompiler.jar', (1, 5),
['--test_jvm_flag'])
self.assertRaises(jscompiler.JsCompilerError, CheckJava15RaisesError)
jscompiler._JavaSupports32BitMode = original_check
def testGetJsCompilerArgs32BitJava(self):
original_check = jscompiler._JavaSupports32BitMode
# Should include the -d32 flag only if 32-bit Java is supported by the
# system.
jscompiler._JavaSupports32BitMode = lambda: True
args = jscompiler._GetJsCompilerArgs('path/to/jscompiler.jar', (1, 7),
['--test_jvm_flag'])
self.assertEqual(
['java', '-d32', '-client', '--test_jvm_flag', '-jar',
'path/to/jscompiler.jar'], args)
# Should exclude the -d32 flag if 32-bit Java is not supported by the
# system.
jscompiler._JavaSupports32BitMode = lambda: False
args = jscompiler._GetJsCompilerArgs('path/to/jscompiler.jar', (1, 7),
['--test_jvm_flag'])
self.assertEqual(
['java', '-client', '--test_jvm_flag', '-jar',
'path/to/jscompiler.jar'], args)
jscompiler._JavaSupports32BitMode = original_check
def testGetJavaVersion(self):
def assertVersion(expected, version_string):
self.assertEquals(expected, jscompiler._ParseJavaVersion(version_string))
assertVersion((1, 7), _TEST_JAVA_VERSION_STRING)
assertVersion((1, 6), _TEST_JAVA_NESTED_VERSION_STRING)
assertVersion((1, 4), 'java version "1.4.0_03-ea"')
_TEST_JAVA_VERSION_STRING = """\
openjdk version "1.7.0-google-v5"
OpenJDK Runtime Environment (build 1.7.0-google-v5-64327-39803485)
OpenJDK Server VM (build 22.0-b10, mixed mode)
"""
_TEST_JAVA_NESTED_VERSION_STRING = """\
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
Java HotSpot(TM) Client VM (build 20.10-b01-428, mixed mode)
"""
if __name__ == '__main__':
unittest.main()
# Copyright 2009 The Closure Library Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Scans a source JS file for its provided and required namespaces.
Simple class to scan a JavaScript file and express its dependencies.
"""
__author__ = 'nnaze@google.com'
import codecs
import re
_BASE_REGEX_STRING = r'^\s*goog\.%s\(\s*[\'"](.+)[\'"]\s*\)'
_MODULE_REGEX = re.compile(_BASE_REGEX_STRING % 'module')
_PROVIDE_REGEX = re.compile(_BASE_REGEX_STRING % 'provide')
_REQUIRE_REGEX_STRING = (r'^\s*(?:(?:var|let|const)\s+[a-zA-Z_$][a-zA-Z0-9$_]*'
r'\s*=\s*)?goog\.require\(\s*[\'"](.+)[\'"]\s*\)')
_REQUIRES_REGEX = re.compile(_REQUIRE_REGEX_STRING)
class Source(object):
"""Scans a JavaScript source for its provided and required namespaces."""
# Matches a "/* ... */" comment.
# Note: We can't definitively distinguish a "/*" in a string literal without a
# state machine tokenizer. We'll assume that a line starting with whitespace
# and "/*" is a comment.
_COMMENT_REGEX = re.compile(
r"""
^\s* # Start of a new line and whitespace
/\* # Opening "/*"
.*? # Non greedy match of any characters (including newlines)
\*/ # Closing "*/""",
re.MULTILINE | re.DOTALL | re.VERBOSE)
def __init__(self, source):
"""Initialize a source.
Args:
source: str, The JavaScript source.
"""
self.provides = set()
self.requires = set()
self.is_goog_module = False
self._source = source
self._ScanSource()
def GetSource(self):
"""Get the source as a string."""
return self._source
@classmethod
def _StripComments(cls, source):
return cls._COMMENT_REGEX.sub('', source)
@classmethod
def _HasProvideGoogFlag(cls, source):
"""Determines whether the @provideGoog flag is in a comment."""
for comment_content in cls._COMMENT_REGEX.findall(source):
if '@provideGoog' in comment_content:
return True
return False
def _ScanSource(self):
"""Fill in provides and requires by scanning the source."""
stripped_source = self._StripComments(self.GetSource())
source_lines = stripped_source.splitlines()
for line in source_lines:
match = _PROVIDE_REGEX.match(line)
if match:
self.provides.add(match.group(1))
match = _MODULE_REGEX.match(line)
if match:
self.provides.add(match.group(1))
self.is_goog_module = True
match = _REQUIRES_REGEX.match(line)
if match:
self.requires.add(match.group(1))
# Closure's base file implicitly provides 'goog'.
# This is indicated with the @provideGoog flag.
if self._HasProvideGoogFlag(self.GetSource()):
if len(self.provides) or len(self.requires):
raise Exception(
'Base file should not provide or require namespaces.')
self.provides.add('goog')
def GetFileContents(path):
"""Get a file's contents as a string.
Args:
path: str, Path to file.
Returns:
str, Contents of file.
Raises:
IOError: An error occurred opening or reading the file.
"""
fileobj = None
try:
fileobj = codecs.open(path, encoding='utf-8-sig')
return fileobj.read()
except IOError as error:
raise IOError('An error occurred opening or reading the file: %s. %s'
% (path, error))
finally:
if fileobj is not None:
fileobj.close()
#!/usr/bin/env python
#
# Copyright 2010 The Closure Library Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Unit test for source."""
__author__ = 'nnaze@google.com (Nathan Naze)'
import unittest
import source
class SourceTestCase(unittest.TestCase):
"""Unit test for source. Tests the parser on a known source input."""
def testSourceScan(self):
test_source = source.Source(_TEST_SOURCE)
self.assertEqual(set(['foo', 'foo.test']),
test_source.provides)
self.assertEqual(set(['goog.dom', 'goog.events.EventType']),
test_source.requires)
self.assertFalse(test_source.is_goog_module)
def testSourceScanBase(self):
test_source = source.Source(_TEST_BASE_SOURCE)
self.assertEqual(set(['goog']),
test_source.provides)
self.assertEqual(test_source.requires, set())
self.assertFalse(test_source.is_goog_module)
def testSourceScanBadBase(self):
def MakeSource():
source.Source(_TEST_BAD_BASE_SOURCE)
self.assertRaises(Exception, MakeSource)
def testSourceScanGoogModule(self):
test_source = source.Source(_TEST_MODULE_SOURCE)
self.assertEqual(set(['foo']),
test_source.provides)
self.assertEqual(set(['bar']),
test_source.requires)
self.assertTrue(test_source.is_goog_module)
def testStripComments(self):
self.assertEquals(
'\nvar foo = function() {}',
source.Source._StripComments((
'/* This is\n'
' a comment split\n'
' over multiple lines\n'
'*/\n'
'var foo = function() {}')))
def testGoogStatementsInComments(self):
test_source = source.Source(_TEST_COMMENT_SOURCE)
self.assertEqual(set(['foo']),
test_source.provides)
self.assertEqual(set(['goog.events.EventType']),
test_source.requires)
self.assertFalse(test_source.is_goog_module)
def testHasProvideGoog(self):
self.assertTrue(source.Source._HasProvideGoogFlag(_TEST_BASE_SOURCE))
self.assertTrue(source.Source._HasProvideGoogFlag(_TEST_BAD_BASE_SOURCE))
self.assertFalse(source.Source._HasProvideGoogFlag(_TEST_COMMENT_SOURCE))
_TEST_MODULE_SOURCE = """
goog.module('foo');
var b = goog.require('bar');
"""
_TEST_SOURCE = """// Fake copyright notice
/** Very important comment. */
goog.provide('foo');
goog.provide('foo.test');
goog.require('goog.dom');
goog.require('goog.events.EventType');
function foo() {
// Set bar to seventeen to increase performance.
this.bar = 17;
}
"""
_TEST_COMMENT_SOURCE = """// Fake copyright notice
goog.provide('foo');
/*
goog.provide('foo.test');
*/
/*
goog.require('goog.dom');
*/
// goog.require('goog.dom');
goog.require('goog.events.EventType');
function bar() {
this.baz = 55;
}
"""
_TEST_BASE_SOURCE = """
/**
* @fileoverview The base file.
* @provideGoog
*/
var goog = goog || {};
"""
_TEST_BAD_BASE_SOURCE = """
/**
* @fileoverview The base file.
* @provideGoog
*/
goog.provide('goog');
"""
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python
#
# Copyright 2010 The Closure Library Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Shared utility functions for scanning directory trees."""
import os
import re
__author__ = 'nnaze@google.com (Nathan Naze)'
# Matches a .js file path.
_JS_FILE_REGEX = re.compile(r'^.+\.js$')
def ScanTreeForJsFiles(root):
"""Scans a directory tree for JavaScript files.
Args:
root: str, Path to a root directory.
Returns:
An iterable of paths to JS files, relative to cwd.
"""
return ScanTree(root, path_filter=_JS_FILE_REGEX)
def ScanTree(root, path_filter=None, ignore_hidden=True):
"""Scans a directory tree for files.
Args:
root: str, Path to a root directory.
path_filter: A regular expression filter. If set, only paths matching
the path_filter are returned.
ignore_hidden: If True, do not follow or return hidden directories or files
(those starting with a '.' character).
Yields:
A string path to files, relative to cwd.
"""
def OnError(os_error):
raise os_error
for dirpath, dirnames, filenames in os.walk(root, onerror=OnError):
# os.walk allows us to modify dirnames to prevent decent into particular
# directories. Avoid hidden directories.
for dirname in dirnames:
if ignore_hidden and dirname.startswith('.'):
dirnames.remove(dirname)
for filename in filenames:
# nothing that starts with '.'
if ignore_hidden and filename.startswith('.'):
continue
fullpath = os.path.join(dirpath, filename)
if path_filter and not path_filter.match(fullpath):
continue
yield os.path.normpath(fullpath)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
*
* @param {type} arg1
* @param {type} arg2
* @returns {html2canvas}
*/
function html2canvas (arg1, arg2) {};
This diff is collapsed.
/**
*
* @param {type} arg1
* @returns {jsPDF}
*/
function jsPDF (arg1) {};
/**
*
* @param {type} arg1
* @param {type} arg2
* @param {type} arg3
* @param {type} arg4
* @returns {undefined}
*/
jsPDF.prototype.fromHTML = function (arg1, arg2, arg3, arg4) {};
/**
*
* @param {type} arg1
* @param {type} arg2
* @param {type} arg3
* @param {type} arg4
* @param {type} arg5
* @param {type} arg6
* @returns {undefined}
*/
jsPDF.prototype.addImage = function (arg1, arg2, arg3, arg4, arg5, arg6) {};
/**
*
* @param {type} arg1
* @returns {undefined}
*/
jsPDF.prototype.save = function (arg1) {};
/**
*
* @param {type} arg1
* @returns {undefined}
*/
jsPDF.prototype.setPage = function (arg1) {};
/**
*
* @param {type} arg1
* @param {type} arg2
* @returns {undefined}
*/
jsPDF.prototype.addHTML = function (arg1, arg2) {};
/**
* @author: Armand Bahi
* @Description: Fichier contenant les externs: fonctions à ne pas renommer durant la compilation
* @externs
*/
/**
* Function for initialise the bootstrap toggle switch checkbox plugin
* @constructor
* @param {object} arg1
*/
function bootstrapToggle(arg1) {}
/**
* Function for initialise the bootstrap colorpicker plugin
* @constructor
* @param {object} arg1
*/
function colorpicker(arg1) {}
/**
* Function for initialise the bootstrap table plugin
* @constructor
* @param {object} arg1
*/
function bootstrapTable(arg1) {}
/**
* @param {object} arg1
* @return {!jQuery}
*/
function sortable(arg1) {}
/**
*
* @param {string} key
* @returns {undefined}
*/
ol.Object.prototype.get = function (key) {}
/**
* Get the collection of layers associated with this map.
* @return {!ol.Collection.<ol.layer.Base>} Layers.
* @api stable
*/
ol.Map.prototype.getLayers = function () {}
/**
* Return the visibility of the layer (`true` or `false`).
* @return {boolean} The visibility of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.getVisible = function () {}
/**
* Set the visibility of the layer (`true` or `false`).
* @param {boolean} visible The visibility of the layer.
* @observable
* @api stable
*/
ol.layer.Base.prototype.setVisible = function (visible) {}
/**
* The tile related to the event.
* @type {ol.Tile}
* @api
*/
ol.source.TileEvent.tile
/**
* @type {string}
* @see http://www.w3.org/TR/pointerevents/#the-touch-action-css-property
*/
CSSProperties.prototype.touchAction;
\ No newline at end of file
Subproject commit e0f852bd97334f8f000a5ca193c57e1035c45812
Module ANC 2018.03.00 for Vitis
\ No newline at end of file
This diff is collapsed.