move source here from internal repo

This commit is contained in:
akhil 2013-09-27 16:05:37 -07:00
commit 7132f89fd2
155 changed files with 19242 additions and 0 deletions

61
.gitignore vendored Normal file
View File

@ -0,0 +1,61 @@
.eclipse/
.idea/
nbproject/
benchmark/
classes/
dist/
test/common.js
test/crypto
test/fixtures
test/pummel
test/simple
test/tmp
test-classes/
test-output/
test-reports/
out/
Debug/
Default/
Release/
*.iml
*.log
*.gypi
*.sln
*.vcxproj
*.vcxproj.filters
src/main/js/lib/_stream_duplex.js
src/main/js/lib/_stream_passthrough.js
src/main/js/lib/_stream_readable.js
src/main/js/lib/_stream_transform.js
src/main/js/lib/_stream_writable.js
src/main/js/lib/assert.js
src/main/js/lib/child_process.js
src/main/js/lib/cluster.js
src/main/js/lib/console.js
src/main/js/lib/constants.js
src/main/js/lib/crypto.js
src/main/js/lib/dgram.js
src/main/js/lib/dns.js
src/main/js/lib/events.js
src/main/js/lib/freelist.js
src/main/js/lib/fs.js
src/main/js/lib/http.js
src/main/js/lib/https.js
src/main/js/lib/module.js
src/main/js/lib/net.js
src/main/js/lib/os.js
src/main/js/lib/path.js
src/main/js/lib/querystring.js
src/main/js/lib/readline.js
src/main/js/lib/stream.js
src/main/js/lib/string_decoder.js
src/main/js/lib/tls.js
src/main/js/lib/tty.js
src/main/js/lib/url.js
src/main/js/lib/util.js
src/main/js/lib/vm.js
src/main/js/lib/zlib.js

9
CONTRIBUTORS Normal file
View File

@ -0,0 +1,9 @@
Akhil Arora
Sundararajan Athijegannathan
Bryan Atsatt
Jean-Francois Denise
Torkel Dominique
Henry Jen
Santiago Pericas-Geertsen
Attila Szegedi
Kinsley Wong

350
LICENSE Normal file
View File

@ -0,0 +1,350 @@
GNU General Public License, version 2,
with the Classpath Exception
The GNU General Public License (GPL)
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies of this license
document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your freedom to share
and change it. By contrast, the GNU General Public License is intended to
guarantee your freedom to share and change free software--to make sure the
software is free for all its users. This General Public License applies to
most of the Free Software Foundation's software and to any other program whose
authors commit to using it. (Some other Free Software Foundation software is
covered by the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not price. Our
General Public Licenses are designed to make sure that you have the freedom to
distribute copies of free software (and charge for this service if you wish),
that you receive source code or can get it if you want it, that you can change
the software or use pieces of it in new free programs; and that you know you
can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny
you these rights or to ask you to surrender the rights. These restrictions
translate to certain responsibilities for you if you distribute copies of the
software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for
a fee, you must give the recipients all the rights that you have. You must
make sure that they, too, receive or can get the source code. And you must
show them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2)
offer you this license which gives you legal permission to copy, distribute
and/or modify the software.
Also, for each author's protection and ours, we want to make certain that
everyone understands that there is no warranty for this free software. If the
software is modified by someone else and passed on, we want its recipients to
know that what they have is not the original, so that any problems introduced
by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We
wish to avoid the danger that redistributors of a free program will
individually obtain patent licenses, in effect making the program proprietary.
To prevent this, we have made it clear that any patent must be licensed for
everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification
follow.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains a notice
placed by the copyright holder saying it may be distributed under the terms of
this General Public License. The "Program", below, refers to any such program
or work, and a "work based on the Program" means either the Program or any
derivative work under copyright law: that is to say, a work containing the
Program or a portion of it, either verbatim or with modifications and/or
translated into another language. (Hereinafter, translation is included
without limitation in the term "modification".) Each licensee is addressed as
"you".
Activities other than copying, distribution and modification are not covered by
this License; they are outside its scope. The act of running the Program is
not restricted, and the output from the Program is covered only if its contents
constitute a work based on the Program (independent of having been made by
running the Program). Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's source code as
you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this License
and to the absence of any warranty; and give any other recipients of the
Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may
at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it, thus
forming a work based on the Program, and copy and distribute such modifications
or work under the terms of Section 1 above, provided that you also meet all of
these conditions:
a) You must cause the modified files to carry prominent notices stating
that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in whole or
in part contains or is derived from the Program or any part thereof, to be
licensed as a whole at no charge to all third parties under the terms of
this License.
c) If the modified program normally reads commands interactively when run,
you must cause it, when started running for such interactive use in the
most ordinary way, to print or display an announcement including an
appropriate copyright notice and a notice that there is no warranty (or
else, saying that you provide a warranty) and that users may redistribute
the program under these conditions, and telling the user how to view a copy
of this License. (Exception: if the Program itself is interactive but does
not normally print such an announcement, your work based on the Program is
not required to print an announcement.)
These requirements apply to the modified work as a whole. If identifiable
sections of that work are not derived from the Program, and can be reasonably
considered independent and separate works in themselves, then this License, and
its terms, do not apply to those sections when you distribute them as separate
works. But when you distribute the same sections as part of a whole which is a
work based on the Program, the distribution of the whole must be on the terms
of this License, whose permissions for other licensees extend to the entire
whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your
rights to work written entirely by you; rather, the intent is to exercise the
right to control the distribution of derivative or collective works based on
the Program.
In addition, mere aggregation of another work not based on the Program with the
Program (or with a work based on the Program) on a volume of a storage or
distribution medium does not bring the other work under the scope of this
License.
3. You may copy and distribute the Program (or a work based on it, under
Section 2) in object code or executable form under the terms of Sections 1 and
2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source
code, which must be distributed under the terms of Sections 1 and 2 above
on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to
give any third party, for a charge no more than your cost of physically
performing source distribution, a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of Sections 1
and 2 above on a medium customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer to
distribute corresponding source code. (This alternative is allowed only
for noncommercial distribution and only if you received the program in
object code or executable form with such an offer, in accord with
Subsection b above.)
The source code for a work means the preferred form of the work for making
modifications to it. For an executable work, complete source code means all
the source code for all modules it contains, plus any associated interface
definition files, plus the scripts used to control compilation and installation
of the executable. However, as a special exception, the source code
distributed need not include anything that is normally distributed (in either
source or binary form) with the major components (compiler, kernel, and so on)
of the operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the source
code from the same place counts as distribution of the source code, even though
third parties are not compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program except as
expressly provided under this License. Any attempt otherwise to copy, modify,
sublicense or distribute the Program is void, and will automatically terminate
your rights under this License. However, parties who have received copies, or
rights, from you under this License will not have their licenses terminated so
long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it.
However, nothing else grants you permission to modify or distribute the Program
or its derivative works. These actions are prohibited by law if you do not
accept this License. Therefore, by modifying or distributing the Program (or
any work based on the Program), you indicate your acceptance of this License to
do so, and all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the Program),
the recipient automatically receives a license from the original licensor to
copy, distribute or modify the Program subject to these terms and conditions.
You may not impose any further restrictions on the recipients' exercise of the
rights granted herein. You are not responsible for enforcing compliance by
third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues), conditions
are imposed on you (whether by court order, agreement or otherwise) that
contradict the conditions of this License, they do not excuse you from the
conditions of this License. If you cannot distribute so as to satisfy
simultaneously your obligations under this License and any other pertinent
obligations, then as a consequence you may not distribute the Program at all.
For example, if a patent license would not permit royalty-free redistribution
of the Program by all those who receive copies directly or indirectly through
you, then the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply and
the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or
other property right claims or to contest validity of any such claims; this
section has the sole purpose of protecting the integrity of the free software
distribution system, which is implemented by public license practices. Many
people have made generous contributions to the wide range of software
distributed through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing to
distribute software through any other system and a licensee cannot impose that
choice.
This section is intended to make thoroughly clear what is believed to be a
consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain
countries either by patents or by copyrighted interfaces, the original
copyright holder who places the Program under this License may add an explicit
geographical distribution limitation excluding those countries, so that
distribution is permitted only in or among countries not thus excluded. In
such case, this License incorporates the limitation as if written in the body
of this License.
9. The Free Software Foundation may publish revised and/or new versions of the
General Public License from time to time. Such new versions will be similar in
spirit to the present version, but may differ in detail to address new problems
or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any later
version", you have the option of following the terms and conditions either of
that version or of any later version published by the Free Software Foundation.
If the Program does not specify a version number of this License, you may
choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs
whose distribution conditions are different, write to the author to ask for
permission. For software which is copyrighted by the Free Software Foundation,
write to the Free Software Foundation; we sometimes make exceptions for this.
Our decision will be guided by the two goals of preserving the free status of
all derivatives of our free software and of promoting the sharing and reuse of
software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER
OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible
use to the public, the best way to achieve this is to make it free software
which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach
them to the start of each source file to most effectively convey the exclusion
of warranty; and each file should have at least the "copyright" line and a
pointer to where the full notice is found.
One line to give the program's name and a brief idea of what it does.
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program 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 General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it
starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes
with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free
software, and you are welcome to redistribute it under certain conditions;
type 'show c' for details.
The hypothetical commands 'show w' and 'show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may be
called something other than 'show w' and 'show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your school,
if any, to sign a "copyright disclaimer" for the program, if necessary. Here
is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
'Gnomovision' (which makes passes at compilers) written by James Hacker.
signature of Ty Coon, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General Public
License instead of this License.
"CLASSPATH" EXCEPTION TO THE GPL
Certain source files distributed by Oracle America and/or its affiliates are
subject to the following clarification and special exception to the GPL, but
only where Oracle has expressly included in the particular source file's header
the words "Oracle designates this particular file as subject to the "Classpath"
exception as provided by Oracle in the LICENSE file that accompanied this code."
Linking this library statically or dynamically with other modules is making
a combined work based on this library. Thus, the terms and conditions of
the GNU General Public License cover the whole combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,
and to copy and distribute the resulting executable under terms of your
choice, provided that you also meet, for each linked independent module,
the terms and conditions of the license of that module. An independent
module is a module which is not derived from or based on this library. If
you modify this library, you may extend this exception to your version of
the library, but you are not obligated to do so. If you do not wish to do
so, delete this exception statement from your version.

