Merge
This commit is contained in:
commit
8e319065d3
@ -360,3 +360,4 @@ f900d5afd9c83a0df8f36161c27c5e4c86a66f4c jdk-9+111
|
||||
09617ce980b99d49abfd54dacfed353c47e2a115 jdk-9+115
|
||||
6743a8e0cab7b5f6f4a0575f6664892f0ab740af jdk-9+116
|
||||
e882bcdbdac436523f3d5681611d3118a3804ea7 jdk-9+117
|
||||
047f95de8f918d8ff5e8cd2636a2abb5c3c8adb8 jdk-9+118
|
||||
|
@ -768,7 +768,7 @@ AC_DEFUN([FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK_HELPER],
|
||||
$2CFLAGS_JDK="${$2CFLAGS_JDK} -fno-strict-aliasing"
|
||||
;;
|
||||
esac
|
||||
TOOLCHAIN_CHECK_COMPILER_VERSION(VERSION: 6, IF_AT_LEAST: FLAGS_SETUP_GCC6_COMPILER_FLAGS)
|
||||
TOOLCHAIN_CHECK_COMPILER_VERSION(VERSION: 6, PREFIX: $2, IF_AT_LEAST: FLAGS_SETUP_GCC6_COMPILER_FLAGS)
|
||||
elif test "x$TOOLCHAIN_TYPE" = xclang; then
|
||||
$2JVM_CFLAGS="[$]$2JVM_CFLAGS -D_GNU_SOURCE"
|
||||
|
||||
@ -964,7 +964,7 @@ AC_DEFUN([FLAGS_SETUP_COMPILER_FLAGS_FOR_JDK_HELPER],
|
||||
-Wunused-value -Woverloaded-virtual"
|
||||
|
||||
if test "x$TOOLCHAIN_TYPE" = xgcc; then
|
||||
TOOLCHAIN_CHECK_COMPILER_VERSION(VERSION: [4.8],
|
||||
TOOLCHAIN_CHECK_COMPILER_VERSION(VERSION: [4.8], PREFIX: $2,
|
||||
IF_AT_LEAST: [
|
||||
# These flags either do not work or give spurious warnings prior to gcc 4.8.
|
||||
$2JVM_CFLAGS="[$]$2JVM_CFLAGS -Wno-format-zero-length -Wtype-limits -Wuninitialized"
|
||||
@ -1411,9 +1411,15 @@ AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_MISC],
|
||||
DISABLE_WARNING_PREFIX=
|
||||
fi
|
||||
CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
|
||||
# Repeate the check for the BUILD_CC
|
||||
# Repeate the check for the BUILD_CC and BUILD_CXX. Need to also reset
|
||||
# CFLAGS since any target specific flags will likely not work with the
|
||||
# build compiler
|
||||
CC_OLD="$CC"
|
||||
CXX_OLD="$CXX"
|
||||
CC="$BUILD_CC"
|
||||
CXX="$BUILD_CXX"
|
||||
CFLAGS_OLD="$CFLAGS"
|
||||
CFLAGS=""
|
||||
FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [-Wno-this-is-a-warning-that-do-not-exist],
|
||||
IF_TRUE: [BUILD_CC_CAN_DISABLE_WARNINGS=true],
|
||||
IF_FALSE: [BUILD_CC_CAN_DISABLE_WARNINGS=false]
|
||||
@ -1424,6 +1430,8 @@ AC_DEFUN_ONCE([FLAGS_SETUP_COMPILER_FLAGS_MISC],
|
||||
BUILD_CC_DISABLE_WARNING_PREFIX=
|
||||
fi
|
||||
CC="$CC_OLD"
|
||||
CXX="$CXX_OLD"
|
||||
CFLAGS="$CFLAGS_OLD"
|
||||
;;
|
||||
clang)
|
||||
DISABLE_WARNING_PREFIX="-Wno-"
|
||||
|
@ -4900,6 +4900,8 @@ TOOLCHAIN_MINIMUM_VERSION_xlc=""
|
||||
|
||||
# Prepare the system so that TOOLCHAIN_CHECK_COMPILER_VERSION can be called.
|
||||
# Must have CC_VERSION_NUMBER and CXX_VERSION_NUMBER.
|
||||
# $1 - optional variable prefix for compiler and version variables (BUILD_)
|
||||
# $2 - optional variable prefix for comparable variable (OPENJDK_BUILD_)
|
||||
|
||||
|
||||
# Check if the configured compiler (C and C++) is of a specific version or
|
||||
@ -4909,6 +4911,7 @@ TOOLCHAIN_MINIMUM_VERSION_xlc=""
|
||||
# VERSION: The version string to check against the found version
|
||||
# IF_AT_LEAST: block to run if the compiler is at least this version (>=)
|
||||
# IF_OLDER_THAN: block to run if the compiler is older than this version (<)
|
||||
# PREFIX: Optional variable prefix for compiler to compare version for (OPENJDK_BUILD_)
|
||||
|
||||
|
||||
|
||||
@ -5073,7 +5076,7 @@ VS_SDK_PLATFORM_NAME_2013=
|
||||
#CUSTOM_AUTOCONF_INCLUDE
|
||||
|
||||
# Do not change or remove the following line, it is needed for consistency checks:
|
||||
DATE_WHEN_GENERATED=1462806878
|
||||
DATE_WHEN_GENERATED=1462970869
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
@ -34795,19 +34798,19 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
|
||||
|
||||
|
||||
if test "x$CC_VERSION_NUMBER" != "x$CXX_VERSION_NUMBER"; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: C and C++ compiler has different version numbers, $CC_VERSION_NUMBER vs $CXX_VERSION_NUMBER." >&5
|
||||
$as_echo "$as_me: WARNING: C and C++ compiler has different version numbers, $CC_VERSION_NUMBER vs $CXX_VERSION_NUMBER." >&2;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: C and C++ compiler have different version numbers, $CC_VERSION_NUMBER vs $CXX_VERSION_NUMBER." >&5
|
||||
$as_echo "$as_me: WARNING: C and C++ compiler have different version numbers, $CC_VERSION_NUMBER vs $CXX_VERSION_NUMBER." >&2;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: This typically indicates a broken setup, and is not supported" >&5
|
||||
$as_echo "$as_me: WARNING: This typically indicates a broken setup, and is not supported" >&2;}
|
||||
fi
|
||||
|
||||
# We only check CC_VERSION_NUMBER since we assume CXX_VERSION_NUMBER is equal.
|
||||
if [[ "$CC_VERSION_NUMBER" =~ (.*\.){3} ]] ; then
|
||||
if [[ "[$]CC_VERSION_NUMBER" =~ (.*\.){3} ]] ; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: C compiler version number has more than three parts (X.Y.Z): $CC_VERSION_NUMBER. Comparisons might be wrong." >&5
|
||||
$as_echo "$as_me: WARNING: C compiler version number has more than three parts (X.Y.Z): $CC_VERSION_NUMBER. Comparisons might be wrong." >&2;}
|
||||
fi
|
||||
|
||||
if [[ "$CC_VERSION_NUMBER" =~ [0-9]{6} ]] ; then
|
||||
if [[ "[$]CC_VERSION_NUMBER" =~ [0-9]{6} ]] ; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: C compiler version number has a part larger than 99999: $CC_VERSION_NUMBER. Comparisons might be wrong." >&5
|
||||
$as_echo "$as_me: WARNING: C compiler version number has a part larger than 99999: $CC_VERSION_NUMBER. Comparisons might be wrong." >&2;}
|
||||
fi
|
||||
@ -34850,6 +34853,13 @@ $as_echo "$as_me: WARNING: C compiler version number has a part larger than 9999
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -34897,6 +34907,8 @@ $as_echo "$as_me: WARNING: You are using $TOOLCHAIN_TYPE older than $TOOLCHAIN_M
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fi
|
||||
|
||||
#
|
||||
@ -46475,6 +46487,268 @@ $as_echo "$as_me: Rewriting BUILD_STRIP to \"$new_complete\"" >&6;}
|
||||
BUILD_LDCXX="$BUILD_CXX"
|
||||
|
||||
PATH="$OLDPATH"
|
||||
|
||||
|
||||
COMPILER=$BUILD_CC
|
||||
COMPILER_NAME=BuildC
|
||||
|
||||
if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
|
||||
# cc -V output typically looks like
|
||||
# cc: Sun C 5.12 Linux_i386 2011/11/16
|
||||
COMPILER_VERSION_OUTPUT=`$COMPILER -V 2>&1`
|
||||
# Check that this is likely to be the Solaris Studio cc.
|
||||
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "^.*: Sun $COMPILER_NAME" > /dev/null
|
||||
if test $? -ne 0; then
|
||||
ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
|
||||
$as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with -V was: \"$COMPILER_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running with -V was: \"$COMPILER_VERSION_OUTPUT\"" >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$ALT_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running with --version was: \"$ALT_VERSION_OUTPUT\"" >&6;}
|
||||
as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
|
||||
fi
|
||||
# Remove usage instructions (if present), and
|
||||
# collapse compiler output into a single line
|
||||
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/ *[Uu]sage:.*//'`
|
||||
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e "s/^.*[ ,\t]$COMPILER_NAME[ ,\t]\([1-9]\.[0-9][0-9]*\).*/\1/"`
|
||||
elif test "x$TOOLCHAIN_TYPE" = xxlc; then
|
||||
# xlc -qversion output typically looks like
|
||||
# IBM XL C/C++ for AIX, V11.1 (5724-X13)
|
||||
# Version: 11.01.0000.0015
|
||||
COMPILER_VERSION_OUTPUT=`$COMPILER -qversion 2>&1`
|
||||
# Check that this is likely to be the IBM XL C compiler.
|
||||
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "IBM XL C" > /dev/null
|
||||
if test $? -ne 0; then
|
||||
ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
|
||||
$as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with -qversion was: \"$COMPILER_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running with -qversion was: \"$COMPILER_VERSION_OUTPUT\"" >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$ALT_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running with --version was: \"$ALT_VERSION_OUTPUT\"" >&6;}
|
||||
as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
|
||||
fi
|
||||
# Collapse compiler output into a single line
|
||||
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
|
||||
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/^.*, V\([1-9][0-9.]*\).*$/\1/'`
|
||||
elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
|
||||
# There is no specific version flag, but all output starts with a version string.
|
||||
# First line typically looks something like:
|
||||
# Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
|
||||
COMPILER_VERSION_OUTPUT=`$COMPILER 2>&1 | $HEAD -n 1 | $TR -d '\r'`
|
||||
# Check that this is likely to be Microsoft CL.EXE.
|
||||
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Microsoft.*Compiler" > /dev/null
|
||||
if test $? -ne 0; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
|
||||
$as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running it was: \"$COMPILER_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running it was: \"$COMPILER_VERSION_OUTPUT\"" >&6;}
|
||||
as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
|
||||
fi
|
||||
# Collapse compiler output into a single line
|
||||
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
|
||||
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/^.*ersion.\([1-9][0-9.]*\) .*$/\1/'`
|
||||
elif test "x$TOOLCHAIN_TYPE" = xgcc; then
|
||||
# gcc --version output typically looks like
|
||||
# gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
|
||||
# Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
# This is free software; see the source for copying conditions. There is NO
|
||||
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
|
||||
# Check that this is likely to be GCC.
|
||||
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null
|
||||
if test $? -ne 0; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
|
||||
$as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$COMPILER_VERSION\"" >&5
|
||||
$as_echo "$as_me: The result from running with --version was: \"$COMPILER_VERSION\"" >&6;}
|
||||
as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
|
||||
fi
|
||||
# Remove Copyright and legalese from version string, and
|
||||
# collapse into a single line
|
||||
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/ *Copyright .*//'`
|
||||
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/^.* \([1-9]\.[0-9.]*\)[^0-9.].*$/\1/'`
|
||||
elif test "x$TOOLCHAIN_TYPE" = xclang; then
|
||||
# clang --version output typically looks like
|
||||
# Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
|
||||
# clang version 3.3 (tags/RELEASE_33/final)
|
||||
# or
|
||||
# Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
|
||||
# Target: x86_64-pc-linux-gnu
|
||||
# Thread model: posix
|
||||
COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
|
||||
# Check that this is likely to be clang
|
||||
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "clang" > /dev/null
|
||||
if test $? -ne 0; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
|
||||
$as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$COMPILER_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running with --version was: \"$COMPILER_VERSION_OUTPUT\"" >&6;}
|
||||
as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
|
||||
fi
|
||||
# Collapse compiler output into a single line
|
||||
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
|
||||
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/^.* version \([1-9][0-9.]*\).*$/\1/'`
|
||||
else
|
||||
as_fn_error $? "Unknown toolchain type $TOOLCHAIN_TYPE." "$LINENO" 5
|
||||
fi
|
||||
# This sets CC_VERSION_NUMBER or CXX_VERSION_NUMBER. (This comment is a grep marker)
|
||||
BUILD_CC_VERSION_NUMBER="$COMPILER_VERSION_NUMBER"
|
||||
# This sets CC_VERSION_STRING or CXX_VERSION_STRING. (This comment is a grep marker)
|
||||
BUILD_CC_VERSION_STRING="$COMPILER_VERSION_STRING"
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: Using $TOOLCHAIN_TYPE $COMPILER_NAME compiler version $COMPILER_VERSION_NUMBER [$COMPILER_VERSION_STRING]" >&5
|
||||
$as_echo "$as_me: Using $TOOLCHAIN_TYPE $COMPILER_NAME compiler version $COMPILER_VERSION_NUMBER [$COMPILER_VERSION_STRING]" >&6;}
|
||||
|
||||
|
||||
COMPILER=$BUILD_CXX
|
||||
COMPILER_NAME=BuildC++
|
||||
|
||||
if test "x$TOOLCHAIN_TYPE" = xsolstudio; then
|
||||
# cc -V output typically looks like
|
||||
# cc: Sun C 5.12 Linux_i386 2011/11/16
|
||||
COMPILER_VERSION_OUTPUT=`$COMPILER -V 2>&1`
|
||||
# Check that this is likely to be the Solaris Studio cc.
|
||||
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "^.*: Sun $COMPILER_NAME" > /dev/null
|
||||
if test $? -ne 0; then
|
||||
ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
|
||||
$as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with -V was: \"$COMPILER_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running with -V was: \"$COMPILER_VERSION_OUTPUT\"" >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$ALT_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running with --version was: \"$ALT_VERSION_OUTPUT\"" >&6;}
|
||||
as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
|
||||
fi
|
||||
# Remove usage instructions (if present), and
|
||||
# collapse compiler output into a single line
|
||||
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/ *[Uu]sage:.*//'`
|
||||
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e "s/^.*[ ,\t]$COMPILER_NAME[ ,\t]\([1-9]\.[0-9][0-9]*\).*/\1/"`
|
||||
elif test "x$TOOLCHAIN_TYPE" = xxlc; then
|
||||
# xlc -qversion output typically looks like
|
||||
# IBM XL C/C++ for AIX, V11.1 (5724-X13)
|
||||
# Version: 11.01.0000.0015
|
||||
COMPILER_VERSION_OUTPUT=`$COMPILER -qversion 2>&1`
|
||||
# Check that this is likely to be the IBM XL C compiler.
|
||||
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "IBM XL C" > /dev/null
|
||||
if test $? -ne 0; then
|
||||
ALT_VERSION_OUTPUT=`$COMPILER --version 2>&1`
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
|
||||
$as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with -qversion was: \"$COMPILER_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running with -qversion was: \"$COMPILER_VERSION_OUTPUT\"" >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$ALT_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running with --version was: \"$ALT_VERSION_OUTPUT\"" >&6;}
|
||||
as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
|
||||
fi
|
||||
# Collapse compiler output into a single line
|
||||
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
|
||||
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/^.*, V\([1-9][0-9.]*\).*$/\1/'`
|
||||
elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
|
||||
# There is no specific version flag, but all output starts with a version string.
|
||||
# First line typically looks something like:
|
||||
# Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
|
||||
COMPILER_VERSION_OUTPUT=`$COMPILER 2>&1 | $HEAD -n 1 | $TR -d '\r'`
|
||||
# Check that this is likely to be Microsoft CL.EXE.
|
||||
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Microsoft.*Compiler" > /dev/null
|
||||
if test $? -ne 0; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
|
||||
$as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running it was: \"$COMPILER_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running it was: \"$COMPILER_VERSION_OUTPUT\"" >&6;}
|
||||
as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
|
||||
fi
|
||||
# Collapse compiler output into a single line
|
||||
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
|
||||
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/^.*ersion.\([1-9][0-9.]*\) .*$/\1/'`
|
||||
elif test "x$TOOLCHAIN_TYPE" = xgcc; then
|
||||
# gcc --version output typically looks like
|
||||
# gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
|
||||
# Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
# This is free software; see the source for copying conditions. There is NO
|
||||
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
|
||||
# Check that this is likely to be GCC.
|
||||
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "Free Software Foundation" > /dev/null
|
||||
if test $? -ne 0; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
|
||||
$as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$COMPILER_VERSION\"" >&5
|
||||
$as_echo "$as_me: The result from running with --version was: \"$COMPILER_VERSION\"" >&6;}
|
||||
as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
|
||||
fi
|
||||
# Remove Copyright and legalese from version string, and
|
||||
# collapse into a single line
|
||||
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/ *Copyright .*//'`
|
||||
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/^.* \([1-9]\.[0-9.]*\)[^0-9.].*$/\1/'`
|
||||
elif test "x$TOOLCHAIN_TYPE" = xclang; then
|
||||
# clang --version output typically looks like
|
||||
# Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
|
||||
# clang version 3.3 (tags/RELEASE_33/final)
|
||||
# or
|
||||
# Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
|
||||
# Target: x86_64-pc-linux-gnu
|
||||
# Thread model: posix
|
||||
COMPILER_VERSION_OUTPUT=`$COMPILER --version 2>&1`
|
||||
# Check that this is likely to be clang
|
||||
$ECHO "$COMPILER_VERSION_OUTPUT" | $GREP "clang" > /dev/null
|
||||
if test $? -ne 0; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&5
|
||||
$as_echo "$as_me: The $COMPILER_NAME compiler (located as $COMPILER) does not seem to be the required $TOOLCHAIN_TYPE compiler." >&6;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: The result from running with --version was: \"$COMPILER_VERSION_OUTPUT\"" >&5
|
||||
$as_echo "$as_me: The result from running with --version was: \"$COMPILER_VERSION_OUTPUT\"" >&6;}
|
||||
as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5
|
||||
fi
|
||||
# Collapse compiler output into a single line
|
||||
COMPILER_VERSION_STRING=`$ECHO $COMPILER_VERSION_OUTPUT`
|
||||
COMPILER_VERSION_NUMBER=`$ECHO $COMPILER_VERSION_OUTPUT | \
|
||||
$SED -e 's/^.* version \([1-9][0-9.]*\).*$/\1/'`
|
||||
else
|
||||
as_fn_error $? "Unknown toolchain type $TOOLCHAIN_TYPE." "$LINENO" 5
|
||||
fi
|
||||
# This sets CC_VERSION_NUMBER or CXX_VERSION_NUMBER. (This comment is a grep marker)
|
||||
BUILD_CXX_VERSION_NUMBER="$COMPILER_VERSION_NUMBER"
|
||||
# This sets CC_VERSION_STRING or CXX_VERSION_STRING. (This comment is a grep marker)
|
||||
BUILD_CXX_VERSION_STRING="$COMPILER_VERSION_STRING"
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: Using $TOOLCHAIN_TYPE $COMPILER_NAME compiler version $COMPILER_VERSION_NUMBER [$COMPILER_VERSION_STRING]" >&5
|
||||
$as_echo "$as_me: Using $TOOLCHAIN_TYPE $COMPILER_NAME compiler version $COMPILER_VERSION_NUMBER [$COMPILER_VERSION_STRING]" >&6;}
|
||||
|
||||
|
||||
if test "x$BUILD_CC_VERSION_NUMBER" != "x$BUILD_CXX_VERSION_NUMBER"; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: C and C++ compiler have different version numbers, $BUILD_CC_VERSION_NUMBER vs $BUILD_CXX_VERSION_NUMBER." >&5
|
||||
$as_echo "$as_me: WARNING: C and C++ compiler have different version numbers, $BUILD_CC_VERSION_NUMBER vs $BUILD_CXX_VERSION_NUMBER." >&2;}
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: This typically indicates a broken setup, and is not supported" >&5
|
||||
$as_echo "$as_me: WARNING: This typically indicates a broken setup, and is not supported" >&2;}
|
||||
fi
|
||||
|
||||
# We only check CC_VERSION_NUMBER since we assume CXX_VERSION_NUMBER is equal.
|
||||
if [[ "[$]BUILD_CC_VERSION_NUMBER" =~ (.*\.){3} ]] ; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: C compiler version number has more than three parts (X.Y.Z): $BUILD_CC_VERSION_NUMBER. Comparisons might be wrong." >&5
|
||||
$as_echo "$as_me: WARNING: C compiler version number has more than three parts (X.Y.Z): $BUILD_CC_VERSION_NUMBER. Comparisons might be wrong." >&2;}
|
||||
fi
|
||||
|
||||
if [[ "[$]BUILD_CC_VERSION_NUMBER" =~ [0-9]{6} ]] ; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: C compiler version number has a part larger than 99999: $BUILD_CC_VERSION_NUMBER. Comparisons might be wrong." >&5
|
||||
$as_echo "$as_me: WARNING: C compiler version number has a part larger than 99999: $BUILD_CC_VERSION_NUMBER. Comparisons might be wrong." >&2;}
|
||||
fi
|
||||
|
||||
OPENJDK_BUILD_COMPARABLE_ACTUAL_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", $1, $2, $3) }' <<< "$BUILD_CC_VERSION_NUMBER"`
|
||||
|
||||
else
|
||||
# If we are not cross compiling, use the normal target compilers for
|
||||
# building the build platform executables.
|
||||
@ -49122,6 +49396,18 @@ $as_echo "$supports" >&6; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -49711,6 +49997,8 @@ $as_echo "$supports" >&6; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
elif test "x$TOOLCHAIN_TYPE" = xclang; then
|
||||
JVM_CFLAGS="$JVM_CFLAGS -D_GNU_SOURCE"
|
||||
|
||||
@ -49935,6 +50223,18 @@ $as_echo "$supports" >&6; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -49987,6 +50287,8 @@ $as_echo "$supports" >&6; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fi
|
||||
if ! [[ " $JVM_VARIANTS " =~ " zero " ]] && ! [[ " $JVM_VARIANTS " =~ " zeroshark " ]] ; then
|
||||
# Non-zero builds have stricter warnings
|
||||
@ -50440,6 +50742,18 @@ $as_echo "$supports" >&6; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -50469,7 +50783,7 @@ $as_echo "$supports" >&6; }
|
||||
# Version comparison method inspired by http://stackoverflow.com/a/24067243
|
||||
COMPARABLE_REFERENCE_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", $1, $2, $3) }' <<< "$REFERENCE_VERSION"`
|
||||
|
||||
if test $COMPARABLE_ACTUAL_VERSION -ge $COMPARABLE_REFERENCE_VERSION ; then
|
||||
if test $OPENJDK_BUILD_COMPARABLE_ACTUAL_VERSION -ge $COMPARABLE_REFERENCE_VERSION ; then
|
||||
:
|
||||
|
||||
else
|
||||
@ -50488,6 +50802,8 @@ $as_echo "$supports" >&6; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
elif test "x$TOOLCHAIN_TYPE" = xclang; then
|
||||
OPENJDK_BUILD_JVM_CFLAGS="$OPENJDK_BUILD_JVM_CFLAGS -D_GNU_SOURCE"
|
||||
|
||||
@ -50712,6 +51028,18 @@ $as_echo "$supports" >&6; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -50741,7 +51069,7 @@ $as_echo "$supports" >&6; }
|
||||
# Version comparison method inspired by http://stackoverflow.com/a/24067243
|
||||
COMPARABLE_REFERENCE_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", $1, $2, $3) }' <<< "$REFERENCE_VERSION"`
|
||||
|
||||
if test $COMPARABLE_ACTUAL_VERSION -ge $COMPARABLE_REFERENCE_VERSION ; then
|
||||
if test $OPENJDK_BUILD_COMPARABLE_ACTUAL_VERSION -ge $COMPARABLE_REFERENCE_VERSION ; then
|
||||
:
|
||||
|
||||
# These flags either do not work or give spurious warnings prior to gcc 4.8.
|
||||
@ -50764,6 +51092,8 @@ $as_echo "$supports" >&6; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fi
|
||||
if ! [[ " $JVM_VARIANTS " =~ " zero " ]] && ! [[ " $JVM_VARIANTS " =~ " zeroshark " ]] ; then
|
||||
# Non-zero builds have stricter warnings
|
||||
@ -51918,9 +52248,15 @@ $as_echo "$supports" >&6; }
|
||||
DISABLE_WARNING_PREFIX=
|
||||
fi
|
||||
CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
|
||||
# Repeate the check for the BUILD_CC
|
||||
# Repeate the check for the BUILD_CC and BUILD_CXX. Need to also reset
|
||||
# CFLAGS since any target specific flags will likely not work with the
|
||||
# build compiler
|
||||
CC_OLD="$CC"
|
||||
CXX_OLD="$CXX"
|
||||
CC="$BUILD_CC"
|
||||
CXX="$BUILD_CXX"
|
||||
CFLAGS_OLD="$CFLAGS"
|
||||
CFLAGS=""
|
||||
|
||||
|
||||
|
||||
@ -52198,6 +52534,8 @@ $as_echo "$supports" >&6; }
|
||||
BUILD_CC_DISABLE_WARNING_PREFIX=
|
||||
fi
|
||||
CC="$CC_OLD"
|
||||
CXX="$CXX_OLD"
|
||||
CFLAGS="$CFLAGS_OLD"
|
||||
;;
|
||||
clang)
|
||||
DISABLE_WARNING_PREFIX="-Wno-"
|
||||
|
@ -59,23 +59,25 @@ TOOLCHAIN_MINIMUM_VERSION_xlc=""
|
||||
|
||||
# Prepare the system so that TOOLCHAIN_CHECK_COMPILER_VERSION can be called.
|
||||
# Must have CC_VERSION_NUMBER and CXX_VERSION_NUMBER.
|
||||
# $1 - optional variable prefix for compiler and version variables (BUILD_)
|
||||
# $2 - optional variable prefix for comparable variable (OPENJDK_BUILD_)
|
||||
AC_DEFUN([TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS],
|
||||
[
|
||||
if test "x$CC_VERSION_NUMBER" != "x$CXX_VERSION_NUMBER"; then
|
||||
AC_MSG_WARN([C and C++ compiler has different version numbers, $CC_VERSION_NUMBER vs $CXX_VERSION_NUMBER.])
|
||||
if test "x[$]$1CC_VERSION_NUMBER" != "x[$]$1CXX_VERSION_NUMBER"; then
|
||||
AC_MSG_WARN([C and C++ compiler have different version numbers, [$]$1CC_VERSION_NUMBER vs [$]$1CXX_VERSION_NUMBER.])
|
||||
AC_MSG_WARN([This typically indicates a broken setup, and is not supported])
|
||||
fi
|
||||
|
||||
# We only check CC_VERSION_NUMBER since we assume CXX_VERSION_NUMBER is equal.
|
||||
if [ [[ "$CC_VERSION_NUMBER" =~ (.*\.){3} ]] ]; then
|
||||
AC_MSG_WARN([C compiler version number has more than three parts (X.Y.Z): $CC_VERSION_NUMBER. Comparisons might be wrong.])
|
||||
if [ [[ "[$]$1CC_VERSION_NUMBER" =~ (.*\.){3} ]] ]; then
|
||||
AC_MSG_WARN([C compiler version number has more than three parts (X.Y.Z): [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])
|
||||
fi
|
||||
|
||||
if [ [[ "$CC_VERSION_NUMBER" =~ [0-9]{6} ]] ]; then
|
||||
AC_MSG_WARN([C compiler version number has a part larger than 99999: $CC_VERSION_NUMBER. Comparisons might be wrong.])
|
||||
if [ [[ "[$]$1CC_VERSION_NUMBER" =~ [0-9]{6} ]] ]; then
|
||||
AC_MSG_WARN([C compiler version number has a part larger than 99999: [$]$1CC_VERSION_NUMBER. Comparisons might be wrong.])
|
||||
fi
|
||||
|
||||
COMPARABLE_ACTUAL_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", [$]1, [$]2, [$]3) }' <<< "$CC_VERSION_NUMBER"`
|
||||
$2COMPARABLE_ACTUAL_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", [$]1, [$]2, [$]3) }' <<< "[$]$1CC_VERSION_NUMBER"`
|
||||
])
|
||||
|
||||
# Check if the configured compiler (C and C++) is of a specific version or
|
||||
@ -85,8 +87,9 @@ AC_DEFUN([TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS],
|
||||
# VERSION: The version string to check against the found version
|
||||
# IF_AT_LEAST: block to run if the compiler is at least this version (>=)
|
||||
# IF_OLDER_THAN: block to run if the compiler is older than this version (<)
|
||||
# PREFIX: Optional variable prefix for compiler to compare version for (OPENJDK_BUILD_)
|
||||
BASIC_DEFUN_NAMED([TOOLCHAIN_CHECK_COMPILER_VERSION],
|
||||
[*VERSION IF_AT_LEAST IF_OLDER_THAN], [$@],
|
||||
[*VERSION PREFIX IF_AT_LEAST IF_OLDER_THAN], [$@],
|
||||
[
|
||||
# Need to assign to a variable since m4 is blocked from modifying parts in [].
|
||||
REFERENCE_VERSION=ARG_VERSION
|
||||
@ -102,7 +105,7 @@ BASIC_DEFUN_NAMED([TOOLCHAIN_CHECK_COMPILER_VERSION],
|
||||
# Version comparison method inspired by http://stackoverflow.com/a/24067243
|
||||
COMPARABLE_REFERENCE_VERSION=`$AWK -F. '{ printf("%05d%05d%05d\n", [$]1, [$]2, [$]3) }' <<< "$REFERENCE_VERSION"`
|
||||
|
||||
if test $COMPARABLE_ACTUAL_VERSION -ge $COMPARABLE_REFERENCE_VERSION ; then
|
||||
if test [$]ARG_PREFIX[COMPARABLE_ACTUAL_VERSION] -ge $COMPARABLE_REFERENCE_VERSION ; then
|
||||
:
|
||||
ARG_IF_AT_LEAST
|
||||
else
|
||||
@ -808,6 +811,10 @@ AC_DEFUN_ONCE([TOOLCHAIN_SETUP_BUILD_COMPILERS],
|
||||
BUILD_LDCXX="$BUILD_CXX"
|
||||
|
||||
PATH="$OLDPATH"
|
||||
|
||||
TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CC, [BuildC])
|
||||
TOOLCHAIN_EXTRACT_COMPILER_VERSION(BUILD_CXX, [BuildC++])
|
||||
TOOLCHAIN_PREPARE_FOR_VERSION_COMPARISONS([BUILD_], [OPENJDK_BUILD_])
|
||||
else
|
||||
# If we are not cross compiling, use the normal target compilers for
|
||||
# building the build platform executables.
|
||||
|
199
common/bin/idea.sh
Normal file
199
common/bin/idea.sh
Normal file
@ -0,0 +1,199 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code 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
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
|
||||
# Shell script for generating an IDEA project from a given list of modules
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 [-h|--help] [-v|--verbose] [-o|--output <path>] [modules]+"
|
||||
exit 1
|
||||
}
|
||||
|
||||
SCRIPT_DIR=`dirname $0`
|
||||
PWD=`pwd`
|
||||
cd $SCRIPT_DIR; SCRIPT_DIR=`pwd`
|
||||
cd ../../; TOP=`pwd`; cd $PWD
|
||||
|
||||
IDEA_OUTPUT=$TOP/.idea
|
||||
VERBOSE="false"
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
case $1 in
|
||||
-h | --help )
|
||||
usage
|
||||
;;
|
||||
|
||||
-v | --vebose )
|
||||
VERBOSE="true"
|
||||
;;
|
||||
|
||||
-o | --output )
|
||||
IDEA_OUTPUT=$2
|
||||
shift
|
||||
;;
|
||||
|
||||
-*) # bad option
|
||||
usage
|
||||
;;
|
||||
|
||||
* ) # non option
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
mkdir $IDEA_OUTPUT || exit 1
|
||||
cd $IDEA_OUTPUT; IDEA_OUTPUT=`pwd`
|
||||
|
||||
IDEA_MAKE="$TOP/make/idea"
|
||||
IDEA_TEMPLATE="$IDEA_MAKE/template"
|
||||
IML_TEMPLATE="$IDEA_TEMPLATE/jdk.iml"
|
||||
ANT_TEMPLATE="$IDEA_TEMPLATE/ant.xml"
|
||||
IDEA_IML="$IDEA_OUTPUT/jdk.iml"
|
||||
IDEA_ANT="$IDEA_OUTPUT/ant.xml"
|
||||
|
||||
if [ "$VERBOSE" = "true" ] ; then
|
||||
echo "output dir: $IDEA_OUTPUT"
|
||||
echo "idea template dir: $IDEA_TEMPLATE"
|
||||
fi
|
||||
|
||||
if [ ! -f "$IML_TEMPLATE" ] ; then
|
||||
echo "FATAL: cannot find $IML_TEMPLATE" >&2; exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$ANT_TEMPLATE" ] ; then
|
||||
echo "FATAL: cannot find $ANT_TEMPLATE" >&2; exit 1
|
||||
fi
|
||||
|
||||
cp -r "$IDEA_TEMPLATE"/* "$IDEA_OUTPUT"
|
||||
cd $TOP ; make -f "$IDEA_MAKE/idea.gmk" -I make/common idea MAKEOVERRIDES= OUT=$IDEA_OUTPUT/env.cfg MODULES="$*" || exit 1
|
||||
cd $SCRIPT_DIR
|
||||
|
||||
. $IDEA_OUTPUT/env.cfg
|
||||
|
||||
# Expect MODULE_ROOTS, MODULE_NAMES, BOOT_JDK & SPEC to be set
|
||||
if [ "x$MODULE_ROOTS" = "x" ] ; then
|
||||
echo "FATAL: MODULE_ROOTS is empty" >&2; exit 1
|
||||
fi
|
||||
|
||||
if [ "x$MODULE_NAMES" = "x" ] ; then
|
||||
echo "FATAL: MODULE_NAMES is empty" >&2; exit 1
|
||||
fi
|
||||
|
||||
if [ "x$BOOT_JDK" = "x" ] ; then
|
||||
echo "FATAL: BOOT_JDK is empty" >&2; exit 1
|
||||
fi
|
||||
|
||||
if [ "x$SPEC" = "x" ] ; then
|
||||
echo "FATAL: SPEC is empty" >&2; exit 1
|
||||
fi
|
||||
|
||||
SOURCE_FOLDER=" <sourceFolder url=\"file://\$MODULE_DIR\$/####\" isTestSource=\"false\" />"
|
||||
SOURCE_FOLDERS_DONE="false"
|
||||
|
||||
addSourceFolder() {
|
||||
root=$@
|
||||
relativePath="`echo "$root" | sed -e s@"$TOP/\(.*$\)"@"\1"@`"
|
||||
folder="`echo "$SOURCE_FOLDER" | sed -e s@"\(.*/\)####\(.*\)"@"\1$relativePath\2"@`"
|
||||
printf "%s\n" "$folder" >> $IDEA_IML
|
||||
}
|
||||
|
||||
### Generate project iml
|
||||
RELATIVE_BUILD_DIR="`dirname $SPEC | sed -e s@"$TOP/\(.*$\)"@"\1"@`"
|
||||
rm -f $IDEA_IML
|
||||
while IFS= read -r line
|
||||
do
|
||||
if echo "$line" | egrep "^ .* <sourceFolder.*####" > /dev/null ; then
|
||||
if [ "$SOURCE_FOLDERS_DONE" = "false" ] ; then
|
||||
SOURCE_FOLDERS_DONE="true"
|
||||
for root in $MODULE_ROOTS; do
|
||||
addSourceFolder $root
|
||||
done
|
||||
fi
|
||||
elif echo "$line" | egrep "^ .* <excludeFolder.*####" > /dev/null ; then
|
||||
ul="`echo "$line" | sed -e s@"\(.*/\)####\(.*\)"@"\1$RELATIVE_BUILD_DIR\2"@`"
|
||||
printf "%s\n" "$ul" >> $IDEA_IML
|
||||
else
|
||||
printf "%s\n" "$line" >> $IDEA_IML
|
||||
fi
|
||||
done < "$IML_TEMPLATE"
|
||||
|
||||
|
||||
MODULE_NAME=" <property name=\"module.name\" value=\"####\" />"
|
||||
|
||||
addModuleName() {
|
||||
mn="`echo "$MODULE_NAME" | sed -e s@"\(.*\)####\(.*\)"@"\1$MODULE_NAMES\2"@`"
|
||||
printf "%s\n" "$mn" >> $IDEA_ANT
|
||||
}
|
||||
|
||||
BUILD_DIR=" <property name=\"build.target.dir\" value=\"####\" />"
|
||||
|
||||
addBuildDir() {
|
||||
DIR=`dirname $SPEC`
|
||||
mn="`echo "$BUILD_DIR" | sed -e s@"\(.*\)####\(.*\)"@"\1$DIR\2"@`"
|
||||
printf "%s\n" "$mn" >> $IDEA_ANT
|
||||
}
|
||||
|
||||
### Generate ant.xml
|
||||
|
||||
rm -f $IDEA_ANT
|
||||
while IFS= read -r line
|
||||
do
|
||||
if echo "$line" | egrep "^ .* <property name=\"module.name\"" > /dev/null ; then
|
||||
addModuleName
|
||||
elif echo "$line" | egrep "^ .* <property name=\"build.target.dir\"" > /dev/null ; then
|
||||
addBuildDir
|
||||
else
|
||||
printf "%s\n" "$line" >> $IDEA_ANT
|
||||
fi
|
||||
done < "$ANT_TEMPLATE"
|
||||
|
||||
### Compile the custom Logger
|
||||
|
||||
CLASSES=$IDEA_OUTPUT/classes
|
||||
|
||||
if [ "x$ANT_HOME" = "x" ] ; then
|
||||
# try some common locations, before giving up
|
||||
if [ -f "/usr/share/ant/lib/ant.jar" ] ; then
|
||||
ANT_HOME="/usr/share/ant"
|
||||
elif [ -f "/usr/local/Cellar/ant/1.9.4/libexec/lib/ant.jar" ] ; then
|
||||
ANT_HOME="/usr/local/Cellar/ant/1.9.4/libexec"
|
||||
else
|
||||
echo "FATAL: cannot find ant. Try setting ANT_HOME." >&2; exit 1
|
||||
fi
|
||||
fi
|
||||
CP=$ANT_HOME/lib/ant.jar
|
||||
rm -rf $CLASSES; mkdir $CLASSES
|
||||
|
||||
if [ "x$CYGPATH" = "x" ] ; then ## CYGPATH may be set in env.cfg
|
||||
JAVAC_SOURCE_FILE=$IDEA_OUTPUT/src/idea/JdkIdeaAntLogger.java
|
||||
JAVAC_CLASSES=$CLASSES
|
||||
JAVAC_CP=$CP
|
||||
else
|
||||
JAVAC_SOURCE_FILE=`cygpath -am $IDEA_OUTPUT/src/idea/JdkIdeaAntLogger.java`
|
||||
JAVAC_CLASSES=`cygpath -am $CLASSES`
|
||||
JAVAC_CP=`cygpath -am $CP`
|
||||
fi
|
||||
|
||||
$BOOT_JDK/bin/javac -d $JAVAC_CLASSES -cp $JAVAC_CP $JAVAC_SOURCE_FILE
|
@ -89,7 +89,7 @@ install_jib() {
|
||||
fi
|
||||
|
||||
if command -v curl > /dev/null; then
|
||||
getcmd="curl -s"
|
||||
getcmd="curl -s -L --retry 3 --retry-delay 5"
|
||||
elif command -v wget > /dev/null; then
|
||||
getcmd="wget --quiet -O -"
|
||||
else
|
||||
|
@ -360,3 +360,4 @@ cc30faa2da498c478e89ab062ff160653ca1b170 jdk-9+113
|
||||
7bab1b1b36824924b1c657a8419369ba93d198d3 jdk-9+115
|
||||
7dfa7377a5e601b8f740741a9a80e04c72dd04d6 jdk-9+116
|
||||
7a1b36bf2fe55a9a7732489ccdd326c910329a7e jdk-9+117
|
||||
8c2c2d17f7ce92a31c9ccb44a122ec62f5a85ace jdk-9+118
|
||||
|
@ -520,3 +520,4 @@ b64432bae5271735fd53300b2005b713e98ef411 jdk-9+114
|
||||
88dd08d7be0fe7fb9f1914b1628f0aae9bf56e25 jdk-9+115
|
||||
61a214186dae6811dd989e9165e42f7dbf02acde jdk-9+116
|
||||
88170d3642905b9e6cac03e8efcc976885a7e6da jdk-9+117
|
||||
9b1075cac08dc836ec32e7b368415cbe3aceaf8c jdk-9+118
|
||||
|
@ -3387,14 +3387,14 @@ bool force_verify_field_access(Klass* current_class, Klass* field_class, AccessF
|
||||
return (!access.is_private() && InstanceKlass::cast(current_class)->is_same_class_package(field_class));
|
||||
}
|
||||
|
||||
// Return the first non-null class loader up the execution stack, or null
|
||||
// if only code from the null class loader is on the stack.
|
||||
// Return the first user-defined class loader up the execution stack, or null
|
||||
// if only code from the bootstrap or platform class loader is on the stack.
|
||||
|
||||
JVM_ENTRY(jobject, JVM_LatestUserDefinedLoader(JNIEnv *env))
|
||||
for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
|
||||
vfst.skip_reflection_related_frames(); // Only needed for 1.4 reflection
|
||||
oop loader = vfst.method()->method_holder()->class_loader();
|
||||
if (loader != NULL) {
|
||||
if (loader != NULL && !SystemDictionary::is_platform_class_loader(loader)) {
|
||||
return JNIHandles::make_local(env, loader);
|
||||
}
|
||||
}
|
||||
|
@ -120,24 +120,33 @@ endif
|
||||
TEST_ROOT := $(shell pwd)
|
||||
|
||||
# Root of all test results
|
||||
ifdef ALT_OUTPUTDIR
|
||||
ABS_BUILD_ROOT = $(ALT_OUTPUTDIR)
|
||||
ifdef TEST_OUTPUT_DIR
|
||||
$(shell $(MKDIR) -p $(TEST_OUTPUT_DIR)/jtreg)
|
||||
ABS_TEST_OUTPUT_DIR := \
|
||||
$(shell $(CD) $(TEST_OUTPUT_DIR)/jtreg && $(PWD))
|
||||
else
|
||||
ABS_BUILD_ROOT = $(TEST_ROOT)/../build/$(PLATFORM)-$(ARCH)
|
||||
ifdef ALT_OUTPUTDIR
|
||||
ABS_OUTPUTDIR = $(shell $(CD) $(ALT_OUTPUTDIR) && $(PWD))
|
||||
else
|
||||
ABS_OUTPUTDIR = $(shell $(CD) $(TEST_ROOT)/.. && $(PWD))
|
||||
endif
|
||||
|
||||
ABS_PLATFORM_BUILD_ROOT = $(ABS_OUTPUTDIR)
|
||||
ABS_TEST_OUTPUT_DIR := $(ABS_PLATFORM_BUILD_ROOT)/testoutput/$(UNIQUE_DIR)
|
||||
endif
|
||||
ABS_TEST_OUTPUT_DIR = $(ABS_BUILD_ROOT)/testoutput/$(UNIQUE_DIR)
|
||||
|
||||
# Expect JPRT to set PRODUCT_HOME (the product or jdk in this case to test)
|
||||
ifndef PRODUCT_HOME
|
||||
# Try to use j2sdk-image if it exists
|
||||
ABS_JDK_IMAGE = $(ABS_BUILD_ROOT)/j2sdk-image
|
||||
PRODUCT_HOME := \
|
||||
$(shell \
|
||||
if [ -d $(ABS_JDK_IMAGE) ] ; then \
|
||||
$(ECHO) "$(ABS_JDK_IMAGE)"; \
|
||||
else \
|
||||
$(ECHO) "$(ABS_BUILD_ROOT)" ; \
|
||||
# Try to use images/jdk if it exists
|
||||
ABS_JDK_IMAGE = $(ABS_PLATFORM_BUILD_ROOT)/images/jdk
|
||||
PRODUCT_HOME := \
|
||||
$(shell \
|
||||
if [ -d $(ABS_JDK_IMAGE) ] ; then \
|
||||
$(ECHO) "$(ABS_JDK_IMAGE)"; \
|
||||
else \
|
||||
$(ECHO) "$(ABS_PLATFORM_BUILD_ROOT)"; \
|
||||
fi)
|
||||
PRODUCT_HOME := $(PRODUCT_HOME)
|
||||
endif
|
||||
|
||||
# Expect JPRT to set JAVA_ARGS (e.g. -server etc.)
|
||||
|
@ -360,3 +360,4 @@ bdbf2342b21bd8ecad1b4e6499a0dfb314952bd7 jdk-9+103
|
||||
1902a5bda18e794b31fc5f520f5e7d827714b50d jdk-9+115
|
||||
9d71d20e614777cd23c1a43b38b5c08a9094d27a jdk-9+116
|
||||
46b57560cd06ebcdd21489250628ff5f9d9d8916 jdk-9+117
|
||||
a8aa25fc6c5fda0ed7a93b8ffee62da326a752fc jdk-9+118
|
||||
|
@ -3387,7 +3387,6 @@ included with JRE 8, JDK 8, and OpenJDK 8, except where noted:
|
||||
Apache Commons Math 2.2
|
||||
Apache Derby 10.10.1.2 [included with JDK 8]
|
||||
Apache Jakarta BCEL 5.2
|
||||
Apache Jakarta Regexp 1.4
|
||||
Apache Santuario XML Security for Java 1.5.4
|
||||
Apache Xalan-Java 2.7.1
|
||||
Apache Xerces Java 2.10.0
|
||||
|
@ -4,64 +4,29 @@
|
||||
*/
|
||||
package com.sun.org.apache.bcel.internal.util;
|
||||
|
||||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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
|
||||
*
|
||||
* Copyright (c) 2001 The Apache Software Foundation. All rights
|
||||
* reserved.
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 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.
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by the
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Apache" and "Apache Software Foundation" and
|
||||
* "Apache BCEL" must not be used to endorse or promote products
|
||||
* derived from this software without prior written permission. For
|
||||
* written permission, please contact apache@apache.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Apache",
|
||||
* "Apache BCEL", nor may "Apache" appear in their name, without
|
||||
* prior written permission of the Apache Software Foundation.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
import com.sun.org.apache.bcel.internal.Constants;
|
||||
import com.sun.org.apache.bcel.internal.generic.*;
|
||||
import com.sun.org.apache.regexp.internal.*;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* InstructionFinder is a tool to search for given instructions patterns,
|
||||
@ -231,28 +196,22 @@ public class InstructionFinder {
|
||||
if(start == -1)
|
||||
throw new ClassGenException("Instruction handle " + from +
|
||||
" not found in instruction list.");
|
||||
try {
|
||||
RE regex = new RE(search);
|
||||
ArrayList matches = new ArrayList();
|
||||
|
||||
while(start < il_string.length() && regex.match(il_string, start)) {
|
||||
int startExpr = regex.getParenStart(0);
|
||||
int endExpr = regex.getParenEnd(0);
|
||||
int lenExpr = regex.getParenLength(0);
|
||||
Pattern regex = Pattern.compile(search);
|
||||
List<InstructionHandle[]> matches = new ArrayList<>();
|
||||
Matcher matcher = regex.matcher(il_string);
|
||||
while(start < il_string.length() && matcher.find(start)) {
|
||||
int startExpr = matcher.start();
|
||||
int endExpr = matcher.end();
|
||||
int lenExpr = endExpr - startExpr;
|
||||
InstructionHandle[] match = getMatch(startExpr, lenExpr);
|
||||
|
||||
InstructionHandle[] match = getMatch(startExpr, lenExpr);
|
||||
|
||||
if((constraint == null) || constraint.checkCode(match))
|
||||
matches.add(match);
|
||||
start = endExpr;
|
||||
}
|
||||
|
||||
return matches.iterator();
|
||||
} catch(RESyntaxException e) {
|
||||
System.err.println(e);
|
||||
if((constraint == null) || constraint.checkCode(match))
|
||||
matches.add(match);
|
||||
start = endExpr;
|
||||
}
|
||||
|
||||
return null;
|
||||
return matches.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.regexp.internal;
|
||||
|
||||
/**
|
||||
* Encapsulates char[] as CharacterIterator
|
||||
*
|
||||
* @author <a href="mailto:ales.novak@netbeans.com">Ales Novak</a>
|
||||
*/
|
||||
public final class CharacterArrayCharacterIterator implements CharacterIterator
|
||||
{
|
||||
/** encapsulated */
|
||||
private final char[] src;
|
||||
/** offset in the char array */
|
||||
private final int off;
|
||||
/** used portion of the array */
|
||||
private final int len;
|
||||
|
||||
/** @param src - encapsulated String */
|
||||
public CharacterArrayCharacterIterator(char[] src, int off, int len)
|
||||
{
|
||||
this.src = src;
|
||||
this.off = off;
|
||||
this.len = len;
|
||||
}
|
||||
|
||||
/** @return a substring */
|
||||
public String substring(int beginIndex, int endIndex)
|
||||
{
|
||||
if (endIndex > len) {
|
||||
throw new IndexOutOfBoundsException("endIndex=" + endIndex
|
||||
+ "; sequence size=" + len);
|
||||
}
|
||||
if (beginIndex < 0 || beginIndex > endIndex) {
|
||||
throw new IndexOutOfBoundsException("beginIndex=" + beginIndex
|
||||
+ "; endIndex=" + endIndex);
|
||||
}
|
||||
return new String(src, off + beginIndex, endIndex - beginIndex);
|
||||
}
|
||||
|
||||
/** @return a substring */
|
||||
public String substring(int beginIndex)
|
||||
{
|
||||
return substring(beginIndex, len);
|
||||
}
|
||||
|
||||
/** @return a character at the specified position. */
|
||||
public char charAt(int pos)
|
||||
{
|
||||
return src[off + pos];
|
||||
}
|
||||
|
||||
/** @return <tt>true</tt> iff if the specified index is after the end of the character stream */
|
||||
public boolean isEnd(int pos)
|
||||
{
|
||||
return (pos >= len);
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.regexp.internal;
|
||||
|
||||
/**
|
||||
* Encapsulates different types of character sources - String, InputStream, ...
|
||||
* Defines a set of common methods
|
||||
*
|
||||
* @author <a href="mailto:ales.novak@netbeans.com">Ales Novak</a>
|
||||
*/
|
||||
public interface CharacterIterator
|
||||
{
|
||||
/** @return a substring */
|
||||
String substring(int beginIndex, int endIndex);
|
||||
|
||||
/** @return a substring */
|
||||
String substring(int beginIndex);
|
||||
|
||||
/** @return a character at the specified position. */
|
||||
char charAt(int pos);
|
||||
|
||||
/** @return <tt>true</tt> iff if the specified index is after the end of the character stream */
|
||||
boolean isEnd(int pos);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,225 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.regexp.internal;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* A subclass of RECompiler which can dump a regular expression program
|
||||
* for debugging purposes.
|
||||
*
|
||||
* @author <a href="mailto:jonl@muppetlabs.com">Jonathan Locke</a>
|
||||
*/
|
||||
public class REDebugCompiler extends RECompiler
|
||||
{
|
||||
/**
|
||||
* Mapping from opcodes to descriptive strings
|
||||
*/
|
||||
static Hashtable hashOpcode = new Hashtable();
|
||||
static
|
||||
{
|
||||
hashOpcode.put(new Integer(RE.OP_RELUCTANTSTAR), "OP_RELUCTANTSTAR");
|
||||
hashOpcode.put(new Integer(RE.OP_RELUCTANTPLUS), "OP_RELUCTANTPLUS");
|
||||
hashOpcode.put(new Integer(RE.OP_RELUCTANTMAYBE), "OP_RELUCTANTMAYBE");
|
||||
hashOpcode.put(new Integer(RE.OP_END), "OP_END");
|
||||
hashOpcode.put(new Integer(RE.OP_BOL), "OP_BOL");
|
||||
hashOpcode.put(new Integer(RE.OP_EOL), "OP_EOL");
|
||||
hashOpcode.put(new Integer(RE.OP_ANY), "OP_ANY");
|
||||
hashOpcode.put(new Integer(RE.OP_ANYOF), "OP_ANYOF");
|
||||
hashOpcode.put(new Integer(RE.OP_BRANCH), "OP_BRANCH");
|
||||
hashOpcode.put(new Integer(RE.OP_ATOM), "OP_ATOM");
|
||||
hashOpcode.put(new Integer(RE.OP_STAR), "OP_STAR");
|
||||
hashOpcode.put(new Integer(RE.OP_PLUS), "OP_PLUS");
|
||||
hashOpcode.put(new Integer(RE.OP_MAYBE), "OP_MAYBE");
|
||||
hashOpcode.put(new Integer(RE.OP_NOTHING), "OP_NOTHING");
|
||||
hashOpcode.put(new Integer(RE.OP_GOTO), "OP_GOTO");
|
||||
hashOpcode.put(new Integer(RE.OP_ESCAPE), "OP_ESCAPE");
|
||||
hashOpcode.put(new Integer(RE.OP_OPEN), "OP_OPEN");
|
||||
hashOpcode.put(new Integer(RE.OP_CLOSE), "OP_CLOSE");
|
||||
hashOpcode.put(new Integer(RE.OP_BACKREF), "OP_BACKREF");
|
||||
hashOpcode.put(new Integer(RE.OP_POSIXCLASS), "OP_POSIXCLASS");
|
||||
hashOpcode.put(new Integer(RE.OP_OPEN_CLUSTER), "OP_OPEN_CLUSTER");
|
||||
hashOpcode.put(new Integer(RE.OP_CLOSE_CLUSTER), "OP_CLOSE_CLUSTER");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a descriptive string for an opcode.
|
||||
* @param opcode Opcode to convert to a string
|
||||
* @return Description of opcode
|
||||
*/
|
||||
String opcodeToString(char opcode)
|
||||
{
|
||||
// Get string for opcode
|
||||
String ret =(String)hashOpcode.get(new Integer(opcode));
|
||||
|
||||
// Just in case we have a corrupt program
|
||||
if (ret == null)
|
||||
{
|
||||
ret = "OP_????";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string describing a (possibly unprintable) character.
|
||||
* @param c Character to convert to a printable representation
|
||||
* @return String representation of character
|
||||
*/
|
||||
String charToString(char c)
|
||||
{
|
||||
// If it's unprintable, convert to '\###'
|
||||
if (c < ' ' || c > 127)
|
||||
{
|
||||
return "\\" + (int)c;
|
||||
}
|
||||
|
||||
// Return the character as a string
|
||||
return String.valueOf(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a descriptive string for a node in a regular expression program.
|
||||
* @param node Node to describe
|
||||
* @return Description of node
|
||||
*/
|
||||
String nodeToString(int node)
|
||||
{
|
||||
// Get opcode and opdata for node
|
||||
char opcode = instruction[node + RE.offsetOpcode];
|
||||
int opdata = (int)instruction[node + RE.offsetOpdata];
|
||||
|
||||
// Return opcode as a string and opdata value
|
||||
return opcodeToString(opcode) + ", opdata = " + opdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a node with a given opcode and opdata at insertAt. The node relative next
|
||||
* pointer is initialized to 0.
|
||||
* @param opcode Opcode for new node
|
||||
* @param opdata Opdata for new node (only the low 16 bits are currently used)
|
||||
* @param insertAt Index at which to insert the new node in the program * /
|
||||
void nodeInsert(char opcode, int opdata, int insertAt) {
|
||||
System.out.println( "====> " + opcode + " " + opdata + " " + insertAt );
|
||||
PrintWriter writer = new PrintWriter( System.out );
|
||||
dumpProgram( writer );
|
||||
super.nodeInsert( opcode, opdata, insertAt );
|
||||
System.out.println( "====< " );
|
||||
dumpProgram( writer );
|
||||
writer.flush();
|
||||
}/**/
|
||||
|
||||
|
||||
/**
|
||||
* Appends a node to the end of a node chain
|
||||
* @param node Start of node chain to traverse
|
||||
* @param pointTo Node to have the tail of the chain point to * /
|
||||
void setNextOfEnd(int node, int pointTo) {
|
||||
System.out.println( "====> " + node + " " + pointTo );
|
||||
PrintWriter writer = new PrintWriter( System.out );
|
||||
dumpProgram( writer );
|
||||
super.setNextOfEnd( node, pointTo );
|
||||
System.out.println( "====< " );
|
||||
dumpProgram( writer );
|
||||
writer.flush();
|
||||
}/**/
|
||||
|
||||
|
||||
/**
|
||||
* Dumps the current program to a PrintWriter
|
||||
* @param p PrintWriter for program dump output
|
||||
*/
|
||||
public void dumpProgram(PrintWriter p)
|
||||
{
|
||||
// Loop through the whole program
|
||||
for (int i = 0; i < lenInstruction; )
|
||||
{
|
||||
// Get opcode, opdata and next fields of current program node
|
||||
char opcode = instruction[i + RE.offsetOpcode];
|
||||
char opdata = instruction[i + RE.offsetOpdata];
|
||||
short next = (short)instruction[i + RE.offsetNext];
|
||||
|
||||
// Display the current program node
|
||||
p.print(i + ". " + nodeToString(i) + ", next = ");
|
||||
|
||||
// If there's no next, say 'none', otherwise give absolute index of next node
|
||||
if (next == 0)
|
||||
{
|
||||
p.print("none");
|
||||
}
|
||||
else
|
||||
{
|
||||
p.print(i + next);
|
||||
}
|
||||
|
||||
// Move past node
|
||||
i += RE.nodeSize;
|
||||
|
||||
// If character class
|
||||
if (opcode == RE.OP_ANYOF)
|
||||
{
|
||||
// Opening bracket for start of char class
|
||||
p.print(", [");
|
||||
|
||||
// Show each range in the char class
|
||||
int rangeCount = opdata;
|
||||
for (int r = 0; r < rangeCount; r++)
|
||||
{
|
||||
// Get first and last chars in range
|
||||
char charFirst = instruction[i++];
|
||||
char charLast = instruction[i++];
|
||||
|
||||
// Print range as X-Y, unless range encompasses only one char
|
||||
if (charFirst == charLast)
|
||||
{
|
||||
p.print(charToString(charFirst));
|
||||
}
|
||||
else
|
||||
{
|
||||
p.print(charToString(charFirst) + "-" + charToString(charLast));
|
||||
}
|
||||
}
|
||||
|
||||
// Annotate the end of the char class
|
||||
p.print("]");
|
||||
}
|
||||
|
||||
// If atom
|
||||
if (opcode == RE.OP_ATOM)
|
||||
{
|
||||
// Open quote
|
||||
p.print(", \"");
|
||||
|
||||
// Print each character in the atom
|
||||
for (int len = opdata; len-- != 0; )
|
||||
{
|
||||
p.print(charToString(instruction[i++]));
|
||||
}
|
||||
|
||||
// Close quote
|
||||
p.print("\"");
|
||||
}
|
||||
|
||||
// Print a newline
|
||||
p.println("");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.regexp.internal;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A class that holds compiled regular expressions. This is exposed mainly
|
||||
* for use by the recompile utility (which helps you produce precompiled
|
||||
* REProgram objects). You should not otherwise need to work directly with
|
||||
* this class.
|
||||
*
|
||||
* @see RE
|
||||
* @see RECompiler
|
||||
*
|
||||
* @author <a href="mailto:jonl@muppetlabs.com">Jonathan Locke</a>
|
||||
*/
|
||||
public class REProgram implements Serializable
|
||||
{
|
||||
static final int OPT_HASBACKREFS = 1;
|
||||
|
||||
char[] instruction; // The compiled regular expression 'program'
|
||||
int lenInstruction; // The amount of the instruction buffer in use
|
||||
char[] prefix; // Prefix string optimization
|
||||
int flags; // Optimization flags (REProgram.OPT_*)
|
||||
int maxParens = -1;
|
||||
|
||||
/**
|
||||
* Constructs a program object from a character array
|
||||
* @param instruction Character array with RE opcode instructions in it
|
||||
*/
|
||||
public REProgram(char[] instruction)
|
||||
{
|
||||
this(instruction, instruction.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a program object from a character array
|
||||
* @param parens Count of parens in the program
|
||||
* @param instruction Character array with RE opcode instructions in it
|
||||
*/
|
||||
public REProgram(int parens, char[] instruction)
|
||||
{
|
||||
this(instruction, instruction.length);
|
||||
this.maxParens = parens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a program object from a character array
|
||||
* @param instruction Character array with RE opcode instructions in it
|
||||
* @param lenInstruction Amount of instruction array in use
|
||||
*/
|
||||
public REProgram(char[] instruction, int lenInstruction)
|
||||
{
|
||||
setInstructions(instruction, lenInstruction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the current regular expression program in a character
|
||||
* array that is exactly the right length to hold the program. If there is
|
||||
* no program compiled yet, getInstructions() will return null.
|
||||
* @return A copy of the current compiled RE program
|
||||
*/
|
||||
public char[] getInstructions()
|
||||
{
|
||||
// Ensure program has been compiled!
|
||||
if (lenInstruction != 0)
|
||||
{
|
||||
// Return copy of program
|
||||
char[] ret = new char[lenInstruction];
|
||||
System.arraycopy(instruction, 0, ret, 0, lenInstruction);
|
||||
return ret;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new regular expression program to run. It is this method which
|
||||
* performs any special compile-time search optimizations. Currently only
|
||||
* two optimizations are in place - one which checks for backreferences
|
||||
* (so that they can be lazily allocated) and another which attempts to
|
||||
* find an prefix anchor string so that substantial amounts of input can
|
||||
* potentially be skipped without running the actual program.
|
||||
* @param instruction Program instruction buffer
|
||||
* @param lenInstruction Length of instruction buffer in use
|
||||
*/
|
||||
public void setInstructions(char[] instruction, int lenInstruction)
|
||||
{
|
||||
// Save reference to instruction array
|
||||
this.instruction = instruction;
|
||||
this.lenInstruction = lenInstruction;
|
||||
|
||||
// Initialize other program-related variables
|
||||
flags = 0;
|
||||
prefix = null;
|
||||
|
||||
// Try various compile-time optimizations if there's a program
|
||||
if (instruction != null && lenInstruction != 0)
|
||||
{
|
||||
// If the first node is a branch
|
||||
if (lenInstruction >= RE.nodeSize && instruction[0 + RE.offsetOpcode] == RE.OP_BRANCH)
|
||||
{
|
||||
// to the end node
|
||||
int next = instruction[0 + RE.offsetNext];
|
||||
if (instruction[next + RE.offsetOpcode] == RE.OP_END)
|
||||
{
|
||||
// and the branch starts with an atom
|
||||
if (lenInstruction >= (RE.nodeSize * 2) && instruction[RE.nodeSize + RE.offsetOpcode] == RE.OP_ATOM)
|
||||
{
|
||||
// then get that atom as an prefix because there's no other choice
|
||||
int lenAtom = instruction[RE.nodeSize + RE.offsetOpdata];
|
||||
prefix = new char[lenAtom];
|
||||
System.arraycopy(instruction, RE.nodeSize * 2, prefix, 0, lenAtom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BackrefScanLoop:
|
||||
|
||||
// Check for backreferences
|
||||
for (int i = 0; i < lenInstruction; i += RE.nodeSize)
|
||||
{
|
||||
switch (instruction[i + RE.offsetOpcode])
|
||||
{
|
||||
case RE.OP_ANYOF:
|
||||
i += (instruction[i + RE.offsetOpdata] * 2);
|
||||
break;
|
||||
|
||||
case RE.OP_ATOM:
|
||||
i += instruction[i + RE.offsetOpdata];
|
||||
break;
|
||||
|
||||
case RE.OP_BACKREF:
|
||||
flags |= OPT_HASBACKREFS;
|
||||
break BackrefScanLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.regexp.internal;
|
||||
|
||||
/**
|
||||
* Exception thrown to indicate a syntax error in a regular expression.
|
||||
* This is a non-checked exception because you should only have problems compiling
|
||||
* a regular expression during development.
|
||||
* If you are making regular expresion programs dynamically then you can catch it
|
||||
* if you wish. But should not be forced to.
|
||||
*
|
||||
* @author <a href="mailto:jonl@muppetlabs.com">Jonathan Locke</a>
|
||||
* @author <a href="mailto:gholam@xtra.co.nz>Michael McCallum</a>
|
||||
*/
|
||||
public class RESyntaxException extends RuntimeException
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
* @param s Further description of the syntax error
|
||||
*/
|
||||
public RESyntaxException(String s)
|
||||
{
|
||||
super("Syntax error: " + s);
|
||||
}
|
||||
}
|
@ -1,883 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.regexp.internal;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.File;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.StringBufferInputStream;
|
||||
import java.io.StringReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Data driven (and optionally interactive) testing harness to exercise regular
|
||||
* expression compiler and matching engine.
|
||||
*
|
||||
* @author <a href="mailto:jonl@muppetlabs.com">Jonathan Locke</a>
|
||||
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
|
||||
* @author <a href="mailto:gholam@xtra.co.nz">Michael McCallum</a>
|
||||
*/
|
||||
public class RETest
|
||||
{
|
||||
// True if we want to see output from success cases
|
||||
static final boolean showSuccesses = false;
|
||||
|
||||
// A new line character.
|
||||
static final String NEW_LINE = System.getProperty( "line.separator" );
|
||||
|
||||
// Construct a debug compiler
|
||||
REDebugCompiler compiler = new REDebugCompiler();
|
||||
|
||||
/**
|
||||
* Main program entrypoint. If an argument is given, it will be compiled
|
||||
* and interactive matching will ensue. If no argument is given, the
|
||||
* file RETest.txt will be used as automated testing input.
|
||||
* @param args Command line arguments (optional regular expression)
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!test( args )) {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing entrypoint.
|
||||
* @param args Command line arguments
|
||||
* @exception Exception thrown in case of error
|
||||
*/
|
||||
public static boolean test( String[] args ) throws Exception
|
||||
{
|
||||
RETest test = new RETest();
|
||||
// Run interactive tests against a single regexp
|
||||
if (args.length == 2)
|
||||
{
|
||||
test.runInteractiveTests(args[1]);
|
||||
}
|
||||
else if (args.length == 1)
|
||||
{
|
||||
// Run automated tests
|
||||
test.runAutomatedTests(args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println( "Usage: RETest ([-i] [regex]) ([/path/to/testfile.txt])" );
|
||||
System.out.println( "By Default will run automated tests from file 'docs/RETest.txt' ..." );
|
||||
System.out.println();
|
||||
test.runAutomatedTests("docs/RETest.txt");
|
||||
}
|
||||
return test.failures == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public RETest()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile and test matching against a single expression
|
||||
* @param expr Expression to compile and test
|
||||
*/
|
||||
void runInteractiveTests(String expr)
|
||||
{
|
||||
RE r = new RE();
|
||||
try
|
||||
{
|
||||
// Compile expression
|
||||
r.setProgram(compiler.compile(expr));
|
||||
|
||||
// Show expression
|
||||
say("" + NEW_LINE + "" + expr + "" + NEW_LINE + "");
|
||||
|
||||
// Show program for compiled expression
|
||||
PrintWriter writer = new PrintWriter( System.out );
|
||||
compiler.dumpProgram( writer );
|
||||
writer.flush();
|
||||
|
||||
boolean running = true;
|
||||
// Test matching against compiled expression
|
||||
while ( running )
|
||||
{
|
||||
// Read from keyboard
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
System.out.print("> ");
|
||||
System.out.flush();
|
||||
String match = br.readLine();
|
||||
|
||||
if ( match != null )
|
||||
{
|
||||
// Try a match against the keyboard input
|
||||
if (r.match(match))
|
||||
{
|
||||
say("Match successful.");
|
||||
}
|
||||
else
|
||||
{
|
||||
say("Match failed.");
|
||||
}
|
||||
|
||||
// Show subparen registers
|
||||
showParens(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
running = false;
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
say("Error: " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit with a fatal error.
|
||||
* @param s Last famous words before exiting
|
||||
*/
|
||||
void die(String s)
|
||||
{
|
||||
say("FATAL ERROR: " + s);
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail with an error. Will print a big failure message to System.out.
|
||||
*
|
||||
* @param log Output before failure
|
||||
* @param s Failure description
|
||||
*/
|
||||
void fail(StringBuffer log, String s)
|
||||
{
|
||||
System.out.print(log.toString());
|
||||
fail(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail with an error. Will print a big failure message to System.out.
|
||||
*
|
||||
* @param s Failure description
|
||||
*/
|
||||
void fail(String s)
|
||||
{
|
||||
failures++;
|
||||
say("" + NEW_LINE + "");
|
||||
say("*******************************************************");
|
||||
say("********************* FAILURE! **********************");
|
||||
say("*******************************************************");
|
||||
say("" + NEW_LINE + "");
|
||||
say(s);
|
||||
say("");
|
||||
// make sure the writer gets flushed.
|
||||
if (compiler != null) {
|
||||
PrintWriter writer = new PrintWriter( System.out );
|
||||
compiler.dumpProgram( writer );
|
||||
writer.flush();
|
||||
say("" + NEW_LINE + "");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Say something to standard out
|
||||
* @param s What to say
|
||||
*/
|
||||
void say(String s)
|
||||
{
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump parenthesized subexpressions found by a regular expression matcher object
|
||||
* @param r Matcher object with results to show
|
||||
*/
|
||||
void showParens(RE r)
|
||||
{
|
||||
// Loop through each paren
|
||||
for (int i = 0; i < r.getParenCount(); i++)
|
||||
{
|
||||
// Show paren register
|
||||
say("$" + i + " = " + r.getParen(i));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* number in automated test
|
||||
*/
|
||||
int testCount = 0;
|
||||
|
||||
/*
|
||||
* Count of failures in automated test
|
||||
*/
|
||||
int failures = 0;
|
||||
|
||||
/**
|
||||
* Run automated tests in RETest.txt file (from Perl 4.0 test battery)
|
||||
* @exception Exception thrown in case of error
|
||||
*/
|
||||
void runAutomatedTests(String testDocument) throws Exception
|
||||
{
|
||||
long ms = System.currentTimeMillis();
|
||||
|
||||
// Some unit tests
|
||||
testPrecompiledRE();
|
||||
testSplitAndGrep();
|
||||
testSubst();
|
||||
testOther();
|
||||
|
||||
// Test from script file
|
||||
File testInput = new File(testDocument);
|
||||
if (! testInput.exists()) {
|
||||
throw new Exception ("Could not find: " + testDocument);
|
||||
}
|
||||
|
||||
BufferedReader br = new BufferedReader(new FileReader(testInput));
|
||||
try
|
||||
{
|
||||
// While input is available, parse lines
|
||||
while (br.ready())
|
||||
{
|
||||
RETestCase testcase = getNextTestCase(br);
|
||||
if (testcase != null) {
|
||||
testcase.runTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
br.close();
|
||||
}
|
||||
|
||||
// Show match time
|
||||
say(NEW_LINE + NEW_LINE + "Match time = " + (System.currentTimeMillis() - ms) + " ms.");
|
||||
|
||||
// Print final results
|
||||
if (failures > 0) {
|
||||
say("*************** THERE ARE FAILURES! *******************");
|
||||
}
|
||||
say("Tests complete. " + testCount + " tests, " + failures + " failure(s).");
|
||||
}
|
||||
|
||||
/**
|
||||
* Run automated unit test
|
||||
* @exception Exception thrown in case of error
|
||||
*/
|
||||
void testOther() throws Exception
|
||||
{
|
||||
// Serialization test 1: Compile regexp and serialize/deserialize it
|
||||
RE r = new RE("(a*)b");
|
||||
say("Serialized/deserialized (a*)b");
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(128);
|
||||
new ObjectOutputStream(out).writeObject(r);
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||
r = (RE)new ObjectInputStream(in).readObject();
|
||||
if (!r.match("aaab"))
|
||||
{
|
||||
fail("Did not match 'aaab' with deserialized RE.");
|
||||
} else {
|
||||
say("aaaab = true");
|
||||
showParens(r);
|
||||
}
|
||||
|
||||
// Serialization test 2: serialize/deserialize used regexp
|
||||
out.reset();
|
||||
say("Deserialized (a*)b");
|
||||
new ObjectOutputStream(out).writeObject(r);
|
||||
in = new ByteArrayInputStream(out.toByteArray());
|
||||
r = (RE)new ObjectInputStream(in).readObject();
|
||||
if (r.getParenCount() != 0)
|
||||
{
|
||||
fail("Has parens after deserialization.");
|
||||
}
|
||||
if (!r.match("aaab"))
|
||||
{
|
||||
fail("Did not match 'aaab' with deserialized RE.");
|
||||
} else {
|
||||
say("aaaab = true");
|
||||
showParens(r);
|
||||
}
|
||||
|
||||
// Test MATCH_CASEINDEPENDENT
|
||||
r = new RE("abc(\\w*)");
|
||||
say("MATCH_CASEINDEPENDENT abc(\\w*)");
|
||||
r.setMatchFlags(RE.MATCH_CASEINDEPENDENT);
|
||||
say("abc(d*)");
|
||||
if (!r.match("abcddd"))
|
||||
{
|
||||
fail("Did not match 'abcddd'.");
|
||||
} else {
|
||||
say("abcddd = true");
|
||||
showParens(r);
|
||||
}
|
||||
|
||||
if (!r.match("aBcDDdd"))
|
||||
{
|
||||
fail("Did not match 'aBcDDdd'.");
|
||||
} else {
|
||||
say("aBcDDdd = true");
|
||||
showParens(r);
|
||||
}
|
||||
|
||||
if (!r.match("ABCDDDDD"))
|
||||
{
|
||||
fail("Did not match 'ABCDDDDD'.");
|
||||
} else {
|
||||
say("ABCDDDDD = true");
|
||||
showParens(r);
|
||||
}
|
||||
|
||||
r = new RE("(A*)b\\1");
|
||||
r.setMatchFlags(RE.MATCH_CASEINDEPENDENT);
|
||||
if (!r.match("AaAaaaBAAAAAA"))
|
||||
{
|
||||
fail("Did not match 'AaAaaaBAAAAAA'.");
|
||||
} else {
|
||||
say("AaAaaaBAAAAAA = true");
|
||||
showParens(r);
|
||||
}
|
||||
|
||||
r = new RE("[A-Z]*");
|
||||
r.setMatchFlags(RE.MATCH_CASEINDEPENDENT);
|
||||
if (!r.match("CaBgDe12"))
|
||||
{
|
||||
fail("Did not match 'CaBgDe12'.");
|
||||
} else {
|
||||
say("CaBgDe12 = true");
|
||||
showParens(r);
|
||||
}
|
||||
|
||||
// Test MATCH_MULTILINE. Test for eol/bol symbols.
|
||||
r = new RE("^abc$", RE.MATCH_MULTILINE);
|
||||
if (!r.match("\nabc")) {
|
||||
fail("\"\\nabc\" doesn't match \"^abc$\"");
|
||||
}
|
||||
if (!r.match("\rabc")) {
|
||||
fail("\"\\rabc\" doesn't match \"^abc$\"");
|
||||
}
|
||||
if (!r.match("\r\nabc")) {
|
||||
fail("\"\\r\\nabc\" doesn't match \"^abc$\"");
|
||||
}
|
||||
if (!r.match("\u0085abc")) {
|
||||
fail("\"\\u0085abc\" doesn't match \"^abc$\"");
|
||||
}
|
||||
if (!r.match("\u2028abc")) {
|
||||
fail("\"\\u2028abc\" doesn't match \"^abc$\"");
|
||||
}
|
||||
if (!r.match("\u2029abc")) {
|
||||
fail("\"\\u2029abc\" doesn't match \"^abc$\"");
|
||||
}
|
||||
|
||||
// Test MATCH_MULTILINE. Test that '.' does not matches new line.
|
||||
r = new RE("^a.*b$", RE.MATCH_MULTILINE);
|
||||
if (r.match("a\nb")) {
|
||||
fail("\"a\\nb\" matches \"^a.*b$\"");
|
||||
}
|
||||
if (r.match("a\rb")) {
|
||||
fail("\"a\\rb\" matches \"^a.*b$\"");
|
||||
}
|
||||
if (r.match("a\r\nb")) {
|
||||
fail("\"a\\r\\nb\" matches \"^a.*b$\"");
|
||||
}
|
||||
if (r.match("a\u0085b")) {
|
||||
fail("\"a\\u0085b\" matches \"^a.*b$\"");
|
||||
}
|
||||
if (r.match("a\u2028b")) {
|
||||
fail("\"a\\u2028b\" matches \"^a.*b$\"");
|
||||
}
|
||||
if (r.match("a\u2029b")) {
|
||||
fail("\"a\\u2029b\" matches \"^a.*b$\"");
|
||||
}
|
||||
}
|
||||
|
||||
private void testPrecompiledRE()
|
||||
{
|
||||
// Pre-compiled regular expression "a*b"
|
||||
char[] re1Instructions =
|
||||
{
|
||||
0x007c, 0x0000, 0x001a, 0x007c, 0x0000, 0x000d, 0x0041,
|
||||
0x0001, 0x0004, 0x0061, 0x007c, 0x0000, 0x0003, 0x0047,
|
||||
0x0000, 0xfff6, 0x007c, 0x0000, 0x0003, 0x004e, 0x0000,
|
||||
0x0003, 0x0041, 0x0001, 0x0004, 0x0062, 0x0045, 0x0000,
|
||||
0x0000,
|
||||
};
|
||||
|
||||
REProgram re1 = new REProgram(re1Instructions);
|
||||
|
||||
// Simple test of pre-compiled regular expressions
|
||||
RE r = new RE(re1);
|
||||
say("a*b");
|
||||
boolean result = r.match("aaab");
|
||||
say("aaab = " + result);
|
||||
showParens(r);
|
||||
if (!result) {
|
||||
fail("\"aaab\" doesn't match to precompiled \"a*b\"");
|
||||
}
|
||||
|
||||
result = r.match("b");
|
||||
say("b = " + result);
|
||||
showParens(r);
|
||||
if (!result) {
|
||||
fail("\"b\" doesn't match to precompiled \"a*b\"");
|
||||
}
|
||||
|
||||
result = r.match("c");
|
||||
say("c = " + result);
|
||||
showParens(r);
|
||||
if (result) {
|
||||
fail("\"c\" matches to precompiled \"a*b\"");
|
||||
}
|
||||
|
||||
result = r.match("ccccaaaaab");
|
||||
say("ccccaaaaab = " + result);
|
||||
showParens(r);
|
||||
if (!result) {
|
||||
fail("\"ccccaaaaab\" doesn't match to precompiled \"a*b\"");
|
||||
}
|
||||
}
|
||||
|
||||
private void testSplitAndGrep()
|
||||
{
|
||||
String[] expected = {"xxxx", "xxxx", "yyyy", "zzz"};
|
||||
RE r = new RE("a*b");
|
||||
String[] s = r.split("xxxxaabxxxxbyyyyaaabzzz");
|
||||
for (int i = 0; i < expected.length && i < s.length; i++) {
|
||||
assertEquals("Wrong splitted part", expected[i], s[i]);
|
||||
}
|
||||
assertEquals("Wrong number of splitted parts", expected.length,
|
||||
s.length);
|
||||
|
||||
r = new RE("x+");
|
||||
expected = new String[] {"xxxx", "xxxx"};
|
||||
s = r.grep(s);
|
||||
for (int i = 0; i < s.length; i++)
|
||||
{
|
||||
say("s[" + i + "] = " + s[i]);
|
||||
assertEquals("Grep fails", expected[i], s[i]);
|
||||
}
|
||||
assertEquals("Wrong number of string found by grep", expected.length,
|
||||
s.length);
|
||||
}
|
||||
|
||||
private void testSubst()
|
||||
{
|
||||
RE r = new RE("a*b");
|
||||
String expected = "-foo-garply-wacky-";
|
||||
String actual = r.subst("aaaabfooaaabgarplyaaabwackyb", "-");
|
||||
assertEquals("Wrong result of substitution in \"a*b\"", expected, actual);
|
||||
|
||||
// Test subst() with backreferences
|
||||
r = new RE("http://[\\.\\w\\-\\?/~_@&=%]+");
|
||||
actual = r.subst("visit us: http://www.apache.org!",
|
||||
"1234<a href=\"$0\">$0</a>", RE.REPLACE_BACKREFERENCES);
|
||||
assertEquals("Wrong subst() result", "visit us: 1234<a href=\"http://www.apache.org\">http://www.apache.org</a>!", actual);
|
||||
|
||||
// Test subst() with backreferences without leading characters
|
||||
// before first backreference
|
||||
r = new RE("(.*?)=(.*)");
|
||||
actual = r.subst("variable=value",
|
||||
"$1_test_$212", RE.REPLACE_BACKREFERENCES);
|
||||
assertEquals("Wrong subst() result", "variable_test_value12", actual);
|
||||
|
||||
// Test subst() with NO backreferences
|
||||
r = new RE("^a$");
|
||||
actual = r.subst("a",
|
||||
"b", RE.REPLACE_BACKREFERENCES);
|
||||
assertEquals("Wrong subst() result", "b", actual);
|
||||
|
||||
// Test subst() with NO backreferences
|
||||
r = new RE("^a$", RE.MATCH_MULTILINE);
|
||||
actual = r.subst("\r\na\r\n",
|
||||
"b", RE.REPLACE_BACKREFERENCES);
|
||||
assertEquals("Wrong subst() result", "\r\nb\r\n", actual);
|
||||
}
|
||||
|
||||
public void assertEquals(String message, String expected, String actual)
|
||||
{
|
||||
if (expected != null && !expected.equals(actual)
|
||||
|| actual != null && !actual.equals(expected))
|
||||
{
|
||||
fail(message + " (expected \"" + expected
|
||||
+ "\", actual \"" + actual + "\")");
|
||||
}
|
||||
}
|
||||
|
||||
public void assertEquals(String message, int expected, int actual)
|
||||
{
|
||||
if (expected != actual) {
|
||||
fail(message + " (expected \"" + expected
|
||||
+ "\", actual \"" + actual + "\")");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts yesno string to boolean.
|
||||
* @param yesno string representation of expected result
|
||||
* @return true if yesno is "YES", false if yesno is "NO"
|
||||
* stops program otherwise.
|
||||
*/
|
||||
private boolean getExpectedResult(String yesno)
|
||||
{
|
||||
if ("NO".equals(yesno))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if ("YES".equals(yesno))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Bad test script
|
||||
die("Test script error!");
|
||||
return false; //to please javac
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds next test description in a given script.
|
||||
* @param br <code>BufferedReader</code> for a script file
|
||||
* @return strign tag for next test description
|
||||
* @exception IOException if some io problems occured
|
||||
*/
|
||||
private String findNextTest(BufferedReader br) throws IOException
|
||||
{
|
||||
String number = "";
|
||||
|
||||
while (br.ready())
|
||||
{
|
||||
number = br.readLine();
|
||||
if (number == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
number = number.trim();
|
||||
if (number.startsWith("#"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (!number.equals(""))
|
||||
{
|
||||
say("Script error. Line = " + number);
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates testcase for the next test description in the script file.
|
||||
* @param br <code>BufferedReader</code> for script file.
|
||||
* @return a new tescase or null.
|
||||
* @exception IOException if some io problems occured
|
||||
*/
|
||||
private RETestCase getNextTestCase(BufferedReader br) throws IOException
|
||||
{
|
||||
// Find next re test case
|
||||
final String tag = findNextTest(br);
|
||||
|
||||
// Are we done?
|
||||
if (!br.ready())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get expression
|
||||
final String expr = br.readLine();
|
||||
|
||||
// Get test information
|
||||
final String matchAgainst = br.readLine();
|
||||
final boolean badPattern = "ERR".equals(matchAgainst);
|
||||
boolean shouldMatch = false;
|
||||
int expectedParenCount = 0;
|
||||
String[] expectedParens = null;
|
||||
|
||||
if (!badPattern) {
|
||||
shouldMatch = getExpectedResult(br.readLine().trim());
|
||||
if (shouldMatch) {
|
||||
expectedParenCount = Integer.parseInt(br.readLine().trim());
|
||||
expectedParens = new String[expectedParenCount];
|
||||
for (int i = 0; i < expectedParenCount; i++) {
|
||||
expectedParens[i] = br.readLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new RETestCase(this, tag, expr, matchAgainst, badPattern,
|
||||
shouldMatch, expectedParens);
|
||||
}
|
||||
}
|
||||
|
||||
final class RETestCase
|
||||
{
|
||||
final private StringBuffer log = new StringBuffer();
|
||||
final private int number;
|
||||
final private String tag; // number from script file
|
||||
final private String pattern;
|
||||
final private String toMatch;
|
||||
final private boolean badPattern;
|
||||
final private boolean shouldMatch;
|
||||
final private String[] parens;
|
||||
final private RETest test;
|
||||
private RE regexp;
|
||||
|
||||
public RETestCase(RETest test, String tag, String pattern,
|
||||
String toMatch, boolean badPattern,
|
||||
boolean shouldMatch, String[] parens)
|
||||
{
|
||||
this.number = ++test.testCount;
|
||||
this.test = test;
|
||||
this.tag = tag;
|
||||
this.pattern = pattern;
|
||||
this.toMatch = toMatch;
|
||||
this.badPattern = badPattern;
|
||||
this.shouldMatch = shouldMatch;
|
||||
if (parens != null) {
|
||||
this.parens = new String[parens.length];
|
||||
for (int i = 0; i < parens.length; i++) {
|
||||
this.parens[i] = parens[i];
|
||||
}
|
||||
} else {
|
||||
this.parens = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void runTest()
|
||||
{
|
||||
test.say(tag + "(" + number + "): " + pattern);
|
||||
if (testCreation()) {
|
||||
testMatch();
|
||||
}
|
||||
}
|
||||
|
||||
boolean testCreation()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Compile it
|
||||
regexp = new RE();
|
||||
regexp.setProgram(test.compiler.compile(pattern));
|
||||
// Expression didn't cause an expected error
|
||||
if (badPattern)
|
||||
{
|
||||
test.fail(log, "Was expected to be an error, but wasn't.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
// Some expressions *should* cause exceptions to be thrown
|
||||
catch (Exception e)
|
||||
{
|
||||
// If it was supposed to be an error, report success and continue
|
||||
if (badPattern)
|
||||
{
|
||||
log.append(" Match: ERR\n");
|
||||
success("Produces an error (" + e.toString() + "), as expected.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wasn't supposed to be an error
|
||||
String message = (e.getMessage() == null) ? e.toString() : e.getMessage();
|
||||
test.fail(log, "Produces an unexpected exception \"" + message + "\"");
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (Error e)
|
||||
{
|
||||
// Internal error happened
|
||||
test.fail(log, "Compiler threw fatal error \"" + e.getMessage() + "\"");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void testMatch()
|
||||
{
|
||||
log.append(" Match against: '" + toMatch + "'\n");
|
||||
// Try regular matching
|
||||
try
|
||||
{
|
||||
// Match against the string
|
||||
boolean result = regexp.match(toMatch);
|
||||
log.append(" Matched: " + (result ? "YES" : "NO") + "\n");
|
||||
|
||||
// Check result, parens, and iterators
|
||||
if (checkResult(result) && (!shouldMatch || checkParens()))
|
||||
{
|
||||
// test match(CharacterIterator, int)
|
||||
// for every CharacterIterator implementation.
|
||||
log.append(" Match using StringCharacterIterator\n");
|
||||
if (!tryMatchUsingCI(new StringCharacterIterator(toMatch)))
|
||||
return;
|
||||
|
||||
log.append(" Match using CharacterArrayCharacterIterator\n");
|
||||
if (!tryMatchUsingCI(new CharacterArrayCharacterIterator(toMatch.toCharArray(), 0, toMatch.length())))
|
||||
return;
|
||||
|
||||
log.append(" Match using StreamCharacterIterator\n");
|
||||
if (!tryMatchUsingCI(new StreamCharacterIterator(new StringBufferInputStream(toMatch))))
|
||||
return;
|
||||
|
||||
log.append(" Match using ReaderCharacterIterator\n");
|
||||
if (!tryMatchUsingCI(new ReaderCharacterIterator(new StringReader(toMatch))))
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Matcher blew it
|
||||
catch(Exception e)
|
||||
{
|
||||
test.fail(log, "Matcher threw exception: " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Internal error
|
||||
catch(Error e)
|
||||
{
|
||||
test.fail(log, "Matcher threw fatal error \"" + e.getMessage() + "\"");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkResult(boolean result)
|
||||
{
|
||||
// Write status
|
||||
if (result == shouldMatch) {
|
||||
success((shouldMatch ? "Matched" : "Did not match")
|
||||
+ " \"" + toMatch + "\", as expected:");
|
||||
return true;
|
||||
} else {
|
||||
if (shouldMatch) {
|
||||
test.fail(log, "Did not match \"" + toMatch + "\", when expected to.");
|
||||
} else {
|
||||
test.fail(log, "Matched \"" + toMatch + "\", when not expected to.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkParens()
|
||||
{
|
||||
// Show subexpression registers
|
||||
if (RETest.showSuccesses)
|
||||
{
|
||||
test.showParens(regexp);
|
||||
}
|
||||
|
||||
log.append(" Paren count: " + regexp.getParenCount() + "\n");
|
||||
if (!assertEquals(log, "Wrong number of parens", parens.length, regexp.getParenCount()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check registers against expected contents
|
||||
for (int p = 0; p < regexp.getParenCount(); p++)
|
||||
{
|
||||
log.append(" Paren " + p + ": " + regexp.getParen(p) + "\n");
|
||||
|
||||
// Compare expected result with actual
|
||||
if ("null".equals(parens[p]) && regexp.getParen(p) == null)
|
||||
{
|
||||
// Consider "null" in test file equal to null
|
||||
continue;
|
||||
}
|
||||
if (!assertEquals(log, "Wrong register " + p, parens[p], regexp.getParen(p)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean tryMatchUsingCI(CharacterIterator matchAgainst)
|
||||
{
|
||||
try {
|
||||
boolean result = regexp.match(matchAgainst, 0);
|
||||
log.append(" Match: " + (result ? "YES" : "NO") + "\n");
|
||||
return checkResult(result) && (!shouldMatch || checkParens());
|
||||
}
|
||||
// Matcher blew it
|
||||
catch(Exception e)
|
||||
{
|
||||
test.fail(log, "Matcher threw exception: " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Internal error
|
||||
catch(Error e)
|
||||
{
|
||||
test.fail(log, "Matcher threw fatal error \"" + e.getMessage() + "\"");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean assertEquals(StringBuffer log, String message, String expected, String actual)
|
||||
{
|
||||
if (expected != null && !expected.equals(actual)
|
||||
|| actual != null && !actual.equals(expected))
|
||||
{
|
||||
test.fail(log, message + " (expected \"" + expected
|
||||
+ "\", actual \"" + actual + "\")");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean assertEquals(StringBuffer log, String message, int expected, int actual)
|
||||
{
|
||||
if (expected != actual) {
|
||||
test.fail(log, message + " (expected \"" + expected
|
||||
+ "\", actual \"" + actual + "\")");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a success
|
||||
* @param s Success story
|
||||
*/
|
||||
void success(String s)
|
||||
{
|
||||
if (RETest.showSuccesses)
|
||||
{
|
||||
test.say("" + RETest.NEW_LINE + "-----------------------" + RETest.NEW_LINE + "");
|
||||
test.say("Expression #" + (number) + " \"" + pattern + "\" ");
|
||||
test.say("Success: " + s);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.regexp.internal;
|
||||
|
||||
/**
|
||||
* This is a class that contains utility helper methods for this package.
|
||||
*
|
||||
* @author <a href="mailto:jonl@muppetlabs.com">Jonathan Locke</a>
|
||||
*/
|
||||
public class REUtil
|
||||
{
|
||||
/** complex: */
|
||||
private static final String complexPrefix = "complex:";
|
||||
|
||||
/**
|
||||
* Creates a regular expression, permitting simple or complex syntax
|
||||
* @param expression The expression, beginning with a prefix if it's complex or
|
||||
* having no prefix if it's simple
|
||||
* @param matchFlags Matching style flags
|
||||
* @return The regular expression object
|
||||
* @exception RESyntaxException thrown in case of error
|
||||
*/
|
||||
public static RE createRE(String expression, int matchFlags) throws RESyntaxException
|
||||
{
|
||||
if (expression.startsWith(complexPrefix))
|
||||
{
|
||||
return new RE(expression.substring(complexPrefix.length()), matchFlags);
|
||||
}
|
||||
return new RE(RE.simplePatternToFullRegularExpression(expression), matchFlags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a regular expression, permitting simple or complex syntax
|
||||
* @param expression The expression, beginning with a prefix if it's complex or
|
||||
* having no prefix if it's simple
|
||||
* @return The regular expression object
|
||||
* @exception RESyntaxException thrown in case of error
|
||||
*/
|
||||
public static RE createRE(String expression) throws RESyntaxException
|
||||
{
|
||||
return createRE(expression, RE.MATCH_NORMAL);
|
||||
}
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.regexp.internal;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Encapsulates java.io.Reader as CharacterIterator
|
||||
*
|
||||
* @author <a href="mailto:ales.novak@netbeans.com">Ales Novak</a>
|
||||
*/
|
||||
public final class ReaderCharacterIterator implements CharacterIterator
|
||||
{
|
||||
/** Underlying reader */
|
||||
private final Reader reader;
|
||||
|
||||
/** Buffer of read chars */
|
||||
private final StringBuffer buff;
|
||||
|
||||
/** read end? */
|
||||
private boolean closed;
|
||||
|
||||
/** @param reader a Reader, which is parsed */
|
||||
public ReaderCharacterIterator(Reader reader)
|
||||
{
|
||||
this.reader = reader;
|
||||
this.buff = new StringBuffer(512);
|
||||
this.closed = false;
|
||||
}
|
||||
|
||||
/** @return a substring */
|
||||
public String substring(int beginIndex, int endIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
ensure(endIndex);
|
||||
return buff.toString().substring(beginIndex, endIndex);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new StringIndexOutOfBoundsException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/** @return a substring */
|
||||
public String substring(int beginIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
readAll();
|
||||
return buff.toString().substring(beginIndex);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new StringIndexOutOfBoundsException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/** @return a character at the specified position. */
|
||||
public char charAt(int pos)
|
||||
{
|
||||
try
|
||||
{
|
||||
ensure(pos);
|
||||
return buff.charAt(pos);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new StringIndexOutOfBoundsException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/** @return <tt>true</tt> iff if the specified index is after the end of the character stream */
|
||||
public boolean isEnd(int pos)
|
||||
{
|
||||
if (buff.length() > pos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
ensure(pos);
|
||||
return (buff.length() <= pos);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new StringIndexOutOfBoundsException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads n characters from the stream and appends them to the buffer */
|
||||
private int read(int n) throws IOException
|
||||
{
|
||||
if (closed)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
char[] c = new char[n];
|
||||
int count = 0;
|
||||
int read = 0;
|
||||
|
||||
do
|
||||
{
|
||||
read = reader.read(c);
|
||||
if (read < 0) // EOF
|
||||
{
|
||||
closed = true;
|
||||
break;
|
||||
}
|
||||
count += read;
|
||||
buff.append(c, 0, read);
|
||||
}
|
||||
while (count < n);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/** Reads rest of the stream. */
|
||||
private void readAll() throws IOException
|
||||
{
|
||||
while(! closed)
|
||||
{
|
||||
read(1000);
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads chars up to the idx */
|
||||
private void ensure(int idx) throws IOException
|
||||
{
|
||||
if (closed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (idx < buff.length())
|
||||
{
|
||||
return;
|
||||
}
|
||||
read(idx + 1 - buff.length());
|
||||
}
|
||||
}
|
@ -1,161 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.regexp.internal;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Encapsulates java.io.InputStream as CharacterIterator.
|
||||
*
|
||||
* @author <a href="mailto:ales.novak@netbeans.com">Ales Novak</a>
|
||||
*/
|
||||
public final class StreamCharacterIterator implements CharacterIterator
|
||||
{
|
||||
/** Underlying is */
|
||||
private final InputStream is;
|
||||
|
||||
/** Buffer of read chars */
|
||||
private final StringBuffer buff;
|
||||
|
||||
/** read end? */
|
||||
private boolean closed;
|
||||
|
||||
/** @param is an InputStream, which is parsed */
|
||||
public StreamCharacterIterator(InputStream is)
|
||||
{
|
||||
this.is = is;
|
||||
this.buff = new StringBuffer(512);
|
||||
this.closed = false;
|
||||
}
|
||||
|
||||
/** @return a substring */
|
||||
public String substring(int beginIndex, int endIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
ensure(endIndex);
|
||||
return buff.toString().substring(beginIndex, endIndex);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new StringIndexOutOfBoundsException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/** @return a substring */
|
||||
public String substring(int beginIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
readAll();
|
||||
return buff.toString().substring(beginIndex);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new StringIndexOutOfBoundsException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @return a character at the specified position. */
|
||||
public char charAt(int pos)
|
||||
{
|
||||
try
|
||||
{
|
||||
ensure(pos);
|
||||
return buff.charAt(pos);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new StringIndexOutOfBoundsException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/** @return <tt>true</tt> iff if the specified index is after the end of the character stream */
|
||||
public boolean isEnd(int pos)
|
||||
{
|
||||
if (buff.length() > pos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
ensure(pos);
|
||||
return (buff.length() <= pos);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new StringIndexOutOfBoundsException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads n characters from the stream and appends them to the buffer */
|
||||
private int read(int n) throws IOException
|
||||
{
|
||||
if (closed)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int c;
|
||||
int i = n;
|
||||
while (--i >= 0)
|
||||
{
|
||||
c = is.read();
|
||||
if (c < 0) // EOF
|
||||
{
|
||||
closed = true;
|
||||
break;
|
||||
}
|
||||
buff.append((char) c);
|
||||
}
|
||||
return n - i;
|
||||
}
|
||||
|
||||
/** Reads rest of the stream. */
|
||||
private void readAll() throws IOException
|
||||
{
|
||||
while(! closed)
|
||||
{
|
||||
read(1000);
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads chars up to the idx */
|
||||
private void ensure(int idx) throws IOException
|
||||
{
|
||||
if (closed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (idx < buff.length())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
read(idx + 1 - buff.length());
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.regexp.internal;
|
||||
|
||||
/**
|
||||
* Encapsulates String as CharacterIterator.
|
||||
*
|
||||
* @author <a href="mailto:ales.novak@netbeans.com">Ales Novak</a>
|
||||
*/
|
||||
public final class StringCharacterIterator implements CharacterIterator
|
||||
{
|
||||
/** encapsulated */
|
||||
private final String src;
|
||||
|
||||
/** @param src - encapsulated String */
|
||||
public StringCharacterIterator(String src)
|
||||
{
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
/** @return a substring */
|
||||
public String substring(int beginIndex, int endIndex)
|
||||
{
|
||||
return src.substring(beginIndex, endIndex);
|
||||
}
|
||||
|
||||
/** @return a substring */
|
||||
public String substring(int beginIndex)
|
||||
{
|
||||
return src.substring(beginIndex);
|
||||
}
|
||||
|
||||
/** @return a character at the specified position. */
|
||||
public char charAt(int pos)
|
||||
{
|
||||
return src.charAt(pos);
|
||||
}
|
||||
|
||||
/** @return <tt>true</tt> iff if the specified index is after the end of the character stream */
|
||||
public boolean isEnd(int pos)
|
||||
{
|
||||
return (pos >= src.length());
|
||||
}
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
/*
|
||||
* reserved comment block
|
||||
* DO NOT REMOVE OR ALTER!
|
||||
*/
|
||||
/*
|
||||
* Copyright 1999-2004 The Apache Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.sun.org.apache.regexp.internal;
|
||||
|
||||
import com.sun.org.apache.regexp.internal.RECompiler;
|
||||
import com.sun.org.apache.regexp.internal.RESyntaxException;
|
||||
|
||||
/**
|
||||
* 'recompile' is a command line tool that pre-compiles one or more regular expressions
|
||||
* for use with the regular expression matcher class 'RE'. For example, the command
|
||||
* "java recompile a*b" produces output like this:
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* // Pre-compiled regular expression "a*b"
|
||||
* char[] re1Instructions =
|
||||
* {
|
||||
* 0x007c, 0x0000, 0x001a, 0x007c, 0x0000, 0x000d, 0x0041,
|
||||
* 0x0001, 0x0004, 0x0061, 0x007c, 0x0000, 0x0003, 0x0047,
|
||||
* 0x0000, 0xfff6, 0x007c, 0x0000, 0x0003, 0x004e, 0x0000,
|
||||
* 0x0003, 0x0041, 0x0001, 0x0004, 0x0062, 0x0045, 0x0000,
|
||||
* 0x0000,
|
||||
* };
|
||||
*
|
||||
* REProgram re1 = new REProgram(re1Instructions);
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* By pasting this output into your code, you can construct a regular expression matcher
|
||||
* (RE) object directly from the pre-compiled data (the character array re1), thus avoiding
|
||||
* the overhead of compiling the expression at runtime. For example:
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* RE r = new RE(re1);
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @see RE
|
||||
* @see RECompiler
|
||||
*
|
||||
* @author <a href="mailto:jonl@muppetlabs.com">Jonathan Locke</a>
|
||||
*/
|
||||
public class recompile
|
||||
{
|
||||
/**
|
||||
* Main application entrypoint.
|
||||
* @param arg Command line arguments
|
||||
*/
|
||||
static public void main(String[] arg)
|
||||
{
|
||||
// Create a compiler object
|
||||
RECompiler r = new RECompiler();
|
||||
|
||||
// Print usage if arguments are incorrect
|
||||
if (arg.length <= 0 || arg.length % 2 != 0)
|
||||
{
|
||||
System.out.println("Usage: recompile <patternname> <pattern>");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
// Loop through arguments, compiling each
|
||||
for (int i = 0; i < arg.length; i += 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Compile regular expression
|
||||
String name = arg[i];
|
||||
String pattern = arg[i+1];
|
||||
String instructions = name + "PatternInstructions";
|
||||
|
||||
// Output program as a nice, formatted character array
|
||||
System.out.print("\n // Pre-compiled regular expression '" + pattern + "'\n"
|
||||
+ " private static char[] " + instructions + " = \n {");
|
||||
|
||||
// Compile program for pattern
|
||||
REProgram program = r.compile(pattern);
|
||||
|
||||
// Number of columns in output
|
||||
int numColumns = 7;
|
||||
|
||||
// Loop through program
|
||||
char[] p = program.getInstructions();
|
||||
for (int j = 0; j < p.length; j++)
|
||||
{
|
||||
// End of column?
|
||||
if ((j % numColumns) == 0)
|
||||
{
|
||||
System.out.print("\n ");
|
||||
}
|
||||
|
||||
// Print character as padded hex number
|
||||
String hex = Integer.toHexString(p[j]);
|
||||
while (hex.length() < 4)
|
||||
{
|
||||
hex = "0" + hex;
|
||||
}
|
||||
System.out.print("0x" + hex + ", ");
|
||||
}
|
||||
|
||||
// End of program block
|
||||
System.out.println("\n };");
|
||||
System.out.println("\n private static RE " + name + "Pattern = new RE(new REProgram(" + instructions + "));");
|
||||
}
|
||||
catch (RESyntaxException e)
|
||||
{
|
||||
System.out.println("Syntax error in expression \"" + arg[i] + "\": " + e.toString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Unexpected exception: " + e.toString());
|
||||
}
|
||||
catch (Error e)
|
||||
{
|
||||
System.out.println("Internal error: " + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -1345,6 +1345,15 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes character reference in hex format.
|
||||
*/
|
||||
private void writeCharRef(int codePoint) throws IOException {
|
||||
fWriter.write( "&#x" );
|
||||
fWriter.write( Integer.toHexString(codePoint) );
|
||||
fWriter.write( ';' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes XML content to underlying writer. Escapes characters unless
|
||||
* escaping character feature is turned off.
|
||||
@ -1368,10 +1377,14 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
|
||||
if (fEncoder != null && !fEncoder.canEncode(ch)){
|
||||
fWriter.write(content, startWritePos, index - startWritePos );
|
||||
|
||||
// Escape this char as underlying encoder cannot handle it
|
||||
fWriter.write( "&#x" );
|
||||
fWriter.write(Integer.toHexString(ch));
|
||||
fWriter.write( ';' );
|
||||
// Check if current and next characters forms a surrogate pair
|
||||
// and escape it to avoid generation of invalid xml content
|
||||
if ( index != end - 1 && Character.isSurrogatePair(ch, content[index+1])) {
|
||||
writeCharRef(Character.toCodePoint(ch, content[index+1]));
|
||||
index++;
|
||||
} else {
|
||||
writeCharRef(ch);
|
||||
}
|
||||
startWritePos = index + 1;
|
||||
continue;
|
||||
}
|
||||
@ -1439,10 +1452,15 @@ public final class XMLStreamWriterImpl extends AbstractMap implements XMLStreamW
|
||||
if (fEncoder != null && !fEncoder.canEncode(ch)){
|
||||
fWriter.write(content, startWritePos, index - startWritePos );
|
||||
|
||||
// Escape this char as underlying encoder cannot handle it
|
||||
fWriter.write( "&#x" );
|
||||
fWriter.write(Integer.toHexString(ch));
|
||||
fWriter.write( ';' );
|
||||
// Check if current and next characters forms a surrogate pair
|
||||
// and escape it to avoid generation of invalid xml content
|
||||
if ( index != end - 1 && Character.isSurrogatePair(ch, content.charAt(index+1))) {
|
||||
writeCharRef(Character.toCodePoint(ch, content.charAt(index+1)));
|
||||
index++;
|
||||
} else {
|
||||
writeCharRef(ch);
|
||||
}
|
||||
|
||||
startWritePos = index + 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -86,5 +86,6 @@ module java.xml {
|
||||
uses javax.xml.transform.TransformerFactory;
|
||||
uses javax.xml.validation.SchemaFactory;
|
||||
uses javax.xml.xpath.XPathFactory;
|
||||
uses org.xml.sax.XMLReader;
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,7 @@ package org.xml.sax;
|
||||
* @see org.xml.sax.DocumentHandler#startElement startElement
|
||||
* @see org.xml.sax.helpers.AttributeListImpl AttributeListImpl
|
||||
*/
|
||||
@Deprecated(since="5")
|
||||
public interface AttributeList {
|
||||
|
||||
|
||||
|
@ -68,6 +68,7 @@ package org.xml.sax;
|
||||
* @see org.xml.sax.Locator
|
||||
* @see org.xml.sax.HandlerBase
|
||||
*/
|
||||
@Deprecated(since="5")
|
||||
public interface DocumentHandler {
|
||||
|
||||
|
||||
|
@ -73,6 +73,7 @@ import java.util.Locale;
|
||||
* @see org.xml.sax.HandlerBase
|
||||
* @see org.xml.sax.InputSource
|
||||
*/
|
||||
@Deprecated(since="5")
|
||||
public interface Parser
|
||||
{
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -32,8 +32,7 @@
|
||||
|
||||
package org.xml.sax.helpers;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Create a new instance of a class by name.
|
||||
@ -57,31 +56,26 @@ import java.lang.reflect.InvocationTargetException;
|
||||
* @version 2.0.1 (sax2r2)
|
||||
*/
|
||||
class NewInstance {
|
||||
|
||||
private static final String DEFAULT_PACKAGE = "com.sun.org.apache.xerces.internal";
|
||||
/**
|
||||
* Creates a new instance of the specified class name
|
||||
*
|
||||
* Package private so this code is not exposed at the API level.
|
||||
*/
|
||||
static Object newInstance (ClassLoader classLoader, String className)
|
||||
static <T> T newInstance (Class<T> type, ClassLoader loader, String clsName)
|
||||
throws ClassNotFoundException, IllegalAccessException,
|
||||
InstantiationException
|
||||
{
|
||||
// make sure we have access to restricted packages
|
||||
boolean internal = false;
|
||||
if (System.getSecurityManager() != null) {
|
||||
if (className != null && className.startsWith(DEFAULT_PACKAGE)) {
|
||||
internal = true;
|
||||
}
|
||||
ClassLoader classLoader = Objects.requireNonNull(loader);
|
||||
String className = Objects.requireNonNull(clsName);
|
||||
|
||||
if (className.startsWith(DEFAULT_PACKAGE)) {
|
||||
return type.cast(new com.sun.org.apache.xerces.internal.parsers.SAXParser());
|
||||
}
|
||||
|
||||
Class driverClass;
|
||||
if (classLoader == null || internal) {
|
||||
driverClass = Class.forName(className);
|
||||
} else {
|
||||
driverClass = classLoader.loadClass(className);
|
||||
}
|
||||
return driverClass.newInstance();
|
||||
Class<?> driverClass = classLoader.loadClass(className);
|
||||
return type.cast(driverClass.newInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,8 +30,6 @@
|
||||
|
||||
package org.xml.sax.helpers;
|
||||
|
||||
import org.xml.sax.Parser;
|
||||
|
||||
|
||||
/**
|
||||
* Java-specific class for dynamically loading SAX parsers.
|
||||
@ -65,6 +63,8 @@ import org.xml.sax.Parser;
|
||||
* @author David Megginson
|
||||
* @version 2.0.1 (sax2r2)
|
||||
*/
|
||||
@SuppressWarnings( "deprecation" )
|
||||
@Deprecated(since="5")
|
||||
public class ParserFactory {
|
||||
private static SecuritySupport ss = new SecuritySupport();
|
||||
|
||||
@ -97,7 +97,7 @@ public class ParserFactory {
|
||||
* @see #makeParser(java.lang.String)
|
||||
* @see org.xml.sax.Parser
|
||||
*/
|
||||
public static Parser makeParser ()
|
||||
public static org.xml.sax.Parser makeParser ()
|
||||
throws ClassNotFoundException,
|
||||
IllegalAccessException,
|
||||
InstantiationException,
|
||||
@ -134,14 +134,13 @@ public class ParserFactory {
|
||||
* @see #makeParser()
|
||||
* @see org.xml.sax.Parser
|
||||
*/
|
||||
public static Parser makeParser (String className)
|
||||
public static org.xml.sax.Parser makeParser (String className)
|
||||
throws ClassNotFoundException,
|
||||
IllegalAccessException,
|
||||
InstantiationException,
|
||||
ClassCastException
|
||||
{
|
||||
return (Parser) NewInstance.newInstance (
|
||||
ss.getContextClassLoader(), className);
|
||||
return NewInstance.newInstance (org.xml.sax.Parser.class, ss.getClassLoader(), className);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -37,72 +37,56 @@ import java.security.*;
|
||||
*/
|
||||
class SecuritySupport {
|
||||
|
||||
|
||||
ClassLoader getContextClassLoader() throws SecurityException{
|
||||
return (ClassLoader)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
ClassLoader cl = null;
|
||||
//try {
|
||||
cl = Thread.currentThread().getContextClassLoader();
|
||||
//} catch (SecurityException ex) { }
|
||||
|
||||
if (cl == null)
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
|
||||
return cl;
|
||||
/**
|
||||
* Returns the current thread's context class loader, or the system class loader
|
||||
* if the context class loader is null.
|
||||
* @return the current thread's context class loader, or the system class loader
|
||||
* @throws SecurityException
|
||||
*/
|
||||
ClassLoader getClassLoader() throws SecurityException{
|
||||
return AccessController.doPrivileged((PrivilegedAction<ClassLoader>)() -> {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) {
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
}
|
||||
|
||||
return cl;
|
||||
});
|
||||
}
|
||||
|
||||
String getSystemProperty(final String propName) {
|
||||
return (String)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return System.getProperty(propName);
|
||||
}
|
||||
});
|
||||
return AccessController.doPrivileged((PrivilegedAction<String>)()
|
||||
-> System.getProperty(propName));
|
||||
}
|
||||
|
||||
FileInputStream getFileInputStream(final File file)
|
||||
throws FileNotFoundException
|
||||
{
|
||||
try {
|
||||
return (FileInputStream)
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws FileNotFoundException {
|
||||
return new FileInputStream(file);
|
||||
}
|
||||
});
|
||||
return AccessController.doPrivileged((PrivilegedExceptionAction<FileInputStream>)() ->
|
||||
new FileInputStream(file));
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (FileNotFoundException)e.getException();
|
||||
}
|
||||
}
|
||||
|
||||
InputStream getResourceAsStream(final ClassLoader cl,
|
||||
final String name)
|
||||
|
||||
InputStream getResourceAsStream(final ClassLoader cl, final String name)
|
||||
{
|
||||
return (InputStream)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = SecuritySupport.class.getResourceAsStream(name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
}
|
||||
});
|
||||
return AccessController.doPrivileged((PrivilegedAction<InputStream>) () -> {
|
||||
InputStream ris;
|
||||
if (cl == null) {
|
||||
ris = SecuritySupport.class.getResourceAsStream(name);
|
||||
} else {
|
||||
ris = cl.getResourceAsStream(name);
|
||||
}
|
||||
return ris;
|
||||
});
|
||||
}
|
||||
|
||||
boolean doesFileExist(final File f) {
|
||||
return ((Boolean)
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
return new Boolean(f.exists());
|
||||
}
|
||||
})).booleanValue();
|
||||
return (AccessController.doPrivileged((PrivilegedAction<Boolean>)() ->
|
||||
new Boolean(f.exists())));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -32,10 +32,17 @@
|
||||
|
||||
package org.xml.sax.helpers;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import org.xml.sax.XMLReader;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
|
||||
/**
|
||||
@ -70,7 +77,11 @@ import org.xml.sax.SAXException;
|
||||
* @since 1.4, SAX 2.0
|
||||
* @author David Megginson, David Brownell
|
||||
* @version 2.0.1 (sax2r2)
|
||||
*
|
||||
* @deprecated It is recommended to use {@link javax.xml.parsers.SAXParserFactory}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
final public class XMLReaderFactory
|
||||
{
|
||||
/**
|
||||
@ -83,47 +94,43 @@ final public class XMLReaderFactory
|
||||
}
|
||||
|
||||
private static final String property = "org.xml.sax.driver";
|
||||
private static SecuritySupport ss = new SecuritySupport();
|
||||
private static final SecuritySupport ss = new SecuritySupport();
|
||||
|
||||
private static String _clsFromJar = null;
|
||||
private static boolean _jarread = false;
|
||||
/**
|
||||
* Attempt to create an XMLReader from system defaults.
|
||||
* In environments which can support it, the name of the XMLReader
|
||||
* class is determined by trying each these options in order, and
|
||||
* using the first one which succeeds:
|
||||
* <ul>
|
||||
*
|
||||
* Obtains a new instance of a {@link org.xml.sax.XMLReader}.
|
||||
* This method uses the following ordered lookup procedure to find and load
|
||||
* the {@link org.xml.sax.XMLReader} implementation class:
|
||||
* <p>
|
||||
* <ol>
|
||||
* <li>If the system property {@code org.xml.sax.driver}
|
||||
* has a value, that is used as an XMLReader class name. </li>
|
||||
* <li>
|
||||
* Use the service-provider loading facility, defined by the
|
||||
* {@link java.util.ServiceLoader} class, to attempt to locate and load an
|
||||
* implementation of the service {@link org.xml.sax.XMLReader} by using the
|
||||
* {@linkplain java.lang.Thread#getContextClassLoader() current thread's context class loader}.
|
||||
* If the context class loader is null, the
|
||||
* {@linkplain ClassLoader#getSystemClassLoader() system class loader} will
|
||||
* be used.
|
||||
* </li>
|
||||
* <li>
|
||||
* Deprecated. Look for a class name in the {@code META-INF/services/org.xml.sax.driver}
|
||||
* file in a jar file available to the runtime.</li>
|
||||
* <li>
|
||||
* <p>
|
||||
* Otherwise, the system-default implementation is returned.
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
* <li>The JAR "Services API" is used to look for a class name
|
||||
* in the <em>META-INF/services/org.xml.sax.driver</em> file in
|
||||
* jarfiles available to the runtime.</li>
|
||||
* @apiNote
|
||||
* The process that looks for a class name in the
|
||||
* {@code META-INF/services/org.xml.sax.driver} file in a jar file does not
|
||||
* conform to the specification of the service-provider loading facility
|
||||
* as defined in {@link java.util.ServiceLoader} and therefore does not
|
||||
* support modularization. It is deprecated as of Java SE 9 and subject to
|
||||
* removal in a future release.
|
||||
*
|
||||
* <li> SAX parser distributions are strongly encouraged to provide
|
||||
* a default XMLReader class name that will take effect only when
|
||||
* previous options (on this list) are not successful.</li>
|
||||
*
|
||||
* <li>Finally, if {@link ParserFactory#makeParser()} can
|
||||
* return a system default SAX1 parser, that parser is wrapped in
|
||||
* a {@link ParserAdapter}. (This is a migration aid for SAX1
|
||||
* environments, where the {@code org.xml.sax.parser} system
|
||||
* property will often be usable.) </li>
|
||||
* </ul>
|
||||
*
|
||||
* <p> In environments such as small embedded systems, which can not
|
||||
* support that flexibility, other mechanisms to determine the default
|
||||
* may be used.
|
||||
*
|
||||
* <p>Note that many Java environments allow system properties to be
|
||||
* initialized on a command line. This means that <em>in most cases</em>
|
||||
* setting a good value for that property ensures that calls to this
|
||||
* method will succeed, except when security policies intervene.
|
||||
* This will also maximize application portability to older SAX
|
||||
* environments, with less robust implementations of this method.
|
||||
*
|
||||
* @return A new XMLReader.
|
||||
* @return a new XMLReader.
|
||||
* @exception org.xml.sax.SAXException If no default XMLReader class
|
||||
* can be identified and instantiated.
|
||||
* @see #createXMLReader(java.lang.String)
|
||||
@ -132,7 +139,7 @@ final public class XMLReaderFactory
|
||||
throws SAXException
|
||||
{
|
||||
String className = null;
|
||||
ClassLoader cl = ss.getContextClassLoader();
|
||||
ClassLoader cl = ss.getClassLoader();
|
||||
|
||||
// 1. try the JVM-instance-wide system property
|
||||
try {
|
||||
@ -140,62 +147,26 @@ final public class XMLReaderFactory
|
||||
}
|
||||
catch (RuntimeException e) { /* continue searching */ }
|
||||
|
||||
// 2. if that fails, try META-INF/services/
|
||||
// 2. try the ServiceLoader
|
||||
if (className == null) {
|
||||
if (!_jarread) {
|
||||
_jarread = true;
|
||||
String service = "META-INF/services/" + property;
|
||||
InputStream in;
|
||||
BufferedReader reader;
|
||||
|
||||
try {
|
||||
if (cl != null) {
|
||||
in = ss.getResourceAsStream(cl, service);
|
||||
|
||||
// If no provider found then try the current ClassLoader
|
||||
if (in == null) {
|
||||
cl = null;
|
||||
in = ss.getResourceAsStream(cl, service);
|
||||
}
|
||||
} else {
|
||||
// No Context ClassLoader, try the current ClassLoader
|
||||
in = ss.getResourceAsStream(cl, service);
|
||||
}
|
||||
|
||||
if (in != null) {
|
||||
reader = new BufferedReader (new InputStreamReader (in, "UTF8"));
|
||||
_clsFromJar = reader.readLine ();
|
||||
in.close ();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
final XMLReader provider = findServiceProvider(XMLReader.class, cl);
|
||||
if (provider != null) {
|
||||
return provider;
|
||||
}
|
||||
className = _clsFromJar;
|
||||
}
|
||||
|
||||
// 3. Distro-specific fallback
|
||||
// 3. try META-INF/services/org.xml.sax.driver. This old process allows
|
||||
// legacy providers to be found
|
||||
if (className == null) {
|
||||
// BEGIN DISTRIBUTION-SPECIFIC
|
||||
|
||||
// EXAMPLE:
|
||||
// className = "com.example.sax.XmlReader";
|
||||
// or a $JAVA_HOME/jre/lib/*properties setting...
|
||||
className = "com.sun.org.apache.xerces.internal.parsers.SAXParser";
|
||||
|
||||
// END DISTRIBUTION-SPECIFIC
|
||||
className = jarLookup(cl);
|
||||
}
|
||||
|
||||
// do we know the XMLReader implementation class yet?
|
||||
if (className != null)
|
||||
return loadClass (cl, className);
|
||||
|
||||
// 4. panic -- adapt any SAX1 parser
|
||||
try {
|
||||
return new ParserAdapter (ParserFactory.makeParser ());
|
||||
} catch (Exception e) {
|
||||
throw new SAXException ("Can't create default XMLReader; "
|
||||
+ "is system property org.xml.sax.driver set?");
|
||||
// 4. Distro-specific fallback
|
||||
if (className == null) {
|
||||
return new com.sun.org.apache.xerces.internal.parsers.SAXParser();
|
||||
}
|
||||
|
||||
return loadClass (cl, className);
|
||||
}
|
||||
|
||||
|
||||
@ -217,14 +188,14 @@ final public class XMLReaderFactory
|
||||
public static XMLReader createXMLReader (String className)
|
||||
throws SAXException
|
||||
{
|
||||
return loadClass (ss.getContextClassLoader(), className);
|
||||
return loadClass (ss.getClassLoader(), className);
|
||||
}
|
||||
|
||||
private static XMLReader loadClass (ClassLoader loader, String className)
|
||||
throws SAXException
|
||||
{
|
||||
try {
|
||||
return (XMLReader) NewInstance.newInstance (loader, className);
|
||||
return NewInstance.newInstance (XMLReader.class, loader, className);
|
||||
} catch (ClassNotFoundException e1) {
|
||||
throw new SAXException("SAX2 driver class " + className +
|
||||
" not found", e1);
|
||||
@ -240,4 +211,64 @@ final public class XMLReaderFactory
|
||||
" does not implement XMLReader", e4);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates a provider by directly reading the jar service file.
|
||||
* @param loader the ClassLoader to be used to read the service file
|
||||
* @return the name of the provider, or null if nothing is found
|
||||
*/
|
||||
private static String jarLookup(final ClassLoader loader) {
|
||||
final ClassLoader cl = Objects.requireNonNull(loader);
|
||||
String clsFromJar = null;
|
||||
String service = "META-INF/services/" + property;
|
||||
InputStream in;
|
||||
BufferedReader reader;
|
||||
|
||||
try {
|
||||
in = ss.getResourceAsStream(cl, service);
|
||||
|
||||
// If no provider found then try the current ClassLoader
|
||||
if (in == null) {
|
||||
in = ss.getResourceAsStream(null, service);
|
||||
}
|
||||
|
||||
if (in != null) {
|
||||
reader = new BufferedReader (new InputStreamReader (in, "UTF8"));
|
||||
clsFromJar = reader.readLine ();
|
||||
in.close ();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return clsFromJar;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to find provider using the ServiceLoader API
|
||||
*
|
||||
* @param type Base class / Service interface of the factory to find.
|
||||
*
|
||||
* @return instance of provider class if found or null
|
||||
*/
|
||||
private static <T> T findServiceProvider(final Class<T> type, final ClassLoader loader)
|
||||
throws SAXException {
|
||||
ClassLoader cl = Objects.requireNonNull(loader);
|
||||
try {
|
||||
return AccessController.doPrivileged((PrivilegedAction<T>) () -> {
|
||||
final ServiceLoader<T> serviceLoader;
|
||||
serviceLoader = ServiceLoader.load(type, cl);
|
||||
final Iterator<T> iterator = serviceLoader.iterator();
|
||||
if (iterator.hasNext()) {
|
||||
return iterator.next();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch(ServiceConfigurationError e) {
|
||||
final RuntimeException x = new RuntimeException(
|
||||
"Provider for " + type + " cannot be created", e);
|
||||
throw new SAXException("Provider for " + type + " cannot be created", x);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,14 +76,20 @@ endif
|
||||
TEST_ROOT := $(shell $(PWD))
|
||||
|
||||
# Root of all test results
|
||||
ifdef ALT_OUTPUTDIR
|
||||
ABS_OUTPUTDIR = $(shell $(CD) $(ALT_OUTPUTDIR) && $(PWD))
|
||||
ifdef TEST_OUTPUT_DIR
|
||||
$(shell $(MKDIR) -p $(TEST_OUTPUT_DIR)/jtreg)
|
||||
ABS_TEST_OUTPUT_DIR := \
|
||||
$(shell $(CD) $(TEST_OUTPUT_DIR)/jtreg && $(PWD))
|
||||
else
|
||||
ABS_OUTPUTDIR = $(shell $(CD) $(TEST_ROOT)/.. && $(PWD))
|
||||
endif
|
||||
ifdef ALT_OUTPUTDIR
|
||||
ABS_OUTPUTDIR = $(shell $(CD) $(ALT_OUTPUTDIR) && $(PWD))
|
||||
else
|
||||
ABS_OUTPUTDIR = $(shell $(CD) $(TEST_ROOT)/.. && $(PWD))
|
||||
endif
|
||||
|
||||
ABS_PLATFORM_BUILD_ROOT = $(ABS_OUTPUTDIR)
|
||||
ABS_TEST_OUTPUT_DIR := $(ABS_PLATFORM_BUILD_ROOT)/testoutput/$(UNIQUE_DIR)
|
||||
ABS_PLATFORM_BUILD_ROOT = $(ABS_OUTPUTDIR)
|
||||
ABS_TEST_OUTPUT_DIR := $(ABS_PLATFORM_BUILD_ROOT)/testoutput/$(UNIQUE_DIR)
|
||||
endif
|
||||
|
||||
# Expect JPRT to set PRODUCT_HOME (the product or jdk in this case to test)
|
||||
ifndef PRODUCT_HOME
|
||||
|
@ -29,3 +29,5 @@ javax/xml/jaxp/isolatedjdk/catalog/PropertiesTest.sh generic-all
|
||||
# 8150145
|
||||
javax/xml/jaxp/unittest/common/TransformationWarningsTest.java generic-all
|
||||
|
||||
# 8156508
|
||||
javax/xml/jaxp/unittest/stream/FactoryFindTest.java generic-all
|
||||
|
@ -38,7 +38,7 @@ import org.testng.annotations.Test;
|
||||
* @library /javax/xml/jaxp/libs
|
||||
* @build jdk.testlibrary.*
|
||||
* @run testng BasicModularXMLParserTest
|
||||
* @bug 8078820
|
||||
* @bug 8078820 8156119
|
||||
* @summary Tests JAXP lib can instantiate the following interfaces
|
||||
* with customized provider module on boot layer
|
||||
*
|
||||
@ -51,6 +51,7 @@ import org.testng.annotations.Test;
|
||||
* javax.xml.transform.TransformerFactory
|
||||
* javax.xml.validation.SchemaFactory
|
||||
* javax.xml.xpath.XPathFactory
|
||||
* org.xml.sax.XMLReader
|
||||
*/
|
||||
|
||||
@Test
|
||||
|
@ -50,7 +50,7 @@ import jdk.testlibrary.CompilerUtils;
|
||||
* @library /javax/xml/jaxp/libs
|
||||
* @build jdk.testlibrary.*
|
||||
* @run testng LayerModularXMLParserTest
|
||||
* @bug 8078820
|
||||
* @bug 8078820 8156119
|
||||
* @summary Tests JAXP lib works with layer and TCCL
|
||||
*/
|
||||
|
||||
@ -75,7 +75,7 @@ public class LayerModularXMLParserTest {
|
||||
* services provided by provider2
|
||||
*/
|
||||
private static final String[] services2 = { "javax.xml.datatype.DatatypeFactory",
|
||||
"javax.xml.stream.XMLEventFactory" };
|
||||
"javax.xml.stream.XMLEventFactory", "org.xml.sax.XMLReader" };
|
||||
|
||||
/*
|
||||
* Compiles all modules used by the test
|
||||
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import jdk.testlibrary.CompilerUtils;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @library /javax/xml/jaxp/libs
|
||||
* @build jdk.testlibrary.*
|
||||
* @run testng XMLReaderFactoryTest
|
||||
* @bug 8152912 8015099 8156119
|
||||
* @summary Tests XMLReaderFactory can work as ServiceLoader compliant, as well as backward compatible
|
||||
*/
|
||||
|
||||
@Test
|
||||
public class XMLReaderFactoryTest {
|
||||
private static final String TEST_SRC = System.getProperty("test.src");
|
||||
|
||||
private static final Path SRC_DIR = Paths.get(TEST_SRC, "src").resolve("xmlprovider3");
|
||||
private static final Path CLASSES_DIR = Paths.get("classes");
|
||||
private static final Path LEGACY_DIR = CLASSES_DIR.resolve("legacy");
|
||||
private static final Path SERVICE_DIR = CLASSES_DIR.resolve("service");
|
||||
|
||||
// resources to copy to the class path
|
||||
private static final String LEGACY_SERVICE_FILE = "legacy/META-INF/services/org.xml.sax.driver";
|
||||
private static final String SERVICE_FILE = "service/META-INF/services/org.xml.sax.XMLReader";
|
||||
|
||||
/*
|
||||
* Compile class and copy service files
|
||||
*/
|
||||
@BeforeTest
|
||||
public void setup() throws Exception {
|
||||
setup(LEGACY_DIR, LEGACY_SERVICE_FILE);
|
||||
setup(SERVICE_DIR, SERVICE_FILE);
|
||||
}
|
||||
|
||||
private void setup(Path dest, String serviceFile) throws Exception {
|
||||
Files.createDirectories(dest);
|
||||
assertTrue(CompilerUtils.compile(SRC_DIR, dest));
|
||||
|
||||
Path file = Paths.get(serviceFile.replace('/', File.separatorChar));
|
||||
Path source = SRC_DIR.resolve(file);
|
||||
Path target = CLASSES_DIR.resolve(file);
|
||||
Files.createDirectories(target.getParent());
|
||||
Files.copy(source, target);
|
||||
|
||||
}
|
||||
|
||||
public void testService() throws Exception {
|
||||
ClassLoader clBackup = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
URL[] classUrls = { SERVICE_DIR.toUri().toURL() };
|
||||
URLClassLoader loader = new URLClassLoader(classUrls, ClassLoader.getSystemClassLoader().getParent());
|
||||
|
||||
// set TCCL and try locating the provider
|
||||
Thread.currentThread().setContextClassLoader(loader);
|
||||
XMLReader reader = XMLReaderFactory.createXMLReader();
|
||||
assertEquals(reader.getClass().getName(), "xp3.XMLReaderImpl");
|
||||
} finally {
|
||||
Thread.currentThread().setContextClassLoader(clBackup);
|
||||
}
|
||||
}
|
||||
|
||||
public void testLegacy() throws Exception {
|
||||
ClassLoader clBackup = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
URL[] classUrls = { LEGACY_DIR.toUri().toURL() };
|
||||
URLClassLoader loader = new URLClassLoader(classUrls, ClassLoader.getSystemClassLoader().getParent());
|
||||
|
||||
// set TCCL and try locating the provider
|
||||
Thread.currentThread().setContextClassLoader(loader);
|
||||
XMLReader reader1 = XMLReaderFactory.createXMLReader();
|
||||
assertEquals(reader1.getClass().getName(), "xp3.XMLReaderImpl");
|
||||
|
||||
// now point to a random URL
|
||||
Thread.currentThread().setContextClassLoader(
|
||||
new URLClassLoader(new URL[0], ClassLoader.getSystemClassLoader().getParent()));
|
||||
// ClassNotFoundException if also trying to load class of reader1, which
|
||||
// would be the case before 8152912
|
||||
XMLReader reader2 = XMLReaderFactory.createXMLReader();
|
||||
assertEquals(reader2.getClass().getName(), "com.sun.org.apache.xerces.internal.parsers.SAXParser");
|
||||
} finally {
|
||||
Thread.currentThread().setContextClassLoader(clBackup);
|
||||
}
|
||||
}
|
||||
}
|
@ -31,6 +31,8 @@ import java.lang.System;
|
||||
import java.util.Iterator;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
public class XMLFactoryHelper {
|
||||
/*
|
||||
* instantiate a xml factory by reflection e.g.
|
||||
@ -41,7 +43,9 @@ public class XMLFactoryHelper {
|
||||
try {
|
||||
// set thread context class loader to module class loader
|
||||
Thread.currentThread().setContextClassLoader(XMLFactoryHelper.class.getClassLoader());
|
||||
if (serviceName.equals("javax.xml.validation.SchemaFactory"))
|
||||
if (serviceName.equals("org.xml.sax.XMLReader"))
|
||||
return XMLReaderFactory.createXMLReader();
|
||||
else if (serviceName.equals("javax.xml.validation.SchemaFactory"))
|
||||
return Class.forName(serviceName).getMethod("newInstance", String.class)
|
||||
.invoke(null, W3C_XML_SCHEMA_NS_URI);
|
||||
else
|
||||
|
@ -30,6 +30,8 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
public class Main {
|
||||
/*
|
||||
* @param args, the names of provider modules, which have been loaded
|
||||
@ -69,7 +71,9 @@ public class Main {
|
||||
*/
|
||||
private static Object instantiateXMLService(String serviceName) {
|
||||
try {
|
||||
if (serviceName.equals("javax.xml.validation.SchemaFactory"))
|
||||
if (serviceName.equals("org.xml.sax.XMLReader"))
|
||||
return XMLReaderFactory.createXMLReader();
|
||||
else if (serviceName.equals("javax.xml.validation.SchemaFactory"))
|
||||
return Class.forName(serviceName).getMethod("newInstance", String.class)
|
||||
.invoke(null, W3C_XML_SCHEMA_NS_URI);
|
||||
else
|
||||
@ -102,6 +106,7 @@ public class Main {
|
||||
"javax.xml.parsers.DocumentBuilderFactory", "javax.xml.parsers.SAXParserFactory",
|
||||
"javax.xml.stream.XMLEventFactory", "javax.xml.stream.XMLInputFactory",
|
||||
"javax.xml.stream.XMLOutputFactory", "javax.xml.transform.TransformerFactory",
|
||||
"javax.xml.validation.SchemaFactory", "javax.xml.xpath.XPathFactory" };
|
||||
"javax.xml.validation.SchemaFactory", "javax.xml.xpath.XPathFactory",
|
||||
"org.xml.sax.XMLReader"};
|
||||
|
||||
}
|
||||
|
@ -26,4 +26,5 @@ module xmlprovider2 {
|
||||
|
||||
provides javax.xml.datatype.DatatypeFactory with xp2.DatatypeFactoryImpl;
|
||||
provides javax.xml.stream.XMLEventFactory with xp2.XMLEventFactoryImpl;
|
||||
provides org.xml.sax.XMLReader with xp2.XMLReaderImpl;
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package xp2;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.DTDHandler;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotRecognizedException;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
public class XMLReaderImpl implements XMLReader {
|
||||
|
||||
@Override
|
||||
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFeature(String name, boolean value) throws SAXNotRecognizedException,
|
||||
SAXNotSupportedException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty(String name, Object value) throws SAXNotRecognizedException,
|
||||
SAXNotSupportedException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntityResolver(EntityResolver resolver) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityResolver getEntityResolver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDTDHandler(DTDHandler handler) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DTDHandler getDTDHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentHandler(ContentHandler handler) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentHandler getContentHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setErrorHandler(ErrorHandler handler) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorHandler getErrorHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parse(InputSource input) throws IOException, SAXException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parse(String systemId) throws IOException, SAXException {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
xp3.XMLReaderImpl
|
@ -0,0 +1 @@
|
||||
xp3.XMLReaderImpl
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package xp3;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.DTDHandler;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.ErrorHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotRecognizedException;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
public class XMLReaderImpl implements XMLReader {
|
||||
|
||||
@Override
|
||||
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFeature(String name, boolean value) throws SAXNotRecognizedException,
|
||||
SAXNotSupportedException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty(String name, Object value) throws SAXNotRecognizedException,
|
||||
SAXNotSupportedException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEntityResolver(EntityResolver resolver) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityResolver getEntityResolver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDTDHandler(DTDHandler handler) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DTDHandler getDTDHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentHandler(ContentHandler handler) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentHandler getContentHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setErrorHandler(ErrorHandler handler) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorHandler getErrorHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parse(InputSource input) throws IOException, SAXException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parse(String systemId) throws IOException, SAXException {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package stream.XMLStreamWriterTest;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.annotations.DataProvider;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8145974
|
||||
* @modules javax.xml
|
||||
* @summary Check that XMLStreamWriter generates valid xml with surrogate pair
|
||||
* used within element text
|
||||
*/
|
||||
|
||||
public class SurrogatesTest {
|
||||
|
||||
// Test that valid surrogate characters can be written/readen by xml stream
|
||||
// reader/writer
|
||||
@Test(dataProvider = "validData")
|
||||
public void xmlWithValidSurrogatesTest(String content)
|
||||
throws Exception {
|
||||
generateAndReadXml(content);
|
||||
}
|
||||
|
||||
// Test that unbalanced surrogate character will
|
||||
@Test(dataProvider = "invalidData",
|
||||
expectedExceptions = XMLStreamException.class)
|
||||
public void xmlWithUnbalancedSurrogatesTest(String content)
|
||||
throws Exception {
|
||||
generateAndReadXml(content);
|
||||
}
|
||||
|
||||
// Generates xml content with XMLStreamWriter and read it to check
|
||||
// for correctness of xml and generated data
|
||||
void generateAndReadXml(String content) throws Exception {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
XMLOutputFactory factory = XMLOutputFactory.newInstance();
|
||||
OutputStreamWriter streamWriter = new OutputStreamWriter(stream);
|
||||
XMLStreamWriter writer = factory.createXMLStreamWriter(streamWriter);
|
||||
|
||||
// Generate xml with selected stream writer type
|
||||
generateXML(writer, content);
|
||||
String output = stream.toString();
|
||||
System.out.println("Generated xml: " + output);
|
||||
// Read generated xml with StAX parser
|
||||
readXML(output.getBytes(), content);
|
||||
}
|
||||
|
||||
// Generates XML with provided xml stream writer. Provided string
|
||||
// is inserted into xml twice: with usage of writeCharacters( String )
|
||||
// and writeCharacters( char [], int , int )
|
||||
private void generateXML(XMLStreamWriter writer, String sequence)
|
||||
throws XMLStreamException {
|
||||
char[] seqArr = sequence.toCharArray();
|
||||
writer.writeStartDocument();
|
||||
writer.writeStartElement("root");
|
||||
|
||||
// Use writeCharacters( String ) to write characters
|
||||
writer.writeStartElement("writeCharactersWithString");
|
||||
writer.writeCharacters(sequence);
|
||||
writer.writeEndElement();
|
||||
|
||||
// Use writeCharacters( char [], int , int ) to write characters
|
||||
writer.writeStartElement("writeCharactersWithArray");
|
||||
writer.writeCharacters(seqArr, 0, seqArr.length);
|
||||
writer.writeEndElement();
|
||||
|
||||
// Close root element and document
|
||||
writer.writeEndElement();
|
||||
writer.writeEndDocument();
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
// Reads generated XML data and check if it contains expected
|
||||
// text in writeCharactersWithString and writeCharactersWithArray
|
||||
// elements
|
||||
private void readXML(byte[] xmlData, String expectedContent)
|
||||
throws Exception {
|
||||
InputStream stream = new ByteArrayInputStream(xmlData);
|
||||
XMLInputFactory factory = XMLInputFactory.newInstance();
|
||||
XMLStreamReader xmlReader
|
||||
= factory.createXMLStreamReader(stream);
|
||||
boolean inTestElement = false;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (xmlReader.hasNext()) {
|
||||
String ename;
|
||||
switch (xmlReader.getEventType()) {
|
||||
case XMLStreamConstants.START_ELEMENT:
|
||||
ename = xmlReader.getLocalName();
|
||||
if (ename.equals("writeCharactersWithString")
|
||||
|| ename.equals("writeCharactersWithArray")) {
|
||||
inTestElement = true;
|
||||
}
|
||||
break;
|
||||
case XMLStreamConstants.END_ELEMENT:
|
||||
ename = xmlReader.getLocalName();
|
||||
if (ename.equals("writeCharactersWithString")
|
||||
|| ename.equals("writeCharactersWithArray")) {
|
||||
inTestElement = false;
|
||||
String content = sb.toString();
|
||||
System.out.println(ename + " text:'" + content + "' expected:'" + expectedContent+"'");
|
||||
Assert.assertEquals(content, expectedContent);
|
||||
sb.setLength(0);
|
||||
}
|
||||
break;
|
||||
case XMLStreamConstants.CHARACTERS:
|
||||
if (inTestElement) {
|
||||
sb.append(xmlReader.getText());
|
||||
}
|
||||
break;
|
||||
}
|
||||
xmlReader.next();
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider(name = "validData")
|
||||
Object[][] getValidData() {
|
||||
return new Object[][] {
|
||||
{"Don't Worry Be \uD83D\uDE0A"},
|
||||
{"BMP characters \uE000\uFFFD"},
|
||||
{"Simple text"},
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider(name = "invalidData")
|
||||
Object[][] getInvalidData() {
|
||||
return new Object[][] {
|
||||
{"Unbalanced surrogate \uD83D"},
|
||||
{"Unbalanced surrogate \uD83Dis here"},
|
||||
{"Surrogate with followup BMP\uD83D\uFFF9"},
|
||||
};
|
||||
}
|
||||
}
|
@ -363,3 +363,4 @@ b314bb02182b9ca94708a91f312c377f5435f740 jdk-9+114
|
||||
4ff86e5489e4c0513dadfa69def8601c110ca5cd jdk-9+115
|
||||
529f0bf896e58525614d863e283ad155531941cb jdk-9+116
|
||||
58265b39fc74b932bda4d4f4649c530a89f55c4e jdk-9+117
|
||||
6ba73d04589ccc0705a5d8ae5111b63632b6ad20 jdk-9+118
|
||||
|
@ -360,3 +360,4 @@ bb8379287f3736f38c52b2d1418784e2592461d1 jdk-9+114
|
||||
35225b837d66582037eeadeb471c13235dfd793d jdk-9+115
|
||||
baeb5edb38939cdb78ae0ac6f4fd368465cbf188 jdk-9+116
|
||||
4da0f73ce03aaf245b92cc040cc0ab0e3fa54dc2 jdk-9+117
|
||||
e1eba5cfa5cc8c66d524396a05323dc93568730a jdk-9+118
|
||||
|
@ -37,10 +37,6 @@ BUILD_TOOLS_JDK := $(call SetupJavaCompilationCompileTarget, \
|
||||
|
||||
################################################################################
|
||||
|
||||
# Add a checksum ("jsum") to the end of a text file. Prevents trivial tampering with class lists.
|
||||
TOOL_ADDJSUM = $(JAVA_SMALL) -cp $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes \
|
||||
build.tools.addjsum.AddJsum
|
||||
|
||||
ifeq ($(BOOT_JDK_MODULAR), true)
|
||||
COMPILEFONTCONFIG_ADD_EXPORTS := -XaddExports:java.desktop/sun.awt=ALL-UNNAMED
|
||||
endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,11 +25,11 @@
|
||||
|
||||
include LauncherCommon.gmk
|
||||
|
||||
JAVA_RC_FLAGS += -i $(JDK_TOPDIR)/src/java.base/windows/native/common
|
||||
JAVA_RC_FLAGS += -I $(JDK_TOPDIR)/src/java.base/windows/native/common
|
||||
ifdef OPENJDK
|
||||
JAVA_RC_FLAGS += -i "$(JDK_TOPDIR)/src/java.base/windows/native/launcher/icons"
|
||||
JAVA_RC_FLAGS += -I $(JDK_TOPDIR)/src/java.base/windows/native/launcher/icons
|
||||
else
|
||||
JAVA_RC_FLAGS += -i "$(JDK_TOPDIR)/src/closed/java.base/windows/native/launcher/icons"
|
||||
JAVA_RC_FLAGS += -I $(JDK_TOPDIR)/src/closed/java.base/windows/native/launcher/icons
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
|
@ -224,9 +224,9 @@ ifeq ($(OPENJDK_TARGET_OS), windows)
|
||||
endif
|
||||
|
||||
ifdef OPENJDK
|
||||
LIBAWT_RC_FLAGS := -i "$(JDK_TOPDIR)/src/java.base/windows/native/launcher/icons"
|
||||
LIBAWT_RC_FLAGS := -I $(JDK_TOPDIR)/src/java.base/windows/native/launcher/icons
|
||||
else
|
||||
LIBAWT_RC_FLAGS := -i "$(JDK_TOPDIR)/src/closed/java.base/windows/native/launcher/icons"
|
||||
LIBAWT_RC_FLAGS := -I $(JDK_TOPDIR)/src/closed/java.base/windows/native/launcher/icons
|
||||
endif
|
||||
LIBAWT_VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/java.desktop/windows/native/libawt/windows/awt.rc
|
||||
endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
# Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
@ -30,28 +30,35 @@ SUNWprivate_1.1 {
|
||||
JNI_OnLoad;
|
||||
Java_com_oracle_security_ucrypto_UcryptoProvider_loadLibraries;
|
||||
Java_com_oracle_security_ucrypto_UcryptoProvider_getMechList;
|
||||
Java_com_oracle_security_ucrypto_NativeDigest_nativeInit;
|
||||
Java_com_oracle_security_ucrypto_NativeDigestMD_nativeInit;
|
||||
Java_com_oracle_security_ucrypto_NativeDigestMD_nativeUpdate;
|
||||
Java_com_oracle_security_ucrypto_NativeDigestMD_nativeDigest;
|
||||
Java_com_oracle_security_ucrypto_NativeDigestMD_nativeClone;
|
||||
Java_com_oracle_security_ucrypto_NativeDigestMD_nativeFree;
|
||||
Java_com_oracle_security_ucrypto_NativeDigest_nativeInit;
|
||||
Java_com_oracle_security_ucrypto_NativeDigest_nativeUpdate;
|
||||
Java_com_oracle_security_ucrypto_NativeDigest_nativeDigest;
|
||||
Java_com_oracle_security_ucrypto_NativeDigest_nativeClone;
|
||||
Java_com_oracle_security_ucrypto_NativeDigest_nativeFree;
|
||||
Java_com_oracle_security_ucrypto_NativeCipher_nativeInit;
|
||||
Java_com_oracle_security_ucrypto_NativeCipher_nativeUpdate;
|
||||
Java_com_oracle_security_ucrypto_NativeCipher_nativeFinal;
|
||||
Java_com_oracle_security_ucrypto_NativeCipher_nativeInit;
|
||||
Java_com_oracle_security_ucrypto_NativeCipher_nativeUpdate;
|
||||
Java_com_oracle_security_ucrypto_NativeCipher_nativeFinal;
|
||||
Java_com_oracle_security_ucrypto_NativeKey_nativeFree;
|
||||
Java_com_oracle_security_ucrypto_NativeKey_00024RSAPrivate_nativeInit;
|
||||
Java_com_oracle_security_ucrypto_NativeKey_00024RSAPrivateCrt_nativeInit;
|
||||
Java_com_oracle_security_ucrypto_NativeKey_00024RSAPublic_nativeInit;
|
||||
Java_com_oracle_security_ucrypto_NativeRSASignature_nativeInit;
|
||||
Java_com_oracle_security_ucrypto_NativeRSASignature_nativeUpdate__JZ_3BII;
|
||||
Java_com_oracle_security_ucrypto_NativeRSASignature_nativeUpdate__JZJI;
|
||||
Java_com_oracle_security_ucrypto_NativeRSASignature_nativeFinal;
|
||||
Java_com_oracle_security_ucrypto_NativeRSACipher_nativeAtomic;
|
||||
|
||||
Java_com_oracle_security_ucrypto_NativeRSASignature_nativeInit;
|
||||
Java_com_oracle_security_ucrypto_NativeRSASignature_nativeUpdate__JZ_3BII;
|
||||
Java_com_oracle_security_ucrypto_NativeRSASignature_nativeUpdate__JZJI;
|
||||
Java_com_oracle_security_ucrypto_NativeRSASignature_nativeFinal;
|
||||
Java_com_oracle_security_ucrypto_NativeRSACipher_nativeAtomic;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeInit;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeUpdate;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeDigest;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeClone;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeDigestMD_nativeFree;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeDigest_nativeInit;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeDigest_nativeUpdate;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeDigest_nativeDigest;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeDigest_nativeClone;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeDigest_nativeFree;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeCipher_nativeInit;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeCipher_nativeUpdate;
|
||||
@ -60,10 +67,10 @@ SUNWprivate_1.1 {
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeKey_00024RSAPrivate_nativeInit;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeKey_00024RSAPrivateCrt_nativeInit;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeKey_00024RSAPublic_nativeInit;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeRSASignature_nativeInit;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeRSASignature_nativeUpdate__JZ_3BII;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeRSASignature_nativeUpdate__JZJI;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeRSASignature_nativeFinal;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeRSASignature_nativeInit;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeRSASignature_nativeUpdate__JZ_3BII;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeRSASignature_nativeUpdate__JZJI;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeRSASignature_nativeFinal;
|
||||
JavaCritical_com_oracle_security_ucrypto_NativeRSACipher_nativeAtomic;
|
||||
|
||||
local:
|
||||
|
@ -262,7 +262,7 @@ SUNWprivate_1.1 {
|
||||
Java_jdk_internal_reflect_Reflection_getCallerClass__;
|
||||
Java_jdk_internal_reflect_Reflection_getCallerClass__I;
|
||||
Java_jdk_internal_reflect_Reflection_getClassAccessFlags;
|
||||
Java_jdk_internal_misc_VM_latestUserDefinedLoader;
|
||||
Java_jdk_internal_misc_VM_latestUserDefinedLoader0;
|
||||
Java_jdk_internal_misc_VM_getuid;
|
||||
Java_jdk_internal_misc_VM_geteuid;
|
||||
Java_jdk_internal_misc_VM_getgid;
|
||||
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This tool is used to help create the class list for class data sharing.
|
||||
*
|
||||
* The classlist is produced internally by first running a select number of
|
||||
* startup benchmarks with the -XX:DumpLoadedClassList=<file> option, then
|
||||
* running this tool in the following fashion to produce a complete classlist:
|
||||
*
|
||||
* jjs -scripting makeClasslist.js -- list1 list2 list3 > classlist.platform
|
||||
*
|
||||
* The lists should be listed in roughly smallest to largest order based on
|
||||
* application size.
|
||||
*
|
||||
* After generating the classlist it's necessary to add a checksum (using
|
||||
* AddJsum.java) before checking it into the workspace as the corresponding
|
||||
* platform-specific classlist, such as make/data/classlist/classlist.linux
|
||||
*/
|
||||
"use strict";
|
||||
var classlist = [];
|
||||
var seenClasses = {};
|
||||
|
||||
for (var a in $ARG) {
|
||||
var arg = $ARG[a];
|
||||
|
||||
var classes = readFully(arg).replace(/[\r\n]+/g, "\n").split("\n");
|
||||
|
||||
for (var c in classes) {
|
||||
var clazz = classes[c];
|
||||
if (clazz !== "" && seenClasses[clazz] === undefined) {
|
||||
seenClasses[clazz] = clazz;
|
||||
classlist.push(clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (c in classlist) {
|
||||
print(classlist[c]);
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package build.tools.addjsum;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
/** Adds a checksum ("jsum") to the end of a text file. The algorithm
|
||||
used is known to the JVM and prevents trivial tampering with the
|
||||
class list used for class data sharing.
|
||||
*/
|
||||
|
||||
public class AddJsum {
|
||||
private static final long JSUM_SEED = 0xCAFEBABEBABECAFEL;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 2) {
|
||||
System.err.println("Usage: java AddJsum [input file name] [output file name]");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
File inFile = new File(args[0]);
|
||||
File outFile = new File(args[1]);
|
||||
BufferedReader reader = new BufferedReader(new FileReader(inFile));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(outFile));
|
||||
Pattern p = Pattern.compile("# [0-9A-Fa-f]*");
|
||||
long computedJsum = JSUM_SEED;
|
||||
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.length() > 0 && line.charAt(0) == '#') {
|
||||
Matcher m = p.matcher(line);
|
||||
if (!m.matches()) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
}
|
||||
} else {
|
||||
computedJsum = jsum(computedJsum, line);
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
String hex = Long.toHexString(computedJsum);
|
||||
int diff = 16 - hex.length();
|
||||
for (int i = 0; i < diff; i++) {
|
||||
hex = "0" + hex;
|
||||
}
|
||||
writer.write("# " + hex);
|
||||
writer.newLine();
|
||||
reader.close();
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error reading or writing file");
|
||||
throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static long jsum(long start, String str) {
|
||||
long h = start;
|
||||
int len = str.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
char c = str.charAt(i);
|
||||
if (c <= ' ') {
|
||||
/* Skip spaces and control characters */
|
||||
continue;
|
||||
}
|
||||
h = 31 * h + c;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
}
|
@ -603,12 +603,12 @@ public class ObjectInputStream
|
||||
* Class.forName(desc.getName(), false, loader)
|
||||
* </pre>
|
||||
* where <code>loader</code> is determined as follows: if there is a
|
||||
* method on the current thread's stack whose declaring class was
|
||||
* defined by a user-defined class loader (and was not a generated to
|
||||
* implement reflective invocations), then <code>loader</code> is class
|
||||
* loader corresponding to the closest such method to the currently
|
||||
* executing frame; otherwise, <code>loader</code> is
|
||||
* <code>null</code>. If this call results in a
|
||||
* method on the current thread's stack whose declaring class is not a
|
||||
* <a href="../lang/ClassLoader.html#builtinLoaders">
|
||||
* <em>platform class</em></a>, then <code>loader</code> is
|
||||
* the class loader of such class; otherwise, <code>loader</code>
|
||||
* is the {@linkplain ClassLoader#getPlatformClassLoader()
|
||||
* platform class loader}. If this call results in a
|
||||
* <code>ClassNotFoundException</code> and the name of the passed
|
||||
* <code>ObjectStreamClass</code> instance is the Java language keyword
|
||||
* for a primitive type or void, then the <code>Class</code> object
|
||||
@ -666,12 +666,15 @@ public class ObjectInputStream
|
||||
* <pre>
|
||||
* Class.forName(i, false, loader)
|
||||
* </pre>
|
||||
* where <code>loader</code> is that of the first non-<code>null</code>
|
||||
* class loader up the execution stack, or <code>null</code> if no
|
||||
* non-<code>null</code> class loaders are on the stack (the same class
|
||||
* loader choice used by the <code>resolveClass</code> method). Unless any
|
||||
* of the resolved interfaces are non-public, this same value of
|
||||
* <code>loader</code> is also the class loader passed to
|
||||
* where <code>loader</code> is determined as follows: if there is a
|
||||
* method on the current thread's stack whose declaring class is not a
|
||||
* <a href="../lang/ClassLoader.html#builtinLoaders">
|
||||
* <em>platform class</em></a>, then <code>loader</code> is
|
||||
* the class loader of such class; otherwise, <code>loader</code>
|
||||
* is the {@linkplain ClassLoader#getPlatformClassLoader()
|
||||
* platform class loader}.
|
||||
* Unless any of the resolved interfaces are non-public, this same value
|
||||
* of <code>loader</code> is also the class loader passed to
|
||||
* <code>Proxy.getProxyClass</code>; if non-public interfaces are present,
|
||||
* their class loader is passed instead (if more than one non-public
|
||||
* interface class loader is encountered, an
|
||||
@ -2154,10 +2157,11 @@ public class ObjectInputStream
|
||||
int ndoubles);
|
||||
|
||||
/**
|
||||
* Returns the first non-null class loader (not counting class loaders of
|
||||
* generated reflection implementation classes) up the execution stack, or
|
||||
* null if only code from the null class loader is on the stack. This
|
||||
* method is also called via reflection by the following RMI-IIOP class:
|
||||
* Returns the first non-null and non-platform class loader
|
||||
* (not counting class loaders of generated reflection implementation classes)
|
||||
* up the execution stack, or null if only code from the bootstrap and
|
||||
* platform class loader is on the stack.
|
||||
* This method is also called via reflection by the following RMI-IIOP class:
|
||||
*
|
||||
* com.sun.corba.se.internal.util.JDKClassLoader
|
||||
*
|
||||
|
@ -1221,13 +1221,13 @@ public final class Integer extends Number implements Comparable<Integer> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code for a {@code int} value; compatible with
|
||||
* Returns a hash code for an {@code int} value; compatible with
|
||||
* {@code Integer.hashCode()}.
|
||||
*
|
||||
* @param value the value to hash
|
||||
* @since 1.8
|
||||
*
|
||||
* @return a hash code value for a {@code int} value.
|
||||
* @return a hash code value for an {@code int} value.
|
||||
*/
|
||||
public static int hashCode(int value) {
|
||||
return value;
|
||||
@ -1596,7 +1596,7 @@ public final class Integer extends Number implements Comparable<Integer> {
|
||||
@Native public static final int SIZE = 32;
|
||||
|
||||
/**
|
||||
* The number of bytes used to represent a {@code int} value in two's
|
||||
* The number of bytes used to represent an {@code int} value in two's
|
||||
* complement binary form.
|
||||
*
|
||||
* @since 1.8
|
||||
@ -1790,9 +1790,8 @@ public final class Integer extends Number implements Comparable<Integer> {
|
||||
i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;
|
||||
i = (i & 0x33333333) << 2 | (i >>> 2) & 0x33333333;
|
||||
i = (i & 0x0f0f0f0f) << 4 | (i >>> 4) & 0x0f0f0f0f;
|
||||
i = (i << 24) | ((i & 0xff00) << 8) |
|
||||
((i >>> 8) & 0xff00) | (i >>> 24);
|
||||
return i;
|
||||
|
||||
return reverseBytes(i);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1820,10 +1819,10 @@ public final class Integer extends Number implements Comparable<Integer> {
|
||||
*/
|
||||
@HotSpotIntrinsicCandidate
|
||||
public static int reverseBytes(int i) {
|
||||
return ((i >>> 24) ) |
|
||||
((i >> 8) & 0xFF00) |
|
||||
((i << 8) & 0xFF0000) |
|
||||
((i << 24));
|
||||
return (i << 24) |
|
||||
((i & 0xff00) << 8) |
|
||||
((i >>> 8) & 0xff00) |
|
||||
(i >>> 24);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1952,10 +1952,8 @@ public final class Long extends Number implements Comparable<Long> {
|
||||
i = (i & 0x5555555555555555L) << 1 | (i >>> 1) & 0x5555555555555555L;
|
||||
i = (i & 0x3333333333333333L) << 2 | (i >>> 2) & 0x3333333333333333L;
|
||||
i = (i & 0x0f0f0f0f0f0f0f0fL) << 4 | (i >>> 4) & 0x0f0f0f0f0f0f0f0fL;
|
||||
i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
|
||||
i = (i << 48) | ((i & 0xffff0000L) << 16) |
|
||||
((i >>> 16) & 0xffff0000L) | (i >>> 48);
|
||||
return i;
|
||||
|
||||
return reverseBytes(i);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1627,8 +1627,7 @@ class SecurityManager {
|
||||
* @deprecated This method relies on the caller being at a stack depth
|
||||
* of 4 which is error-prone and cannot be enforced by the runtime.
|
||||
* Users of this method should instead invoke {@link #checkPermission}
|
||||
* directly. This method will be changed in a future release
|
||||
* to check the permission {@code java.security.AllPermission}.
|
||||
* directly.
|
||||
* This method is subject to removal in a future version of Java SE.
|
||||
*
|
||||
* @see java.lang.reflect.Member
|
||||
|
@ -318,7 +318,7 @@ public class ModuleDescriptor
|
||||
/**
|
||||
* Tests this module export for equality with the given object.
|
||||
*
|
||||
* <p> If the given object is not a {@code Exports} then this method
|
||||
* <p> If the given object is not an {@code Exports} then this method
|
||||
* returns {@code false}. Two module exports objects are equal if the
|
||||
* package names are equal and the set of target module names is equal.
|
||||
* </p>
|
||||
|
@ -903,7 +903,7 @@ class Field extends AccessibleObject implements Member {
|
||||
* Sets the value of a field as an {@code int} on the specified object.
|
||||
* This method is equivalent to
|
||||
* {@code set(obj, iObj)},
|
||||
* where {@code iObj} is a {@code Integer} object and
|
||||
* where {@code iObj} is an {@code Integer} object and
|
||||
* {@code iObj.intValue() == i}.
|
||||
*
|
||||
* @param obj the object whose field should be modified
|
||||
|
@ -36,13 +36,13 @@ public class InaccessibleObjectException extends RuntimeException {
|
||||
private static final long serialVersionUID = 4158786093378140901L;
|
||||
|
||||
/**
|
||||
* Constructs a {@code InaccessibleObjectException} with no detail message.
|
||||
* Constructs an {@code InaccessibleObjectException} with no detail message.
|
||||
*/
|
||||
public InaccessibleObjectException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@code InaccessibleObjectException} with the given detail
|
||||
* Constructs an {@code InaccessibleObjectException} with the given detail
|
||||
* message.
|
||||
*
|
||||
* @param msg
|
||||
|
@ -4676,7 +4676,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
||||
*
|
||||
* @return this {@code BigInteger} converted to an {@code int}.
|
||||
* @throws ArithmeticException if the value of {@code this} will
|
||||
* not exactly fit in a {@code int}.
|
||||
* not exactly fit in an {@code int}.
|
||||
* @see BigInteger#intValue
|
||||
* @since 1.8
|
||||
*/
|
||||
|
@ -246,7 +246,7 @@ public class InetSocketAddress
|
||||
* the range of valid port values, or if the hostname
|
||||
* parameter is {@code null}.
|
||||
* @see #isUnresolved()
|
||||
* @return a {@code InetSocketAddress} representing the unresolved
|
||||
* @return an {@code InetSocketAddress} representing the unresolved
|
||||
* socket address
|
||||
* @since 1.5
|
||||
*/
|
||||
|
@ -106,8 +106,8 @@ public class URLDecoder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a {@code application/x-www-form-urlencoded} string using a specific
|
||||
* encoding scheme.
|
||||
* Decodes an {@code application/x-www-form-urlencoded} string using
|
||||
* a specific encoding scheme.
|
||||
* The supplied encoding is used to determine
|
||||
* what characters are represented by any consecutive sequences of the
|
||||
* form "<i>{@code %xy}</i>".
|
||||
|
@ -225,7 +225,7 @@ public class URLEncoder {
|
||||
/*
|
||||
* If this character represents the start of a Unicode
|
||||
* surrogate pair, then pass in two characters. It's not
|
||||
* clear what should be done if a bytes reserved in the
|
||||
* clear what should be done if a byte reserved in the
|
||||
* surrogate pairs range occurs outside of a legal
|
||||
* surrogate pair. For now, just treat it as if it were
|
||||
* any other character.
|
||||
|
@ -196,10 +196,9 @@ import java.util.Objects;
|
||||
* of the JDK reference implementation.
|
||||
* <p>
|
||||
* This implementation supports the Hash_DRBG and HMAC_DRBG mechanisms with
|
||||
* DRBG algorithm SHA-1, SHA-224, SHA-512/224, SHA-256, SHA-512/256,
|
||||
* SHA-384 and SHA-512, and CTR_DRBG (both using derivation function and
|
||||
* not using derivation function) with DRBG algorithm 3KeyTDEA
|
||||
* (also known as DESede in JCE), AES-128, AES-192 and AES-256.
|
||||
* DRBG algorithm SHA-224, SHA-512/224, SHA-256, SHA-512/256, SHA-384 and
|
||||
* SHA-512, and CTR_DRBG (both using derivation function and not using
|
||||
* derivation function) with DRBG algorithm AES-128, AES-192 and AES-256.
|
||||
* <p>
|
||||
* The mechanism name and DRBG algorithm name are determined by the
|
||||
* {@linkplain Security#getProperty(String) security property}
|
||||
|
@ -65,7 +65,7 @@ extends GeneralSecurityException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code InvalidAlgorithmParameterException} with the
|
||||
* Creates an {@code InvalidAlgorithmParameterException} with the
|
||||
* specified detail message and cause.
|
||||
*
|
||||
* @param message the detail message (which is saved for later retrieval
|
||||
@ -80,7 +80,7 @@ extends GeneralSecurityException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code InvalidAlgorithmParameterException} with the
|
||||
* Creates an {@code InvalidAlgorithmParameterException} with the
|
||||
* specified cause and a detail message of
|
||||
* {@code (cause==null ? null : cause.toString())}
|
||||
* (which typically contains the class and detail message of
|
||||
|
@ -58,7 +58,7 @@ public class InvalidKeyException extends KeyException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code InvalidKeyException} with the specified
|
||||
* Creates an {@code InvalidKeyException} with the specified
|
||||
* detail message and cause.
|
||||
*
|
||||
* @param message the detail message (which is saved for later retrieval
|
||||
@ -73,7 +73,7 @@ public class InvalidKeyException extends KeyException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code InvalidKeyException} with the specified cause
|
||||
* Creates an {@code InvalidKeyException} with the specified cause
|
||||
* and a detail message of {@code (cause==null ? null : cause.toString())}
|
||||
* (which typically contains the class and detail message of
|
||||
* {@code cause}).
|
||||
|
@ -139,12 +139,10 @@ public class ProtectionDomain {
|
||||
*/
|
||||
final Key key = new Key();
|
||||
|
||||
private static final Debug debug = Debug.getInstance("domain");
|
||||
|
||||
/**
|
||||
* Creates a new ProtectionDomain with the given CodeSource and
|
||||
* Permissions. If the permissions object is not null, then
|
||||
* {@code setReadOnly())} will be called on the passed in
|
||||
* {@code setReadOnly()} will be called on the passed in
|
||||
* Permissions object. The only permissions granted to this domain
|
||||
* are the ones specified; the current Policy will not be consulted.
|
||||
*
|
||||
@ -338,6 +336,13 @@ public class ProtectionDomain {
|
||||
" "+pc+"\n";
|
||||
}
|
||||
|
||||
/*
|
||||
* holder class for the static field "debug" to delay its initialization
|
||||
*/
|
||||
private static class DebugHolder {
|
||||
private static final Debug debug = Debug.getInstance("domain");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true (merge policy permissions) in the following cases:
|
||||
*
|
||||
@ -359,7 +364,7 @@ public class ProtectionDomain {
|
||||
if (sm == null) {
|
||||
return true;
|
||||
} else {
|
||||
if (debug != null) {
|
||||
if (DebugHolder.debug != null) {
|
||||
if (sm.getClass().getClassLoader() == null &&
|
||||
Policy.getPolicyNoCheck().getClass().getClassLoader()
|
||||
== null) {
|
||||
|
@ -1809,7 +1809,7 @@ public abstract class Provider extends Properties {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this service has its Supported* properties for
|
||||
* Return whether this service has its supported properties for
|
||||
* keys defined. Parses the attributes if not yet initialized.
|
||||
*/
|
||||
private boolean hasKeyAttributes() {
|
||||
|
@ -62,8 +62,6 @@ public class SecureClassLoader extends ClassLoader {
|
||||
private final Map<CodeSourceKey, ProtectionDomain> pdcache
|
||||
= new ConcurrentHashMap<>(11);
|
||||
|
||||
private static final Debug debug = Debug.getInstance("scl");
|
||||
|
||||
static {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
@ -202,6 +200,13 @@ public class SecureClassLoader extends ClassLoader {
|
||||
return new Permissions(); // ProtectionDomain defers the binding
|
||||
}
|
||||
|
||||
/*
|
||||
* holder class for the static field "debug" to delay its initialization
|
||||
*/
|
||||
private static class DebugHolder {
|
||||
private static final Debug debug = Debug.getInstance("scl");
|
||||
}
|
||||
|
||||
/*
|
||||
* Returned cached ProtectionDomain for the specified CodeSource.
|
||||
*/
|
||||
@ -222,9 +227,9 @@ public class SecureClassLoader extends ClassLoader {
|
||||
= SecureClassLoader.this.getPermissions(cs);
|
||||
ProtectionDomain pd = new ProtectionDomain(
|
||||
cs, perms, SecureClassLoader.this, null);
|
||||
if (debug != null) {
|
||||
debug.println(" getPermissions " + pd);
|
||||
debug.println("");
|
||||
if (DebugHolder.debug != null) {
|
||||
DebugHolder.debug.println(" getPermissions " + pd);
|
||||
DebugHolder.debug.println("");
|
||||
}
|
||||
return pd;
|
||||
}
|
||||
|
@ -549,7 +549,7 @@ public final class Security {
|
||||
|
||||
/**
|
||||
* Returns an array containing all installed providers that satisfy the
|
||||
* specified* selection criteria, or null if no such providers have been
|
||||
* specified selection criteria, or null if no such providers have been
|
||||
* installed. The returned providers are ordered
|
||||
* according to their
|
||||
* {@linkplain #insertProviderAt(java.security.Provider, int)
|
||||
|
@ -63,7 +63,7 @@ public class InvalidKeySpecException extends GeneralSecurityException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code InvalidKeySpecException} with the specified
|
||||
* Creates an {@code InvalidKeySpecException} with the specified
|
||||
* detail message and cause.
|
||||
*
|
||||
* @param message the detail message (which is saved for later retrieval
|
||||
@ -78,7 +78,7 @@ public class InvalidKeySpecException extends GeneralSecurityException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@code InvalidKeySpecException} with the specified cause
|
||||
* Creates an {@code InvalidKeySpecException} with the specified cause
|
||||
* and a detail message of {@code (cause==null ? null : cause.toString())}
|
||||
* (which typically contains the class and detail message of
|
||||
* {@code cause}).
|
||||
|
@ -1068,7 +1068,7 @@ public class MessageFormat extends Format {
|
||||
* index information as described above.
|
||||
* @return An <code>Object</code> array parsed from the string. In case of
|
||||
* error, returns null.
|
||||
* @throws NullPointerException if {@code source} or {@code pos} is null.
|
||||
* @throws NullPointerException if {@code pos} is null.
|
||||
*/
|
||||
public Object parseObject(String source, ParsePosition pos) {
|
||||
return parse(source, pos);
|
||||
|
@ -799,33 +799,33 @@ public final class Instant
|
||||
* The supported fields behave as follows:
|
||||
* <ul>
|
||||
* <li>{@code NANOS} -
|
||||
* Returns a {@code Instant} with the specified number of nanoseconds added.
|
||||
* Returns an {@code Instant} with the specified number of nanoseconds added.
|
||||
* This is equivalent to {@link #plusNanos(long)}.
|
||||
* <li>{@code MICROS} -
|
||||
* Returns a {@code Instant} with the specified number of microseconds added.
|
||||
* Returns an {@code Instant} with the specified number of microseconds added.
|
||||
* This is equivalent to {@link #plusNanos(long)} with the amount
|
||||
* multiplied by 1,000.
|
||||
* <li>{@code MILLIS} -
|
||||
* Returns a {@code Instant} with the specified number of milliseconds added.
|
||||
* Returns an {@code Instant} with the specified number of milliseconds added.
|
||||
* This is equivalent to {@link #plusNanos(long)} with the amount
|
||||
* multiplied by 1,000,000.
|
||||
* <li>{@code SECONDS} -
|
||||
* Returns a {@code Instant} with the specified number of seconds added.
|
||||
* Returns an {@code Instant} with the specified number of seconds added.
|
||||
* This is equivalent to {@link #plusSeconds(long)}.
|
||||
* <li>{@code MINUTES} -
|
||||
* Returns a {@code Instant} with the specified number of minutes added.
|
||||
* Returns an {@code Instant} with the specified number of minutes added.
|
||||
* This is equivalent to {@link #plusSeconds(long)} with the amount
|
||||
* multiplied by 60.
|
||||
* <li>{@code HOURS} -
|
||||
* Returns a {@code Instant} with the specified number of hours added.
|
||||
* Returns an {@code Instant} with the specified number of hours added.
|
||||
* This is equivalent to {@link #plusSeconds(long)} with the amount
|
||||
* multiplied by 3,600.
|
||||
* <li>{@code HALF_DAYS} -
|
||||
* Returns a {@code Instant} with the specified number of half-days added.
|
||||
* Returns an {@code Instant} with the specified number of half-days added.
|
||||
* This is equivalent to {@link #plusSeconds(long)} with the amount
|
||||
* multiplied by 43,200 (12 hours).
|
||||
* <li>{@code DAYS} -
|
||||
* Returns a {@code Instant} with the specified number of days added.
|
||||
* Returns an {@code Instant} with the specified number of days added.
|
||||
* This is equivalent to {@link #plusSeconds(long)} with the amount
|
||||
* multiplied by 86,400 (24 hours).
|
||||
* </ul>
|
||||
@ -958,7 +958,7 @@ public final class Instant
|
||||
/**
|
||||
* Returns a copy of this instant with the specified amount subtracted.
|
||||
* <p>
|
||||
* This returns a {@code Instant}, based on this one, with the amount
|
||||
* This returns an {@code Instant}, based on this one, with the amount
|
||||
* in terms of the unit subtracted. If it is not possible to subtract the amount,
|
||||
* because the unit is not supported or for some other reason, an exception is thrown.
|
||||
* <p>
|
||||
|
@ -665,7 +665,7 @@ public final class LocalDateTime
|
||||
* The {@link #isSupported(TemporalField) supported fields} will return valid
|
||||
* values based on this date-time, except {@code NANO_OF_DAY}, {@code MICRO_OF_DAY},
|
||||
* {@code EPOCH_DAY} and {@code PROLEPTIC_MONTH} which are too large to fit in
|
||||
* an {@code int} and throw a {@code UnsupportedTemporalTypeException}.
|
||||
* an {@code int} and throw an {@code UnsupportedTemporalTypeException}.
|
||||
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
|
||||
* <p>
|
||||
* If the field is not a {@code ChronoField}, then the result of this method
|
||||
|
@ -619,7 +619,7 @@ public final class LocalTime
|
||||
* If the field is a {@link ChronoField} then the query is implemented here.
|
||||
* The {@link #isSupported(TemporalField) supported fields} will return valid
|
||||
* values based on this time, except {@code NANO_OF_DAY} and {@code MICRO_OF_DAY}
|
||||
* which are too large to fit in an {@code int} and throw a {@code UnsupportedTemporalTypeException}.
|
||||
* which are too large to fit in an {@code int} and throw an {@code UnsupportedTemporalTypeException}.
|
||||
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
|
||||
* <p>
|
||||
* If the field is not a {@code ChronoField}, then the result of this method
|
||||
|
@ -576,7 +576,7 @@ public final class OffsetDateTime
|
||||
* The {@link #isSupported(TemporalField) supported fields} will return valid
|
||||
* values based on this date-time, except {@code NANO_OF_DAY}, {@code MICRO_OF_DAY},
|
||||
* {@code EPOCH_DAY}, {@code PROLEPTIC_MONTH} and {@code INSTANT_SECONDS} which are too
|
||||
* large to fit in an {@code int} and throw a {@code UnsupportedTemporalTypeException}.
|
||||
* large to fit in an {@code int} and throw an {@code UnsupportedTemporalTypeException}.
|
||||
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
|
||||
* <p>
|
||||
* If the field is not a {@code ChronoField}, then the result of this method
|
||||
|
@ -481,7 +481,7 @@ public final class OffsetTime
|
||||
* If the field is a {@link ChronoField} then the query is implemented here.
|
||||
* The {@link #isSupported(TemporalField) supported fields} will return valid
|
||||
* values based on this time, except {@code NANO_OF_DAY} and {@code MICRO_OF_DAY}
|
||||
* which are too large to fit in an {@code int} and throw a {@code UnsupportedTemporalTypeException}.
|
||||
* which are too large to fit in an {@code int} and throw an {@code UnsupportedTemporalTypeException}.
|
||||
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
|
||||
* <p>
|
||||
* If the field is not a {@code ChronoField}, then the result of this method
|
||||
|
@ -793,7 +793,7 @@ public final class ZonedDateTime
|
||||
* The {@link #isSupported(TemporalField) supported fields} will return valid
|
||||
* values based on this date-time, except {@code NANO_OF_DAY}, {@code MICRO_OF_DAY},
|
||||
* {@code EPOCH_DAY}, {@code PROLEPTIC_MONTH} and {@code INSTANT_SECONDS} which are too
|
||||
* large to fit in an {@code int} and throw a {@code UnsupportedTemporalTypeException}.
|
||||
* large to fit in an {@code int} and throw an {@code UnsupportedTemporalTypeException}.
|
||||
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
|
||||
* <p>
|
||||
* If the field is not a {@code ChronoField}, then the result of this method
|
||||
|
@ -308,6 +308,7 @@ import java.util.Set;
|
||||
* N nano-of-day number 1234000000
|
||||
*
|
||||
* V time-zone ID zone-id America/Los_Angeles; Z; -08:30
|
||||
* v generic time-zone name zone-name Pacific Time; PT
|
||||
* z time-zone name zone-name Pacific Standard Time; PST
|
||||
* O localized zone-offset offset-O GMT+8; GMT+08:00; UTC-08:00
|
||||
* X zone-offset 'Z' for zero offset-X Z; -08; -0830; -08:30; -083015; -08:30:15
|
||||
@ -365,9 +366,17 @@ import java.util.Set;
|
||||
* letters throws {@code IllegalArgumentException}.
|
||||
* <p>
|
||||
* <b>Zone names</b>: This outputs the display name of the time-zone ID. If the
|
||||
* count of letters is one, two or three, then the short name is output. If the
|
||||
* count of letters is four, then the full name is output. Five or more letters
|
||||
* throws {@code IllegalArgumentException}.
|
||||
* pattern letter is 'z' the output is the daylight savings aware zone name.
|
||||
* If there is insufficient information to determine whether DST applies,
|
||||
* the name ignoring daylight savings time will be used.
|
||||
* If the count of letters is one, two or three, then the short name is output.
|
||||
* If the count of letters is four, then the full name is output.
|
||||
* Five or more letters throws {@code IllegalArgumentException}.
|
||||
* <p>
|
||||
* If the pattern letter is 'v' the output provides the zone name ignoring
|
||||
* daylight savings time. If the count of letters is one, then the short name is output.
|
||||
* If the count of letters is four, then the full name is output.
|
||||
* Two, three and five or more letters throw {@code IllegalArgumentException}.
|
||||
* <p>
|
||||
* <b>Offset X and x</b>: This formats the offset based on the number of pattern
|
||||
* letters. One letter outputs just the hour, such as '+01', unless the minute
|
||||
|
@ -81,9 +81,11 @@ import java.time.DateTimeException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.chrono.ChronoLocalDate;
|
||||
import java.time.chrono.ChronoLocalDateTime;
|
||||
import java.time.chrono.Chronology;
|
||||
import java.time.chrono.Era;
|
||||
import java.time.chrono.IsoChronology;
|
||||
@ -1157,10 +1159,11 @@ public final class DateTimeFormatterBuilder {
|
||||
* result of {@link ZoneOffset#getId()}.
|
||||
* If the zone is not an offset, the textual name will be looked up
|
||||
* for the locale set in the {@link DateTimeFormatter}.
|
||||
* If the temporal object being printed represents an instant, then the text
|
||||
* will be the summer or winter time text as appropriate.
|
||||
* If the temporal object being printed represents an instant, or if it is a
|
||||
* local date-time that is not in a daylight saving gap or overlap then
|
||||
* the text will be the summer or winter time text as appropriate.
|
||||
* If the lookup for text does not find any suitable result, then the
|
||||
* {@link ZoneId#getId() ID} will be printed instead.
|
||||
* {@link ZoneId#getId() ID} will be printed.
|
||||
* If the zone cannot be obtained then an exception is thrown unless the
|
||||
* section of the formatter is optional.
|
||||
* <p>
|
||||
@ -1177,7 +1180,7 @@ public final class DateTimeFormatterBuilder {
|
||||
* @return this, for chaining, not null
|
||||
*/
|
||||
public DateTimeFormatterBuilder appendZoneText(TextStyle textStyle) {
|
||||
appendInternal(new ZoneTextPrinterParser(textStyle, null));
|
||||
appendInternal(new ZoneTextPrinterParser(textStyle, null, false));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -1193,10 +1196,11 @@ public final class DateTimeFormatterBuilder {
|
||||
* result of {@link ZoneOffset#getId()}.
|
||||
* If the zone is not an offset, the textual name will be looked up
|
||||
* for the locale set in the {@link DateTimeFormatter}.
|
||||
* If the temporal object being printed represents an instant, then the text
|
||||
* If the temporal object being printed represents an instant, or if it is a
|
||||
* local date-time that is not in a daylight saving gap or overlap, then the text
|
||||
* will be the summer or winter time text as appropriate.
|
||||
* If the lookup for text does not find any suitable result, then the
|
||||
* {@link ZoneId#getId() ID} will be printed instead.
|
||||
* {@link ZoneId#getId() ID} will be printed.
|
||||
* If the zone cannot be obtained then an exception is thrown unless the
|
||||
* section of the formatter is optional.
|
||||
* <p>
|
||||
@ -1220,7 +1224,70 @@ public final class DateTimeFormatterBuilder {
|
||||
public DateTimeFormatterBuilder appendZoneText(TextStyle textStyle,
|
||||
Set<ZoneId> preferredZones) {
|
||||
Objects.requireNonNull(preferredZones, "preferredZones");
|
||||
appendInternal(new ZoneTextPrinterParser(textStyle, preferredZones));
|
||||
appendInternal(new ZoneTextPrinterParser(textStyle, preferredZones, false));
|
||||
return this;
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
/**
|
||||
* Appends the generic time-zone name, such as 'Pacific Time', to the formatter.
|
||||
* <p>
|
||||
* This appends an instruction to format/parse the generic textual
|
||||
* name of the zone to the builder. The generic name is the same throughout the whole
|
||||
* year, ignoring any daylight saving changes. For example, 'Pacific Time' is the
|
||||
* generic name, whereas 'Pacific Standard Time' and 'Pacific Daylight Time' are the
|
||||
* specific names, see {@link #appendZoneText(TextStyle)}.
|
||||
* <p>
|
||||
* During formatting, the zone is obtained using a mechanism equivalent
|
||||
* to querying the temporal with {@link TemporalQueries#zoneId()}.
|
||||
* If the zone is a {@code ZoneOffset} it will be printed using the
|
||||
* result of {@link ZoneOffset#getId()}.
|
||||
* If the zone is not an offset, the textual name will be looked up
|
||||
* for the locale set in the {@link DateTimeFormatter}.
|
||||
* If the lookup for text does not find any suitable result, then the
|
||||
* {@link ZoneId#getId() ID} will be printed.
|
||||
* If the zone cannot be obtained then an exception is thrown unless the
|
||||
* section of the formatter is optional.
|
||||
* <p>
|
||||
* During parsing, either the textual zone name, the zone ID or the offset
|
||||
* is accepted. Many textual zone names are not unique, such as CST can be
|
||||
* for both "Central Standard Time" and "China Standard Time". In this
|
||||
* situation, the zone id will be determined by the region information from
|
||||
* formatter's {@link DateTimeFormatter#getLocale() locale} and the standard
|
||||
* zone id for that area, for example, America/New_York for the America Eastern zone.
|
||||
* The {@link #appendGenericZoneText(TextStyle, Set)} may be used
|
||||
* to specify a set of preferred {@link ZoneId} in this situation.
|
||||
*
|
||||
* @param textStyle the text style to use, not null
|
||||
* @return this, for chaining, not null
|
||||
*/
|
||||
public DateTimeFormatterBuilder appendGenericZoneText(TextStyle textStyle) {
|
||||
appendInternal(new ZoneTextPrinterParser(textStyle, null, true));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the generic time-zone name, such as 'Pacific Time', to the formatter.
|
||||
* <p>
|
||||
* This appends an instruction to format/parse the generic textual
|
||||
* name of the zone to the builder. The generic name is the same throughout the whole
|
||||
* year, ignoring any daylight saving changes. For example, 'Pacific Time' is the
|
||||
* generic name, whereas 'Pacific Standard Time' and 'Pacific Daylight Time' are the
|
||||
* specific names, see {@link #appendZoneText(TextStyle)}.
|
||||
* <p>
|
||||
* This method also allows a set of preferred {@link ZoneId} to be
|
||||
* specified for parsing. The matched preferred zone id will be used if the
|
||||
* textural zone name being parsed is not unique.
|
||||
* <p>
|
||||
* See {@link #appendGenericZoneText(TextStyle)} for details about
|
||||
* formatting and parsing.
|
||||
*
|
||||
* @param textStyle the text style to use, not null
|
||||
* @param preferredZones the set of preferred zone ids, not null
|
||||
* @return this, for chaining, not null
|
||||
*/
|
||||
public DateTimeFormatterBuilder appendGenericZoneText(TextStyle textStyle,
|
||||
Set<ZoneId> preferredZones) {
|
||||
appendInternal(new ZoneTextPrinterParser(textStyle, preferredZones, true));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -1416,6 +1483,7 @@ public final class DateTimeFormatterBuilder {
|
||||
* N nano-of-day number 1234000000
|
||||
*
|
||||
* V time-zone ID zone-id America/Los_Angeles; Z; -08:30
|
||||
* v generic time-zone name zone-name PT, Pacific Time
|
||||
* z time-zone name zone-name Pacific Standard Time; PST
|
||||
* O localized zone-offset offset-O GMT+8; GMT+08:00; UTC-08:00;
|
||||
* X zone-offset 'Z' for zero offset-X Z; -08; -0830; -08:30; -083015; -08:30:15
|
||||
@ -1537,6 +1605,8 @@ public final class DateTimeFormatterBuilder {
|
||||
* Pattern Count Equivalent builder methods
|
||||
* ------- ----- --------------------------
|
||||
* VV 2 appendZoneId()
|
||||
* v 1 appendGenericZoneText(TextStyle.SHORT)
|
||||
* vvvv 4 appendGenericZoneText(TextStyle.FULL)
|
||||
* z 1 appendZoneText(TextStyle.SHORT)
|
||||
* zz 2 appendZoneText(TextStyle.SHORT)
|
||||
* zzz 3 appendZoneText(TextStyle.SHORT)
|
||||
@ -1643,6 +1713,14 @@ public final class DateTimeFormatterBuilder {
|
||||
throw new IllegalArgumentException("Pattern letter count must be 2: " + cur);
|
||||
}
|
||||
appendZoneId();
|
||||
} else if (cur == 'v') {
|
||||
if (count == 1) {
|
||||
appendGenericZoneText(TextStyle.SHORT);
|
||||
} else if (count == 4) {
|
||||
appendGenericZoneText(TextStyle.FULL);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Wrong number of pattern letters: " + cur);
|
||||
}
|
||||
} else if (cur == 'Z') {
|
||||
if (count < 4) {
|
||||
appendOffset("+HHMM", "+0000");
|
||||
@ -1894,6 +1972,8 @@ public final class DateTimeFormatterBuilder {
|
||||
// 310 - z - time-zone names, matches LDML and SimpleDateFormat 1 to 4
|
||||
// 310 - Z - matches SimpleDateFormat and LDML
|
||||
// 310 - V - time-zone id, matches LDML
|
||||
// 310 - v - general timezone names, not matching exactly with LDML because LDML specify to fall back
|
||||
// to 'VVVV' if general-nonlocation unavailable but here it's not falling back because of lack of data
|
||||
// 310 - p - prefix for padding
|
||||
// 310 - X - matches LDML, almost matches SDF for 1, exact match 2&3, extended 4&5
|
||||
// 310 - x - matches LDML
|
||||
@ -1901,7 +1981,6 @@ public final class DateTimeFormatterBuilder {
|
||||
// LDML - U - cycle year name, not supported by 310 yet
|
||||
// LDML - l - deprecated
|
||||
// LDML - j - not relevant
|
||||
// LDML - v,V - extended time-zone names
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@ -3723,9 +3802,12 @@ public final class DateTimeFormatterBuilder {
|
||||
/** The preferred zoneid map */
|
||||
private Set<String> preferredZones;
|
||||
|
||||
ZoneTextPrinterParser(TextStyle textStyle, Set<ZoneId> preferredZones) {
|
||||
/** Display in generic time-zone format. True in case of pattern letter 'v' */
|
||||
private final boolean isGeneric;
|
||||
ZoneTextPrinterParser(TextStyle textStyle, Set<ZoneId> preferredZones, boolean isGeneric) {
|
||||
super(TemporalQueries.zone(), "ZoneText(" + textStyle + ")");
|
||||
this.textStyle = Objects.requireNonNull(textStyle, "textStyle");
|
||||
this.isGeneric = isGeneric;
|
||||
if (preferredZones != null && preferredZones.size() != 0) {
|
||||
this.preferredZones = new HashSet<>();
|
||||
for (ZoneId id : preferredZones) {
|
||||
@ -3788,11 +3870,21 @@ public final class DateTimeFormatterBuilder {
|
||||
String zname = zone.getId();
|
||||
if (!(zone instanceof ZoneOffset)) {
|
||||
TemporalAccessor dt = context.getTemporal();
|
||||
String name = getDisplayName(zname,
|
||||
dt.isSupported(ChronoField.INSTANT_SECONDS)
|
||||
? (zone.getRules().isDaylightSavings(Instant.from(dt)) ? DST : STD)
|
||||
: GENERIC,
|
||||
context.getLocale());
|
||||
int type = GENERIC;
|
||||
if (!isGeneric) {
|
||||
if (dt.isSupported(ChronoField.INSTANT_SECONDS)) {
|
||||
type = zone.getRules().isDaylightSavings(Instant.from(dt)) ? DST : STD;
|
||||
} else if (dt.isSupported(ChronoField.EPOCH_DAY) &&
|
||||
dt.isSupported(ChronoField.NANO_OF_DAY)) {
|
||||
LocalDate date = LocalDate.ofEpochDay(dt.getLong(ChronoField.EPOCH_DAY));
|
||||
LocalTime time = LocalTime.ofNanoOfDay(dt.getLong(ChronoField.NANO_OF_DAY));
|
||||
LocalDateTime ldt = date.atTime(time);
|
||||
if (zone.getRules().getTransition(ldt) == null) {
|
||||
type = zone.getRules().isDaylightSavings(ldt.atZone(zone).toInstant()) ? DST : STD;
|
||||
}
|
||||
}
|
||||
}
|
||||
String name = getDisplayName(zname, type, context.getLocale());
|
||||
if (name != null) {
|
||||
zname = name;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -402,6 +402,12 @@ public final class IsoFields {
|
||||
long moy = temporal.getLong(MONTH_OF_YEAR);
|
||||
return ((moy + 2) / 3);
|
||||
}
|
||||
public ValueRange rangeRefinedBy(TemporalAccessor temporal) {
|
||||
if (isSupportedBy(temporal) == false) {
|
||||
throw new UnsupportedTemporalTypeException("Unsupported field: QuarterOfYear");
|
||||
}
|
||||
return super.rangeRefinedBy(temporal);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
|
||||
@ -529,6 +535,12 @@ public final class IsoFields {
|
||||
}
|
||||
return getWeekBasedYear(LocalDate.from(temporal));
|
||||
}
|
||||
public ValueRange rangeRefinedBy(TemporalAccessor temporal) {
|
||||
if (isSupportedBy(temporal) == false) {
|
||||
throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear");
|
||||
}
|
||||
return super.rangeRefinedBy(temporal);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
|
||||
|
@ -614,7 +614,7 @@ public final class ZoneRules implements Serializable {
|
||||
* One technique, using this method, would be:
|
||||
* <pre>
|
||||
* ZoneOffsetTransition trans = rules.getTransition(localDT);
|
||||
* if (trans == null) {
|
||||
* if (trans != null) {
|
||||
* // Gap or Overlap: determine what to do from transition
|
||||
* } else {
|
||||
* // Normal case: only one valid offset
|
||||
|
@ -267,7 +267,7 @@ public interface Comparator<T> {
|
||||
|
||||
/**
|
||||
* Returns a lexicographic-order comparator with a function that
|
||||
* extracts a {@code int} sort key.
|
||||
* extracts an {@code int} sort key.
|
||||
*
|
||||
* @implSpec This default implementation behaves as if {@code
|
||||
* thenComparing(comparingInt(keyExtractor))}.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -146,12 +146,26 @@ final class DualPivotQuicksort {
|
||||
}
|
||||
}
|
||||
|
||||
// Check special cases
|
||||
// Implementation note: variable "right" is increased by 1.
|
||||
if (run[count] == right++) { // The last run contains one element
|
||||
run[++count] = right;
|
||||
} else if (count <= 1) { // The array is already sorted
|
||||
// These invariants should hold true:
|
||||
// run[0] = 0
|
||||
// run[<last>] = right + 1; (terminator)
|
||||
|
||||
if (count == 0) {
|
||||
// A single equal run
|
||||
return;
|
||||
} else if (count == 1 && run[count] > right) {
|
||||
// Either a single ascending or a transformed descending run.
|
||||
// Always check that a final run is a proper terminator, otherwise
|
||||
// we have an unterminated trailing run, to handle downstream.
|
||||
return;
|
||||
}
|
||||
right++;
|
||||
if (run[count] < right) {
|
||||
// Corner case: the final run is not a terminator. This may happen
|
||||
// if a final run is an equals run, or there is a single-element run
|
||||
// at the end. Fix up by adding a proper terminator at the end.
|
||||
// Note that we terminate with (right + 1), incremented earlier.
|
||||
run[++count] = right;
|
||||
}
|
||||
|
||||
// Determine alternation base for merge
|
||||
@ -598,12 +612,26 @@ final class DualPivotQuicksort {
|
||||
}
|
||||
}
|
||||
|
||||
// Check special cases
|
||||
// Implementation note: variable "right" is increased by 1.
|
||||
if (run[count] == right++) { // The last run contains one element
|
||||
run[++count] = right;
|
||||
} else if (count <= 1) { // The array is already sorted
|
||||
// These invariants should hold true:
|
||||
// run[0] = 0
|
||||
// run[<last>] = right + 1; (terminator)
|
||||
|
||||
if (count == 0) {
|
||||
// A single equal run
|
||||
return;
|
||||
} else if (count == 1 && run[count] > right) {
|
||||
// Either a single ascending or a transformed descending run.
|
||||
// Always check that a final run is a proper terminator, otherwise
|
||||
// we have an unterminated trailing run, to handle downstream.
|
||||
return;
|
||||
}
|
||||
right++;
|
||||
if (run[count] < right) {
|
||||
// Corner case: the final run is not a terminator. This may happen
|
||||
// if a final run is an equals run, or there is a single-element run
|
||||
// at the end. Fix up by adding a proper terminator at the end.
|
||||
// Note that we terminate with (right + 1), incremented earlier.
|
||||
run[++count] = right;
|
||||
}
|
||||
|
||||
// Determine alternation base for merge
|
||||
@ -1086,12 +1114,26 @@ final class DualPivotQuicksort {
|
||||
}
|
||||
}
|
||||
|
||||
// Check special cases
|
||||
// Implementation note: variable "right" is increased by 1.
|
||||
if (run[count] == right++) { // The last run contains one element
|
||||
run[++count] = right;
|
||||
} else if (count <= 1) { // The array is already sorted
|
||||
// These invariants should hold true:
|
||||
// run[0] = 0
|
||||
// run[<last>] = right + 1; (terminator)
|
||||
|
||||
if (count == 0) {
|
||||
// A single equal run
|
||||
return;
|
||||
} else if (count == 1 && run[count] > right) {
|
||||
// Either a single ascending or a transformed descending run.
|
||||
// Always check that a final run is a proper terminator, otherwise
|
||||
// we have an unterminated trailing run, to handle downstream.
|
||||
return;
|
||||
}
|
||||
right++;
|
||||
if (run[count] < right) {
|
||||
// Corner case: the final run is not a terminator. This may happen
|
||||
// if a final run is an equals run, or there is a single-element run
|
||||
// at the end. Fix up by adding a proper terminator at the end.
|
||||
// Note that we terminate with (right + 1), incremented earlier.
|
||||
run[++count] = right;
|
||||
}
|
||||
|
||||
// Determine alternation base for merge
|
||||
@ -1574,12 +1616,26 @@ final class DualPivotQuicksort {
|
||||
}
|
||||
}
|
||||
|
||||
// Check special cases
|
||||
// Implementation note: variable "right" is increased by 1.
|
||||
if (run[count] == right++) { // The last run contains one element
|
||||
run[++count] = right;
|
||||
} else if (count <= 1) { // The array is already sorted
|
||||
// These invariants should hold true:
|
||||
// run[0] = 0
|
||||
// run[<last>] = right + 1; (terminator)
|
||||
|
||||
if (count == 0) {
|
||||
// A single equal run
|
||||
return;
|
||||
} else if (count == 1 && run[count] > right) {
|
||||
// Either a single ascending or a transformed descending run.
|
||||
// Always check that a final run is a proper terminator, otherwise
|
||||
// we have an unterminated trailing run, to handle downstream.
|
||||
return;
|
||||
}
|
||||
right++;
|
||||
if (run[count] < right) {
|
||||
// Corner case: the final run is not a terminator. This may happen
|
||||
// if a final run is an equals run, or there is a single-element run
|
||||
// at the end. Fix up by adding a proper terminator at the end.
|
||||
// Note that we terminate with (right + 1), incremented earlier.
|
||||
run[++count] = right;
|
||||
}
|
||||
|
||||
// Determine alternation base for merge
|
||||
@ -2158,12 +2214,26 @@ final class DualPivotQuicksort {
|
||||
}
|
||||
}
|
||||
|
||||
// Check special cases
|
||||
// Implementation note: variable "right" is increased by 1.
|
||||
if (run[count] == right++) { // The last run contains one element
|
||||
run[++count] = right;
|
||||
} else if (count <= 1) { // The array is already sorted
|
||||
// These invariants should hold true:
|
||||
// run[0] = 0
|
||||
// run[<last>] = right + 1; (terminator)
|
||||
|
||||
if (count == 0) {
|
||||
// A single equal run
|
||||
return;
|
||||
} else if (count == 1 && run[count] > right) {
|
||||
// Either a single ascending or a transformed descending run.
|
||||
// Always check that a final run is a proper terminator, otherwise
|
||||
// we have an unterminated trailing run, to handle downstream.
|
||||
return;
|
||||
}
|
||||
right++;
|
||||
if (run[count] < right) {
|
||||
// Corner case: the final run is not a terminator. This may happen
|
||||
// if a final run is an equals run, or there is a single-element run
|
||||
// at the end. Fix up by adding a proper terminator at the end.
|
||||
// Note that we terminate with (right + 1), incremented earlier.
|
||||
run[++count] = right;
|
||||
}
|
||||
|
||||
// Determine alternation base for merge
|
||||
@ -2701,12 +2771,26 @@ final class DualPivotQuicksort {
|
||||
}
|
||||
}
|
||||
|
||||
// Check special cases
|
||||
// Implementation note: variable "right" is increased by 1.
|
||||
if (run[count] == right++) { // The last run contains one element
|
||||
run[++count] = right;
|
||||
} else if (count <= 1) { // The array is already sorted
|
||||
// These invariants should hold true:
|
||||
// run[0] = 0
|
||||
// run[<last>] = right + 1; (terminator)
|
||||
|
||||
if (count == 0) {
|
||||
// A single equal run
|
||||
return;
|
||||
} else if (count == 1 && run[count] > right) {
|
||||
// Either a single ascending or a transformed descending run.
|
||||
// Always check that a final run is a proper terminator, otherwise
|
||||
// we have an unterminated trailing run, to handle downstream.
|
||||
return;
|
||||
}
|
||||
right++;
|
||||
if (run[count] < right) {
|
||||
// Corner case: the final run is not a terminator. This may happen
|
||||
// if a final run is an equals run, or there is a single-element run
|
||||
// at the end. Fix up by adding a proper terminator at the end.
|
||||
// Note that we terminate with (right + 1), incremented earlier.
|
||||
run[++count] = right;
|
||||
}
|
||||
|
||||
// Determine alternation base for merge
|
||||
|
@ -0,0 +1,375 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.regex;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern.CharPredicate;
|
||||
import java.util.regex.Pattern.BmpCharPredicate;
|
||||
|
||||
class CharPredicates {
|
||||
|
||||
static final CharPredicate ALPHABETIC = Character::isAlphabetic;
|
||||
|
||||
// \p{gc=Decimal_Number}
|
||||
static final CharPredicate DIGIT = Character::isDigit;
|
||||
|
||||
static final CharPredicate LETTER = Character::isLetter;
|
||||
|
||||
static final CharPredicate IDEOGRAPHIC = Character::isIdeographic;
|
||||
|
||||
static final CharPredicate LOWERCASE = Character::isLowerCase;
|
||||
|
||||
static final CharPredicate UPPERCASE = Character::isUpperCase;
|
||||
|
||||
static final CharPredicate TITLECASE = Character::isTitleCase;
|
||||
|
||||
// \p{Whitespace}
|
||||
static final CharPredicate WHITE_SPACE = ch ->
|
||||
((((1 << Character.SPACE_SEPARATOR) |
|
||||
(1 << Character.LINE_SEPARATOR) |
|
||||
(1 << Character.PARAGRAPH_SEPARATOR)) >> Character.getType(ch)) & 1)
|
||||
!= 0 || (ch >= 0x9 && ch <= 0xd) || (ch == 0x85);
|
||||
|
||||
// \p{gc=Control}
|
||||
static final CharPredicate CONTROL = ch ->
|
||||
Character.getType(ch) == Character.CONTROL;
|
||||
|
||||
// \p{gc=Punctuation}
|
||||
static final CharPredicate PUNCTUATION = ch ->
|
||||
((((1 << Character.CONNECTOR_PUNCTUATION) |
|
||||
(1 << Character.DASH_PUNCTUATION) |
|
||||
(1 << Character.START_PUNCTUATION) |
|
||||
(1 << Character.END_PUNCTUATION) |
|
||||
(1 << Character.OTHER_PUNCTUATION) |
|
||||
(1 << Character.INITIAL_QUOTE_PUNCTUATION) |
|
||||
(1 << Character.FINAL_QUOTE_PUNCTUATION)) >> Character.getType(ch)) & 1)
|
||||
!= 0;
|
||||
|
||||
// \p{gc=Decimal_Number}
|
||||
// \p{Hex_Digit} -> PropList.txt: Hex_Digit
|
||||
static final CharPredicate HEX_DIGIT = DIGIT.union(
|
||||
ch -> (ch >= 0x0030 && ch <= 0x0039) ||
|
||||
(ch >= 0x0041 && ch <= 0x0046) ||
|
||||
(ch >= 0x0061 && ch <= 0x0066) ||
|
||||
(ch >= 0xFF10 && ch <= 0xFF19) ||
|
||||
(ch >= 0xFF21 && ch <= 0xFF26) ||
|
||||
(ch >= 0xFF41 && ch <= 0xFF46));
|
||||
|
||||
static final CharPredicate ASSIGNED = ch ->
|
||||
Character.getType(ch) != Character.UNASSIGNED;
|
||||
|
||||
// PropList.txt:Noncharacter_Code_Point
|
||||
static final CharPredicate NONCHARACTER_CODE_POINT = ch ->
|
||||
(ch & 0xfffe) == 0xfffe || (ch >= 0xfdd0 && ch <= 0xfdef);
|
||||
|
||||
// \p{alpha}
|
||||
// \p{digit}
|
||||
static final CharPredicate ALNUM = ALPHABETIC.union(DIGIT);
|
||||
|
||||
// \p{Whitespace} --
|
||||
// [\N{LF} \N{VT} \N{FF} \N{CR} \N{NEL} -> 0xa, 0xb, 0xc, 0xd, 0x85
|
||||
// \p{gc=Line_Separator}
|
||||
// \p{gc=Paragraph_Separator}]
|
||||
static final CharPredicate BLANK = ch ->
|
||||
Character.getType(ch) == Character.SPACE_SEPARATOR ||
|
||||
ch == 0x9; // \N{HT}
|
||||
|
||||
// [^
|
||||
// \p{space}
|
||||
// \p{gc=Control}
|
||||
// \p{gc=Surrogate}
|
||||
// \p{gc=Unassigned}]
|
||||
static final CharPredicate GRAPH = ch ->
|
||||
((((1 << Character.SPACE_SEPARATOR) |
|
||||
(1 << Character.LINE_SEPARATOR) |
|
||||
(1 << Character.PARAGRAPH_SEPARATOR) |
|
||||
(1 << Character.CONTROL) |
|
||||
(1 << Character.SURROGATE) |
|
||||
(1 << Character.UNASSIGNED)) >> Character.getType(ch)) & 1)
|
||||
== 0;
|
||||
|
||||
// \p{graph}
|
||||
// \p{blank}
|
||||
// -- \p{cntrl}
|
||||
static final CharPredicate PRINT = GRAPH.union(BLANK).and(CONTROL.negate());
|
||||
|
||||
// 200C..200D PropList.txt:Join_Control
|
||||
static final CharPredicate JOIN_CONTROL = ch -> ch == 0x200C || ch == 0x200D;
|
||||
|
||||
// \p{alpha}
|
||||
// \p{gc=Mark}
|
||||
// \p{digit}
|
||||
// \p{gc=Connector_Punctuation}
|
||||
// \p{Join_Control} 200C..200D
|
||||
static final CharPredicate WORD =
|
||||
ALPHABETIC.union(ch -> ((((1 << Character.NON_SPACING_MARK) |
|
||||
(1 << Character.ENCLOSING_MARK) |
|
||||
(1 << Character.COMBINING_SPACING_MARK) |
|
||||
(1 << Character.DECIMAL_DIGIT_NUMBER) |
|
||||
(1 << Character.CONNECTOR_PUNCTUATION))
|
||||
>> Character.getType(ch)) & 1) != 0,
|
||||
JOIN_CONTROL);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private static final HashMap<String, CharPredicate> posix = new HashMap<>(12);
|
||||
private static final HashMap<String, CharPredicate> uprops = new HashMap<>(18);
|
||||
|
||||
private static void defPosix(String name, CharPredicate p) {
|
||||
posix.put(name, p);
|
||||
}
|
||||
private static void defUProp(String name, CharPredicate p) {
|
||||
uprops.put(name, p);
|
||||
}
|
||||
|
||||
static {
|
||||
defPosix("ALPHA", ALPHABETIC);
|
||||
defPosix("LOWER", LOWERCASE);
|
||||
defPosix("UPPER", UPPERCASE);
|
||||
defPosix("SPACE", WHITE_SPACE);
|
||||
defPosix("PUNCT", PUNCTUATION);
|
||||
defPosix("XDIGIT",HEX_DIGIT);
|
||||
defPosix("ALNUM", ALNUM);
|
||||
defPosix("CNTRL", CONTROL);
|
||||
defPosix("DIGIT", DIGIT);
|
||||
defPosix("BLANK", BLANK);
|
||||
defPosix("GRAPH", GRAPH);
|
||||
defPosix("PRINT", PRINT);
|
||||
|
||||
defUProp("ALPHABETIC", ALPHABETIC);
|
||||
defUProp("ASSIGNED", ASSIGNED);
|
||||
defUProp("CONTROL", CONTROL);
|
||||
defUProp("HEXDIGIT", HEX_DIGIT);
|
||||
defUProp("IDEOGRAPHIC", IDEOGRAPHIC);
|
||||
defUProp("JOINCONTROL", JOIN_CONTROL);
|
||||
defUProp("LETTER", LETTER);
|
||||
defUProp("LOWERCASE", LOWERCASE);
|
||||
defUProp("NONCHARACTERCODEPOINT", NONCHARACTER_CODE_POINT);
|
||||
defUProp("TITLECASE", TITLECASE);
|
||||
defUProp("PUNCTUATION", PUNCTUATION);
|
||||
defUProp("UPPERCASE", UPPERCASE);
|
||||
defUProp("WHITESPACE", WHITE_SPACE);
|
||||
defUProp("WORD", WORD);
|
||||
defUProp("WHITE_SPACE", WHITE_SPACE);
|
||||
defUProp("HEX_DIGIT", HEX_DIGIT);
|
||||
defUProp("NONCHARACTER_CODE_POINT", NONCHARACTER_CODE_POINT);
|
||||
defUProp("JOIN_CONTROL", JOIN_CONTROL);
|
||||
}
|
||||
|
||||
public static CharPredicate forUnicodeProperty(String propName) {
|
||||
propName = propName.toUpperCase(Locale.ROOT);
|
||||
CharPredicate p = uprops.get(propName);
|
||||
if (p != null)
|
||||
return p;
|
||||
return posix.get(propName);
|
||||
}
|
||||
|
||||
public static CharPredicate forPOSIXName(String propName) {
|
||||
return posix.get(propName.toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Returns a predicate matching all characters belong to a named
|
||||
* UnicodeScript.
|
||||
*/
|
||||
static CharPredicate forUnicodeScript(String name) {
|
||||
final Character.UnicodeScript script;
|
||||
try {
|
||||
script = Character.UnicodeScript.forName(name);
|
||||
return ch -> script == Character.UnicodeScript.of(ch);
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a predicate matching all characters in a UnicodeBlock.
|
||||
*/
|
||||
static CharPredicate forUnicodeBlock(String name) {
|
||||
final Character.UnicodeBlock block;
|
||||
try {
|
||||
block = Character.UnicodeBlock.forName(name);
|
||||
return ch -> block == Character.UnicodeBlock.of(ch);
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// unicode categories, aliases, properties, java methods ...
|
||||
|
||||
private static final HashMap<String, CharPredicate> props = new HashMap<>(128);
|
||||
|
||||
/**
|
||||
* Returns a predicate matching all characters in a named property.
|
||||
*/
|
||||
static CharPredicate forProperty(String name) {
|
||||
return props.get(name);
|
||||
}
|
||||
|
||||
private static void defProp(String name, CharPredicate p) {
|
||||
props.put(name, p);
|
||||
}
|
||||
|
||||
private static void defCategory(String name, final int typeMask) {
|
||||
CharPredicate p = ch -> (typeMask & (1 << Character.getType(ch))) != 0;
|
||||
props.put(name, p);
|
||||
}
|
||||
|
||||
private static void defRange(String name, final int lower, final int upper) {
|
||||
BmpCharPredicate p = ch -> lower <= ch && ch <= upper;
|
||||
props.put(name, p);
|
||||
}
|
||||
|
||||
private static void defCtype(String name, final int ctype) {
|
||||
BmpCharPredicate p = ch -> ch < 128 && ASCII.isType(ch, ctype);
|
||||
// PrintPattern.pmap.put(p, name);
|
||||
props.put(name, p);
|
||||
}
|
||||
|
||||
static {
|
||||
// Unicode character property aliases, defined in
|
||||
// http://www.unicode.org/Public/UNIDATA/PropertyValueAliases.txt
|
||||
defCategory("Cn", 1<<Character.UNASSIGNED);
|
||||
defCategory("Lu", 1<<Character.UPPERCASE_LETTER);
|
||||
defCategory("Ll", 1<<Character.LOWERCASE_LETTER);
|
||||
defCategory("Lt", 1<<Character.TITLECASE_LETTER);
|
||||
defCategory("Lm", 1<<Character.MODIFIER_LETTER);
|
||||
defCategory("Lo", 1<<Character.OTHER_LETTER);
|
||||
defCategory("Mn", 1<<Character.NON_SPACING_MARK);
|
||||
defCategory("Me", 1<<Character.ENCLOSING_MARK);
|
||||
defCategory("Mc", 1<<Character.COMBINING_SPACING_MARK);
|
||||
defCategory("Nd", 1<<Character.DECIMAL_DIGIT_NUMBER);
|
||||
defCategory("Nl", 1<<Character.LETTER_NUMBER);
|
||||
defCategory("No", 1<<Character.OTHER_NUMBER);
|
||||
defCategory("Zs", 1<<Character.SPACE_SEPARATOR);
|
||||
defCategory("Zl", 1<<Character.LINE_SEPARATOR);
|
||||
defCategory("Zp", 1<<Character.PARAGRAPH_SEPARATOR);
|
||||
defCategory("Cc", 1<<Character.CONTROL);
|
||||
defCategory("Cf", 1<<Character.FORMAT);
|
||||
defCategory("Co", 1<<Character.PRIVATE_USE);
|
||||
defCategory("Cs", 1<<Character.SURROGATE);
|
||||
defCategory("Pd", 1<<Character.DASH_PUNCTUATION);
|
||||
defCategory("Ps", 1<<Character.START_PUNCTUATION);
|
||||
defCategory("Pe", 1<<Character.END_PUNCTUATION);
|
||||
defCategory("Pc", 1<<Character.CONNECTOR_PUNCTUATION);
|
||||
defCategory("Po", 1<<Character.OTHER_PUNCTUATION);
|
||||
defCategory("Sm", 1<<Character.MATH_SYMBOL);
|
||||
defCategory("Sc", 1<<Character.CURRENCY_SYMBOL);
|
||||
defCategory("Sk", 1<<Character.MODIFIER_SYMBOL);
|
||||
defCategory("So", 1<<Character.OTHER_SYMBOL);
|
||||
defCategory("Pi", 1<<Character.INITIAL_QUOTE_PUNCTUATION);
|
||||
defCategory("Pf", 1<<Character.FINAL_QUOTE_PUNCTUATION);
|
||||
defCategory("L", ((1<<Character.UPPERCASE_LETTER) |
|
||||
(1<<Character.LOWERCASE_LETTER) |
|
||||
(1<<Character.TITLECASE_LETTER) |
|
||||
(1<<Character.MODIFIER_LETTER) |
|
||||
(1<<Character.OTHER_LETTER)));
|
||||
defCategory("M", ((1<<Character.NON_SPACING_MARK) |
|
||||
(1<<Character.ENCLOSING_MARK) |
|
||||
(1<<Character.COMBINING_SPACING_MARK)));
|
||||
defCategory("N", ((1<<Character.DECIMAL_DIGIT_NUMBER) |
|
||||
(1<<Character.LETTER_NUMBER) |
|
||||
(1<<Character.OTHER_NUMBER)));
|
||||
defCategory("Z", ((1<<Character.SPACE_SEPARATOR) |
|
||||
(1<<Character.LINE_SEPARATOR) |
|
||||
(1<<Character.PARAGRAPH_SEPARATOR)));
|
||||
defCategory("C", ((1<<Character.CONTROL) |
|
||||
(1<<Character.FORMAT) |
|
||||
(1<<Character.PRIVATE_USE) |
|
||||
(1<<Character.SURROGATE))); // Other
|
||||
defCategory("P", ((1<<Character.DASH_PUNCTUATION) |
|
||||
(1<<Character.START_PUNCTUATION) |
|
||||
(1<<Character.END_PUNCTUATION) |
|
||||
(1<<Character.CONNECTOR_PUNCTUATION) |
|
||||
(1<<Character.OTHER_PUNCTUATION) |
|
||||
(1<<Character.INITIAL_QUOTE_PUNCTUATION) |
|
||||
(1<<Character.FINAL_QUOTE_PUNCTUATION)));
|
||||
defCategory("S", ((1<<Character.MATH_SYMBOL) |
|
||||
(1<<Character.CURRENCY_SYMBOL) |
|
||||
(1<<Character.MODIFIER_SYMBOL) |
|
||||
(1<<Character.OTHER_SYMBOL)));
|
||||
defCategory("LC", ((1<<Character.UPPERCASE_LETTER) |
|
||||
(1<<Character.LOWERCASE_LETTER) |
|
||||
(1<<Character.TITLECASE_LETTER)));
|
||||
defCategory("LD", ((1<<Character.UPPERCASE_LETTER) |
|
||||
(1<<Character.LOWERCASE_LETTER) |
|
||||
(1<<Character.TITLECASE_LETTER) |
|
||||
(1<<Character.MODIFIER_LETTER) |
|
||||
(1<<Character.OTHER_LETTER) |
|
||||
(1<<Character.DECIMAL_DIGIT_NUMBER)));
|
||||
defRange("L1", 0x00, 0xFF); // Latin-1
|
||||
props.put("all", ch -> true);
|
||||
|
||||
// Posix regular expression character classes, defined in
|
||||
// http://www.unix.org/onlinepubs/009695399/basedefs/xbd_chap09.html
|
||||
defRange("ASCII", 0x00, 0x7F); // ASCII
|
||||
defCtype("Alnum", ASCII.ALNUM); // Alphanumeric characters
|
||||
defCtype("Alpha", ASCII.ALPHA); // Alphabetic characters
|
||||
defCtype("Blank", ASCII.BLANK); // Space and tab characters
|
||||
defCtype("Cntrl", ASCII.CNTRL); // Control characters
|
||||
defRange("Digit", '0', '9'); // Numeric characters
|
||||
defCtype("Graph", ASCII.GRAPH); // printable and visible
|
||||
defRange("Lower", 'a', 'z'); // Lower-case alphabetic
|
||||
defRange("Print", 0x20, 0x7E); // Printable characters
|
||||
defCtype("Punct", ASCII.PUNCT); // Punctuation characters
|
||||
defCtype("Space", ASCII.SPACE); // Space characters
|
||||
defRange("Upper", 'A', 'Z'); // Upper-case alphabetic
|
||||
defCtype("XDigit",ASCII.XDIGIT); // hexadecimal digits
|
||||
|
||||
// Java character properties, defined by methods in Character.java
|
||||
defProp("javaLowerCase", java.lang.Character::isLowerCase);
|
||||
defProp("javaUpperCase", Character::isUpperCase);
|
||||
defProp("javaAlphabetic", java.lang.Character::isAlphabetic);
|
||||
defProp("javaIdeographic", java.lang.Character::isIdeographic);
|
||||
defProp("javaTitleCase", java.lang.Character::isTitleCase);
|
||||
defProp("javaDigit", java.lang.Character::isDigit);
|
||||
defProp("javaDefined", java.lang.Character::isDefined);
|
||||
defProp("javaLetter", java.lang.Character::isLetter);
|
||||
defProp("javaLetterOrDigit", java.lang.Character::isLetterOrDigit);
|
||||
defProp("javaJavaIdentifierStart", java.lang.Character::isJavaIdentifierStart);
|
||||
defProp("javaJavaIdentifierPart", java.lang.Character::isJavaIdentifierPart);
|
||||
defProp("javaUnicodeIdentifierStart", java.lang.Character::isUnicodeIdentifierStart);
|
||||
defProp("javaUnicodeIdentifierPart", java.lang.Character::isUnicodeIdentifierPart);
|
||||
defProp("javaIdentifierIgnorable", java.lang.Character::isIdentifierIgnorable);
|
||||
defProp("javaSpaceChar", java.lang.Character::isSpaceChar);
|
||||
defProp("javaWhitespace", java.lang.Character::isWhitespace);
|
||||
defProp("javaISOControl", java.lang.Character::isISOControl);
|
||||
defProp("javaMirrored", java.lang.Character::isMirrored);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Posix ASCII variants, not in the lookup map
|
||||
*/
|
||||
static final BmpCharPredicate ASCII_DIGIT = ch -> ch < 128 && ASCII.isDigit(ch);
|
||||
static final BmpCharPredicate ASCII_WORD = ch -> ch < 128 && ASCII.isWord(ch);
|
||||
static final BmpCharPredicate ASCII_SPACE = ch -> ch < 128 && ASCII.isSpace(ch);
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.regex;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A lightweight hashset implementation for positive 'int'. Not safe for
|
||||
* concurrent access.
|
||||
*/
|
||||
class IntHashSet {
|
||||
private int[] entries;
|
||||
private int[] hashes;
|
||||
private int pos = 0;
|
||||
|
||||
public IntHashSet() {
|
||||
this.entries = new int[16 << 1]; // initCapacity = 16;
|
||||
this.hashes = new int[(16 / 2) | 1]; // odd -> fewer collisions
|
||||
Arrays.fill(this.entries, -1);
|
||||
Arrays.fill(this.hashes, -1);
|
||||
}
|
||||
|
||||
public boolean contains(int i) {
|
||||
int h = hashes[i % hashes.length];
|
||||
while (h != -1) {
|
||||
if (entries[h] == i)
|
||||
return true;
|
||||
h = entries[h + 1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void add(int i) {
|
||||
int h0 = i % hashes.length;
|
||||
int next = hashes[h0];
|
||||
// if invoker guarantees contains(i) checked before add(i)
|
||||
// the following check is not needed.
|
||||
int next0 = next;
|
||||
while (next0 != -1) {
|
||||
if (entries[next0 ] == i)
|
||||
return;
|
||||
next0 = entries[next0 + 1];
|
||||
}
|
||||
hashes[h0] = pos;
|
||||
entries[pos++] = i;
|
||||
entries[pos++] = next;
|
||||
if (pos == entries.length)
|
||||
expand();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
Arrays.fill(this.entries, -1);
|
||||
Arrays.fill(this.hashes, -1);
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
private void expand() {
|
||||
int[] old = entries;
|
||||
int[] es = new int[old.length << 1];
|
||||
int hlen = (old.length / 2) | 1;
|
||||
int[] hs = new int[hlen];
|
||||
Arrays.fill(es, -1);
|
||||
Arrays.fill(hs, -1);
|
||||
for (int n = 0; n < pos;) { // re-hashing
|
||||
int i = old[n];
|
||||
int hsh = i % hlen;
|
||||
int next = hs[hsh];
|
||||
hs[hsh] = n;
|
||||
es[n++] = i;
|
||||
es[n++] = next;
|
||||
}
|
||||
this.entries = es;
|
||||
this.hashes = hs;
|
||||
}
|
||||
}
|
@ -177,6 +177,14 @@ public final class Matcher implements MatchResult {
|
||||
*/
|
||||
int[] locals;
|
||||
|
||||
/**
|
||||
* Storage used by top greedy Loop node to store a specific hash set to
|
||||
* keep the beginning index of the failed repetition match. The nodes
|
||||
* themselves are stateless, so they rely on this field to hold state
|
||||
* during a match.
|
||||
*/
|
||||
IntHashSet[] localsPos;
|
||||
|
||||
/**
|
||||
* Boolean indicating whether or not more input could change
|
||||
* the results of the last match.
|
||||
@ -239,6 +247,7 @@ public final class Matcher implements MatchResult {
|
||||
int parentGroupCount = Math.max(parent.capturingGroupCount, 10);
|
||||
groups = new int[parentGroupCount * 2];
|
||||
locals = new int[parent.localCount];
|
||||
localsPos = new IntHashSet[parent.localTCNCount];
|
||||
|
||||
// Put fields into initial states
|
||||
reset();
|
||||
@ -375,6 +384,7 @@ public final class Matcher implements MatchResult {
|
||||
groups[i] = -1;
|
||||
for (int i = 0; i < locals.length; i++)
|
||||
locals[i] = -1;
|
||||
localsPos = new IntHashSet[parentPattern.localTCNCount];
|
||||
modCount++;
|
||||
return this;
|
||||
}
|
||||
@ -397,6 +407,10 @@ public final class Matcher implements MatchResult {
|
||||
groups[i] = -1;
|
||||
for(int i=0; i<locals.length; i++)
|
||||
locals[i] = -1;
|
||||
for (int i = 0; i < localsPos.length; i++) {
|
||||
if (localsPos[i] != null)
|
||||
localsPos[i].clear();
|
||||
}
|
||||
lastAppendPosition = 0;
|
||||
from = 0;
|
||||
to = getTextLength();
|
||||
@ -1706,6 +1720,10 @@ public final class Matcher implements MatchResult {
|
||||
this.oldLast = oldLast < 0 ? from : oldLast;
|
||||
for (int i = 0; i < groups.length; i++)
|
||||
groups[i] = -1;
|
||||
for (int i = 0; i < localsPos.length; i++) {
|
||||
if (localsPos[i] != null)
|
||||
localsPos[i].clear();
|
||||
}
|
||||
acceptMode = NOANCHOR;
|
||||
boolean result = parentPattern.root.match(this, from, text);
|
||||
if (!result)
|
||||
@ -1729,6 +1747,10 @@ public final class Matcher implements MatchResult {
|
||||
this.oldLast = oldLast < 0 ? from : oldLast;
|
||||
for (int i = 0; i < groups.length; i++)
|
||||
groups[i] = -1;
|
||||
for (int i = 0; i < localsPos.length; i++) {
|
||||
if (localsPos[i] != null)
|
||||
localsPos[i].clear();
|
||||
}
|
||||
acceptMode = anchor;
|
||||
boolean result = parentPattern.matchRoot.match(this, from, text);
|
||||
if (!result)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.regex;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Pattern.CharPredicate;
|
||||
import java.util.regex.CharPredicates;
|
||||
import static java.util.regex.ASCII.*;
|
||||
|
||||
/**
|
||||
* A utility class to print out the pattern node tree.
|
||||
*/
|
||||
|
||||
class PrintPattern {
|
||||
|
||||
private static HashMap<Pattern.Node, Integer> ids = new HashMap<>();
|
||||
|
||||
private static void print(Pattern.Node node, String text, int depth) {
|
||||
if (!ids.containsKey(node))
|
||||
ids.put(node, ids.size());
|
||||
print("%6d:%" + (depth==0? "": depth<<1) + "s<%s>", ids.get(node), "", text);
|
||||
if (ids.containsKey(node.next))
|
||||
print(" (=>%d)", ids.get(node.next));
|
||||
print("%n");
|
||||
}
|
||||
|
||||
private static void print(String s, int depth) {
|
||||
print(" %" + (depth==0?"":depth<<1) + "s<%s>%n", "", s);
|
||||
}
|
||||
|
||||
private static void print(String fmt, Object ... args) {
|
||||
System.err.printf(fmt, args);
|
||||
}
|
||||
|
||||
private static String toStringCPS(int[] cps) {
|
||||
StringBuilder sb = new StringBuilder(cps.length);
|
||||
for (int cp : cps)
|
||||
sb.append(toStringCP(cp));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String toStringCP(int cp) {
|
||||
return (isPrint(cp) ? "" + (char)cp
|
||||
: "\\u" + Integer.toString(cp, 16));
|
||||
}
|
||||
|
||||
private static String toStringRange(int min, int max) {
|
||||
if (max == Pattern.MAX_REPS) {
|
||||
if (min == 0)
|
||||
return " * ";
|
||||
else if (min == 1)
|
||||
return " + ";
|
||||
return "{" + min + ", max}";
|
||||
}
|
||||
return "{" + min + ", " + max + "}";
|
||||
}
|
||||
|
||||
private static String toStringCtype(int type) {
|
||||
switch(type) {
|
||||
case UPPER: return "ASCII.UPPER";
|
||||
case LOWER: return "ASCII.LOWER";
|
||||
case DIGIT: return "ASCII.DIGIT";
|
||||
case SPACE: return "ASCII.SPACE";
|
||||
case PUNCT: return "ASCII.PUNCT";
|
||||
case CNTRL: return "ASCII.CNTRL";
|
||||
case BLANK: return "ASCII.BLANK";
|
||||
case UNDER: return "ASCII.UNDER";
|
||||
case ASCII: return "ASCII.ASCII";
|
||||
case ALPHA: return "ASCII.ALPHA";
|
||||
case ALNUM: return "ASCII.ALNUM";
|
||||
case GRAPH: return "ASCII.GRAPH";
|
||||
case WORD: return "ASCII.WORD";
|
||||
case XDIGIT: return "ASCII.XDIGIT";
|
||||
default: return "ASCII ?";
|
||||
}
|
||||
}
|
||||
|
||||
private static String toString(Pattern.Node node) {
|
||||
String name = node.getClass().getName();
|
||||
return name.substring(name.lastIndexOf('$') + 1);
|
||||
}
|
||||
|
||||
static HashMap<CharPredicate, String> pmap;
|
||||
static {
|
||||
pmap = new HashMap<>();
|
||||
pmap.put(Pattern.ALL, "All");
|
||||
pmap.put(Pattern.DOT, "Dot");
|
||||
pmap.put(Pattern.UNIXDOT, "UnixDot");
|
||||
pmap.put(Pattern.VertWS, "VertWS");
|
||||
pmap.put(Pattern.HorizWS, "HorizWS");
|
||||
|
||||
pmap.put(CharPredicates.ASCII_DIGIT, "ASCII.DIGIT");
|
||||
pmap.put(CharPredicates.ASCII_WORD, "ASCII.WORD");
|
||||
pmap.put(CharPredicates.ASCII_SPACE, "ASCII.SPACE");
|
||||
}
|
||||
|
||||
static void walk(Pattern.Node node, int depth) {
|
||||
depth++;
|
||||
while(node != null) {
|
||||
String name = toString(node);
|
||||
String str;
|
||||
if (node instanceof Pattern.Prolog) {
|
||||
print(node, name, depth);
|
||||
// print the loop here
|
||||
Pattern.Loop loop = ((Pattern.Prolog)node).loop;
|
||||
name = toString(loop);
|
||||
str = name + " " + toStringRange(loop.cmin, loop.cmax);
|
||||
print(loop, str, depth);
|
||||
walk(loop.body, depth);
|
||||
print("/" + name, depth);
|
||||
node = loop;
|
||||
} else if (node instanceof Pattern.Loop) {
|
||||
return; // stop here, body.next -> loop
|
||||
} else if (node instanceof Pattern.Curly) {
|
||||
Pattern.Curly c = (Pattern.Curly)node;
|
||||
str = "Curly " + c.type + " " + toStringRange(c.cmin, c.cmax);
|
||||
print(node, str, depth);
|
||||
walk(c.atom, depth);
|
||||
print("/Curly", depth);
|
||||
} else if (node instanceof Pattern.GroupCurly) {
|
||||
Pattern.GroupCurly gc = (Pattern.GroupCurly)node;
|
||||
str = "GroupCurly " + gc.groupIndex / 2 +
|
||||
", " + gc.type + " " + toStringRange(gc.cmin, gc.cmax);
|
||||
print(node, str, depth);
|
||||
walk(gc.atom, depth);
|
||||
print("/GroupCurly", depth);
|
||||
} else if (node instanceof Pattern.GroupHead) {
|
||||
Pattern.GroupHead head = (Pattern.GroupHead)node;
|
||||
Pattern.GroupTail tail = head.tail;
|
||||
print(head, "Group.head " + (tail.groupIndex / 2), depth);
|
||||
walk(head.next, depth);
|
||||
print(tail, "/Group.tail " + (tail.groupIndex / 2), depth);
|
||||
node = tail;
|
||||
} else if (node instanceof Pattern.GroupTail) {
|
||||
return; // stopper
|
||||
} else if (node instanceof Pattern.Ques) {
|
||||
print(node, "Ques " + ((Pattern.Ques)node).type, depth);
|
||||
walk(((Pattern.Ques)node).atom, depth);
|
||||
print("/Ques", depth);
|
||||
} else if (node instanceof Pattern.Branch) {
|
||||
Pattern.Branch b = (Pattern.Branch)node;
|
||||
print(b, name, depth);
|
||||
int i = 0;
|
||||
while (true) {
|
||||
if (b.atoms[i] != null) {
|
||||
walk(b.atoms[i], depth);
|
||||
} else {
|
||||
print(" (accepted)", depth);
|
||||
}
|
||||
if (++i == b.size)
|
||||
break;
|
||||
print("-branch.separator-", depth);
|
||||
}
|
||||
node = b.conn;
|
||||
print(node, "/Branch", depth);
|
||||
} else if (node instanceof Pattern.BranchConn) {
|
||||
return;
|
||||
} else if (node instanceof Pattern.CharProperty) {
|
||||
str = pmap.get(((Pattern.CharProperty)node).predicate);
|
||||
if (str == null)
|
||||
str = toString(node);
|
||||
else
|
||||
str = "Single \"" + str + "\"";
|
||||
print(node, str, depth);
|
||||
} else if (node instanceof Pattern.SliceNode) {
|
||||
str = name + " \"" +
|
||||
toStringCPS(((Pattern.SliceNode)node).buffer) + "\"";
|
||||
print(node, str, depth);
|
||||
} else if (node instanceof Pattern.CharPropertyGreedy) {
|
||||
Pattern.CharPropertyGreedy gcp = (Pattern.CharPropertyGreedy)node;
|
||||
String pstr = pmap.get(gcp.predicate);
|
||||
if (pstr == null)
|
||||
pstr = gcp.predicate.toString();
|
||||
else
|
||||
pstr = "Single \"" + pstr + "\"";
|
||||
str = name + " " + pstr + ((gcp.cmin == 0) ? "*" : "+");
|
||||
print(node, str, depth);
|
||||
} else if (node instanceof Pattern.BackRef) {
|
||||
str = "GroupBackRef " + ((Pattern.BackRef)node).groupIndex / 2;
|
||||
print(node, str, depth);
|
||||
} else if (node instanceof Pattern.LastNode) {
|
||||
print(node, "END", depth);
|
||||
} else if (node == Pattern.accept) {
|
||||
return;
|
||||
} else {
|
||||
print(node, name, depth);
|
||||
}
|
||||
node = node.next;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Pattern p = Pattern.compile(args[0]);
|
||||
System.out.println(" Pattern: " + p);
|
||||
walk(p.root, 0);
|
||||
}
|
||||
}
|
@ -1,246 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.util.regex;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
enum UnicodeProp {
|
||||
|
||||
ALPHABETIC {
|
||||
public boolean is(int ch) {
|
||||
return Character.isAlphabetic(ch);
|
||||
}
|
||||
},
|
||||
|
||||
LETTER {
|
||||
public boolean is(int ch) {
|
||||
return Character.isLetter(ch);
|
||||
}
|
||||
},
|
||||
|
||||
IDEOGRAPHIC {
|
||||
public boolean is(int ch) {
|
||||
return Character.isIdeographic(ch);
|
||||
}
|
||||
},
|
||||
|
||||
LOWERCASE {
|
||||
public boolean is(int ch) {
|
||||
return Character.isLowerCase(ch);
|
||||
}
|
||||
},
|
||||
|
||||
UPPERCASE {
|
||||
public boolean is(int ch) {
|
||||
return Character.isUpperCase(ch);
|
||||
}
|
||||
},
|
||||
|
||||
TITLECASE {
|
||||
public boolean is(int ch) {
|
||||
return Character.isTitleCase(ch);
|
||||
}
|
||||
},
|
||||
|
||||
WHITE_SPACE {
|
||||
// \p{Whitespace}
|
||||
public boolean is(int ch) {
|
||||
return ((((1 << Character.SPACE_SEPARATOR) |
|
||||
(1 << Character.LINE_SEPARATOR) |
|
||||
(1 << Character.PARAGRAPH_SEPARATOR)) >> Character.getType(ch)) & 1)
|
||||
!= 0 || (ch >= 0x9 && ch <= 0xd) || (ch == 0x85);
|
||||
}
|
||||
},
|
||||
|
||||
CONTROL {
|
||||
// \p{gc=Control}
|
||||
public boolean is(int ch) {
|
||||
return Character.getType(ch) == Character.CONTROL;
|
||||
}
|
||||
},
|
||||
|
||||
PUNCTUATION {
|
||||
// \p{gc=Punctuation}
|
||||
public boolean is(int ch) {
|
||||
return ((((1 << Character.CONNECTOR_PUNCTUATION) |
|
||||
(1 << Character.DASH_PUNCTUATION) |
|
||||
(1 << Character.START_PUNCTUATION) |
|
||||
(1 << Character.END_PUNCTUATION) |
|
||||
(1 << Character.OTHER_PUNCTUATION) |
|
||||
(1 << Character.INITIAL_QUOTE_PUNCTUATION) |
|
||||
(1 << Character.FINAL_QUOTE_PUNCTUATION)) >> Character.getType(ch)) & 1)
|
||||
!= 0;
|
||||
}
|
||||
},
|
||||
|
||||
HEX_DIGIT {
|
||||
// \p{gc=Decimal_Number}
|
||||
// \p{Hex_Digit} -> PropList.txt: Hex_Digit
|
||||
public boolean is(int ch) {
|
||||
return DIGIT.is(ch) ||
|
||||
(ch >= 0x0030 && ch <= 0x0039) ||
|
||||
(ch >= 0x0041 && ch <= 0x0046) ||
|
||||
(ch >= 0x0061 && ch <= 0x0066) ||
|
||||
(ch >= 0xFF10 && ch <= 0xFF19) ||
|
||||
(ch >= 0xFF21 && ch <= 0xFF26) ||
|
||||
(ch >= 0xFF41 && ch <= 0xFF46);
|
||||
}
|
||||
},
|
||||
|
||||
ASSIGNED {
|
||||
public boolean is(int ch) {
|
||||
return Character.getType(ch) != Character.UNASSIGNED;
|
||||
}
|
||||
},
|
||||
|
||||
NONCHARACTER_CODE_POINT {
|
||||
// PropList.txt:Noncharacter_Code_Point
|
||||
public boolean is(int ch) {
|
||||
return (ch & 0xfffe) == 0xfffe || (ch >= 0xfdd0 && ch <= 0xfdef);
|
||||
}
|
||||
},
|
||||
|
||||
DIGIT {
|
||||
// \p{gc=Decimal_Number}
|
||||
public boolean is(int ch) {
|
||||
return Character.isDigit(ch);
|
||||
}
|
||||
},
|
||||
|
||||
ALNUM {
|
||||
// \p{alpha}
|
||||
// \p{digit}
|
||||
public boolean is(int ch) {
|
||||
return ALPHABETIC.is(ch) || DIGIT.is(ch);
|
||||
}
|
||||
},
|
||||
|
||||
BLANK {
|
||||
// \p{Whitespace} --
|
||||
// [\N{LF} \N{VT} \N{FF} \N{CR} \N{NEL} -> 0xa, 0xb, 0xc, 0xd, 0x85
|
||||
// \p{gc=Line_Separator}
|
||||
// \p{gc=Paragraph_Separator}]
|
||||
public boolean is(int ch) {
|
||||
return Character.getType(ch) == Character.SPACE_SEPARATOR ||
|
||||
ch == 0x9; // \N{HT}
|
||||
}
|
||||
},
|
||||
|
||||
GRAPH {
|
||||
// [^
|
||||
// \p{space}
|
||||
// \p{gc=Control}
|
||||
// \p{gc=Surrogate}
|
||||
// \p{gc=Unassigned}]
|
||||
public boolean is(int ch) {
|
||||
return ((((1 << Character.SPACE_SEPARATOR) |
|
||||
(1 << Character.LINE_SEPARATOR) |
|
||||
(1 << Character.PARAGRAPH_SEPARATOR) |
|
||||
(1 << Character.CONTROL) |
|
||||
(1 << Character.SURROGATE) |
|
||||
(1 << Character.UNASSIGNED)) >> Character.getType(ch)) & 1)
|
||||
== 0;
|
||||
}
|
||||
},
|
||||
|
||||
PRINT {
|
||||
// \p{graph}
|
||||
// \p{blank}
|
||||
// -- \p{cntrl}
|
||||
public boolean is(int ch) {
|
||||
return (GRAPH.is(ch) || BLANK.is(ch)) && !CONTROL.is(ch);
|
||||
}
|
||||
},
|
||||
|
||||
WORD {
|
||||
// \p{alpha}
|
||||
// \p{gc=Mark}
|
||||
// \p{digit}
|
||||
// \p{gc=Connector_Punctuation}
|
||||
// \p{Join_Control} 200C..200D
|
||||
|
||||
public boolean is(int ch) {
|
||||
return ALPHABETIC.is(ch) ||
|
||||
((((1 << Character.NON_SPACING_MARK) |
|
||||
(1 << Character.ENCLOSING_MARK) |
|
||||
(1 << Character.COMBINING_SPACING_MARK) |
|
||||
(1 << Character.DECIMAL_DIGIT_NUMBER) |
|
||||
(1 << Character.CONNECTOR_PUNCTUATION)) >> Character.getType(ch)) & 1)
|
||||
!= 0 ||
|
||||
JOIN_CONTROL.is(ch);
|
||||
}
|
||||
},
|
||||
|
||||
JOIN_CONTROL {
|
||||
// 200C..200D PropList.txt:Join_Control
|
||||
public boolean is(int ch) {
|
||||
return (ch == 0x200C || ch == 0x200D);
|
||||
}
|
||||
};
|
||||
|
||||
private static final HashMap<String, String> posix = new HashMap<>();
|
||||
private static final HashMap<String, String> aliases = new HashMap<>();
|
||||
static {
|
||||
posix.put("ALPHA", "ALPHABETIC");
|
||||
posix.put("LOWER", "LOWERCASE");
|
||||
posix.put("UPPER", "UPPERCASE");
|
||||
posix.put("SPACE", "WHITE_SPACE");
|
||||
posix.put("PUNCT", "PUNCTUATION");
|
||||
posix.put("XDIGIT","HEX_DIGIT");
|
||||
posix.put("ALNUM", "ALNUM");
|
||||
posix.put("CNTRL", "CONTROL");
|
||||
posix.put("DIGIT", "DIGIT");
|
||||
posix.put("BLANK", "BLANK");
|
||||
posix.put("GRAPH", "GRAPH");
|
||||
posix.put("PRINT", "PRINT");
|
||||
|
||||
aliases.put("WHITESPACE", "WHITE_SPACE");
|
||||
aliases.put("HEXDIGIT","HEX_DIGIT");
|
||||
aliases.put("NONCHARACTERCODEPOINT", "NONCHARACTER_CODE_POINT");
|
||||
aliases.put("JOINCONTROL", "JOIN_CONTROL");
|
||||
}
|
||||
|
||||
public static UnicodeProp forName(String propName) {
|
||||
propName = propName.toUpperCase(Locale.ENGLISH);
|
||||
String alias = aliases.get(propName);
|
||||
if (alias != null)
|
||||
propName = alias;
|
||||
try {
|
||||
return valueOf (propName);
|
||||
} catch (IllegalArgumentException x) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static UnicodeProp forPOSIXName(String propName) {
|
||||
propName = posix.get(propName.toUpperCase(Locale.ENGLISH));
|
||||
if (propName == null)
|
||||
return null;
|
||||
return valueOf (propName);
|
||||
}
|
||||
|
||||
public abstract boolean is(int ch);
|
||||
}
|
@ -40,7 +40,7 @@ public class UnsupportedCallbackException extends Exception {
|
||||
private Callback callback;
|
||||
|
||||
/**
|
||||
* Constructs a {@code UnsupportedCallbackException}
|
||||
* Constructs an {@code UnsupportedCallbackException}
|
||||
* with no detail message.
|
||||
*
|
||||
* @param callback the unrecognized {@code Callback}.
|
||||
|
@ -390,10 +390,25 @@ public class VM {
|
||||
private static final int JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT = 0x0020;
|
||||
|
||||
/*
|
||||
* Returns the first non-null class loader up the execution stack,
|
||||
* or null if only code from the null class loader is on the stack.
|
||||
* Returns the first user-defined class loader up the execution stack,
|
||||
* or the platform class loader if only code from the platform or
|
||||
* bootstrap class loader is on the stack.
|
||||
*/
|
||||
public static native ClassLoader latestUserDefinedLoader();
|
||||
public static ClassLoader latestUserDefinedLoader() {
|
||||
ClassLoader loader = latestUserDefinedLoader0();
|
||||
return loader != null ? loader : ClassLoader.getPlatformClassLoader();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the first user-defined class loader up the execution stack,
|
||||
* or null if only code from the platform or bootstrap class loader is
|
||||
* on the stack. VM does not keep a reference of platform loader and so
|
||||
* it returns null.
|
||||
*
|
||||
* This method should be replaced with StackWalker::walk and then we can
|
||||
* remove the logic in the VM.
|
||||
*/
|
||||
private static native ClassLoader latestUserDefinedLoader0();
|
||||
|
||||
/**
|
||||
* Returns {@code true} if we are in a set UID program.
|
||||
|
@ -784,7 +784,7 @@ public abstract class FtpClient implements java.io.Closeable {
|
||||
*
|
||||
* @param path the pathname of the directory to list or {@code null}
|
||||
* for the current working directoty.
|
||||
* @return a {@code Iterator} of files or {@code null} if the
|
||||
* @return an {@code Iterator} of files or {@code null} if the
|
||||
* command failed.
|
||||
* @throws IOException if an error occurred during the transmission
|
||||
* @see #setDirParser(FtpDirParser)
|
||||
|
@ -51,12 +51,9 @@ import static java.security.DrbgParameters.Capability.*;
|
||||
* configuration is eagerly called to set up parameters, and instantiation
|
||||
* is lazily called only when nextBytes or reseed is called.
|
||||
* <p>
|
||||
* Synchronized keyword should be added to all externally callable engine
|
||||
* methods including {@link #engineReseed}, {@link #engineSetSeed}, and
|
||||
* {@link #engineNextBytes} (but not {@link #engineGenerateSeed}).
|
||||
* Internal methods like {@link #configure} and {@link #instantiateAlgorithm}
|
||||
* are not synchronized. They will either be called in a constructor or
|
||||
* in another synchronized method.
|
||||
* SecureRandom methods like reseed and nextBytes are not thread-safe.
|
||||
* An implementation is required to protect shared access to instantiate states
|
||||
* (instantiated, nonce) and DRBG states (v, c, key, reseedCounter).
|
||||
*/
|
||||
public abstract class AbstractDrbg extends SecureRandomSpi {
|
||||
|
||||
@ -78,8 +75,10 @@ public abstract class AbstractDrbg extends SecureRandomSpi {
|
||||
* Reseed counter of a DRBG instance. A mechanism should increment it
|
||||
* after each random bits generation and reset it in reseed. A mechanism
|
||||
* does <em>not</em> need to compare it to {@link #reseedInterval}.
|
||||
*
|
||||
* Volatile, will be used in a double checked locking.
|
||||
*/
|
||||
protected transient int reseedCounter = 0;
|
||||
protected transient volatile int reseedCounter = 0;
|
||||
|
||||
// Mech features. If not same as below, must be redefined in constructor.
|
||||
|
||||
@ -268,10 +267,9 @@ public abstract class AbstractDrbg extends SecureRandomSpi {
|
||||
* {@code DEFAULT_STRENGTH} is 128) for HashDRBG:
|
||||
* <pre>
|
||||
* requested effective
|
||||
* (SHA-1, -1) (SHA-1,128)
|
||||
* (SHA-1, 112) (SHA-1,112)
|
||||
* (SHA-1, 192) IAE
|
||||
* (SHA-224, 256) IAE
|
||||
* (SHA-256, -1) (SHA-256,128)
|
||||
* (SHA-256, 112) (SHA-256,112)
|
||||
* (SHA-256, 128) (SHA-256,128)
|
||||
* (SHA-3, -1) IAE
|
||||
* (null, -1) (SHA-256,128)
|
||||
@ -383,9 +381,14 @@ public abstract class AbstractDrbg extends SecureRandomSpi {
|
||||
instantiateIfNecessary(null);
|
||||
|
||||
// Step 7: Auto reseed
|
||||
// Double checked locking, safe because reseedCounter is volatile
|
||||
if (reseedCounter > reseedInterval || pr) {
|
||||
reseedAlgorithm(getEntropyInput(pr), ai);
|
||||
ai = null;
|
||||
synchronized (this) {
|
||||
if (reseedCounter > reseedInterval || pr) {
|
||||
reseedAlgorithm(getEntropyInput(pr), ai);
|
||||
ai = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 8, 10: Generate_algorithm
|
||||
@ -615,8 +618,7 @@ public abstract class AbstractDrbg extends SecureRandomSpi {
|
||||
* @throws IllegalArgumentException if {@code params} is
|
||||
* inappropriate for this SecureRandom.
|
||||
*/
|
||||
protected final synchronized void configure(
|
||||
SecureRandomParameters params) {
|
||||
protected final void configure(SecureRandomParameters params) {
|
||||
if (debug != null) {
|
||||
debug.println(this, "configure " + this + " with " + params);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user