79
README Normal file
View File

@ -0,0 +1,79 @@
Build Instructions
1. Install jdk8
a) Install the latest jdk8 build from http://jdk8.java.net/download.html
2. Download node.js
a) git clone https://github.com/joyent/node.git source
b) cd source
c) git checkout v0.10.18
(do 'git pull' to refresh repo if you get an error saying this version is unknown)
3. Clone dependencies
a) git://java.net/avatar-js~libuv (read-only)
ssh://<id>@git.java.net/avatar-js~libuv libuv
b) git://java.net/avatar-js~http-parser (read-only)
ssh://<id>@git.java.net/avatar-js~http-parser http-parser
c) git://java.net/avatar-js~src (read-only)
ssh://<id>@git.java.net/avatar-js~src avatar-js
d) Download testng from http://testng.org/doc/download.html
unzip bundle and place testng.jar somewhere in your workspace
3. Edit ~/.avatar-js.properties to set various locations, for example
source.home = /ws/source
avatar-js.home = /ws/avatar-js
libuv.home = /ws/libuv
http-parser.home = /ws/http-parser
testng.jar = /ws/lib/testng.jar
4. Setup environment so that native libraries can be found
cd avatar-js
export LD_LIBRARY_PATH=$PWD/dist:$LD_LIBRARY_PATH (linux)
export DYLD_LIBRARY_PATH=$PWD/dist:$DYLD_LIBRARY_PATH (mac)
export PATH=%CWD%/dist;%PATH% (windows)
5. Configure
a) ant setup
6. Build - ensure jdk8 and appropriate c++ compiler is in PATH
a) ant jar-all
b) ant clean-all (to clean project and dependencies)
c) ant -Dbuild.type=Release jar-all (to build Release configuration)
7. Test
a) java -jar dist/avatar-jar.jar src/test/js/test-runner.js test/simple/
(test-runner.js supports many options, look at source for help)
8. Running applications
java -jar dist/avatar-js.jar app.js
Limitations and Gotchas
1. Platforms tested
a) Ubuntu Linux x64
b) Mac OS X Mountain Lion
c) Windows 7 & 8 x64
2. Dependencies
Requires a recent build of jdk8 (b106+)
3. Globals - some additional globals are exposed
a) context of type ScriptContext [http://download.java.net/jdk8/docs/api/javax/script/ScriptContext.html]
b) __avatar (non-iterable) container for some avatar-specific globals
4. Limitations of the vm module
Objects loaded in a new context and accessed from the current context have some strong limitations -
a) Only a subset of JavaScript API is available on these objects
b) equality (==, ===) will not work as expected
5. Limitations on __proto__
a) __proto__ cannot be set to undefined
affects the ejs module used by express
6. No const keyword
a) the const keyword is not supported, replace with var
affects the mongodb and grunt modules

29
THIRD_PARTY_README Normal file
View File

@ -0,0 +1,29 @@
DO NOT TRANSLATE OR LOCALIZE.
-----------------------------
%% This notice is provided with respect to Node.js.
--- begin of LICENSE ---
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
--- end of LICENSE ---
--------------------------------------------------------------------------------

122
avatar-js.gyp Normal file
View File

@ -0,0 +1,122 @@
{
'includes': {
'config.gypi',
},
'variables': {
'AVATAR-JS_PATH%': 'out/<(target)/lib.target',
},
'target_defaults': {
'default_configuration': '<(target)',
'configurations': {
'Debug': {
'defines': [ 'DEBUG', '_DEBUG' ],
'cflags': [ '-g', '-O0' ],
'conditions': [
['OS == "win"', {
'msvs_settings': {
'VCLinkerTool': {
'GenerateDebugInformation': 'true',
},
},
}],
[ 'OS=="linux"', {
}],
[ 'OS=="mac"', {
}],
],
},
'Release': {
'defines': [ 'NDEBUG' ],
'conditions': [
['OS == "win"', {
}],
[ 'OS=="linux"', {
}],
[ 'OS=="mac"', {
}],
],
},
}
},
'targets': [
{
'target_name': 'avatar-js',
'type': 'shared_library',
'defines': [
],
'dependencies': [
],
'include_dirs': [
'<(JAVA_HOME)/include',
],
'conditions': [
['OS == "linux"', {
'sources': [
'os.cpp',
'process.cpp',
'throw.cpp',
],
'libraries': [
],
'defines': [
'__POSIX__',
],
'cflags': [
'-fPIC',
],
'ldflags': [
],
'include_dirs': [
'<(JAVA_HOME)/include/linux',
],
}],
['OS == "mac"', {
'target_conditions': [
['target_arch=="x64"', {
'xcode_settings': {'ARCHS': ['x86_64']},
}]
],
'sources': [
'<(AVATAR-JS_PATH)/../obj.target/avatar-js/os.cpp',
'<(AVATAR-JS_PATH)/../obj.target/avatar-js/process.cpp',
'<(AVATAR-JS_PATH)/../obj.target/avatar-js/throw.cpp',
],
'libraries': [
],
'defines': [
'__POSIX__',
],
'include_dirs': [
'<(JAVA_HOME)/include/darwin',
],
}],
['OS == "win"', {
'target_conditions': [
['target_arch=="x64"', {
'msvs_configuration_platform': 'x64'
}]
],
'sources': [
'<(AVATAR-JS_PATH)/../obj.target/avatar-js/os.cpp',
'<(AVATAR-JS_PATH)/../obj.target/avatar-js/process.cpp',
'<(AVATAR-JS_PATH)/../obj.target/avatar-js/throw.cpp',
],
'defines': [
'_WIN32',
],
'cflags': [
],
'ldflags': [
],
'include_dirs': [
'<(JAVA_HOME)/include/win32',
],
'libraries': [
],
}]
],
},
],
}

465
build.xml Normal file
View File

@ -0,0 +1,465 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="avatar-js" default="build" basedir=".">
<property file="${user.home}/.avatar-js.properties"/>
<property file="${basedir}/project.properties"/>
<import file="${avatar-js.home}/common.xml"/>
<macrodef name="run-ant">
<attribute name="dir"/>
<attribute name="target"/>
<sequential>
<echo>cd @{dir}; ant @{target}</echo>
<ant dir="@{dir}" target="@{target}" inheritall="false"/>
</sequential>
</macrodef>
<macrodef name="git-pull">
<attribute name="dir"/>
<sequential>
<echo>cd @{dir}; git pull --rebase</echo>
<exec dir="@{dir}" executable="git">
<arg value="pull"/>
<arg value="--rebase"/>
</exec>
</sequential>
</macrodef>
<target name="jar-all" depends="init">
<run-ant dir="${libuv.home}" target="jar"/>
<run-ant dir="${http-parser.home}" target="jar"/>
<antcall target="jar" inheritall="false"/>
</target>
<target name="clean-all" depends="init">
<run-ant dir="${libuv.home}" target="clean"/>
<run-ant dir="${http-parser.home}" target="clean"/>
<antcall target="clean" inheritall="false"/>
</target>
<target name="test-all" depends="init">
<run-ant dir="${libuv.home}" target="test"/>
<run-ant dir="${http-parser.home}" target="test"/>
<antcall target="test" inheritall="false"/>
</target>
<target name="pull-all" depends="init">
<git-pull dir="${libuv.home}"/>
<git-pull dir="${http-parser.home}"/>
<git-pull dir="${basedir}"/>
</target>
<target name="setup" depends="copy-source-files, patch-source-files"/>
<target name="build" depends="setup, jar-all"/>
<target name="init" depends="common-init">
<property name="product.name" value="avatar-js"/>
<property name="build.type" value="Debug"/>
<property name="src.java.dir" location="src/main/java"/>
<property name="test.java.dir" location="src/test/java"/>
<property name="src.js.dir" location="src/main/js"/>
<property name="test.js.dir" location="src/test/js"/>
<property name="patches.dir" location="${basedir}/patches"/>
<property name="test.dir" location="${basedir}/test"/>
<property name="build.properties.file" location="${classes.dir}/build.properties"/>
<property name="native.build.dir" value="${basedir}/out/${build.type}/obj.target/${product.name}/"/>
<loadproperties srcFile="project.properties"/>
<property name="javac.debug" value="true"/>
<property name="javac.debuglevel" value="lines"/>
<path id="javac.classpath.id">
<zipfileset dir="${libuv.home}/dist" includes="*.jar"/>
<zipfileset dir="${http-parser.home}/dist" includes="*.jar"/>
</path>
<path id="javac.test.classpath.id" refid="javac.classpath.id"/>
</target>
<target name="copy-source-files" depends="init" description="copy source files to local project">
<mkdir dir="${test.dir}"/>
<!-- copy modules -->
<property name="source.lib.dir" value="${source.home}/lib"/>
<available type="dir" file="${source.lib.dir}" property="source.lib.dir.available"/>
<fail message="source lib dir not found at ${source.lib.dir}" unless="source.lib.dir.available"/>
<copy todir="src/main/js/lib" overwrite="true">
<filelist dir="${source.lib.dir}" files="${source.lib.modules}"/>
</copy>
<!-- copy test/simple -->
<property name="source.test.simple.dir" value="${source.home}/test/simple"/>
<property name="source.test.pummel.dir" value="${source.home}/test/pummel"/>
<property name="source.test.fixtures.dir" value="${source.home}/test/fixtures"/>
<available type="dir" file="${source.test.simple.dir}" property="source.test.simple.dir.available"/>
<fail message="source test/simple dir not found at ${source.test.simple.dir}"
unless="source.test.simple.dir.available"/>
<copy todir="${test.dir}/simple" overwrite="true">
<filelist dir="${source.test.simple.dir}" files="${source.test.simple.list}"/>
</copy>
<copy todir="${test.dir}/pummel" overwrite="true">
<fileset dir="${source.home}/test/pummel"/>
</copy>
<copy todir="${test.dir}/fixtures" overwrite="true">
<fileset dir="${source.home}/test/fixtures"/>
</copy>
<!-- copy test/simple/test-crypto-* tests in crypto dir -->
<copy todir="${test.dir}/crypto" overwrite="true">
<filelist dir="${source.test.simple.dir}" files="${source.test.simple.crypto.list}"/>
</copy>
<!-- copy test/pummel/test-crypto-* tests in crypto dir -->
<copy todir="${test.dir}/crypto" overwrite="true">
<filelist dir="${source.test.pummel.dir}" files="${source.test.pummel.crypto.list}"/>
</copy>
<!-- copy test infrastructure -->
<copy todir="${test.dir}" file="${source.home}/test/common.js" overwrite="true"/>
<copy todir="${test.dir}/fixtures" overwrite="true">
<fileset dir="${source.home}/test/fixtures"/>
</copy>
<!-- Replace crypto keys -->
<copy todir="${test.dir}/fixtures" overwrite="true">
<fileset dir="crypto/fixtures"/>
</copy>
<!-- Replace tls keys -->
<copy todir="${test.dir}/fixtures/keys" overwrite="true">
<fileset dir="crypto/fixtures/keys"/>
</copy>
<!-- copy benchmarks -->
<copy todir="${basedir}/benchmark" overwrite="true">
<fileset dir="${source.home}/benchmark"/>
</copy>
<mkdir dir="${test.dir}/tmp"/>
</target>
<target name="configure-unix" depends="config-gyp" if="isLinux">
<exec executable="python" dir="." failonerror="true">
<arg value="${source.home}/tools/gyp/gyp"/>
<arg value="--depth=."/>
<arg value="--format=make"/>
<arg value="${product.name}.gyp"/>
<arg value="-Dtarget=${build.type}"/>
<arg value="-Dtarget_arch=x64"/>
</exec>
</target>
<target name="configure-mac" depends="config-gyp" if="isMacOSX">
<exec executable="python" dir="." failonerror="true">
<arg value="${source.home}/tools/gyp/gyp"/>
<arg value="--depth=."/>
<arg value="--format=make"/>
<arg value="${product.name}.gyp"/>
<arg value="-Dtarget=${build.type}"/>
<arg value="-Dtarget_arch=x64"/>
</exec>
</target>
<target name="configure-windows" depends="config-gyp" if="isWindows">
<exec executable="python" dir="." failonerror="true">
<arg value="${source.home}/tools/gyp/gyp"/>
<arg value="--depth=."/>
<arg value="${product.name}.gyp"/>
<arg value="-Dtarget=${build.type}"/>
<arg value="-Dtarget_arch=x64"/>
</exec>
</target>
<target name="javah" depends="compile">
<javah destdir="${native.build.dir}" classpath="${classes.dir}">
<class name="net.java.avatar.js.os.OS"/>
<class name="net.java.avatar.js.os.Process"/>
</javah>
</target>
<target name="jar" depends="generate-build-properties, compile, make">
<copy todir="${classes.dir}">
<fileset dir="${src.js.dir}">
<include name="**/*.js"/>
</fileset>
</copy>
<mkdir dir="${dist.dir}"/>
<property name="product.jar" value="${dist.dir}/${product.name}.jar"/>
<jar destfile="${product.jar}">
<fileset dir="${classes.dir}" includes="**/*.class"/>
<fileset dir="${classes.dir}" includes="**/*.js"/>
<fileset dir="${classes.dir}" includes="**/*.properties"/>
<zipgroupfileset dir="${libuv.home}/dist" includes="libuv-java.jar"/>
<zipgroupfileset dir="${http-parser.home}/dist" includes="http-parser-java.jar"/>
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="net.java.avatar.js.Server"/>
</manifest>
</jar>
<copy todir="${dist.dir}">
<fileset dir="${libuv.home}/dist" includes="*.so*"/>
<fileset dir="${libuv.home}/dist" includes="*.dll"/>
<fileset dir="${libuv.home}/dist" includes="*.dylib"/>
<fileset dir="${http-parser.home}/dist" includes="*.so*"/>
<fileset dir="${http-parser.home}/dist" includes="*.dll"/>
<fileset dir="${http-parser.home}/dist" includes="*.dylib"/>
</copy>
</target>
<target name="generate-build-properties" depends="init"
description="generate a properties file containing build info and a list of built-in modules">
<!-- list of built-in modules -->
<pathconvert property="builtin.modules" pathsep=" ">
<fileset dir="${src.js.dir}/lib">
<include name="*.js"/>
</fileset>
<chainedmapper>
<flattenmapper/>
<globmapper from="*.js" to="*"/>
</chainedmapper>
</pathconvert>
<echo file="${build.properties.file}" append="false">${ant.project.name}.source.compatible.version=${source.compatible.version}${line.separator}</echo>
<echo file="${build.properties.file}" append="true">${ant.project.name}.libuv.compatible.version=${libuv.compatible.version}${line.separator}</echo>
<echo file="${build.properties.file}" append="true">${ant.project.name}.build.java.version=${java.version}${line.separator}</echo>
<echo file="${build.properties.file}" append="true">${ant.project.name}.build.java.vm.version=${java.vm.version}${line.separator}</echo>
<echo file="${build.properties.file}" append="true">${ant.project.name}.build.java.vm.name=${java.vm.name}${line.separator}</echo>
<echo file="${build.properties.file}" append="true">${ant.project.name}.build.java.class.version=${java.class.version}${line.separator}</echo>
<echo file="${build.properties.file}" append="true">${ant.project.name}.build.os.name=${os.name}${line.separator}</echo>
<echo file="${build.properties.file}" append="true">${ant.project.name}.build.os.arch=${os.arch}${line.separator}</echo>
<echo file="${build.properties.file}" append="true">${ant.project.name}.build.os.version=${os.version}${line.separator}</echo>
<echo file="${build.properties.file}" append="true">${ant.project.name}.build.time=${DSTAMP}.${TSTAMP}${line.separator}</echo>
<echo file="${build.properties.file}" append="true">${ant.project.name}.builtin.modules=${builtin.modules}${line.separator}</echo>
</target>
<property name="diff.options" value="-uwr"/>
<macrodef name="apply-diff" description="diff wrapper">
<attribute name="src"/>
<attribute name="mod"/>
<attribute name="name"/>
<sequential>
<echo>diff ${diff.options} ${source.home}/@{src}/@{name} @{mod}/@{name}</echo>
<exec executable="diff" output="${patches.dir}/@{name}.patch">
<arg value="${diff.options}"/>
<arg value="${source.home}/@{src}/@{name}"/>
<arg value="@{mod}/@{name}"/>
</exec>
</sequential>
</macrodef>
<macrodef name="apply-patch-dir" description="patch dir wrapper">
<attribute name="name"/>
<sequential>
<echo>applying ${patches.dir}/@{name}.patch</echo>
<patch patchfile="${patches.dir}/@{name}.patch"
ignorewhitespace="true" reverse="false" strip="0" quiet="false"/>
</sequential>
</macrodef>
<macrodef name="apply-patch-file" description="patch file wrapper">
<attribute name="name"/>
<attribute name="target"/>
<sequential>
<echo>applying ${patches.dir}/@{name}.patch to @{target}</echo>
<patch patchfile="${patches.dir}/@{name}.patch" originalfile="@{target}/@{name}"
ignorewhitespace="true" reverse="false" strip="0" quiet="false"/>
</sequential>
</macrodef>
<!-- keep sorted and synchronized with patch-source-files -->
<target name="diff-source-files" depends="init"
description="generate patch files listing changes to source files">
<mkdir dir="${patches.dir}"/>
<!-- modules -->
<apply-diff src="lib" mod="src/main/js/lib" name="fs.js"/>
<apply-diff src="lib" mod="src/main/js/lib" name="http.js"/>
<apply-diff src="lib" mod="src/main/js/lib" name="querystring.js"/>
<apply-diff src="lib" mod="src/main/js/lib" name="module.js"/>
<apply-diff src="lib" mod="src/main/js/lib" name="net.js"/>
<apply-diff src="lib" mod="src/main/js/lib" name="string_decoder.js"/>
<apply-diff src="lib" mod="src/main/js/lib" name="tls.js"/>
<!-- tests -->
<apply-diff src="test" mod="${test.dir}" name="common.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-buffer.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-chdir.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-child-process-fork-exec-argv.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-dgram-address.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-dgram-ref.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-error-reporting.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-fs-readfile-pipe.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-http.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-http-client-timeout-agent.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-http-end-throw-socket-handling.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-http-head-request.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-http-many-ended-pipelines.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-http-many-keep-alive-connections.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-https-strict.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-module-loading.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-net-pingpong.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-net-server-address.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-net-write-slow.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-next-tick.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-next-tick-starvation.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-os.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-process-exec-argv.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-pipe-head.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-readline-interface.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-script-context.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-stream2-read-sync-stack.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-string-decoder.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-timers-unref.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-timers-zero-timeout.js"/>
<!-- tls tests -->
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-tls-connect-pipe.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-tls-fast-writing.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-tls-over-http-tunnel.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-tls-pause.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-tls-peer-certificate.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-tls-peer-certificate-multi-keys.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-tls-server-missing-options.js"/>
<apply-diff src="test/simple" mod="${test.dir}/simple" name="test-tls-server-verify.js"/>
<apply-diff src="test/simple" mod="${test.dir}/crypto" name="test-tls-getcipher.js"/>
<apply-diff src="test/simple" mod="${test.dir}/crypto" name="test-tls-honorcipherorder.js"/>
<!-- crypto tests -->
<apply-diff src="test/simple" mod="${test.dir}/crypto" name="test-crypto.js"/>
<apply-diff src="test/simple" mod="${test.dir}/crypto" name="test-crypto-binary-default.js"/>
<apply-diff src="test/pummel" mod="${test.dir}/crypto" name="test-crypto-dh.js"/>
</target>
<!-- keep sorted and synchronized with diff-source-files -->
<target name="patch-source-files" depends="init" description="apply patches to source files">
<!-- modules -->
<apply-patch-file target="src/main/js/lib" name="fs.js"/>
<apply-patch-file target="src/main/js/lib" name="http.js"/>
<apply-patch-file target="src/main/js/lib" name="querystring.js"/>
<apply-patch-file target="src/main/js/lib" name="module.js"/>
<apply-patch-file target="src/main/js/lib" name="net.js"/>
<apply-patch-file target="src/main/js/lib" name="string_decoder.js"/>
<apply-patch-file target="src/main/js/lib" name="tls.js"/>
<!-- tests -->
<apply-patch-file target="${test.dir}" name="common.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-buffer.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-chdir.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-child-process-fork-exec-argv.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-dgram-address.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-dgram-ref.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-error-reporting.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-fs-readfile-pipe.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-http.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-http-client-timeout-agent.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-http-end-throw-socket-handling.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-http-head-request.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-http-many-ended-pipelines.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-http-many-keep-alive-connections.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-https-strict.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-module-loading.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-net-pingpong.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-net-server-address.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-net-write-slow.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-next-tick.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-next-tick-starvation.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-os.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-process-exec-argv.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-pipe-head.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-readline-interface.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-script-context.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-stream2-read-sync-stack.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-string-decoder.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-timers-unref.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-timers-zero-timeout.js"/>
<!-- tls tests -->
<apply-patch-file target="${test.dir}/simple" name="test-tls-connect-pipe.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-tls-fast-writing.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-tls-over-http-tunnel.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-tls-pause.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-tls-peer-certificate.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-tls-peer-certificate-multi-keys.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-tls-server-missing-options.js"/>
<apply-patch-file target="${test.dir}/simple" name="test-tls-server-verify.js"/>
<apply-patch-file target="${test.dir}/crypto" name="test-tls-getcipher.js"/>
<apply-patch-file target="${test.dir}/crypto" name="test-tls-honorcipherorder.js"/>
<!-- crypto tests -->
<apply-patch-file target="${test.dir}/crypto" name="test-crypto.js"/>
<apply-patch-file target="${test.dir}/crypto" name="test-crypto-binary-default.js"/>
<apply-patch-file target="${test.dir}/crypto" name="test-crypto-dh.js"/>
</target>
<target name="generate-policy-file" depends="init">
<property name="policy.file" value="dist/avatar-js.policy"/>
<!-- avatar-js jar requires AllPermission -->
<echo message="grant codeBase &quot;file:/${basedir}/dist/${product.name}.jar&quot; {" file="${policy.file}"/>
<echo message="" file="${policy.file}" append="true"/>
<echo message=" permission java.security.AllPermission;" file="${policy.file}" append="true"/>
<echo message="" file="${policy.file}" append="true"/>
<echo message="};" file="${policy.file}" append="true"/>
<echo message="" file="${policy.file}" append="true"/>
<!-- tests require AllPermissions -->
<echo message="grant codeBase &quot;file:/${basedir}/test/-&quot; {" file="${policy.file}" append="true"/>
<echo message="" file="${policy.file}" append="true"/>
<echo message=" permission java.security.AllPermission;" file="${policy.file}" append="true"/>
<echo message="" file="${policy.file}" append="true"/>
<echo message="};" file="${policy.file}" append="true"/>
<echo message="" file="${policy.file}" append="true" />
<!-- for Windows - normalize path separators in URLs -->
<replace file="${policy.file}">
<replacetoken>\</replacetoken>
<replacevalue>/</replacevalue>
</replace>
<!-- for Unix - avoid leading // in URLs -->
<replace file="${policy.file}">
<replacetoken>//</replacetoken>
<replacevalue>/</replacevalue>
</replace>
</target>
<target name="test-security" depends="init, generate-policy-file, run-security-policy-tests, run-security-no-policy-tests"/>
<target name="run-security-policy-tests" depends="init">
<java fork="true" jar="dist/${product.name}.jar" failonerror="true">
<arg value="src/test/js/test-runner.js" />
<arg value="-secure" />
<arg value="src/test/js/security" />
</java>
</target>
<target name="run-security-no-policy-tests" depends="init">
<java fork="true" jar="dist/${product.name}.jar" failonerror="true">
<arg value="src/test/js/test-runner.js" />
<arg value="src/test/js/security/nopolicy" />
</java>
</target>
<target name="package-linux" depends="init" if="isLinux">
<property name="package.name" value="${product.name}-linux"/>
</target>
<target name="package-macos" depends="init" if="isMacOSX">
<property name="package.name" value="${product.name}-macosx"/>
</target>
<target name="package-windows" depends="init" if="isWindows">
<property name="package.name" value="${product.name}-windows"/>
</target>
<target name="package" depends="build, package-linux, package-macos, package-windows">
<delete dir="dist/${product.name}"/>
<delete file="dist/${package.name}.zip"/>
<copy todir="${dist.dir}/${product.name}/lib">
<fileset dir="${dist.dir}" includes="*.so*"/>
<fileset dir="${dist.dir}" includes="*.dll"/>
<fileset dir="${dist.dir}" includes="*.dylib"/>
<fileset dir="${dist.dir}" includes="*.jar"/>
</copy>
<copy todir="${dist.dir}/${product.name}">
<fileset dir="." includes="README"/>
<fileset dir="." includes="LICENSE"/>
</copy>
<zip basedir="${dist.dir}/" includes="${product.name}/**"
destfile="${dist.dir}/${package.name}.zip"/>
</target>
</project>

224
common.xml Normal file
View File

@ -0,0 +1,224 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="avatar-js-libs" basedir=".">
<target name="common-init">
<property file="${user.home}/.avatar-js.properties"/>
<property name="javac.debug" value="true"/>
<property name="javac.debuglevel" value="lines"/>
<property name="common.dir" location="${basedir}/.."/>
<property name="common.lib.dir" value="${common.dir}/lib"/>
<property name="common.dist.dir" value="${common.dir}/dist"/>
<property name="classes.dir" location="classes"/>
<property name="dist.dir" location="dist"/>
<property name="test.classes.dir" location="test-classes"/>
<property name="test.reports.dir" location="test-reports"/>
<property name="test.output.dir" location="test-output"/>
<condition property="isMacOSX">
<and>
<os family="unix"/>
<os family="mac"/>
</and>
</condition>
<condition property="isLinux">
<and>
<os family="unix"/>
<not>
<os family="mac"/>
</not>
</and>
</condition>
<condition property="isUnix">
<and>
<os family="unix"/>
<not>
<os family="windows"/>
</not>
</and>
</condition>
<condition property="isWindows">
<and>
<os family="windows"/>
<not>
<os family="unix"/>
</not>
</and>
</condition>
<!-- workaround for ant setting java.home to the jdk's jre -->
<condition property="is.jre">
<matches string="${java.home}" pattern="[/|\\]jre$"/>
</condition>
<condition property="jdk.home" value="${java.home}/..">
<isset property="is.jre"/>
</condition>
<condition property="jdk.home" value="${java.home}">
<not>
<isset property="is.jre"/>
</not>
</condition>
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath location="${testng.jar}"/>
</taskdef>
<tstamp/>
</target>
<target name="init-linux" depends="init" if="isLinux">
<property name="product.lib" value="${dist.dir}/${product.name}.so"/>
</target>
<target name="init-macos" depends="init" if="isMacOSX">
<property name="product.lib" value="${dist.dir}/${product.name}.dylib"/>
</target>
<target name="init-windows" depends="init" if="isWindows">
<property name="product.lib" value="${dist.dir}/${product.name}.dll"/>
</target>
<target name="config-gyp">
<property name="gypi" value="config.gypi"/>
<echo file="${gypi}" append="false"># Do not edit. Generated by 'ant configure'. ${line.separator}</echo>
<echo file="${gypi}" append="true">{ 'variables': { ${line.separator}</echo>
<echo file="${gypi}" append="true"> 'JAVA_HOME%': '${jdk.home}', ${line.separator}</echo>
<echo file="${gypi}" append="true"> 'SOURCE_HOME%': '${source.home}', ${line.separator}</echo>
<echo file="${gypi}" append="true"> },${line.separator}</echo>
<echo file="${gypi}" append="true"> 'target_defaults': {'default_configuration': '${build.type}'}${line.separator}</echo>
<echo file="${gypi}" append="true">}${line.separator}</echo>
</target>
<macrodef name="gyp">
<attribute name="format"/>
<attribute name="library"/>
<attribute name="target"/>
<sequential>
<exec executable="python" dir="." failonerror="true">
<arg value="${source.home}/tools/gyp/gyp"/>
<arg value="--depth=."/>
<arg value="--format=@{format}"/>
<arg value="-Dtarget_arch=x64"/>
<arg value="-Dlibrary=@{library}"/>
<arg value="-Dtarget=@{target}"/>
<arg value="${product.name}.gyp"/>
</exec>
</sequential>
</macrodef>
<target name="configure" depends="init-linux, init-macos, init-windows, configure-unix, configure-mac, configure-windows">
<copy todir="${native.build.dir}">
<fileset dir="src/main/native" includes="**/*.cpp"/>
<fileset dir="src/main/native" includes="**/*.h"/>
</copy>
<uptodate property="product.lib.uptodate" targetfile="${product.lib}">
<srcfiles dir="${native.build.dir}" includes="**/*.h"/>
<srcfiles dir="${native.build.dir}" includes="**/*.cpp"/>
</uptodate>
</target>
<target name="compile" depends="init">
<mkdir dir="${classes.dir}"/>
<javac includeantruntime="false" debug="${javac.debug}" destdir="${classes.dir}" srcdir="${src.java.dir}">
<compilerarg value="-Xlint:all"/>
<compilerarg value="-deprecation"/>
<compilerarg value="-Werror"/>
<classpath refid="javac.classpath.id"/>
</javac>
</target>
<target name="make" depends="configure, compile, javah, make-linux, make-macos, make-windows"
description="runs make to build native sources"/>
<target name="make-linux" if="isLinux" unless="product.lib.uptodate">
<exec executable="make" failonerror="true"/>
<copy todir="${dist.dir}">
<fileset dir="out/${build.type}/lib.target">
<include name="*.so"/>
</fileset>
<firstmatchmapper>
<globmapper from="libuv.so" to="libuv.so.0.10"/>
<globmapper from="*" to="*"/>
</firstmatchmapper>
</copy>
</target>
<target name="make-macos" if="isMacOSX" unless="product.lib.uptodate">
<exec executable="make" failonerror="true"/>
<copy todir="${dist.dir}">
<fileset dir="out/${build.type}">
<include name="*.dylib"/>
</fileset>
</copy>
</target>
<target name="make-windows" if="isWindows" unless="product.lib.uptodate">
<exec executable="msbuild" failonerror="true">
<arg value="${product.name}.sln"/>
<arg value="/p:Platform=x64"/>
<arg value="/p:Configuration=${build.type}"/>
</exec>
<copy todir="${dist.dir}">
<fileset dir="${build.type}">
<include name="*.dll"/>
</fileset>
<firstmatchmapper>
<globmapper from="libuv-java.dll" to="uv-java.dll"/>
<globmapper from="*" to="*"/>
</firstmatchmapper>
</copy>
</target>
<target name="clean" depends="init" description="clean output dirs">
<delete dir="out"/>
<delete dir="${classes.dir}"/>
<delete dir="${test.classes.dir}"/>
<delete dir="${test.reports.dir}"/>
<delete dir="${test.output.dir}"/>
<delete dir="${dist.dir}"/>
<delete dir="${build.type}"/>
<delete dir="Debug"/>
<delete dir="Default"/>
<delete dir="Release"/>
<delete file="config.gypi"/>
<delete file="Makefile"/>
<delete file="${product.name}.Makefile"/>
<delete file="${product.name}.target.mk"/>
<delete file="${product.name}.sln"/>
<delete file="${product.name}.vcxproj"/>
<delete file="${product.name}.vcxproj.filters"/>
<delete file="gyp-mac-tool"/>
</target>
<target name="test" depends="compile-tests">
<testng outputdir="${test.reports.dir}" useDefaultListeners="true"
listener="org.testng.reporters.XMLReporter">
<classfileset dir="${test.classes.dir}" includes="**/*Test.class"/>
<classpath path="${classes.dir}"/>
<classpath path="${test.classes.dir}"/>
<classpath refid="javac.test.classpath.id"/>
<jvmarg value="-Xverify:all"/>
<jvmarg value="-Xcheck:jni"/>
<jvmarg value="-Xmx1g"/>
<sysproperty key="java.library.path" value="${dist.dir}"/>
</testng>
</target>
<target name="compile-tests" depends="jar">
<mkdir dir="${test.classes.dir}"/>
<javac includeantruntime="false" debug="true" destdir="${test.classes.dir}" srcdir="${test.java.dir}">
<classpath path="${classes.dir}"/>
<classpath path="${testng.jar}"/>
<classpath refid="javac.test.classpath.id"/>
</javac>
<copy todir="${test.classes.dir}" failonerror="false">
<fileset dir="${test.java.dir}/../js"/>
</copy>
</target>
</project>

227
crypto/README Normal file
View File

@ -0,0 +1,227 @@
This document provides information on how to use Crypto and TLS modules as well as how to run associated nodejs tests.
-------
CRYPTO
-------
Running the nodejs pummel and simple crypto tests
=================================================
- The crypto tests are located in test/crypto.
- You need to run the tests with a JDK configured with Unlimited Strength Jurisdiction Policy.
(See Installing section)
- java -jar dist/avatar-js.jar src/test/js/test-runner.js test/crypto
Running the Avatar.js specific crypto tests
===========================================
- The specific crypto test is src/test/js/crypto/test-crypto.js
- You need to run the test with a JDK configured with Unlimited Strength Jurisdiction Policy.
(See Installing section)
- java -jar dist/avatar-js.jar src/test/js/test-runner.js src/test/js/crypto/test-crypto.js
Running the Avatar.js specific crypto tests with unsupported algorithms
=======================================================================
- This test is not mandatory to test crypto.
- The specific crypto test is src/test/js/crypto/test-crypto.js
- Install a provider that offer support for unsupported algorithms.
In jre/lib/security/java.security add security.provider.11=<Your provider class>
- java -classpath <provider jar>:dist/avatar-js.jar net.java.avatar.js.Server src/test/js/crypto/test-crypto.js -unsupported
Installing the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 7
===============================================================================================
- Download the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 7
from: http://www.oracle.com/technetwork/java/javase/downloads/index.html
- Read the UnlimitedJCEPolicy/README.txt for installation procedure
crypto module API Limitations
=============================
Cipher Class
------------
There is the flexibility to change set autoPadding after update has been called on Cipher.
This is not possible with Avatar.js. Be sure to set the autoPadding before to call update."
NB: I never found an example with padding called after update. Seems a documentation typo. Anyway, we should mention it.
"des-ede" support
-----------------
JCE support 3DES with three separate sub keys, for two separate sub keys triple DES (this is what des-ede is),
create a 24 bytes lon key by duplicating the first 8 bytes of your key
crypto module algorithm limitations
===================================
The following algorithm are not supported by Oracle JCE provider:
- Unsupported OpenSSL Ciphers:
desx DESX algorithm.
gost89 GOST 28147-89 in CFB mode (provided by ccgost engine)
gost89-cnt `GOST 28147-89 in CNT mode (provided by ccgost engine)
idea-cbc IDEA algorithm in CBC mode
idea same as idea-cbc
idea-cfb IDEA in CFB mode
idea-ecb IDEA in ECB mode
idea-ofb IDEA in OFB mode
rc5 in all modes
aes 128/192/256 in cfb1 mode
- Unsupported OpenSSL Hash digest:
-mdc2 to use the mdc2 message digest algorithm
-ripemd160 to use the ripemd160 message digest algorithm
-md4 to use the md4 message digest algorithm
-sha to use the sha message digest algorithm
- Unsupported OpenSSL HashMac digest:
-mdc2 to use the mdc2 message digest algorithm
-ripemd160 to use the ripemd160 message digest algorithm
-md4 to use the md4 message digest algorithm
-md2 to use the md2 message digest algorithm
-sha to use the sha message digest algorithm
- Unsupported Digest with DSA: "dsa-md5", "dsa-md2", "dsa-sha384", "dsa-sha512"
- Unsupported Digest with RSA:
- What OpenSSL calls sha is in fact sha-0. What JCE default Provider calls sha in in fact sha-1 (sha-0 is not supported by the default Provider).
This is not documented but "sha" algorithm name exists. In order to have sha-0 to be applied when sha is provided, you will have to use a provider
that takes precendence over the default provider. Look at src/test/js/crypto/test-crypto.js on how to add a custom naming mapping.
- Can't read DSA key size > 1024 for DSS1 (DSA+SHA-1).
- Diffie Hellman, prime numbers can't be smaller than 512 and greater than 2048 bits inclusive, http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6521495
Avatar.js crypto test keys
==========================
Some keys have been regenerated to allow for Avatar.js to pass crypto tests.
The regenerated keys are located in the crypto/fixtures dir. They are copied at install time to the test/fixtures dir.
Some private keys are not in pk8 format. They have been regenerated as follow:
pkcs8 -topk8 -in ../test/fixtures/test_key.pem -inform pem -out test_key.pem -outform pem -nocrypt
pkcs8 -topk8 -in ../test/fixtures/test_rsa_privkey.pem -inform pem -out test_rsa_privkey.pem -outform pem -nocrypt
pkcs8 -topk8 -in ../test/fixtures/test_rsa_privkey_2.pem -inform pem -out test_rsa_privkey_2.pem -outform pem -nocrypt
Public RSA key regenerated
openssl rsa -in test_rsa_privkey_2.pem -pubout -outform PEM -out test_rsa_pubkey_2.pem
DSA keys regerated in 1024 bits. This is a limitation for DSS1 algorithm (DSA+SHA1) in Java. We have generated a new key pair of strength 1024.
1) openssl dsaparam -out dsaparam.pem 1024
2) openssl gendsa -out est_dsa_privkey.pem dsaparam.pem
3) pkcs8 -topk8 -in test_dsa_privkey.pem -inform pem -out test_dsa_privkey.pem -outform pem -nocrypt
4) openssl dsa -in test_dsa_privkey.pem -pubout -outform PEM -out test_dsa_pubkey.pem YES
-------
TLS
-------
This module implements support for TLS/SSL.
TODO
----
- OpenSSL name and expression mapping.
- 3 Missing tests: 2 in pummel, 1 openssl one that depends on process.stdin.write
Limitations
===========
- honorCipherOrder is not supported, Java runtime is picking from the client list
the strongest cipher suite as documented in http://docs.oracle.com/javase/7/docs/technotes/guides/security/SunProviders.html
- SSLv2 is not supported by Oracle JCE. SSLv2 is unsecure, use TLS 1.0 or higher.
- NPN is not supported. Need to log an RFE againt JRE to have support in JDK 9.
- In nodejs, asking the client to authenticate is a "REQUEST" not a "REQUIRE". In Java, this is a "REQUIRE".
We managed to make Java to accept untrusted certificate, but there is no way to make Java to accept none certificate. In this case,
the connection is closed by the server. The test test-tls-server-verify.js has been updated to have client not sending certificate
to not be tested. test-https-pfx.js has been disabled. This behavior is tracked by: JDK-8007788
- In tls, there is the ability to provide some undocumented options (the Secure options). I didn't find any isuage of these options. I am wandering if this is not dead code.
Change with respect to nodejs documentation
============================================
- Defaults ciphersuite is the one from Java JSSE.
- Not (yet) support for cipher suite OpenSSL names, use standard full cipher suite names.
Nodejs TLS test keys
=====================
Some keys have been regenerated to allow for Avatar.js to pass tls tests.
The regenerated keys are located in the crypto/fixtures/keys dir.
They are copied at install time to the test/fixtures/keys dir.
openssl pkcs8 -topk8 -in ../test/fixtures/keys/agent1-key.pem -inform pem -out crypto/fixtures/keys/agent1-key.pem -outform pem -nocrypt
openssl pkcs8 -topk8 -in ../test/fixtures/keys/agent2-key.pem -inform pem -out crypto/fixtures/keys/agent2-key.pem -outform pem -nocrypt
openssl pkcs8 -topk8 -in ../test/fixtures/keys/agent3-key.pem -inform pem -out crypto/fixtures/keys/agent3-key.pem -outform pem -nocrypt
openssl pkcs8 -topk8 -in ../test/fixtures/keys/agent4-key.pem -inform pem -out crypto/fixtures/keys/agent4-key.pem -outform pem -nocrypt
openssl pkcs8 -topk8 -in ../test/fixtures/pass-key.pem -inform pem -out crypto/fixtures/pass-key.pem -outform pem
passphrase as password.
openssl pkcs8 -topk8 -in ../test/fixtures/agent.key -inform pem -out crypto/fixtures/agent.key -outform pem -nocrypt
Nodejs tests that require Unlimited Strength
============================================
These tests require that you install Unlimited Strength. They are copied at build time in the
test/crypto dir
- test-tls-getcipher.js
- test-tls-honorcipherorder.js
Running the Avatar.js specific tls tests
========================================
- This test is not mandatory to test tls.
- The specific tls test is src/test/crypto/test-tls.js
- java -jar dist/avatar-js.jar src/test/crypto/test-tls.js
- java -jar dist/avatar-js.jar src/test/crypto/test-tls-altnames.js
Generation of the certificate for test-tls-altnames.js test
===========================================================
- key, cnf, csr and crt files are located in the crypto/altnames dir.
- Generate the priv key
openssl genrsa -out altnames-agent-key-trans.pem 1024
- To PK8
openssl pkcs8 -topk8 -in altnames-agent-key-trans.pem -inform pem -out altnames-agent-key.pem -outform pem -nocrypt
- Generate the request:
openssl req -new -out altnames-agent-key.csr -key altnames-agent-key.pem -config altnames.cnf
- Generate the certificate:
openssl x509 -req -days 9999 -in altnames-agent-key.csr -signkey altnames-agent-key.pem -out altnames-agent.crt -extensions v3_req -extfile altnames.cnf
JRE Bugs that are affecting TLS
===============================
JDK-8005859 for wish we have a workaround: https://jbs.oracle.com/bugs/browse/JDK-8005859
JDK-8007785 for NPN support
JDK-8007788 to accept null certificate when asked client to authenticate
Notes
=====
The main difference between Java and nodejs
is related to Certificate validation handling.
Nominal usage of Java SSL support doesn't allow for unverified server certificate.
If a certificate is received and it is not trusted, then an Exception is thrown and Handshake is closed.
Nodejs allows for untrusted connection. To achieve the nodejs behavior,
the TrustManger needs to be wrapped inside a trustmanager that will delegate to the actual trustmanager
and not re-throw any exception. The status (trusted or not) is kept.
tls.js, when handshake is over, will call verifyError. According to the error value,
tls will open the secure connection, but the connection will be marked has being not authorized.
The actual errors (certificate validation is NOT considered has being an error) are:
- invalid server side private key.
- invalid non encrypted received content
Java SSL support allows for more flexibility than nodejs in order to retrieve
the set of trusted authorities.
The default source of trust is used when no "ca" option is provided (on server and/or client side)
the default mechanism to retrieve trustores is used
(as documented in http://download.java.net/jdk8/docs/technotes/guides/security/jsse/JSSERefGuide.html).
For example, to provide your own truststore use the system properties -Djavax.net.ssl.trustStore
and -Djavax.net.ssl.trustStorePassword.

View File

@ -0,0 +1,14 @@
-----BEGIN CERTIFICATE REQUEST-----
MIICDzCCAXgCAQAwUDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAk1OMREwDwYDVQQH
EwhOZXctWW9yazEhMB8GA1UECxMYRG9tYWluIENvbnRyb2wgVmFsaWRhdGVkMIGf
MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLQBMqVCo6gb+96zaAZd+qExNvHcPB
PUkvPFRserkP4LaHsWeeZGIl3S66m7U+wgAdyg59uEjh8gRJvu2raXLFObdeY0s6
kLhobuYrAvv0rXwIBqtVJl2actfbn+1V8aw5ou+oz7MqgDI0OL6mWfXCpc2CvpWU
sfRtql/mLZIppQIDAQABoH8wfQYJKoZIhvcNAQkOMXAwbjAJBgNVHRMEAjAAMAsG
A1UdDwQEAwIF4DBUBgNVHREETTBLghNob3N0MS5hdmF0YXItanMuY29tghNob3N0
Mi5hdmF0YXItanMub3JnghNob3N0My5hdmF0YXItanMubmV0hwQKpmm5hwQKpmm6
MA0GCSqGSIb3DQEBBQUAA4GBACdXXDRzT4xDv+Q27iYzAG+gO0/BYdAr+Ps9F7sM
YDiXSs7uhAq8/HBWuy32jq6j59HPtE3wTZvRmSUC9U5wEM4E17NL802W9TzrUBwj
naUNnVTOpUUAmKil5hZXWM6bojQYxTgerxbxhyfOi538xlQBvgj4WfUAk3jKcQdv
Qh2V
-----END CERTIFICATE REQUEST-----

View File

@ -0,0 +1,16 @@
-----BEGIN PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMtAEypUKjqBv73r
NoBl36oTE28dw8E9SS88VGx6uQ/gtoexZ55kYiXdLrqbtT7CAB3KDn24SOHyBEm+
7atpcsU5t15jSzqQuGhu5isC+/StfAgGq1UmXZpy19uf7VXxrDmi76jPsyqAMjQ4
vqZZ9cKlzYK+lZSx9G2qX+YtkimlAgMBAAECgYAhCpOTCAetZzZii4BaszT/EwbP
w4j1Ox9QnIAk+nZnTGKgAIkVyL/j4+ca0wFN6H/YV+avLWw7vvpPeshsW0Ia34/a
2I+C4SNwlk9kAZgHmQbpzM2sGSxr4Uh8sFl2JhpWAzkUYEAoXQV01037A/IEEsTg
YOIpozRRq7OkGb7kwQJBAPJkttyWhb0bEtY2SbeUb8/l0QF7vKtxzRSRCHJ7X32u
kXzT5RSP70EuqjJw1+EgyMIod2ANWkHJYny/BlmOk/kCQQDWqNvl/pVhti+7xOvk
OZiLKBinrfbLvZgUgA/B48xE+rj6vBez6o6xZNunwYUvzvfytjilESFeGYelQk2C
V1YNAkBb5Q7mhjJhxTfY+m/sJ1xUhx4737thjB1h5LI9JMTJEzuZBYRdzUu5fIWN
5fYSJam24jyPr8A+HKk3/fvcTA+RAkBzgpYiI2a7F9CD2CmfvCaL612pDYHajQGD
No5EJZLMI6batdCDblqutrlEgmxrF5JxNwEwQhGUk2Rc11riIqEZAkEA51pRhjMf
aiHIx0BOKJZY/SsKFNqYPYgin13YrOisC1Wdk0/QFF7jfkcxYrItvwmqN+uzT+X2
2Ag3XmQD37fdeg==
-----END PRIVATE KEY-----

View File

@ -0,0 +1,16 @@
-----BEGIN CERTIFICATE-----
MIICjjCCAfegAwIBAgIJALj9ti/tk4KIMA0GCSqGSIb3DQEBBQUAMFAxCzAJBgNV
BAYTAlVTMQswCQYDVQQIEwJNTjERMA8GA1UEBxMITmV3LVlvcmsxITAfBgNVBAsT
GERvbWFpbiBDb250cm9sIFZhbGlkYXRlZDAeFw0xMzA5MTkwNzM1MzdaFw00MTAy
MDMwNzM1MzdaMFAxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJNTjERMA8GA1UEBxMI
TmV3LVlvcmsxITAfBgNVBAsTGERvbWFpbiBDb250cm9sIFZhbGlkYXRlZDCBnzAN
BgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAy0ATKlQqOoG/ves2gGXfqhMTbx3DwT1J
LzxUbHq5D+C2h7FnnmRiJd0uupu1PsIAHcoOfbhI4fIESb7tq2lyxTm3XmNLOpC4
aG7mKwL79K18CAarVSZdmnLX25/tVfGsOaLvqM+zKoAyNDi+pln1wqXNgr6VlLH0
bapf5i2SKaUCAwEAAaNwMG4wCQYDVR0TBAIwADALBgNVHQ8EBAMCBeAwVAYDVR0R
BE0wS4ITaG9zdDEuYXZhdGFyLWpzLmNvbYITaG9zdDIuYXZhdGFyLWpzLm9yZ4IT
aG9zdDMuYXZhdGFyLWpzLm5ldIcECqZpuYcECqZpujANBgkqhkiG9w0BAQUFAAOB
gQAYLiHqAw5y6CP5U0QHeNLGOZGRhph+Z54zo3Bwr/3FOiNPBnjRopYwzahVIyPu
VF2yhaEZt3nIWhM3OKxOFFVIPGJ0nAPVWQD33W6npttqNkQGu66sVFVuNZEzD6tv
pgRYjucwOvlPmaTyTXgcLS1gvJLvh6rEbhziVfs4H4xUGQ==
-----END CERTI