This commit is contained in:
Alejandro Murillo 2016-05-17 05:38:15 -07:00
commit ffaebaa66e
314 changed files with 8086 additions and 10746 deletions
.hgignore.hgtags.hgtags-top-repo
common
corba
hotspot
.hgtags
src/share/vm/prims
test
jaxp
jaxws
jdk/src

@ -1,5 +1,6 @@
^build/
^dist/
^.idea/
nbproject/private/
^webrev
^.hgtip

@ -360,3 +360,4 @@ c84d0cce090e161d736de69e941830adf8c2f87a jdk-9+114
8d78fb40648dd221ce4ef19f9d5aa41ee1a3a884 jdk-9+115
84aba7335005a3a47751dcf1f37935f97df9f99a jdk-9+116
82b8d12a553f5617737c238cec060281d52e351c jdk-9+117
7c04fcb12bd4a31570a238e663fa846dfa5ec3b8 jdk-9+118

@ -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

@ -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);
}

@ -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,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

@ -95,12 +95,12 @@ class Invokers {
/*non-public*/ MethodHandle varHandleMethodInvoker(VarHandle.AccessMode ak) {
// TODO cache invoker
return makeVarHandleMethodInvoker(ak);
return makeVarHandleMethodInvoker(ak, false);
}
/*non-public*/ MethodHandle varHandleMethodExactInvoker(VarHandle.AccessMode ak) {
// TODO cache invoker
return makeVarHandleMethodExactInvoker(ak);
return makeVarHandleMethodInvoker(ak, true);
}
private MethodHandle cachedInvoker(int idx) {
@ -127,26 +127,11 @@ class Invokers {
return invoker;
}
private MethodHandle makeVarHandleMethodInvoker(VarHandle.AccessMode ak) {
private MethodHandle makeVarHandleMethodInvoker(VarHandle.AccessMode ak, boolean isExact) {
MethodType mtype = targetType;
MethodType invokerType = mtype.insertParameterTypes(0, VarHandle.class);
LambdaForm lform = varHandleMethodGenericInvokerHandleForm(ak.methodName(), mtype);
VarHandle.AccessDescriptor ad = new VarHandle.AccessDescriptor(mtype, ak.at.ordinal(), ak.ordinal());
MethodHandle invoker = BoundMethodHandle.bindSingle(invokerType, lform, ad);
invoker = invoker.withInternalMemberName(MemberName.makeVarHandleMethodInvoke(ak.methodName(), mtype), false);
assert(checkVarHandleInvoker(invoker));
maybeCompileToBytecode(invoker);
return invoker;
}
private MethodHandle makeVarHandleMethodExactInvoker(VarHandle.AccessMode ak) {
MethodType mtype = targetType;
MethodType invokerType = mtype.insertParameterTypes(0, VarHandle.class);
LambdaForm lform = varHandleMethodExactInvokerHandleForm(ak.methodName(), mtype);
LambdaForm lform = varHandleMethodInvokerHandleForm(ak.methodName(), mtype, isExact);
VarHandle.AccessDescriptor ad = new VarHandle.AccessDescriptor(mtype, ak.at.ordinal(), ak.ordinal());
MethodHandle invoker = BoundMethodHandle.bindSingle(invokerType, lform, ad);
@ -400,59 +385,7 @@ class Invokers {
return lform;
}
private static LambdaForm varHandleMethodExactInvokerHandleForm(String name, MethodType mtype) {
// TODO Cache form?
final int THIS_MH = 0;
final int CALL_VH = THIS_MH + 1;
final int ARG_BASE = CALL_VH + 1;
final int ARG_LIMIT = ARG_BASE + mtype.parameterCount();
int nameCursor = ARG_LIMIT;
final int VAD_ARG = nameCursor++;
final int CHECK_TYPE = nameCursor++;
final int GET_MEMBER = nameCursor++;
final int LINKER_CALL = nameCursor++;
MethodType invokerFormType = mtype.insertParameterTypes(0, VarHandle.class)
.basicType()
.appendParameterTypes(MemberName.class);
MemberName linker = new MemberName(MethodHandle.class, "linkToStatic", invokerFormType, REF_invokeStatic);
try {
linker = MemberName.getFactory().resolveOrFail(REF_invokeStatic, linker, null, NoSuchMethodException.class);
} catch (ReflectiveOperationException ex) {
throw newInternalError(ex);
}
Name[] names = new Name[LINKER_CALL + 1];
names[THIS_MH] = argument(THIS_MH, BasicType.basicType(Object.class));
names[CALL_VH] = argument(CALL_VH, BasicType.basicType(Object.class));
for (int i = 0; i < mtype.parameterCount(); i++) {
names[ARG_BASE + i] = argument(ARG_BASE + i, BasicType.basicType(mtype.parameterType(i)));
}
BoundMethodHandle.SpeciesData speciesData = BoundMethodHandle.speciesData_L();
names[THIS_MH] = names[THIS_MH].withConstraint(speciesData);
NamedFunction getter = speciesData.getterFunction(0);
names[VAD_ARG] = new Name(getter, names[THIS_MH]);
Object[] outArgs = Arrays.copyOfRange(names, CALL_VH, ARG_LIMIT + 1, Object[].class);
names[CHECK_TYPE] = new Name(NF_checkVarHandleExactType, names[CALL_VH], names[VAD_ARG]);
names[GET_MEMBER] = new Name(NF_getVarHandleMemberName, names[CALL_VH], names[VAD_ARG]);
outArgs[outArgs.length - 1] = names[GET_MEMBER];
names[LINKER_CALL] = new Name(linker, outArgs);
LambdaForm lform = new LambdaForm(name + ":VarHandle_exactInvoker" + shortenSignature(basicTypeSignature(mtype)),
ARG_LIMIT, names);
lform.compileToBytecode();
return lform;
}
private static LambdaForm varHandleMethodGenericInvokerHandleForm(String name, MethodType mtype) {
private static LambdaForm varHandleMethodInvokerHandleForm(String name, MethodType mtype, boolean isExact) {
// TODO Cache form?
final int THIS_MH = 0;
@ -477,8 +410,11 @@ class Invokers {
NamedFunction getter = speciesData.getterFunction(0);
names[VAD_ARG] = new Name(getter, names[THIS_MH]);
names[CHECK_TYPE] = new Name(NF_checkVarHandleGenericType, names[CALL_VH], names[VAD_ARG]);
if (isExact) {
names[CHECK_TYPE] = new Name(NF_checkVarHandleExactType, names[CALL_VH], names[VAD_ARG]);
} else {
names[CHECK_TYPE] = new Name(NF_checkVarHandleGenericType, names[CALL_VH], names[VAD_ARG]);
}
Object[] outArgs = new Object[ARG_LIMIT];
outArgs[0] = names[CHECK_TYPE];
for (int i = 1; i < ARG_LIMIT; i++) {
@ -488,7 +424,8 @@ class Invokers {
MethodType outCallType = mtype.insertParameterTypes(0, VarHandle.class)
.basicType();
names[LINKER_CALL] = new Name(outCallType, outArgs);
LambdaForm lform = new LambdaForm(name + ":VarHandle_invoker" + shortenSignature(basicTypeSignature(mtype)),
String debugName = isExact ? ":VarHandle_exactInvoker" : ":VarHandle_invoker";
LambdaForm lform = new LambdaForm(name + debugName + shortenSignature(basicTypeSignature(mtype)),
ARG_LIMIT, names);
lform.prepare();
@ -511,21 +448,13 @@ class Invokers {
/*non-public*/ static
@ForceInline
void checkVarHandleExactType(VarHandle handle, VarHandle.AccessDescriptor ad) {
MethodType erasedTarget = handle.vform.methodType_table[ad.type];
MethodType erasedSymbolic = ad.symbolicMethodTypeErased;
if (erasedTarget != erasedSymbolic)
throw newWrongMethodTypeException(erasedTarget, erasedSymbolic);
}
/*non-public*/ static
@ForceInline
MemberName getVarHandleMemberName(VarHandle handle, VarHandle.AccessDescriptor ad) {
MemberName mn = handle.vform.memberName_table[ad.mode];
if (mn == null) {
throw handle.unsupported();
MethodHandle checkVarHandleExactType(VarHandle handle, VarHandle.AccessDescriptor ad) {
MethodHandle mh = handle.getMethodHandle(ad.mode);
MethodType mt = mh.type();
if (mt != ad.symbolicMethodTypeInvoker) {
throw newWrongMethodTypeException(mt, ad.symbolicMethodTypeInvoker);
}
return mn;
return mh;
}
/*non-public*/ static
@ -649,8 +578,7 @@ class Invokers {
NF_getCallSiteTarget,
NF_checkCustomized,
NF_checkVarHandleGenericType,
NF_checkVarHandleExactType,
NF_getVarHandleMemberName;
NF_checkVarHandleExactType;
static {
try {
NamedFunction nfs[] = {
@ -666,8 +594,6 @@ class Invokers {
.getDeclaredMethod("checkVarHandleGenericType", VarHandle.class, VarHandle.AccessDescriptor.class)),
NF_checkVarHandleExactType = new NamedFunction(Invokers.class
.getDeclaredMethod("checkVarHandleExactType", VarHandle.class, VarHandle.AccessDescriptor.class)),
NF_getVarHandleMemberName = new NamedFunction(Invokers.class
.getDeclaredMethod("getVarHandleMemberName", VarHandle.class, VarHandle.AccessDescriptor.class))
};
// Each nf must be statically invocable or we get tied up in our bootstraps.
assert(InvokerBytecodeGenerator.isStaticallyInvocable(nfs));

@ -1475,11 +1475,11 @@ public abstract class VarHandle {
TypesAndInvokers tis = getTypesAndInvokers();
MethodHandle mh = tis.methodHandle_table[mode];
if (mh == null) {
mh = tis.methodHandle_table[mode] = getMethodHandleUncached(tis, mode);
mh = tis.methodHandle_table[mode] = getMethodHandleUncached(mode);
}
return mh;
}
private final MethodHandle getMethodHandleUncached(TypesAndInvokers tis, int mode) {
private final MethodHandle getMethodHandleUncached(int mode) {
MethodType mt = accessModeType(AccessMode.values()[mode]).
insertParameterTypes(0, VarHandle.class);
MemberName mn = vform.getMemberName(mode);

@ -111,7 +111,7 @@ import java.util.Spliterator;
* to zero.
*
*
* <h2> Clearing, flipping, and rewinding </h2>
* <h2> Additional operations </h2>
*
* <p> In addition to methods for accessing the position, limit, and capacity
* values and for marking and resetting, this class also defines the following
@ -131,6 +131,12 @@ import java.util.Spliterator;
* it already contains: It leaves the limit unchanged and sets the position
* to zero. </p></li>
*
* <li><p> {@link #slice} creates a subsequence of a buffer: It leaves the
* limit and the position unchanged. </p></li>
*
* <li><p> {@link #duplicate} creates a shallow copy of a buffer: It leaves
* the limit and the position unchanged. </p></li>
*
* </ul>
*
*
@ -567,6 +573,46 @@ public abstract class Buffer {
*/
public abstract boolean isDirect();
/**
* Creates a new buffer whose content is a shared subsequence of
* this buffer's content.
*
* <p> The content of the new buffer will start at this buffer's current
* position. Changes to this buffer's content will be visible in the new
* buffer, and vice versa; the two buffers' position, limit, and mark
* values will be independent.
*
* <p> The new buffer's position will be zero, its capacity and its limit
* will be the number of elements remaining in this buffer, its mark will be
* undefined. The new buffer will be direct if, and only if, this buffer is
* direct, and it will be read-only if, and only if, this buffer is
* read-only. </p>
*
* @return The new buffer
*
* @since 9
*/
public abstract Buffer slice();
/**
* Creates a new buffer that shares this buffer's content.
*
* <p> The content of the new buffer will be that of this buffer. Changes
* to this buffer's content will be visible in the new buffer, and vice
* versa; the two buffers' position, limit, and mark values will be
* independent.
*
* <p> The new buffer's capacity, limit, position and mark values will be
* identical to those of this buffer. The new buffer will be direct if, and
* only if, this buffer is direct, and it will be read-only if, and only if,
* this buffer is read-only. </p>
*
* @return The new buffer
*
* @since 9
*/
public abstract Buffer duplicate();
// -- Package-private methods for bounds checking, etc. --

@ -70,8 +70,7 @@ import java.util.stream.$Streamtype$Stream;
*
#end[byte]
*
* <li><p> Methods for {@link #compact compacting}, {@link
* #duplicate duplicating}, and {@link #slice slicing}
* <li><p> A method for {@link #compact compacting}
* $a$ $type$ buffer. </p></li>
*
* </ul>
@ -535,6 +534,7 @@ public abstract class $Type$Buffer
* @see #alignedSlice(int)
#end[byte]
*/
@Override
public abstract $Type$Buffer slice();
/**
@ -557,6 +557,7 @@ public abstract class $Type$Buffer
*
* @return The new $type$ buffer
*/
@Override
public abstract $Type$Buffer duplicate();
/**

@ -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

@ -68,13 +68,14 @@ public class ClassLoaders {
if (s != null && s.length() > 0)
bcp = toURLClassPath(s);
// we have a class path if -cp is specified or -m is not specified
// we have a class path if -cp is specified or -m is not specified.
// If neither is specified then default to -cp <working directory>.
URLClassPath ucp = null;
String mainMid = System.getProperty("jdk.module.main");
String cp = System.getProperty("java.class.path");
if (mainMid == null && (cp == null || cp.length() == 0))
cp = ".";
if (cp != null && cp.length() > 0)
if (mainMid == null && cp == null)
cp = "";
if (cp != null)
ucp = toURLClassPath(cp);
@ -197,7 +198,7 @@ public class ClassLoaders {
* @see java.lang.instrument.Instrumentation#appendToSystemClassLoaderSearch
*/
void appendToClassPathForInstrumentation(String path) {
appendToUCP(path, ucp);
addClassPathToUCP(path, ucp);
}
/**
@ -224,7 +225,7 @@ public class ClassLoaders {
*/
private static URLClassPath toURLClassPath(String cp) {
URLClassPath ucp = new URLClassPath(new URL[0]);
appendToUCP(cp, ucp);
addClassPathToUCP(cp, ucp);
return ucp;
}
@ -232,20 +233,28 @@ public class ClassLoaders {
* Converts the elements in the given class path to file URLs and adds
* them to the given URLClassPath.
*/
private static void appendToUCP(String cp, URLClassPath ucp) {
String[] elements = cp.split(File.pathSeparator);
if (elements.length == 0) {
// contains path separator(s) only, default to current directory
// to be compatible with long standing behavior
elements = new String[] { "" };
private static void addClassPathToUCP(String cp, URLClassPath ucp) {
int off = 0;
int next;
while ((next = cp.indexOf(File.pathSeparator, off)) != -1) {
addURLToUCP(cp.substring(off, next), ucp);
off = next + 1;
}
for (String s: elements) {
try {
URL url = Paths.get(s).toRealPath().toUri().toURL();
ucp.addURL(url);
} catch (InvalidPathException | IOException ignore) {
// malformed path string or class path element does not exist
}
// remaining
addURLToUCP(cp.substring(off), ucp);
}
/**
* Attempts to convert to the given string to a file URL and adds it
* to the given URLClassPath.
*/
private static void addURLToUCP(String s, URLClassPath ucp) {
try {
URL url = Paths.get(s).toRealPath().toUri().toURL();
ucp.addURL(url);
} catch (InvalidPathException | IOException ignore) {
// malformed path string or class path element does not exist
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -259,14 +259,10 @@ public class PolicyFile extends java.security.Policy {
private static final Debug debug = Debug.getInstance("policy");
private static final String NONE = "NONE";
private static final String P11KEYSTORE = "PKCS11";
private static final String SELF = "${{self}}";
private static final String X500PRINCIPAL =
"javax.security.auth.x500.X500Principal";
private static final String POLICY = "java.security.policy";
private static final String SECURITY_MANAGER = "java.security.manager";
private static final String POLICY_URL = "policy.url.";
private static final String AUTH_POLICY = "java.security.auth.policy";
private static final String AUTH_POLICY_URL = "auth.policy.url.";
@ -287,6 +283,17 @@ public class PolicyFile extends java.security.Policy {
private static final Class<?>[] PARAMS1 = { String.class };
private static final Class<?>[] PARAMS2 = { String.class, String.class };
/**
* When a policy file has a syntax error, the exception code may generate
* another permission check and this can cause the policy file to be parsed
* repeatedly, leading to a StackOverflowError or ClassCircularityError.
* To avoid this, this set is populated with policy files that have been
* previously parsed and have syntax errors, so that they can be
* subsequently ignored.
*/
private static AtomicReference<Set<URL>> badPolicyURLs =
new AtomicReference<>(new HashSet<>());
/**
* Initializes the Policy object and reads the default policy
* configuration file(s) into the Policy object.
@ -580,6 +587,16 @@ public class PolicyFile extends java.security.Policy {
* @param policyFile the policy Reader object.
*/
private boolean init(URL policy, PolicyInfo newInfo) {
// skip parsing policy file if it has been previously parsed and
// has syntax errors
if (badPolicyURLs.get().contains(policy)) {
if (debug != null) {
debug.println("skipping bad policy file: " + policy);
}
return false;
}
boolean success = false;
PolicyParser pp = new PolicyParser(expandProperties);
InputStreamReader isr = null;
@ -622,13 +639,18 @@ public class PolicyFile extends java.security.Policy {
addGrantEntry(ge, keyStore, newInfo);
}
} catch (PolicyParser.ParsingException pe) {
// record bad policy file to avoid later reparsing it
badPolicyURLs.updateAndGet(k -> {
k.add(policy);
return k;
});
MessageFormat form = new MessageFormat(ResourcesMgr.getString
(POLICY + ".error.parsing.policy.message"));
Object[] source = {policy, pe.getLocalizedMessage()};
System.err.println(form.format(source));
if (debug != null)
if (debug != null) {
pe.printStackTrace();
}
} catch (Exception e) {
if (debug != null) {
debug.println("error parsing "+policy);

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -213,7 +213,9 @@ public class PolicyParser {
new MessageFormat(ResourcesMgr.getString(
"duplicate.keystore.domain.name"));
Object[] source = {domainName};
throw new ParsingException(form.format(source));
String msg = "duplicate keystore domain name: " +
domainName;
throw new ParsingException(msg, form, source);
}
}
} else {
@ -743,7 +745,8 @@ public class PolicyParser {
ResourcesMgr.getString
("expected.expect.read.end.of.file."));
Object[] source = {expect};
throw new ParsingException(form.format(source));
String msg = "expected [" + expect + "], read [end of file]";
throw new ParsingException(msg, form, source);
case StreamTokenizer.TT_WORD:
if (expect.equalsIgnoreCase(st.sval)) {
lookahead = st.nextToken();
@ -1244,7 +1247,8 @@ public class PolicyParser {
MessageFormat form = new MessageFormat(ResourcesMgr.getString(
"duplicate.keystore.name"));
Object[] source = {keystoreName};
throw new ParsingException(form.format(source));
String msg = "duplicate keystore name: " + keystoreName;
throw new ParsingException(msg, form, source);
}
}
@ -1316,6 +1320,8 @@ public class PolicyParser {
private static final long serialVersionUID = -4330692689482574072L;
private String i18nMessage;
private MessageFormat form;
private Object[] source;
/**
* Constructs a ParsingException with the specified
@ -1330,26 +1336,34 @@ public class PolicyParser {
i18nMessage = msg;
}
public ParsingException(String msg, MessageFormat form,
Object[] source) {
super(msg);
this.form = form;
this.source = source;
}
public ParsingException(int line, String msg) {
super("line " + line + ": " + msg);
MessageFormat form = new MessageFormat
(ResourcesMgr.getString("line.number.msg"));
Object[] source = {line, msg};
i18nMessage = form.format(source);
// don't call form.format unless getLocalizedMessage is called
// to avoid unnecessary permission checks
form = new MessageFormat(ResourcesMgr.getString("line.number.msg"));
source = new Object[] {line, msg};
}
public ParsingException(int line, String expect, String actual) {
super("line " + line + ": expected [" + expect +
"], found [" + actual + "]");
MessageFormat form = new MessageFormat(ResourcesMgr.getString
// don't call form.format unless getLocalizedMessage is called
// to avoid unnecessary permission checks
form = new MessageFormat(ResourcesMgr.getString
("line.number.expected.expect.found.actual."));
Object[] source = {line, expect, actual};
i18nMessage = form.format(source);
source = new Object[] {line, expect, actual};
}
@Override
public String getLocalizedMessage() {
return i18nMessage;
return i18nMessage != null ? i18nMessage : form.format(source);
}
}

@ -35,6 +35,7 @@ import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Iterator;
@ -155,6 +156,15 @@ class HttpClientImpl extends HttpClient implements BufferHandler {
selmgr.register(exchange);
}
/**
* Only used from RawChannel to disconnect the channel from
* the selector
*/
void cancelRegistration(SocketChannel s) {
selmgr.cancel(s);
}
Http2ClientImpl client2() {
return client2;
}
@ -220,6 +230,13 @@ class HttpClientImpl extends HttpClient implements BufferHandler {
selector.wakeup();
}
synchronized void cancel(SocketChannel e) {
SelectionKey key = e.keyFor(selector);
if (key != null)
key.cancel();
selector.wakeup();
}
void wakeupSelector() {
selector.wakeup();
}

@ -176,7 +176,7 @@ class HttpResponseImpl extends HttpResponse {
*
* @return
*/
RawChannel rawChannel() {
RawChannel rawChannel() throws IOException {
if (rawchan == null) {
rawchan = new RawChannel(request.client(), connection);
}

@ -29,6 +29,7 @@ import java.nio.channels.ByteChannel;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
//
// Used to implement WebSocket. Each RawChannel corresponds to a TCP connection
@ -56,9 +57,21 @@ final class RawChannel implements ByteChannel, GatheringByteChannel {
interface NonBlockingEvent extends RawEvent {
}
RawChannel(HttpClientImpl client, HttpConnection connection) {
RawChannel(HttpClientImpl client, HttpConnection connection)
throws IOException {
this.client = client;
this.connection = connection;
SocketChannel chan = connection.channel();
client.cancelRegistration(chan);
chan.configureBlocking(false);
}
SocketChannel socketChannel() {
return connection.channel();
}
ByteBuffer getRemaining() {
return connection.getRemaining();
}
private class RawAsyncEvent extends AsyncEvent {

@ -24,6 +24,8 @@
*/
package java.net.http;
import java.io.UncheckedIOException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
@ -126,6 +128,8 @@ final class WSOpeningHandshake {
return CompletableFuture.completedFuture(result);
} catch (WebSocketHandshakeException e) {
return CompletableFuture.failedFuture(e);
} catch (UncheckedIOException ee) {
return CompletableFuture.failedFuture(ee.getCause());
}
});
}
@ -149,7 +153,12 @@ final class WSOpeningHandshake {
checkAccept(response, h);
checkExtensions(response, h);
String subprotocol = checkAndReturnSubprotocol(response, h);
RawChannel channel = ((HttpResponseImpl) response).rawChannel();
RawChannel channel = null;
try {
channel = ((HttpResponseImpl) response).rawChannel();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return new Result(subprotocol, channel);
}

@ -34,11 +34,9 @@ import java.util.Objects;
import java.util.Set;
import jdk.tools.jlink.internal.JlinkTask;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.PluginContext;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.builder.ImageBuilder;
import jdk.tools.jlink.internal.PluginContextImpl;
import jdk.tools.jlink.internal.PluginRepository;
/**
@ -71,7 +69,6 @@ public final class Jlink {
private final List<Plugin> plugins;
private final ImageBuilder imageBuilder;
private final String lastSorterPluginName;
private final PluginContext pluginContext;
/**
* Empty plugins configuration.
@ -86,7 +83,7 @@ public final class Jlink {
* @param plugins List of plugins.
*/
public PluginsConfiguration(List<Plugin> plugins) {
this(plugins, null, null, null);
this(plugins, null, null);
}
/**
@ -101,28 +98,10 @@ public final class Jlink {
*/
public PluginsConfiguration(List<Plugin> plugins,
ImageBuilder imageBuilder, String lastSorterPluginName) {
this(plugins, imageBuilder, lastSorterPluginName, null);
}
/**
* Plugins configuration with a last sorter and an ImageBuilder. No
* sorting can occur after the last sorter plugin. The ImageBuilder is
* in charge to layout the image content on disk.
*
* @param plugins List of transformer plugins.
* @param imageBuilder Image builder.
* @param lastSorterPluginName Name of last sorter plugin, no sorting
* @param ctx the plugin context
* can occur after it.
*/
public PluginsConfiguration(List<Plugin> plugins,
ImageBuilder imageBuilder, String lastSorterPluginName,
PluginContext ctx) {
this.plugins = plugins == null ? Collections.emptyList()
: plugins;
this.imageBuilder = imageBuilder;
this.lastSorterPluginName = lastSorterPluginName;
this.pluginContext = ctx != null? ctx : new PluginContextImpl();
}
/**
@ -146,13 +125,6 @@ public final class Jlink {
return lastSorterPluginName;
}
/**
* @return the pluginContext
*/
public PluginContext getPluginContext() {
return pluginContext;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();

@ -1,3 +1,4 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@ -24,8 +25,6 @@
*/
package jdk.tools.jlink.builder;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.plugin.PluginException;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
@ -47,8 +46,10 @@ import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
@ -56,23 +57,40 @@ import java.util.Set;
import jdk.tools.jlink.internal.BasicImageWriter;
import jdk.tools.jlink.internal.plugins.FileCopierPlugin;
import jdk.tools.jlink.internal.plugins.FileCopierPlugin.SymImageFile;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.Module;
import jdk.tools.jlink.plugin.Pool.ModuleData;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
/**
*
* Default Image Builder. This builder creates the default runtime image layout.
*/
public class DefaultImageBuilder implements ImageBuilder {
public final class DefaultImageBuilder implements ImageBuilder {
/**
* The default java executable Image.
*/
static class DefaultExecutableImage extends ExecutableImage {
static final class DefaultExecutableImage implements ExecutableImage {
private final Path home;
private final List<String> args;
private final Set<String> modules;
public DefaultExecutableImage(Path home, Set<String> modules) {
super(home, modules, createArgs(home));
this(home, modules, createArgs(home));
}
private DefaultExecutableImage(Path home, Set<String> modules,
List<String> args) {
Objects.requireNonNull(home);
Objects.requireNonNull(args);
if (!Files.exists(home)) {
throw new IllegalArgumentException("Invalid image home");
}
this.home = home;
this.modules = Collections.unmodifiableSet(modules);
this.args = Collections.unmodifiableList(args);
}
private static List<String> createArgs(Path home) {
@ -83,6 +101,21 @@ public class DefaultImageBuilder implements ImageBuilder {
return javaArgs;
}
@Override
public Path getHome() {
return home;
}
@Override
public Set<String> getModules() {
return modules;
}
@Override
public List<String> getExecutionArgs() {
return args;
}
@Override
public void storeLaunchArgs(List<String> args) {
try {
@ -111,17 +144,19 @@ public class DefaultImageBuilder implements ImageBuilder {
Files.createDirectories(mdir);
}
private void storeFiles(Set<String> modules, Properties release) throws IOException {
private void storeFiles(Set<String> modules, Map<String, String> release) throws IOException {
if (release != null) {
addModules(release, modules);
Properties props = new Properties();
props.putAll(release);
addModules(props, modules);
File r = new File(root.toFile(), "release");
try (FileOutputStream fo = new FileOutputStream(r)) {
release.store(fo, null);
props.store(fo, null);
}
}
}
private void addModules(Properties release, Set<String> modules) throws IOException {
private void addModules(Properties props, Set<String> modules) throws IOException {
StringBuilder builder = new StringBuilder();
int i = 0;
for (String m : modules) {
@ -131,28 +166,32 @@ public class DefaultImageBuilder implements ImageBuilder {
}
i++;
}
release.setProperty("MODULES", builder.toString());
props.setProperty("MODULES", builder.toString());
}
@Override
public void storeFiles(Pool files, Properties release) {
public void storeFiles(ModulePool files) {
try {
for (ModuleData f : files.getContent()) {
if (!f.getType().equals(Pool.ModuleDataType.CLASS_OR_RESOURCE)) {
accept(f);
files.entries().forEach(f -> {
if (!f.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
try {
accept(f);
} catch (IOException ioExp) {
throw new UncheckedIOException(ioExp);
}
}
}
for (Module m : files.getModules()) {
});
files.modules().forEach(m -> {
// Only add modules that contain packages
if (!m.getAllPackages().isEmpty()) {
// Skip the fake module used by FileCopierPlugin when copying files.
if (m.getName().equals(FileCopierPlugin.FAKE_MODULE)) {
continue;
return;
}
modules.add(m.getName());
}
}
storeFiles(modules, release);
});
storeFiles(modules, files.getReleaseProperties());
if (Files.getFileStore(root).supportsFileAttributeView(PosixFileAttributeView.class)) {
// launchers in the bin directory need execute permission
@ -168,8 +207,8 @@ public class DefaultImageBuilder implements ImageBuilder {
Path lib = root.resolve("lib");
if (Files.isDirectory(lib)) {
Files.find(lib, 2, (path, attrs) -> {
return path.getFileName().toString().equals("jspawnhelper") ||
path.getFileName().toString().equals("jexec");
return path.getFileName().toString().equals("jspawnhelper")
|| path.getFileName().toString().equals("jexec");
}).forEach(this::setExecutable);
}
}
@ -180,27 +219,23 @@ public class DefaultImageBuilder implements ImageBuilder {
}
}
@Override
public void storeFiles(Pool files) {
storeFiles(files, new Properties());
}
/**
* Generates launcher scripts.
*
* @param imageContent The image content.
* @param modules The set of modules that the runtime image contains.
* @throws IOException
*/
protected void prepareApplicationFiles(Pool imageContent, Set<String> modules) throws IOException {
protected void prepareApplicationFiles(ModulePool imageContent, Set<String> modules) throws IOException {
// generate launch scripts for the modules with a main class
for (String module : modules) {
String path = "/" + module + "/module-info.class";
ModuleData res = imageContent.get(path);
if (res == null) {
Optional<ModuleEntry> res = imageContent.findEntry(path);
if (!res.isPresent()) {
throw new IOException("module-info.class not found for " + module + " module");
}
Optional<String> mainClass;
ByteArrayInputStream stream = new ByteArrayInputStream(res.getBytes());
ByteArrayInputStream stream = new ByteArrayInputStream(res.get().getBytes());
mainClass = ModuleDescriptor.read(stream).mainClass();
if (mainClass.isPresent()) {
Path cmd = root.resolve("bin").resolve(module);
@ -263,9 +298,9 @@ public class DefaultImageBuilder implements ImageBuilder {
}
}
private void accept(ModuleData file) throws IOException {
private void accept(ModuleEntry file) throws IOException {
String fullPath = file.getPath();
String module = "/" + file.getModule()+ "/";
String module = "/" + file.getModule() + "/";
String filename = fullPath.substring(module.length());
// Remove radical native|config|...
filename = filename.substring(filename.indexOf('/') + 1);
@ -404,8 +439,7 @@ public class DefaultImageBuilder implements ImageBuilder {
public static ExecutableImage getExecutableImage(Path root) {
if (Files.exists(root.resolve("bin").resolve(getJavaProcessName()))) {
return new DefaultImageBuilder.DefaultExecutableImage(root,
retrieveModules(root));
return new DefaultExecutableImage(root, retrieveModules(root));
}
return null;
}

@ -29,7 +29,7 @@ import java.util.Properties;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.ModulePool;
/**
* Implement this interface to develop your own image layout. First the jimage
@ -45,7 +45,7 @@ public interface ImageBuilder {
* @param release the release properties
* @throws PluginException
*/
public default void storeFiles(Pool content, Properties release) {
public default void storeFiles(ModulePool content, Properties release) {
storeFiles(content);
}
@ -55,7 +55,7 @@ public interface ImageBuilder {
* @param content Pool of module content.
* @throws PluginException
*/
public default void storeFiles(Pool content) {
public default void storeFiles(ModulePool content) {
throw new UnsupportedOperationException("storeFiles");
}

@ -44,12 +44,11 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import jdk.tools.jlink.internal.Archive.Entry;
import jdk.tools.jlink.internal.Archive.Entry.EntryType;
import jdk.tools.jlink.internal.PoolImpl.CompressedModuleData;
import jdk.tools.jlink.internal.ModulePoolImpl.CompressedModuleData;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleData;
import jdk.tools.jlink.plugin.Pool.ModuleDataType;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.ModuleEntry;
/**
* An image (native endian.)
@ -145,7 +144,7 @@ public final class ImageFileCreator {
}));
ByteOrder order = ByteOrder.nativeOrder();
BasicImageWriter writer = new BasicImageWriter(order);
PoolImpl pool = createPools(archives, entriesForModule, order, writer);
ModulePoolImpl pool = createPools(archives, entriesForModule, order, writer);
try (OutputStream fos = Files.newOutputStream(jimageFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
DataOutputStream out = new DataOutputStream(bos)) {
@ -163,9 +162,9 @@ public final class ImageFileCreator {
ByteOrder byteOrder)
throws IOException {
BasicImageWriter writer = new BasicImageWriter(byteOrder);
PoolImpl allContent = createPools(archives,
ModulePoolImpl allContent = createPools(archives,
entriesForModule, byteOrder, writer);
PoolImpl result = generateJImage(allContent,
ModulePoolImpl result = generateJImage(allContent,
writer, plugins, plugins.getJImageFileOutputStream());
//Handle files.
@ -176,12 +175,12 @@ public final class ImageFileCreator {
}
}
private static PoolImpl generateJImage(PoolImpl allContent,
private static ModulePoolImpl generateJImage(ModulePoolImpl allContent,
BasicImageWriter writer,
ImagePluginStack pluginSupport,
DataOutputStream out
) throws IOException {
PoolImpl resultResources;
ModulePoolImpl resultResources;
try {
resultResources = pluginSupport.visitResources(allContent);
} catch (PluginException pe) {
@ -190,14 +189,14 @@ public final class ImageFileCreator {
throw new IOException(ex);
}
Set<String> duplicates = new HashSet<>();
long offset = 0;
long[] offset = new long[1];
List<ModuleData> content = new ArrayList<>();
List<ModuleEntry> content = new ArrayList<>();
List<String> paths = new ArrayList<>();
// the order of traversing the resources and the order of
// the module content being written must be the same
for (ModuleData res : resultResources.getContent()) {
if (res.getType().equals(ModuleDataType.CLASS_OR_RESOURCE)) {
resultResources.entries().forEach(res -> {
if (res.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
String path = res.getPath();
content.add(res);
long uncompressedSize = res.getLength();
@ -216,24 +215,24 @@ public final class ImageFileCreator {
// TODO Need to hang bytes on resource and write
// from resource not zip.
// Skipping resource throws off writing from zip.
offset += onFileSize;
continue;
offset[0] += onFileSize;
return;
}
duplicates.add(path);
writer.addLocation(path, offset, compressedSize, uncompressedSize);
writer.addLocation(path, offset[0], compressedSize, uncompressedSize);
paths.add(path);
offset += onFileSize;
offset[0] += onFileSize;
}
}
});
ImageResourcesTree tree = new ImageResourcesTree(offset, writer, paths);
ImageResourcesTree tree = new ImageResourcesTree(offset[0], writer, paths);
// write header and indices
byte[] bytes = writer.getBytes();
out.write(bytes, 0, bytes.length);
// write module content
for (ModuleData res : content) {
for (ModuleEntry res : content) {
byte[] buf = res.getBytes();
out.write(buf, 0, buf.length);
}
@ -245,26 +244,26 @@ public final class ImageFileCreator {
return resultResources;
}
private static Pool.ModuleDataType mapImageFileType(EntryType type) {
private static ModuleEntry.Type mapImageFileType(EntryType type) {
switch(type) {
case CONFIG: {
return Pool.ModuleDataType.CONFIG;
return ModuleEntry.Type.CONFIG;
}
case NATIVE_CMD: {
return Pool.ModuleDataType.NATIVE_CMD;
return ModuleEntry.Type.NATIVE_CMD;
}
case NATIVE_LIB: {
return Pool.ModuleDataType.NATIVE_LIB;
return ModuleEntry.Type.NATIVE_LIB;
}
}
return null;
}
private static PoolImpl createPools(Set<Archive> archives,
private static ModulePoolImpl createPools(Set<Archive> archives,
Map<String, List<Entry>> entriesForModule,
ByteOrder byteOrder,
BasicImageWriter writer) throws IOException {
PoolImpl resources = new PoolImpl(byteOrder, new StringTable() {
ModulePoolImpl resources = new ModulePoolImpl(byteOrder, new StringTable() {
@Override
public int addString(String str) {
@ -291,7 +290,7 @@ public final class ImageFileCreator {
path = "/" + mn + "/" + path;
}
try {
resources.add(Pool.newResource(path, bytes));
resources.add(ModuleEntry.create(path, bytes));
} catch (Exception ex) {
throw new IOException(ex);
}
@ -300,7 +299,7 @@ public final class ImageFileCreator {
try {
// Entry.path() contains the kind of file native, conf, bin, ...
// Keep it to avoid naming conflict (eg: native/jvm.cfg and config/jvm.cfg
resources.add(Pool.newImageFile(mn,
resources.add(ModuleEntry.create(mn,
"/" + mn + "/" + entry.path(), mapImageFileType(entry.type()),
entry.stream(), entry.size()));
} catch (Exception ex) {

@ -28,22 +28,17 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Properties;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.builder.ImageBuilder;
import jdk.tools.jlink.Jlink;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.PluginContext;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Plugin.CATEGORY;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Plugin.Category;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.PostProcessorPlugin;
import jdk.tools.jlink.plugin.TransformerPlugin;
@ -52,17 +47,18 @@ import jdk.tools.jlink.plugin.TransformerPlugin;
*/
public final class ImagePluginConfiguration {
private static final List<Plugin.CATEGORY> CATEGORIES_ORDER = new ArrayList<>();
private static final List<Plugin.Category> CATEGORIES_ORDER = new ArrayList<>();
static {
CATEGORIES_ORDER.add(Plugin.CATEGORY.FILTER);
CATEGORIES_ORDER.add(Plugin.CATEGORY.TRANSFORMER);
CATEGORIES_ORDER.add(Plugin.CATEGORY.MODULEINFO_TRANSFORMER);
CATEGORIES_ORDER.add(Plugin.CATEGORY.SORTER);
CATEGORIES_ORDER.add(Plugin.CATEGORY.COMPRESSOR);
CATEGORIES_ORDER.add(Plugin.CATEGORY.VERIFIER);
CATEGORIES_ORDER.add(Plugin.CATEGORY.PROCESSOR);
CATEGORIES_ORDER.add(Plugin.CATEGORY.PACKAGER);
CATEGORIES_ORDER.add(Plugin.Category.FILTER);
CATEGORIES_ORDER.add(Plugin.Category.TRANSFORMER);
CATEGORIES_ORDER.add(Plugin.Category.MODULEINFO_TRANSFORMER);
CATEGORIES_ORDER.add(Plugin.Category.SORTER);
CATEGORIES_ORDER.add(Plugin.Category.COMPRESSOR);
CATEGORIES_ORDER.add(Plugin.Category.METAINFO_ADDER);
CATEGORIES_ORDER.add(Plugin.Category.VERIFIER);
CATEGORIES_ORDER.add(Plugin.Category.PROCESSOR);
CATEGORIES_ORDER.add(Plugin.Category.PACKAGER);
}
private ImagePluginConfiguration() {
@ -76,8 +72,8 @@ public final class ImagePluginConfiguration {
if (pluginsConfiguration == null) {
return new ImagePluginStack();
}
Map<Plugin.CATEGORY, List<Plugin>> plugins = new LinkedHashMap<>();
for (Plugin.CATEGORY cat : CATEGORIES_ORDER) {
Map<Plugin.Category, List<Plugin>> plugins = new LinkedHashMap<>();
for (Plugin.Category cat : CATEGORIES_ORDER) {
plugins.put(cat, new ArrayList<>());
}
@ -89,7 +85,7 @@ public final class ImagePluginConfiguration {
+ " added more than once to stack ");
}
seen.add(plug.getName());
CATEGORY category = Utils.getCategory(plug);
Category category = Utils.getCategory(plug);
if (category == null) {
throw new PluginException("Invalid category for "
+ plug.getName());
@ -100,10 +96,10 @@ public final class ImagePluginConfiguration {
List<TransformerPlugin> transformerPlugins = new ArrayList<>();
List<PostProcessorPlugin> postProcessingPlugins = new ArrayList<>();
for (Entry<Plugin.CATEGORY, List<Plugin>> entry : plugins.entrySet()) {
for (Entry<Plugin.Category, List<Plugin>> entry : plugins.entrySet()) {
// Sort according to plugin constraints
List<Plugin> orderedPlugins = PluginOrderingGraph.sort(entry.getValue());
CATEGORY category = entry.getKey();
Category category = entry.getKey();
for (Plugin p : orderedPlugins) {
if (Utils.isPostProcessor(category)) {
@SuppressWarnings("unchecked")
@ -143,14 +139,13 @@ public final class ImagePluginConfiguration {
}
@Override
public void storeFiles(Pool files) {
public void storeFiles(ModulePool files) {
throw new PluginException("No directory setup to store files");
}
};
}
PluginContext ctxt = pluginsConfiguration.getPluginContext();
return new ImagePluginStack(builder, transformerPlugins,
lastSorter, postProcessingPlugins, ctxt);
lastSorter, postProcessingPlugins);
}
}

@ -37,20 +37,21 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jdk.internal.jimage.decompressor.Decompressor;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.PluginContext;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.builder.ImageBuilder;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleData;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.LinkModule;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PostProcessorPlugin;
/**
@ -64,9 +65,9 @@ public final class ImagePluginStack {
ExecutableImage retrieve(ImagePluginStack stack) throws IOException;
}
public static final class OrderedResourcePool extends PoolImpl {
public static final class OrderedResourcePool extends ModulePoolImpl {
private final List<ModuleData> orderedList = new ArrayList<>();
private final List<ModuleEntry> orderedList = new ArrayList<>();
public OrderedResourcePool(ByteOrder order, StringTable table) {
super(order, table);
@ -78,22 +79,22 @@ public final class ImagePluginStack {
* @param resource The Resource to add.
*/
@Override
public void add(ModuleData resource) {
public void add(ModuleEntry resource) {
super.add(resource);
orderedList.add(resource);
}
List<ModuleData> getOrderedList() {
List<ModuleEntry> getOrderedList() {
return Collections.unmodifiableList(orderedList);
}
}
private final static class CheckOrderResourcePool extends PoolImpl {
private final static class CheckOrderResourcePool extends ModulePoolImpl {
private final List<ModuleData> orderedList;
private final List<ModuleEntry> orderedList;
private int currentIndex;
public CheckOrderResourcePool(ByteOrder order, List<ModuleData> orderedList, StringTable table) {
public CheckOrderResourcePool(ByteOrder order, List<ModuleEntry> orderedList, StringTable table) {
super(order, table);
this.orderedList = orderedList;
}
@ -104,8 +105,8 @@ public final class ImagePluginStack {
* @param resource The Resource to add.
*/
@Override
public void add(ModuleData resource) {
ModuleData ordered = orderedList.get(currentIndex);
public void add(ModuleEntry resource) {
ModuleEntry ordered = orderedList.get(currentIndex);
if (!resource.equals(ordered)) {
throw new PluginException("Resource " + resource.getPath() + " not in the right order");
}
@ -166,26 +167,16 @@ public final class ImagePluginStack {
private final List<ResourcePrevisitor> resourcePrevisitors = new ArrayList<>();
private final ImageBuilder imageBuilder;
private final Properties release;
public ImagePluginStack() {
this(null, Collections.emptyList(), null,
Collections.emptyList(), null);
Collections.emptyList());
}
public ImagePluginStack(ImageBuilder imageBuilder,
List<TransformerPlugin> contentPlugins,
Plugin lastSorter,
List<PostProcessorPlugin> postprocessingPlugins) {
this(imageBuilder, contentPlugins, lastSorter,
postprocessingPlugins, null);
}
public ImagePluginStack(ImageBuilder imageBuilder,
List<TransformerPlugin> contentPlugins,
Plugin lastSorter,
List<PostProcessorPlugin> postprocessingPlugins,
PluginContext ctxt) {
Objects.requireNonNull(contentPlugins);
this.lastSorter = lastSorter;
for (TransformerPlugin p : contentPlugins) {
@ -200,7 +191,6 @@ public final class ImagePluginStack {
this.postProcessingPlugins.add(p);
}
this.imageBuilder = imageBuilder;
this.release = ctxt != null? ctxt.getReleaseProperties() : new Properties();
}
public void operate(ImageProvider provider) throws Exception {
@ -231,12 +221,12 @@ public final class ImagePluginStack {
* @return The result of the visit.
* @throws IOException
*/
public PoolImpl visitResources(PoolImpl resources)
public ModulePoolImpl visitResources(ModulePoolImpl resources)
throws Exception {
Objects.requireNonNull(resources);
resources.setReadOnly();
if (resources.isEmpty()) {
return new PoolImpl(resources.getByteOrder(),
return new ModulePoolImpl(resources.getByteOrder(),
resources.getStringTable());
}
PreVisitStrings previsit = new PreVisitStrings();
@ -250,11 +240,11 @@ public final class ImagePluginStack {
resources.getStringTable().addString(s);
}
PoolImpl current = resources;
List<Pool.ModuleData> frozenOrder = null;
ModulePoolImpl current = resources;
List<ModuleEntry> frozenOrder = null;
for (TransformerPlugin p : contentPlugins) {
current.setReadOnly();
PoolImpl output = null;
ModulePoolImpl output = null;
if (p == lastSorter) {
if (frozenOrder != null) {
throw new Exception("Order of resources is already frozen. Plugin "
@ -268,7 +258,7 @@ public final class ImagePluginStack {
output = new CheckOrderResourcePool(current.getByteOrder(),
frozenOrder, resources.getStringTable());
} else {
output = new PoolImpl(current.getByteOrder(),
output = new ModulePoolImpl(current.getByteOrder(),
resources.getStringTable());
}
}
@ -287,15 +277,15 @@ public final class ImagePluginStack {
}
/**
* This pool wrap the original pool and automatically uncompress moduledata
* This pool wrap the original pool and automatically uncompress ModuleEntry
* if needed.
*/
private class LastPool extends Pool {
private class LastModule implements Module {
private class LastPool implements ModulePool {
private class LastModule implements LinkModule {
private final Module module;
final LinkModule module;
LastModule(Module module) {
LastModule(LinkModule module) {
this.module = module;
}
@ -305,9 +295,9 @@ public final class ImagePluginStack {
}
@Override
public ModuleData get(String path) {
ModuleData d = module.get(path);
return getUncompressed(d);
public Optional<ModuleEntry> findEntry(String path) {
Optional<ModuleEntry> d = module.findEntry(path);
return d.isPresent()? Optional.of(getUncompressed(d.get())) : Optional.empty();
}
@Override
@ -316,7 +306,7 @@ public final class ImagePluginStack {
}
@Override
public void add(ModuleData data) {
public void add(ModuleEntry data) {
throw new PluginException("pool is readonly");
}
@ -331,19 +321,24 @@ public final class ImagePluginStack {
}
@Override
public Collection<ModuleData> getContent() {
List<ModuleData> lst = new ArrayList<>();
for(ModuleData md : module.getContent()) {
public Stream<ModuleEntry> entries() {
List<ModuleEntry> lst = new ArrayList<>();
module.entries().forEach(md -> {
lst.add(getUncompressed(md));
}
return lst;
});
return lst.stream();
}
@Override
public int getEntryCount() {
return module.getEntryCount();
}
}
private final PoolImpl pool;
private final ModulePoolImpl pool;
Decompressor decompressor = new Decompressor();
Collection<ModuleData> content;
Collection<ModuleEntry> content;
LastPool(PoolImpl pool) {
LastPool(ModulePoolImpl pool) {
this.pool = pool;
}
@ -353,23 +348,14 @@ public final class ImagePluginStack {
}
@Override
public void add(ModuleData resource) {
public void add(ModuleEntry resource) {
throw new PluginException("pool is readonly");
}
/**
* Retrieves the module of the provided name.
*
* @param name The module name
* @return the module or null if the module doesn't exist.
*/
@Override
public Module getModule(String name) {
Module module = pool.getModule(name);
if (module != null) {
module = new LastModule(module);
}
return module;
public Optional<LinkModule> findModule(String name) {
Optional<LinkModule> module = pool.findModule(name);
return module.isPresent()? Optional.of(new LastModule(module.get())) : Optional.empty();
}
/**
@ -378,45 +364,55 @@ public final class ImagePluginStack {
* @return The collection of modules.
*/
@Override
public Collection<Module> getModules() {
List<Module> modules = new ArrayList<>();
for (Module m : pool.getModules()) {
public Stream<? extends LinkModule> modules() {
List<LinkModule> modules = new ArrayList<>();
pool.modules().forEach(m -> {
modules.add(new LastModule(m));
}
return modules;
});
return modules.stream();
}
@Override
public int getModuleCount() {
return pool.getModuleCount();
}
/**
* Get all resources contained in this pool instance.
*
* @return The collection of resources;
* @return The stream of resources;
*/
@Override
public Collection<ModuleData> getContent() {
public Stream<? extends ModuleEntry> entries() {
if (content == null) {
content = new ArrayList<>();
for (ModuleData md : pool.getContent()) {
pool.entries().forEach(md -> {
content.add(getUncompressed(md));
}
});
}
return content;
return content.stream();
}
@Override
public int getEntryCount() {
return pool.getEntryCount();
}
/**
* Get the resource for the passed path.
*
* @param path A resource path
* @return A Resource instance or null if the resource is not found
* @return A Resource instance if the resource is found
*/
@Override
public ModuleData get(String path) {
public Optional<ModuleEntry> findEntry(String path) {
Objects.requireNonNull(path);
Pool.ModuleData res = pool.get(path);
return getUncompressed(res);
Optional<ModuleEntry> res = pool.findEntry(path);
return res.isPresent()? Optional.of(getUncompressed(res.get())) : Optional.empty();
}
@Override
public boolean contains(ModuleData res) {
public boolean contains(ModuleEntry res) {
return pool.contains(res);
}
@ -426,8 +422,8 @@ public final class ImagePluginStack {
}
@Override
public void visit(Visitor visitor, Pool output) {
pool.visit(visitor, output);
public void transformAndCopy(Function<ModuleEntry, ModuleEntry> visitor, ModulePool output) {
pool.transformAndCopy(visitor, output);
}
@Override
@ -435,14 +431,19 @@ public final class ImagePluginStack {
return pool.getByteOrder();
}
private ModuleData getUncompressed(ModuleData res) {
@Override
public Map<String, String> getReleaseProperties() {
return Collections.unmodifiableMap(pool.getReleaseProperties());
}
private ModuleEntry getUncompressed(ModuleEntry res) {
if (res != null) {
if (res instanceof PoolImpl.CompressedModuleData) {
if (res instanceof ModulePoolImpl.CompressedModuleData) {
try {
byte[] bytes = decompressor.decompressResource(getByteOrder(),
(int offset) -> pool.getStringTable().getString(offset),
res.getBytes());
res = Pool.newResource(res.getPath(),
res = ModuleEntry.create(res.getPath(),
new ByteArrayInputStream(bytes),
bytes.length);
} catch (IOException ex) {
@ -462,20 +463,24 @@ public final class ImagePluginStack {
* @param writer
* @throws java.lang.Exception
*/
public void storeFiles(PoolImpl original, PoolImpl transformed,
public void storeFiles(ModulePoolImpl original, ModulePoolImpl transformed,
BasicImageWriter writer)
throws Exception {
Objects.requireNonNull(original);
try {
// fill release information available from transformed "java.base" module!
ModuleDescriptor desc = transformed.getModule("java.base").getDescriptor();
desc.osName().ifPresent(s -> release.put("OS_NAME", s));
desc.osVersion().ifPresent(s -> release.put("OS_VERSION", s));
desc.osArch().ifPresent(s -> release.put("OS_ARCH", s));
} catch (Exception ignored) {
}
Objects.requireNonNull(transformed);
Optional<LinkModule> javaBase = transformed.findModule("java.base");
javaBase.ifPresent(mod -> {
try {
Map<String, String> release = transformed.getReleaseProperties();
// fill release information available from transformed "java.base" module!
ModuleDescriptor desc = mod.getDescriptor();
desc.osName().ifPresent(s -> release.put("OS_NAME", s));
desc.osVersion().ifPresent(s -> release.put("OS_VERSION", s));
desc.osArch().ifPresent(s -> release.put("OS_ARCH", s));
} catch (Exception ignored) {}
});
imageBuilder.storeFiles(new LastPool(transformed), release);
imageBuilder.storeFiles(new LastPool(transformed));
}
public ExecutableImage getExecutableImage() throws IOException {

@ -0,0 +1,164 @@
/*
* 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 jdk.tools.jlink.internal;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.Objects;
import jdk.tools.jlink.plugin.ModuleEntry;
/**
* A LinkModuleEntry is the elementary unit of data inside an image. It is
* generally a file. e.g.: a java class file, a resource file, a shared library,
* ...
* <br>
* A LinkModuleEntry is identified by a path of the form:
* <ul>
* <li>For jimage content: /{module name}/{package1}/.../{packageN}/{file
* name}</li>
* <li>For other files (shared lib, launchers, config, ...):/{module name}/
* {@literal bin|conf|native}/{dir1}>/.../{dirN}/{file name}</li>
* </ul>
*/
public class ModuleEntryImpl implements ModuleEntry {
private final Type type;
private final String path;
private final String module;
private final long length;
private final InputStream stream;
private byte[] buffer;
/**
* Create a new LinkModuleEntry.
*
* @param module The module name.
* @param path The data path identifier.
* @param type The data type.
* @param stream The data content stream.
* @param length The stream length.
*/
public ModuleEntryImpl(String module, String path, Type type, InputStream stream, long length) {
Objects.requireNonNull(module);
Objects.requireNonNull(path);
Objects.requireNonNull(type);
Objects.requireNonNull(stream);
this.path = path;
this.type = type;
this.module = module;
this.stream = stream;
this.length = length;
}
/**
* The LinkModuleEntry module name.
*
* @return The module name.
*/
@Override
public final String getModule() {
return module;
}
/**
* The LinkModuleEntry path.
*
* @return The module path.
*/
@Override
public final String getPath() {
return path;
}
/**
* The LinkModuleEntry's type.
*
* @return The data type.
*/
@Override
public final Type getType() {
return type;
}
/**
* The LinkModuleEntry content as an array of byte.
*
* @return An Array of bytes.
*/
@Override
public byte[] getBytes() {
if (buffer == null) {
try (InputStream is = stream) {
buffer = is.readAllBytes();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
return buffer;
}
/**
* The LinkModuleEntry content length.
*
* @return The length.
*/
@Override
public long getLength() {
return length;
}
/**
* The LinkModuleEntry stream.
*
* @return The module data stream.
*/
@Override
public InputStream stream() {
return stream;
}
@Override
public int hashCode() {
int hash = 7;
hash = 89 * hash + Objects.hashCode(this.path);
return hash;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof ModuleEntryImpl)) {
return false;
}
ModuleEntryImpl f = (ModuleEntryImpl) other;
return f.path.equals(path);
}
@Override
public String toString() {
return getPath();
}
}

@ -0,0 +1,421 @@
/*
* 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.
*/
package jdk.tools.jlink.internal;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.module.ModuleDescriptor;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Stream;
import jdk.internal.jimage.decompressor.CompressedResourceHeader;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.LinkModule;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.internal.plugins.FileCopierPlugin;
/**
* Pool of module data.
*/
public class ModulePoolImpl implements ModulePool {
private class ModuleImpl implements LinkModule {
final Map<String, ModuleEntry> moduleContent = new LinkedHashMap<>();
private ModuleDescriptor descriptor;
final String name;
private ModuleImpl(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
@Override
public Optional<ModuleEntry> findEntry(String path) {
if (!path.startsWith("/")) {
path = "/" + path;
}
if (!path.startsWith("/" + name)) {
path = "/" + name + path;
}
return Optional.ofNullable(moduleContent.get(path));
}
@Override
public ModuleDescriptor getDescriptor() {
if (descriptor == null) {
String p = "/" + name + "/module-info.class";
Optional<ModuleEntry> content = findEntry(p);
if (!content.isPresent()) {
throw new PluginException("No module-info for " + name
+ " module");
}
ByteBuffer bb = ByteBuffer.wrap(content.get().getBytes());
descriptor = ModuleDescriptor.read(bb);
}
return descriptor;
}
@Override
public void add(ModuleEntry data) {
if (isReadOnly()) {
throw new PluginException("LinkConfiguration is readonly");
}
Objects.requireNonNull(data);
if (!data.getModule().equals(name)) {
throw new PluginException("Can't add resource " + data.getPath()
+ " to module " + name);
}
ModulePoolImpl.this.add(data);
}
@Override
public Set<String> getAllPackages() {
Set<String> pkgs = new HashSet<>();
moduleContent.values().stream().filter(m -> m.getType().
equals(ModuleEntry.Type.CLASS_OR_RESOURCE)).forEach(res -> {
// Module metadata only contains packages with .class files
if (ImageFileCreator.isClassPackage(res.getPath())) {
String[] split = ImageFileCreator.splitPath(res.getPath());
String pkg = split[1];
if (pkg != null && !pkg.isEmpty()) {
pkgs.add(pkg);
}
}
});
return pkgs;
}
@Override
public String toString() {
return getName();
}
@Override
public Stream<? extends ModuleEntry> entries() {
return moduleContent.values().stream();
}
@Override
public int getEntryCount() {
return moduleContent.values().size();
}
}
private final Map<String, ModuleEntry> resources = new LinkedHashMap<>();
private final Map<String, ModuleImpl> modules = new LinkedHashMap<>();
private final ModuleImpl fileCopierModule = new ModuleImpl(FileCopierPlugin.FAKE_MODULE);
private Map<String, String> releaseProps = new HashMap<>();
private final ByteOrder order;
private boolean isReadOnly;
private final StringTable table;
public ModulePoolImpl() {
this(ByteOrder.nativeOrder());
}
public ModulePoolImpl(ByteOrder order) {
this(order, new StringTable() {
@Override
public int addString(String str) {
return -1;
}
@Override
public String getString(int id) {
return null;
}
});
}
public ModulePoolImpl(ByteOrder order, StringTable table) {
this.order = order;
this.table = table;
}
/**
* Add a ModuleEntry.
*
* @param data The ModuleEntry to add.
*/
@Override
public void add(ModuleEntry data) {
if (isReadOnly()) {
throw new PluginException("LinkConfiguration is readonly");
}
Objects.requireNonNull(data);
if (resources.get(data.getPath()) != null) {
throw new PluginException("Resource " + data.getPath()
+ " already present");
}
String modulename = data.getModule();
ModuleImpl m = modules.get(modulename);
// ## TODO: FileCopierPlugin should not add content to a module
// FAKE_MODULE is not really a module to be added in the image
if (FileCopierPlugin.FAKE_MODULE.equals(modulename)) {
m = fileCopierModule;
}
if (m == null) {
m = new ModuleImpl(modulename);
modules.put(modulename, m);
}
resources.put(data.getPath(), data);
m.moduleContent.put(data.getPath(), data);
}
/**
* Retrieves the module for the provided name.
*
* @param name The module name
* @return the module of matching name, if found
*/
@Override
public Optional<LinkModule> findModule(String name) {
Objects.requireNonNull(name);
return Optional.ofNullable(modules.get(name));
}
/**
* The stream of modules contained in this LinkConfiguration.
*
* @return The stream of modules.
*/
@Override
public Stream<? extends LinkModule> modules() {
return modules.values().stream();
}
/**
* Return the number of LinkModule count in this LinkConfiguration.
*
* @return the module count.
*/
@Override
public int getModuleCount() {
return modules.size();
}
/**
* Get all ModuleEntry contained in this LinkConfiguration instance.
*
* @return The stream of LinkModuleEntries.
*/
@Override
public Stream<? extends ModuleEntry> entries() {
return resources.values().stream();
}
/**
* Return the number of ModuleEntry count in this LinkConfiguration.
*
* @return the entry count.
*/
@Override
public int getEntryCount() {
return resources.values().size();
}
/**
* Get the ModuleEntry for the passed path.
*
* @param path A data path
* @return A ModuleEntry instance or null if the data is not found
*/
@Override
public Optional<ModuleEntry> findEntry(String path) {
Objects.requireNonNull(path);
return Optional.ofNullable(resources.get(path));
}
/**
* Check if the LinkConfiguration contains the given ModuleEntry.
*
* @param data The module data to check existence for.
* @return The module data or null if not found.
*/
@Override
public boolean contains(ModuleEntry data) {
Objects.requireNonNull(data);
return findEntry(data.getPath()).isPresent();
}
/**
* Check if the LinkConfiguration contains some content at all.
*
* @return True, no content, false otherwise.
*/
@Override
public boolean isEmpty() {
return resources.isEmpty();
}
/**
* Visit each ModuleEntry in this LinkConfiguration to transform it and
* copy the transformed ModuleEntry to the output LinkConfiguration.
*
* @param transform The function called for each ModuleEntry found in
* the LinkConfiguration. The transform function should return a
* ModuleEntry instance which will be added to the output or it should
* return null if the passed ModuleEntry is to be ignored for the
* output.
*
* @param output The LinkConfiguration to be filled with Visitor returned
* ModuleEntry.
*/
@Override
public void transformAndCopy(Function<ModuleEntry, ModuleEntry> transform,
ModulePool output) {
entries().forEach(resource -> {
ModuleEntry res = transform.apply(resource);
if (res != null) {
output.add(res);
}
});
}
/**
* The ByteOrder currently in use when generating the jimage file.
*
* @return The ByteOrder.
*/
@Override
public ByteOrder getByteOrder() {
return order;
}
@Override
public Map<String, String> getReleaseProperties() {
return isReadOnly()? Collections.unmodifiableMap(releaseProps) : releaseProps;
}
public StringTable getStringTable() {
return table;
}
/**
* Make this Resources instance read-only. No resource can be added.
*/
public void setReadOnly() {
isReadOnly = true;
}
/**
* Read only state.
*
* @return true if readonly false otherwise.
*/
@Override
public boolean isReadOnly() {
return isReadOnly;
}
/**
* A resource that has been compressed.
*/
public static final class CompressedModuleData extends ModuleEntryImpl {
final long uncompressed_size;
private CompressedModuleData(String module, String path,
InputStream stream, long size,
long uncompressed_size) {
super(module, path, ModuleEntry.Type.CLASS_OR_RESOURCE, stream, size);
this.uncompressed_size = uncompressed_size;
}
public long getUncompressedSize() {
return uncompressed_size;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof CompressedModuleData)) {
return false;
}
CompressedModuleData f = (CompressedModuleData) other;
return f.getPath().equals(getPath());
}
@Override
public int hashCode() {
return super.hashCode();
}
}
public static CompressedModuleData newCompressedResource(ModuleEntry original,
ByteBuffer compressed,
String plugin, String pluginConfig, StringTable strings,
ByteOrder order) {
Objects.requireNonNull(original);
Objects.requireNonNull(compressed);
Objects.requireNonNull(plugin);
boolean isTerminal = !(original instanceof CompressedModuleData);
long uncompressed_size = original.getLength();
if (original instanceof CompressedModuleData) {
CompressedModuleData comp = (CompressedModuleData) original;
uncompressed_size = comp.getUncompressedSize();
}
int nameOffset = strings.addString(plugin);
int configOffset = -1;
if (pluginConfig != null) {
configOffset = strings.addString(plugin);
}
CompressedResourceHeader rh
= new CompressedResourceHeader(compressed.limit(), original.getLength(),
nameOffset, configOffset, isTerminal);
// Merge header with content;
byte[] h = rh.getBytes(order);
ByteBuffer bb = ByteBuffer.allocate(compressed.limit() + h.length);
bb.order(order);
bb.put(h);
bb.put(compressed);
byte[] contentWithHeader = bb.array();
CompressedModuleData compressedResource
= new CompressedModuleData(original.getModule(), original.getPath(),
new ByteArrayInputStream(contentWithHeader),
contentWithHeader.length, uncompressed_size);
return compressedResource;
}
}

@ -1,167 +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.
*/
package jdk.tools.jlink.internal;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Objects;
import jdk.internal.jimage.decompressor.CompressedResourceHeader;
import jdk.tools.jlink.plugin.Pool;
/**
* Pool of module data.
*/
public class PoolImpl extends Pool {
/**
* A resource that has been compressed.
*/
public static final class CompressedModuleData extends ModuleData {
private final long uncompressed_size;
private CompressedModuleData(String module, String path,
InputStream stream, long size,
long uncompressed_size) {
super(module, path, ModuleDataType.CLASS_OR_RESOURCE, stream, size);
this.uncompressed_size = uncompressed_size;
}
public long getUncompressedSize() {
return uncompressed_size;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof CompressedModuleData)) {
return false;
}
CompressedModuleData f = (CompressedModuleData) other;
return f.getPath().equals(getPath());
}
@Override
public int hashCode() {
return super.hashCode();
}
}
private boolean isReadOnly;
private final StringTable table;
public PoolImpl() {
this(ByteOrder.nativeOrder(), new StringTable() {
@Override
public int addString(String str) {
return -1;
}
@Override
public String getString(int id) {
return null;
}
});
}
public PoolImpl(ByteOrder order) {
this(order, new StringTable() {
@Override
public int addString(String str) {
return -1;
}
@Override
public String getString(int id) {
return null;
}
});
}
public PoolImpl(ByteOrder order, StringTable table) {
super(order);
this.table = table;
}
public StringTable getStringTable() {
return table;
}
/**
* Make this Resources instance read-only. No resource can be added.
*/
public void setReadOnly() {
isReadOnly = true;
}
/**
* Read only state.
*
* @return true if readonly false otherwise.
*/
@Override
public boolean isReadOnly() {
return isReadOnly;
}
public static CompressedModuleData newCompressedResource(ModuleData original,
ByteBuffer compressed,
String plugin, String pluginConfig, StringTable strings,
ByteOrder order) {
Objects.requireNonNull(original);
Objects.requireNonNull(compressed);
Objects.requireNonNull(plugin);
boolean isTerminal = !(original instanceof CompressedModuleData);
long uncompressed_size = original.getLength();
if (original instanceof CompressedModuleData) {
CompressedModuleData comp = (CompressedModuleData) original;
uncompressed_size = comp.getUncompressedSize();
}
int nameOffset = strings.addString(plugin);
int configOffset = -1;
if (pluginConfig != null) {
configOffset = strings.addString(plugin);
}
CompressedResourceHeader rh
= new CompressedResourceHeader(compressed.limit(), original.getLength(),
nameOffset, configOffset, isTerminal);
// Merge header with content;
byte[] h = rh.getBytes(order);
ByteBuffer bb = ByteBuffer.allocate(compressed.limit() + h.length);
bb.order(order);
bb.put(h);
bb.put(compressed);
byte[] contentWithHeader = bb.array();
CompressedModuleData compressedResource
= new CompressedModuleData(original.getModule(), original.getPath(),
new ByteArrayInputStream(contentWithHeader),
contentWithHeader.length, uncompressed_size);
return compressedResource;
}
}

@ -24,7 +24,7 @@
*/
package jdk.tools.jlink.internal;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.ModulePool;
/**
* Plugin wishing to pre-visit the resources must implement this interface.
@ -44,5 +44,5 @@ public interface ResourcePrevisitor {
* usage.
* @throws PluginException
*/
public void previsit(Pool resources, StringTable strings);
public void previsit(ModulePool resources, StringTable strings);
}

@ -52,7 +52,7 @@ import jdk.internal.module.ConfigurableModuleFinder.Phase;
import jdk.tools.jlink.Jlink;
import jdk.tools.jlink.Jlink.PluginsConfiguration;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.Plugin.CATEGORY;
import jdk.tools.jlink.plugin.Plugin.Category;
import jdk.tools.jlink.builder.DefaultImageBuilder;
import jdk.tools.jlink.builder.ImageBuilder;
import jdk.tools.jlink.plugin.PluginException;
@ -346,7 +346,6 @@ public final class TaskHelper {
}
}
PluginContextImpl pluginContext = new PluginContextImpl();
List<Plugin> pluginsList = new ArrayList<>();
for (Entry<Plugin, List<Map<String, String>>> entry : pluginToMaps.entrySet()) {
Plugin plugin = entry.getKey();
@ -356,7 +355,7 @@ public final class TaskHelper {
// we call configure once for each occurrence. It is upto the plugin
// to 'merge' and/or 'override' arguments.
for (Map<String, String> map : argsMaps) {
plugin.configure(Collections.unmodifiableMap(map), pluginContext);
plugin.configure(Collections.unmodifiableMap(map));
}
if (!Utils.isDisabled(plugin)) {
@ -371,7 +370,7 @@ public final class TaskHelper {
}
return new Jlink.PluginsConfiguration(pluginsList,
builder, lastSorter, pluginContext);
builder, lastSorter);
}
}
@ -594,7 +593,7 @@ public final class TaskHelper {
+ ": " + plugin.getClass().getName());
log.println(bundleHelper.getMessage("main.plugin.module")
+ ": " + plugin.getClass().getModule().getName());
CATEGORY category = Utils.getCategory(plugin);
Category category = Utils.getCategory(plugin);
log.println(bundleHelper.getMessage("main.plugin.category")
+ ": " + category.getName());
log.println(bundleHelper.getMessage("main.plugin.state")

@ -30,7 +30,6 @@ import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.plugin.Plugin.PluginType;
public class Utils {
@ -50,25 +49,26 @@ public class Utils {
return arguments;
};
public static boolean isPostProcessor(Plugin.CATEGORY category) {
return category.equals(Plugin.CATEGORY.VERIFIER)
|| category.equals(Plugin.CATEGORY.PROCESSOR)
|| category.equals(Plugin.CATEGORY.PACKAGER);
public static boolean isPostProcessor(Plugin.Category category) {
return category.equals(Plugin.Category.VERIFIER)
|| category.equals(Plugin.Category.PROCESSOR)
|| category.equals(Plugin.Category.PACKAGER);
}
public static boolean isPreProcessor(Plugin.CATEGORY category) {
return category.equals(Plugin.CATEGORY.COMPRESSOR)
|| category.equals(Plugin.CATEGORY.FILTER)
|| category.equals(Plugin.CATEGORY.MODULEINFO_TRANSFORMER)
|| category.equals(Plugin.CATEGORY.SORTER)
|| category.equals(Plugin.CATEGORY.TRANSFORMER);
public static boolean isPreProcessor(Plugin.Category category) {
return category.equals(Plugin.Category.COMPRESSOR)
|| category.equals(Plugin.Category.FILTER)
|| category.equals(Plugin.Category.MODULEINFO_TRANSFORMER)
|| category.equals(Plugin.Category.SORTER)
|| category.equals(Plugin.Category.TRANSFORMER)
|| category.equals(Plugin.Category.METAINFO_ADDER);
}
public static boolean isPostProcessor(Plugin prov) {
if (prov.getType() != null) {
for (PluginType pt : prov.getType()) {
if (pt instanceof Plugin.CATEGORY) {
return isPostProcessor((Plugin.CATEGORY) pt);
for (Plugin.Category pt : prov.getType()) {
if (pt instanceof Plugin.Category) {
return isPostProcessor(pt);
}
}
}
@ -77,20 +77,20 @@ public class Utils {
public static boolean isPreProcessor(Plugin prov) {
if (prov.getType() != null) {
for (PluginType pt : prov.getType()) {
if (pt instanceof Plugin.CATEGORY) {
return isPreProcessor((Plugin.CATEGORY) pt);
for (Plugin.Category pt : prov.getType()) {
if (pt instanceof Plugin.Category) {
return isPreProcessor(pt);
}
}
}
return false;
}
public static Plugin.CATEGORY getCategory(Plugin provider) {
public static Plugin.Category getCategory(Plugin provider) {
if (provider.getType() != null) {
for (Plugin.PluginType t : provider.getType()) {
if (t instanceof Plugin.CATEGORY) {
return (Plugin.CATEGORY) t;
for (Plugin.Category t : provider.getType()) {
if (t instanceof Plugin.Category) {
return t;
}
}
}
@ -140,15 +140,15 @@ public class Utils {
}
public static boolean isFunctional(Plugin prov) {
return prov.getState().contains(Plugin.STATE.FUNCTIONAL);
return prov.getState().contains(Plugin.State.FUNCTIONAL);
}
public static boolean isAutoEnabled(Plugin prov) {
return prov.getState().contains(Plugin.STATE.AUTO_ENABLED);
return prov.getState().contains(Plugin.State.AUTO_ENABLED);
}
public static boolean isDisabled(Plugin prov) {
return prov.getState().contains(Plugin.STATE.DISABLED);
return prov.getState().contains(Plugin.State.DISABLED);
}
// is this a builtin (jdk.jlink) plugin?

@ -30,7 +30,7 @@ import jdk.tools.jlink.Jlink;
import jdk.tools.jlink.builder.ImageBuilder;
import jdk.tools.jlink.plugin.Plugin;
import jdk.tools.jlink.builder.*;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.ModulePool;
import java.io.ByteArrayOutputStream;
import java.io.File;

@ -26,16 +26,13 @@ package jdk.tools.jlink.internal.plugins;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.internal.PoolImpl;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.internal.ModulePoolImpl;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.internal.ImagePluginStack;
import jdk.tools.jlink.internal.ResourcePrevisitor;
@ -62,10 +59,10 @@ public final class DefaultCompressPlugin implements TransformerPlugin, ResourceP
}
@Override
public void visit(Pool in, Pool out) {
public void visit(ModulePool in, ModulePool out) {
if (ss != null && zip != null) {
Pool output = new ImagePluginStack.OrderedResourcePool(in.getByteOrder(),
((PoolImpl) in).getStringTable());
ModulePool output = new ImagePluginStack.OrderedResourcePool(in.getByteOrder(),
((ModulePoolImpl) in).getStringTable());
ss.visit(in, output);
zip.visit(output, out);
} else if (ss != null) {
@ -76,16 +73,16 @@ public final class DefaultCompressPlugin implements TransformerPlugin, ResourceP
}
@Override
public void previsit(Pool resources, StringTable strings) {
public void previsit(ModulePool resources, StringTable strings) {
if (ss != null) {
ss.previsit(resources, strings);
}
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.COMPRESSOR);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.COMPRESSOR);
return Collections.unmodifiableSet(set);
}

@ -32,8 +32,8 @@ import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleDataType;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.internal.Utils;
/**
@ -51,9 +51,9 @@ public final class ExcludeFilesPlugin implements TransformerPlugin {
}
@Override
public void visit(Pool in, Pool out) {
in.visit((file) -> {
if (!file.getType().equals(ModuleDataType.CLASS_OR_RESOURCE)) {
public void visit(ModulePool in, ModulePool out) {
in.transformAndCopy((file) -> {
if (!file.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
file = predicate.test(file.getPath()) ? file : null;
}
return file;
@ -61,9 +61,9 @@ public final class ExcludeFilesPlugin implements TransformerPlugin {
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.FILTER);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
}

@ -32,7 +32,8 @@ import java.util.Set;
import java.util.function.Predicate;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.internal.Utils;
/**
@ -50,9 +51,9 @@ public final class ExcludePlugin implements TransformerPlugin {
}
@Override
public void visit(Pool in, Pool out) {
in.visit((resource) -> {
if (resource.getType().equals(Pool.ModuleDataType.CLASS_OR_RESOURCE)) {
public void visit(ModulePool in, ModulePool out) {
in.transformAndCopy((resource) -> {
if (resource.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
resource = predicate.test(resource.getPath()) ? resource : null;
}
return resource;
@ -75,9 +76,9 @@ public final class ExcludePlugin implements TransformerPlugin {
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.FILTER);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
}

@ -40,9 +40,10 @@ import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleDataType;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.internal.Utils;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
/**
@ -102,24 +103,24 @@ public final class ExcludeVMPlugin implements TransformerPlugin {
* e.g.: /java.base/native/amd64/server/libjvm.so
* /java.base/native/server/libjvm.dylib
*/
private List<Pool.ModuleData> getVMs(Pool in) {
private List<ModuleEntry> getVMs(ModulePool in) {
String jvmlib = jvmlib();
List<Pool.ModuleData> ret = in.getModule("java.base").getContent().stream().filter((t) -> {
List<ModuleEntry> ret = in.findModule("java.base").get().entries().filter((t) -> {
return t.getPath().endsWith("/" + jvmlib);
}).collect(Collectors.toList());
return ret;
}
@Override
public void visit(Pool in, Pool out) {
public void visit(ModulePool in, ModulePool out) {
String jvmlib = jvmlib();
TreeSet<Jvm> existing = new TreeSet<>(new JvmComparator());
TreeSet<Jvm> removed = new TreeSet<>(new JvmComparator());
if (!keepAll) {
// First retrieve all available VM names and removed VM
List<Pool.ModuleData> jvms = getVMs(in);
List<ModuleEntry> jvms = getVMs(in);
for (Jvm jvm : Jvm.values()) {
for (Pool.ModuleData md : jvms) {
for (ModuleEntry md : jvms) {
if (md.getPath().endsWith("/" + jvm.getName() + "/" + jvmlib)) {
existing.add(jvm);
if (isRemoved(md)) {
@ -137,9 +138,9 @@ public final class ExcludeVMPlugin implements TransformerPlugin {
}
// Rewrite the jvm.cfg file.
in.visit((file) -> {
in.transformAndCopy((file) -> {
if (!keepAll) {
if (file.getType().equals(ModuleDataType.NATIVE_LIB)) {
if (file.getType().equals(ModuleEntry.Type.NATIVE_LIB)) {
if (file.getPath().endsWith(JVM_CFG)) {
try {
file = handleJvmCfgFile(file, existing, removed);
@ -155,14 +156,14 @@ public final class ExcludeVMPlugin implements TransformerPlugin {
}
private boolean isRemoved(Pool.ModuleData file) {
private boolean isRemoved(ModuleEntry file) {
return !predicate.test(file.getPath());
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.FILTER);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
}
@ -217,7 +218,7 @@ public final class ExcludeVMPlugin implements TransformerPlugin {
}
}
private Pool.ModuleData handleJvmCfgFile(Pool.ModuleData orig,
private ModuleEntry handleJvmCfgFile(ModuleEntry orig,
TreeSet<Jvm> existing,
TreeSet<Jvm> removed) throws IOException {
if (keepAll) {
@ -253,7 +254,7 @@ public final class ExcludeVMPlugin implements TransformerPlugin {
byte[] content = builder.toString().getBytes(StandardCharsets.UTF_8);
return Pool.newImageFile(orig.getModule(),
return ModuleEntry.create(orig.getModule(),
orig.getPath(),
orig.getType(),
new ByteArrayInputStream(content), content.length);

@ -41,10 +41,10 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import jdk.tools.jlink.internal.ModuleEntryImpl;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleData;
import jdk.tools.jlink.plugin.Pool.ModuleDataType;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.internal.Utils;
@ -68,12 +68,12 @@ public class FileCopierPlugin implements TransformerPlugin {
/**
* Symbolic link to another path.
*/
public static abstract class SymImageFile extends Pool.ModuleData {
public static abstract class SymImageFile extends ModuleEntryImpl {
private final String targetPath;
public SymImageFile(String targetPath, String module, String path,
Pool.ModuleDataType type, InputStream stream, long size) {
ModuleEntry.Type type, InputStream stream, long size) {
super(module, path, type, stream, size);
this.targetPath = targetPath;
}
@ -86,7 +86,7 @@ public class FileCopierPlugin implements TransformerPlugin {
private static final class SymImageFileImpl extends SymImageFile {
public SymImageFileImpl(String targetPath, Path file, String module,
String path, ModuleDataType type) {
String path, ModuleEntry.Type type) {
super(targetPath, module, path, type, newStream(file), length(file));
}
}
@ -110,11 +110,11 @@ public class FileCopierPlugin implements TransformerPlugin {
private static final class DirectoryCopy implements FileVisitor<Path> {
private final Path source;
private final Pool pool;
private final ModulePool pool;
private final String targetDir;
private final List<SymImageFile> symlinks = new ArrayList<>();
DirectoryCopy(Path source, Pool pool, String targetDir) {
DirectoryCopy(Path source, ModulePool pool, String targetDir) {
this.source = source;
this.pool = pool;
this.targetDir = targetDir;
@ -148,7 +148,7 @@ public class FileCopierPlugin implements TransformerPlugin {
}
SymImageFileImpl impl = new SymImageFileImpl(symTarget.toString(),
file, path, Objects.requireNonNull(file.getFileName()).toString(),
Pool.ModuleDataType.OTHER);
ModuleEntry.Type.OTHER);
symlinks.add(impl);
} else {
addFile(pool, file, path);
@ -172,14 +172,14 @@ public class FileCopierPlugin implements TransformerPlugin {
}
}
private static void addFile(Pool pool, Path file, String path)
private static void addFile(ModulePool pool, Path file, String path)
throws IOException {
Objects.requireNonNull(pool);
Objects.requireNonNull(file);
Objects.requireNonNull(path);
ModuleData impl = Pool.newImageFile(FAKE_MODULE,
ModuleEntry impl = ModuleEntry.create(FAKE_MODULE,
"/" + FAKE_MODULE + "/other/" + path,
Pool.ModuleDataType.OTHER, newStream(file), length(file));
ModuleEntry.Type.OTHER, newStream(file), length(file));
try {
pool.add(impl);
} catch (Exception ex) {
@ -188,9 +188,9 @@ public class FileCopierPlugin implements TransformerPlugin {
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.TRANSFORMER);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
@ -239,8 +239,8 @@ public class FileCopierPlugin implements TransformerPlugin {
}
@Override
public void visit(Pool in, Pool out) {
in.visit((file) -> {
public void visit(ModulePool in, ModulePool out) {
in.transformAndCopy((file) -> {
return file;
}, out);

@ -33,8 +33,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
/**
@ -60,8 +61,8 @@ public final class GenerateJLIClassesPlugin implements TransformerPlugin {
}
@Override
public Set<PluginType> getType() {
return Collections.singleton(CATEGORY.TRANSFORMER);
public Set<Category> getType() {
return Collections.singleton(Category.TRANSFORMER);
}
@Override
@ -75,8 +76,8 @@ public final class GenerateJLIClassesPlugin implements TransformerPlugin {
}
@Override
public Set<STATE> getState() {
return EnumSet.of(STATE.AUTO_ENABLED, STATE.FUNCTIONAL);
public Set<State> getState() {
return EnumSet.of(State.AUTO_ENABLED, State.FUNCTIONAL);
}
@Override
@ -151,8 +152,8 @@ public final class GenerateJLIClassesPlugin implements TransformerPlugin {
}
@Override
public void visit(Pool in, Pool out) {
for (Pool.ModuleData data : in.getContent()) {
public void visit(ModulePool in, ModulePool out) {
in.entries().forEach(data -> {
if (("/java.base/" + BMH + ".class").equals(data.getPath())) {
// Add BoundMethodHandle unchanged
out.add(data);
@ -162,11 +163,11 @@ public final class GenerateJLIClassesPlugin implements TransformerPlugin {
out.add(data);
}
}
}
});
}
@SuppressWarnings("unchecked")
private void generateConcreteClass(String types, Pool.ModuleData data, Pool out) {
private void generateConcreteClass(String types, ModuleEntry data, ModulePool out) {
try {
// Generate class
Map.Entry<String, byte[]> result = (Map.Entry<String, byte[]>)
@ -175,9 +176,9 @@ public final class GenerateJLIClassesPlugin implements TransformerPlugin {
byte[] bytes = result.getValue();
// Add class to pool
Pool.ModuleData ndata = new Pool.ModuleData(data.getModule(),
ModuleEntry ndata = ModuleEntry.create(data.getModule(),
"/java.base/" + className + ".class",
Pool.ModuleDataType.CLASS_OR_RESOURCE,
ModuleEntry.Type.CLASS_OR_RESOURCE,
new ByteArrayInputStream(bytes), bytes.length);
if (!out.contains(ndata)) {
out.add(ndata);

@ -34,6 +34,7 @@ import java.util.IllformedLocaleException;
import java.util.Locale;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Pattern;
@ -44,9 +45,10 @@ import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.tools.jlink.internal.ResourcePrevisitor;
import jdk.tools.jlink.internal.StringTable;
import jdk.tools.jlink.internal.Utils;
import jdk.tools.jlink.plugin.LinkModule;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleDataType;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
/**
@ -112,19 +114,19 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
}
@Override
public void visit(Pool in, Pool out) {
in.visit((resource) -> {
public void visit(ModulePool in, ModulePool out) {
in.transformAndCopy((resource) -> {
if (resource.getModule().equals(MODULENAME)) {
String path = resource.getPath();
resource = predicate.test(path) ? resource: null;
if (resource != null &&
resource.getType().equals(ModuleDataType.CLASS_OR_RESOURCE)) {
resource.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
byte[] bytes = resource.getBytes();
ClassReader cr = new ClassReader(bytes);
if (Arrays.stream(cr.getInterfaces())
.anyMatch(i -> i.contains(METAINFONAME)) &&
stripUnsupportedLocales(bytes, cr)) {
resource = new Pool.ModuleData(MODULENAME, path,
resource = ModuleEntry.create(MODULENAME, path,
resource.getType(),
new ByteArrayInputStream(bytes), bytes.length);
}
@ -135,9 +137,9 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.FILTER);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
}
@ -172,12 +174,13 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
}
@Override
public void previsit(Pool resources, StringTable strings) {
public void previsit(ModulePool resources, StringTable strings) {
final Pattern p = Pattern.compile(".*((Data_)|(Names_))(?<tag>.*)\\.class");
Pool.Module module = resources.getModule(MODULENAME);
Optional<LinkModule> optMod = resources.findModule(MODULENAME);
// jdk.localedata module validation
if (module != null) {
if (optMod.isPresent()) {
LinkModule module = optMod.get();
Set<String> packages = module.getAllPackages();
if (!packages.containsAll(LOCALEDATA_PACKAGES)) {
throw new PluginException(PluginsResourceBundle.getMessage(NAME + ".missingpackages") +
@ -186,7 +189,7 @@ public final class IncludeLocalesPlugin implements TransformerPlugin, ResourcePr
.collect(Collectors.joining(",\n\t")));
}
available = Stream.concat(module.getContent().stream()
available = Stream.concat(module.entries()
.map(md -> p.matcher(md.getPath()))
.filter(m -> m.matches())
.map(m -> m.group("tag").replaceAll("_", "-")),

@ -24,7 +24,6 @@
*/
package jdk.tools.jlink.internal.plugins;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@ -287,9 +286,9 @@ public final class OptimizationPlugin extends AsmPlugin {
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.TRANSFORMER);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
}

@ -36,9 +36,8 @@ import java.util.Map;
import java.util.Set;
import java.util.function.ToIntFunction;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleData;
import jdk.tools.jlink.plugin.Pool.ModuleDataType;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.internal.Utils;
@ -62,15 +61,15 @@ public final class OrderResourcesPlugin implements TransformerPlugin {
}
static class SortWrapper {
private final ModuleData resource;
private final ModuleEntry resource;
private final int ordinal;
SortWrapper(ModuleData resource, int ordinal) {
SortWrapper(ModuleEntry resource, int ordinal) {
this.resource = resource;
this.ordinal = ordinal;
}
ModuleData getResource() {
ModuleEntry getResource() {
return resource;
}
@ -95,7 +94,7 @@ public final class OrderResourcesPlugin implements TransformerPlugin {
return path;
}
private int getOrdinal(ModuleData resource) {
private int getOrdinal(ModuleEntry resource) {
String path = resource.getPath();
Integer value = orderedPaths.get(stripModule(path));
@ -126,23 +125,23 @@ public final class OrderResourcesPlugin implements TransformerPlugin {
}
@Override
public void visit(Pool in, Pool out) {
in.getContent().stream()
public void visit(ModulePool in, ModulePool out) {
in.entries()
.filter(resource -> resource.getType()
.equals(ModuleDataType.CLASS_OR_RESOURCE))
.equals(ModuleEntry.Type.CLASS_OR_RESOURCE))
.map((resource) -> new SortWrapper(resource, getOrdinal(resource)))
.sorted(OrderResourcesPlugin::compare)
.forEach((wrapper) -> out.add(wrapper.getResource()));
in.getContent().stream()
in.entries()
.filter(other -> !other.getType()
.equals(ModuleDataType.CLASS_OR_RESOURCE))
.equals(ModuleEntry.Type.CLASS_OR_RESOURCE))
.forEach((other) -> out.add(other));
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.SORTER);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.SORTER);
return Collections.unmodifiableSet(set);
}

@ -24,34 +24,33 @@
*/
package jdk.tools.jlink.internal.plugins;
import java.lang.module.ModuleDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Properties;
import java.util.Set;
import java.util.function.Function;
import jdk.tools.jlink.internal.Utils;
import jdk.tools.jlink.plugin.ExecutableImage;
import jdk.tools.jlink.plugin.PluginContext;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.PostProcessorPlugin;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.Plugin.Category;
import jdk.tools.jlink.plugin.Plugin.State;
import jdk.tools.jlink.plugin.TransformerPlugin;
/**
* This plugin adds/deletes information for 'release' file.
*/
public final class ReleaseInfoPlugin implements PostProcessorPlugin {
public final class ReleaseInfoPlugin implements TransformerPlugin {
// option name
public static final String NAME = "release-info";
public static final String KEYS = "keys";
private final Map<String, String> release = new HashMap<>();
@Override
public Set<PluginType> getType() {
return Collections.singleton(CATEGORY.PROCESSOR);
public Set<Category> getType() {
return Collections.singleton(Category.METAINFO_ADDER);
}
@Override
@ -65,8 +64,8 @@ public final class ReleaseInfoPlugin implements PostProcessorPlugin {
}
@Override
public Set<STATE> getState() {
return EnumSet.of(STATE.FUNCTIONAL);
public Set<State> getState() {
return EnumSet.of(State.FUNCTIONAL);
}
@Override
@ -80,49 +79,49 @@ public final class ReleaseInfoPlugin implements PostProcessorPlugin {
}
@Override
public void configure(Map<String, String> config, PluginContext ctx) {
Properties release = ctx != null? ctx.getReleaseProperties() : null;
if (release != null) {
String operation = config.get(NAME);
switch (operation) {
case "add": {
// leave it to open-ended! source, java_version, java_full_version
// can be passed via this option like:
//
// --release-info add:build_type=fastdebug,source=openjdk,java_version=9
// and put whatever value that was passed in command line.
public void configure(Map<String, String> config) {
String operation = config.get(NAME);
switch (operation) {
case "add": {
// leave it to open-ended! source, java_version, java_full_version
// can be passed via this option like:
//
// --release-info add:build_type=fastdebug,source=openjdk,java_version=9
// and put whatever value that was passed in command line.
config.keySet().stream().
filter(s -> !NAME.equals(s)).
forEach(s -> release.put(s, config.get(s)));
}
break;
case "del": {
// --release-info del:keys=openjdk,java_version
String[] keys = Utils.listParser.apply(config.get(KEYS));
for (String k : keys) {
release.remove(k);
}
}
break;
default: {
// --release-info <file>
try (FileInputStream fis = new FileInputStream(operation)) {
release.load(fis);
} catch (IOException exp) {
throw new RuntimeException(exp);
}
}
break;
config.keySet().stream().
filter(s -> !NAME.equals(s)).
forEach(s -> release.put(s, config.get(s)));
}
break;
case "del": {
// --release-info del:keys=openjdk,java_version
String[] keys = Utils.listParser.apply(config.get(KEYS));
for (String k : keys) {
release.remove(k);
}
}
break;
default: {
// --release-info <file>
Properties props = new Properties();
try (FileInputStream fis = new FileInputStream(operation)) {
props.load(fis);
} catch (IOException exp) {
throw new RuntimeException(exp);
}
props.forEach((k, v) -> release.put(k.toString(), v.toString()));
}
break;
}
}
@Override
public List<String> process(ExecutableImage image) {
// Nothing to do! Release info copied already during configure!
return Collections.emptyList();
public void visit(ModulePool in, ModulePool out) {
in.transformAndCopy(Function.identity(), out);
out.getReleaseProperties().putAll(in.getReleaseProperties());
out.getReleaseProperties().putAll(release);
}
}

@ -56,11 +56,11 @@ import java.util.stream.Collectors;
import jdk.internal.jimage.decompressor.CompressIndexes;
import jdk.internal.jimage.decompressor.SignatureParser;
import jdk.internal.jimage.decompressor.StringSharingDecompressor;
import jdk.tools.jlink.internal.PoolImpl;
import jdk.tools.jlink.internal.ModulePoolImpl;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleData;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.internal.ResourcePrevisitor;
import jdk.tools.jlink.internal.StringTable;
import jdk.tools.jlink.internal.Utils;
@ -228,7 +228,7 @@ public class StringSharingPlugin implements TransformerPlugin, ResourcePrevisito
}
}
public byte[] transform(ModuleData resource, Pool out,
public byte[] transform(ModuleEntry resource, ModulePool out,
StringTable strings) throws IOException, Exception {
byte[] content = resource.getBytes();
ClassFile cf;
@ -243,7 +243,7 @@ public class StringSharingPlugin implements TransformerPlugin, ResourcePrevisito
}
@SuppressWarnings("fallthrough")
private byte[] optimize(ModuleData resource, Pool resources,
private byte[] optimize(ModuleEntry resource, ModulePool resources,
StringTable strings,
Set<Integer> descriptorIndexes, byte[] content) throws Exception {
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(content));
@ -348,27 +348,27 @@ public class StringSharingPlugin implements TransformerPlugin, ResourcePrevisito
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.COMPRESSOR);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.COMPRESSOR);
return Collections.unmodifiableSet(set);
}
@Override
public void visit(Pool in, Pool result) {
public void visit(ModulePool in, ModulePool result) {
CompactCPHelper visit = new CompactCPHelper();
in.visit((resource) -> {
ModuleData res = resource;
in.transformAndCopy((resource) -> {
ModuleEntry res = resource;
if (predicate.test(resource.getPath()) && resource.getPath().endsWith(".class")) {
byte[] compressed = null;
try {
compressed = visit.transform(resource, result, ((PoolImpl) in).getStringTable());
compressed = visit.transform(resource, result, ((ModulePoolImpl) in).getStringTable());
} catch (Exception ex) {
throw new PluginException(ex);
}
res = PoolImpl.newCompressedResource(resource,
res = ModulePoolImpl.newCompressedResource(resource,
ByteBuffer.wrap(compressed), getName(), null,
((PoolImpl) in).getStringTable(), in.getByteOrder());
((ModulePoolImpl) in).getStringTable(), in.getByteOrder());
}
return res;
}, result);
@ -405,10 +405,10 @@ public class StringSharingPlugin implements TransformerPlugin, ResourcePrevisito
}
@Override
public void previsit(Pool resources, StringTable strings) {
public void previsit(ModulePool resources, StringTable strings) {
CompactCPHelper preVisit = new CompactCPHelper();
for (ModuleData resource : resources.getContent()) {
if (resource.getType().equals(Pool.ModuleDataType.CLASS_OR_RESOURCE)
resources.entries().forEach(resource -> {
if (resource.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)
&& resource.getPath().endsWith(".class") && predicate.test(resource.getPath())) {
try {
preVisit.transform(resource, null, strings);
@ -416,6 +416,6 @@ public class StringSharingPlugin implements TransformerPlugin, ResourcePrevisito
throw new PluginException(ex);
}
}
}
});
}
}

@ -29,14 +29,12 @@ import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleData;
import jdk.tools.jlink.plugin.Pool.ModuleDataType;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
/**
@ -61,9 +59,9 @@ public final class StripDebugPlugin implements TransformerPlugin {
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.TRANSFORMER);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.TRANSFORMER);
return Collections.unmodifiableSet(set);
}
@ -73,11 +71,11 @@ public final class StripDebugPlugin implements TransformerPlugin {
}
@Override
public void visit(Pool in, Pool out) {
public void visit(ModulePool in, ModulePool out) {
//remove *.diz files as well as debug attributes.
in.visit((resource) -> {
ModuleData res = resource;
if (resource.getType().equals(ModuleDataType.CLASS_OR_RESOURCE)) {
in.transformAndCopy((resource) -> {
ModuleEntry res = resource;
if (resource.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
String path = resource.getPath();
if (path.endsWith(".class")) {
if (path.endsWith("module-info.class")) {
@ -87,7 +85,7 @@ public final class StripDebugPlugin implements TransformerPlugin {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
reader.accept(writer, ClassReader.SKIP_DEBUG);
byte[] content = writer.toByteArray();
res = Pool.newResource(path, new ByteArrayInputStream(content), content.length);
res = ModuleEntry.create(path, new ByteArrayInputStream(content), content.length);
}
}
} else if (predicate.test(res.getPath())) {

@ -26,9 +26,9 @@ package jdk.tools.jlink.internal.plugins;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
/**
@ -45,16 +45,16 @@ public final class StripNativeCommandsPlugin implements TransformerPlugin {
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.FILTER);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.FILTER);
return Collections.unmodifiableSet(set);
}
@Override
public void visit(Pool in, Pool out) {
in.visit((file) -> {
return file.getType() == Pool.ModuleDataType.NATIVE_CMD ? null : file;
public void visit(ModulePool in, ModulePool out) {
in.transformAndCopy((file) -> {
return file.getType() == ModuleEntry.Type.NATIVE_CMD ? null : file;
}, out);
}

@ -36,6 +36,7 @@ import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@ -50,9 +51,10 @@ import jdk.internal.org.objectweb.asm.Opcodes;
import static jdk.internal.org.objectweb.asm.Opcodes.*;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.internal.plugins.SystemModuleDescriptorPlugin.Builder.*;
import jdk.tools.jlink.plugin.ModuleEntry;
/**
* Jlink plugin to reconstitute module descriptors for installed modules.
@ -81,8 +83,8 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
}
@Override
public Set<PluginType> getType() {
return Collections.singleton(CATEGORY.TRANSFORMER);
public Set<Category> getType() {
return Collections.singleton(Category.TRANSFORMER);
}
@Override
@ -96,9 +98,9 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
}
@Override
public Set<STATE> getState() {
return enabled ? EnumSet.of(STATE.AUTO_ENABLED, STATE.FUNCTIONAL)
: EnumSet.of(STATE.DISABLED);
public Set<State> getState() {
return enabled ? EnumSet.of(State.AUTO_ENABLED, State.FUNCTIONAL)
: EnumSet.of(State.DISABLED);
}
@Override
@ -110,7 +112,7 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
@Override
public void visit(Pool in, Pool out) {
public void visit(ModulePool in, ModulePool out) {
if (!enabled) {
throw new PluginException(NAME + " was set");
}
@ -119,13 +121,14 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
// generate the byte code to create ModuleDescriptors
// skip parsing module-info.class and skip name check
for (Pool.Module module : in.getModules()) {
Pool.ModuleData data = module.get("module-info.class");
if (data == null) {
in.modules().forEach(module -> {
Optional<ModuleEntry> optData = module.findEntry("module-info.class");
if (! optData.isPresent()) {
// automatic module not supported yet
throw new PluginException("module-info.class not found for " +
module.getName() + " module");
}
ModuleEntry data = optData.get();
assert module.getName().equals(data.getModule());
try {
ByteArrayInputStream bain = new ByteArrayInputStream(data.getBytes());
@ -141,7 +144,7 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
ModuleInfoRewriter minfoWriter =
new ModuleInfoRewriter(bain, mbuilder.conceals());
// replace with the overridden version
data = new Pool.ModuleData(data.getModule(),
data = ModuleEntry.create(data.getModule(),
data.getPath(),
data.getType(),
minfoWriter.stream(),
@ -151,19 +154,17 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
} catch (IOException e) {
throw new PluginException(e);
}
}
});
// Generate the new class
ClassWriter cwriter = builder.build();
for (Pool.ModuleData data : in.getContent()) {
in.entries().forEach(data -> {
if (data.getPath().endsWith("module-info.class"))
continue;
return;
if (builder.isOverriddenClass(data.getPath())) {
byte[] bytes = cwriter.toByteArray();
Pool.ModuleData ndata =
new Pool.ModuleData(data.getModule(),
ModuleEntry ndata =
ModuleEntry.create(data.getModule(),
data.getPath(),
data.getType(),
new ByteArrayInputStream(bytes),
@ -172,7 +173,7 @@ public final class SystemModuleDescriptorPlugin implements TransformerPlugin {
} else {
out.add(data);
}
}
});
}
/*

@ -34,10 +34,9 @@ import java.util.Set;
import java.util.function.Predicate;
import java.util.zip.Deflater;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.internal.PoolImpl;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleData;
import jdk.tools.jlink.plugin.Pool.ModuleDataType;
import jdk.tools.jlink.internal.ModulePoolImpl;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.internal.Utils;
@ -68,9 +67,9 @@ public final class ZipPlugin implements TransformerPlugin {
}
@Override
public Set<PluginType> getType() {
Set<PluginType> set = new HashSet<>();
set.add(CATEGORY.COMPRESSOR);
public Set<Category> getType() {
Set<Category> set = new HashSet<>();
set.add(Category.COMPRESSOR);
return Collections.unmodifiableSet(set);
}
@ -124,16 +123,16 @@ public final class ZipPlugin implements TransformerPlugin {
}
@Override
public void visit(Pool in, Pool out) {
in.visit((resource) -> {
ModuleData res = resource;
if (resource.getType().equals(ModuleDataType.CLASS_OR_RESOURCE)
public void visit(ModulePool in, ModulePool out) {
in.transformAndCopy((resource) -> {
ModuleEntry res = resource;
if (resource.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)
&& predicate.test(resource.getPath())) {
byte[] compressed;
compressed = compress(resource.getBytes());
res = PoolImpl.newCompressedResource(resource,
res = ModulePoolImpl.newCompressedResource(resource,
ByteBuffer.wrap(compressed), getName(), null,
((PoolImpl) in).getStringTable(), in.getByteOrder());
((ModulePoolImpl) in).getStringTable(), in.getByteOrder());
}
return res;
}, out);

@ -26,9 +26,9 @@ package jdk.tools.jlink.internal.plugins.asm;
import java.util.Objects;
import jdk.tools.jlink.plugin.TransformerPlugin;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleData;
import jdk.tools.jlink.internal.PoolImpl;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool;
import jdk.tools.jlink.internal.ModulePoolImpl;
/**
* Extend this class to develop your own plugin in order to transform jimage
@ -41,17 +41,17 @@ public abstract class AsmPlugin implements TransformerPlugin {
}
@Override
public void visit(Pool allContent, Pool outResources) {
public void visit(ModulePool allContent, ModulePool outResources) {
Objects.requireNonNull(allContent);
Objects.requireNonNull(outResources);
PoolImpl resources = new PoolImpl(allContent.getByteOrder());
for(ModuleData md : allContent.getContent()) {
if(md.getType().equals(Pool.ModuleDataType.CLASS_OR_RESOURCE)) {
ModulePoolImpl resources = new ModulePoolImpl(allContent.getByteOrder());
allContent.entries().forEach(md -> {
if(md.getType().equals(ModuleEntry.Type.CLASS_OR_RESOURCE)) {
resources.add(md);
} else {
outResources.add(md);
}
}
});
AsmPools pools = new AsmPools(resources);
visit(pools);
pools.fillOutputResources(outResources);

@ -24,13 +24,12 @@
*/
package jdk.tools.jlink.internal.plugins.asm;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.ModulePool;
/**
* A pool of ClassReader and other resource files.
@ -138,14 +137,14 @@ public interface AsmPool {
* @return The ClassReader or null if the class is not found.
* @throws jdk.tools.jlink.plugin.PluginException
*/
public ClassReader getClassReader(Pool.ModuleData res);
public ClassReader getClassReader(ModuleEntry res);
/**
* Returns all the classes contained in the writable pool.
*
* @return The collection of classes.
*/
public Collection<Pool.ModuleData> getClasses();
public Collection<ModuleEntry> getClasses();
}
/**
@ -185,14 +184,14 @@ public interface AsmPool {
* @param res The java resource
* @return The Resource or null if the resource is not found.
*/
public ResourceFile getResourceFile(Pool.ModuleData res);
public ResourceFile getResourceFile(ModuleEntry res);
/**
* Returns all the resources contained in the writable pool.
*
* @return The array of resources.
*/
public Collection<Pool.ModuleData> getResourceFiles();
public Collection<ModuleEntry> getResourceFiles();
}
/**
@ -206,7 +205,7 @@ public interface AsmPool {
* @return The resource paths ordered in the way to use for storage in the jimage.
* @throws jdk.tools.jlink.plugin.PluginException
*/
public List<String> sort(Pool resources);
public List<String> sort(ModulePool resources);
}
/**
@ -237,7 +236,7 @@ public interface AsmPool {
*
* @return The classes.
*/
public Collection<Pool.ModuleData> getClasses();
public Collection<ModuleEntry> getClasses();
/**
* Returns the resources contained in the pool. Resources are all the file
@ -245,7 +244,7 @@ public interface AsmPool {
*
* @return The array of resource files.
*/
public Collection<Pool.ModuleData> getResourceFiles();
public Collection<ModuleEntry> getResourceFiles();
/**
* Retrieves a resource based on the binary name. This name doesn't contain
@ -266,7 +265,7 @@ public interface AsmPool {
* @param res The resource
* @return The resource file or null if it doesn't exist.
*/
public ResourceFile getResourceFile(Pool.ModuleData res);
public ResourceFile getResourceFile(ModuleEntry res);
/**
* Retrieve a ClassReader from the pool.
@ -284,7 +283,7 @@ public interface AsmPool {
* @return A reader or null if the class is unknown
* @throws jdk.tools.jlink.plugin.PluginException
*/
public ClassReader getClassReader(Pool.ModuleData res);
public ClassReader getClassReader(ModuleEntry res);
/**
* To visit the set of ClassReaders.
@ -310,6 +309,6 @@ public interface AsmPool {
* @param output The pool used to fill the jimage.
* @throws jdk.tools.jlink.plugin.PluginException
*/
public void fillOutputResources(Pool output);
public void fillOutputResources(ModulePool output);
}

@ -41,15 +41,14 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.tools.jlink.internal.ImageFileCreator;
import jdk.tools.jlink.internal.PoolImpl;
import jdk.tools.jlink.internal.ModulePoolImpl;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleData;
import jdk.tools.jlink.plugin.ModulePool;
/**
* A pool of ClassReader and other resource files. This class allows to
@ -94,7 +93,7 @@ final class AsmPoolImpl implements AsmModulePool {
}
byte[] content = writer.toByteArray();
ModuleData res = Pool.newResource(path,
ModuleEntry res = ModuleEntry.create(path,
new ByteArrayInputStream(content), content.length);
transformedClasses.put(className, res);
}
@ -108,7 +107,7 @@ final class AsmPoolImpl implements AsmModulePool {
public void forgetClass(String className) {
Objects.requireNonNull(className);
// do we have a resource?
ModuleData res = transformedClasses.get(className);
ModuleEntry res = transformedClasses.get(className);
if (res == null) {
res = inputClasses.get(className);
if (res == null) {
@ -130,7 +129,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public ClassReader getClassReader(String binaryName) {
Objects.requireNonNull(binaryName);
ModuleData res = transformedClasses.get(binaryName);
ModuleEntry res = transformedClasses.get(binaryName);
ClassReader reader = null;
if (res != null) {
reader = getClassReader(res);
@ -144,16 +143,16 @@ final class AsmPoolImpl implements AsmModulePool {
* @return The array of transformed classes.
*/
@Override
public Collection<ModuleData> getClasses() {
List<ModuleData> classes = new ArrayList<>();
for (Entry<String, ModuleData> entry : transformedClasses.entrySet()) {
public Collection<ModuleEntry> getClasses() {
List<ModuleEntry> classes = new ArrayList<>();
for (Entry<String, ModuleEntry> entry : transformedClasses.entrySet()) {
classes.add(entry.getValue());
}
return classes;
}
@Override
public ClassReader getClassReader(ModuleData res) {
public ClassReader getClassReader(ModuleEntry res) {
return newClassReader(res.getBytes());
}
}
@ -176,7 +175,7 @@ final class AsmPoolImpl implements AsmModulePool {
public void addResourceFile(ResourceFile resFile) {
Objects.requireNonNull(resFile);
String path = toResourceNamePath(resFile.getPath());
ModuleData res = Pool.newResource(path, resFile.getContent());
ModuleEntry res = ModuleEntry.create(path, resFile.getContent());
transformedResources.put(resFile.getPath(), res);
}
@ -191,7 +190,7 @@ final class AsmPoolImpl implements AsmModulePool {
Objects.requireNonNull(resourceName);
String path = toResourceNamePath(resourceName);
// do we have a resource?
ModuleData res = transformedResources.get(resourceName);
ModuleEntry res = transformedResources.get(resourceName);
if (res == null) {
res = inputResources.get(resourceName);
if (res == null) {
@ -212,7 +211,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public ResourceFile getResourceFile(String name) {
Objects.requireNonNull(name);
ModuleData res = transformedResources.get(name);
ModuleEntry res = transformedResources.get(name);
ResourceFile resFile = null;
if (res != null) {
resFile = getResourceFile(res);
@ -226,24 +225,24 @@ final class AsmPoolImpl implements AsmModulePool {
* @return The array of transformed classes.
*/
@Override
public Collection<ModuleData> getResourceFiles() {
List<ModuleData> resources = new ArrayList<>();
for (Entry<String, ModuleData> entry : transformedResources.entrySet()) {
public Collection<ModuleEntry> getResourceFiles() {
List<ModuleEntry> resources = new ArrayList<>();
for (Entry<String, ModuleEntry> entry : transformedResources.entrySet()) {
resources.add(entry.getValue());
}
return resources;
}
@Override
public ResourceFile getResourceFile(ModuleData res) {
public ResourceFile getResourceFile(ModuleEntry res) {
return new ResourceFile(toJavaBinaryResourceName(res.getPath()),
res.getBytes());
}
}
private final Pool jimageResources;
private final Map<String, ModuleData> inputClasses;
private final Map<String, ModuleData> inputResources;
private final ModulePool jimageResources;
private final Map<String, ModuleEntry> inputClasses;
private final Map<String, ModuleEntry> inputResources;
private final Map<String, String> inputClassPackageMapping;
private final Map<String, String> inputOtherPackageMapping;
@ -254,9 +253,9 @@ final class AsmPoolImpl implements AsmModulePool {
private Sorter sorter;
private final Map<String, ModuleData> transformedClasses
private final Map<String, ModuleEntry> transformedClasses
= new LinkedHashMap<>();
private final Map<String, ModuleData> transformedResources
private final Map<String, ModuleEntry> transformedResources
= new LinkedHashMap<>();
private final List<String> forgetResources = new ArrayList<>();
private final Map<String, String> newPackageMapping = new HashMap<>();
@ -274,7 +273,7 @@ final class AsmPoolImpl implements AsmModulePool {
* @param pools The resource pools.
* @param descriptor The module descriptor.
*/
AsmPoolImpl(Pool inputResources, String moduleName,
AsmPoolImpl(ModulePool inputResources, String moduleName,
AsmPools pools,
ModuleDescriptor descriptor) {
Objects.requireNonNull(inputResources);
@ -285,11 +284,11 @@ final class AsmPoolImpl implements AsmModulePool {
this.moduleName = moduleName;
this.pools = pools;
this.descriptor = descriptor;
Map<String, ModuleData> classes = new LinkedHashMap<>();
Map<String, ModuleData> resources = new LinkedHashMap<>();
Map<String, ModuleEntry> classes = new LinkedHashMap<>();
Map<String, ModuleEntry> resources = new LinkedHashMap<>();
Map<String, String> packageClassToModule = new HashMap<>();
Map<String, String> packageOtherToModule = new HashMap<>();
for (ModuleData res : inputResources.getContent()) {
inputResources.entries().forEach(res -> {
if (res.getPath().endsWith(".class")) {
classes.put(toJavaBinaryClassName(res.getPath()), res);
} else {
@ -305,7 +304,7 @@ final class AsmPoolImpl implements AsmModulePool {
packageOtherToModule.put(split[1], res.getModule());
}
}
}
});
this.inputClasses = Collections.unmodifiableMap(classes);
this.inputResources = Collections.unmodifiableMap(resources);
@ -356,7 +355,7 @@ final class AsmPoolImpl implements AsmModulePool {
* @return The array of classes.
*/
@Override
public Collection<ModuleData> getClasses() {
public Collection<ModuleEntry> getClasses() {
return inputClasses.values();
}
@ -367,7 +366,7 @@ final class AsmPoolImpl implements AsmModulePool {
* @return The array of classes.
*/
@Override
public Collection<ModuleData> getResourceFiles() {
public Collection<ModuleEntry> getResourceFiles() {
return inputResources.values();
}
@ -385,7 +384,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public ResourceFile getResourceFile(String binaryName) {
Objects.requireNonNull(binaryName);
ModuleData res = inputResources.get(binaryName);
ModuleEntry res = inputResources.get(binaryName);
ResourceFile resFile = null;
if (res != null) {
resFile = getResourceFile(res);
@ -402,7 +401,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public ClassReader getClassReader(String binaryName) {
Objects.requireNonNull(binaryName);
ModuleData res = inputClasses.get(binaryName);
ModuleEntry res = inputClasses.get(binaryName);
ClassReader reader = null;
if (res != null) {
reader = getClassReader(res);
@ -411,13 +410,13 @@ final class AsmPoolImpl implements AsmModulePool {
}
@Override
public ResourceFile getResourceFile(ModuleData res) {
public ResourceFile getResourceFile(ModuleEntry res) {
return new ResourceFile(toJavaBinaryResourceName(res.getPath()),
res.getBytes());
}
@Override
public ClassReader getClassReader(ModuleData res) {
public ClassReader getClassReader(ModuleEntry res) {
return newClassReader(res.getBytes());
}
@ -505,7 +504,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public void visitClassReaders(ClassReaderVisitor visitor) {
Objects.requireNonNull(visitor);
for (ModuleData res : getClasses()) {
for (ModuleEntry res : getClasses()) {
ClassReader reader = newClassReader(res.getBytes());
ClassWriter writer = visitor.visit(reader);
if (writer != null) {
@ -523,7 +522,7 @@ final class AsmPoolImpl implements AsmModulePool {
@Override
public void visitResourceFiles(ResourceFileVisitor visitor) {
Objects.requireNonNull(visitor);
for (ModuleData resource : getResourceFiles()) {
for (ModuleEntry resource : getResourceFiles()) {
ResourceFile resFile
= new ResourceFile(toJavaBinaryResourceName(resource.getPath()),
resource.getBytes());
@ -540,18 +539,18 @@ final class AsmPoolImpl implements AsmModulePool {
* been set, it is used to sort the returned resources. *
*/
@Override
public void fillOutputResources(Pool outputResources) {
public void fillOutputResources(ModulePool outputResources) {
List<String> added = new ArrayList<>();
// If the sorter is null, use the input order.
// New resources are added at the end
// First input classes that have not been removed
Pool output = new PoolImpl(outputResources.getByteOrder(),
((PoolImpl)outputResources).getStringTable());
for (ModuleData inResource : jimageResources.getContent()) {
ModulePool output = new ModulePoolImpl(outputResources.getByteOrder(),
((ModulePoolImpl)outputResources).getStringTable());
jimageResources.entries().forEach(inResource -> {
if (!forgetResources.contains(inResource.getPath())) {
ModuleData resource = inResource;
ModuleEntry resource = inResource;
// Do we have a transformed class with the same name?
ModuleData res = transformedResources.
ModuleEntry res = transformedResources.
get(toJavaBinaryResourceName(inResource.getPath()));
if (res != null) {
resource = res;
@ -565,10 +564,10 @@ final class AsmPoolImpl implements AsmModulePool {
output.add(resource);
added.add(resource.getPath());
}
}
});
// Then new resources
for (Map.Entry<String, ModuleData> entry : transformedResources.entrySet()) {
ModuleData resource = entry.getValue();
for (Map.Entry<String, ModuleEntry> entry : transformedResources.entrySet()) {
ModuleEntry resource = entry.getValue();
if (!forgetResources.contains(resource.getPath())) {
if (!added.contains(resource.getPath())) {
output.add(resource);
@ -576,8 +575,8 @@ final class AsmPoolImpl implements AsmModulePool {
}
}
// And new classes
for (Map.Entry<String, ModuleData> entry : transformedClasses.entrySet()) {
ModuleData resource = entry.getValue();
for (Map.Entry<String, ModuleEntry> entry : transformedClasses.entrySet()) {
ModuleEntry resource = entry.getValue();
if (!forgetResources.contains(resource.getPath())) {
if (!added.contains(resource.getPath())) {
output.add(resource);

@ -41,11 +41,11 @@ import java.util.Objects;
import java.util.Set;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.tools.jlink.internal.PoolImpl;
import jdk.tools.jlink.internal.ModulePoolImpl;
import jdk.tools.jlink.internal.plugins.asm.AsmPool.Sorter;
import jdk.tools.jlink.plugin.ModuleEntry;
import jdk.tools.jlink.plugin.PluginException;
import jdk.tools.jlink.plugin.Pool;
import jdk.tools.jlink.plugin.Pool.ModuleData;
import jdk.tools.jlink.plugin.ModulePool;
/**
* A container for pools of ClassReader and other resource files. A pool of all
@ -97,10 +97,10 @@ public final class AsmPools {
}
@Override
public Collection<Pool.ModuleData> getClasses() {
List<Pool.ModuleData> all = new ArrayList<>();
public Collection<ModuleEntry> getClasses() {
List<ModuleEntry> all = new ArrayList<>();
visitAllPools((AsmModulePool pool) -> {
for (Pool.ModuleData rf : pool.getTransformedClasses().getClasses()) {
for (ModuleEntry rf : pool.getTransformedClasses().getClasses()) {
all.add(rf);
}
});
@ -108,7 +108,7 @@ public final class AsmPools {
}
@Override
public ClassReader getClassReader(Pool.ModuleData res) {
public ClassReader getClassReader(ModuleEntry res) {
return visitPools((AsmModulePool pool) -> {
return pool.getTransformedClasses().getClassReader(res);
});
@ -140,10 +140,10 @@ public final class AsmPools {
}
@Override
public Collection<Pool.ModuleData> getResourceFiles() {
List<Pool.ModuleData> all = new ArrayList<>();
public Collection<ModuleEntry> getResourceFiles() {
List<ModuleEntry> all = new ArrayList<>();
visitAllPools((AsmModulePool pool) -> {
for (Pool.ModuleData rf : pool.getTransformedResourceFiles().getResourceFiles()) {
for (ModuleEntry rf : pool.getTransformedResourceFiles().getResourceFiles()) {
all.add(rf);
}
});
@ -151,7 +151,7 @@ public final class AsmPools {
}
@Override
public ResourceFile getResourceFile(Pool.ModuleData res) {
public ResourceFile getResourceFile(ModuleEntry res) {
return visitPools((AsmModulePool pool) -> {
return pool.getTransformedResourceFiles().getResourceFile(res);
});
@ -175,10 +175,10 @@ public final class AsmPools {
}
@Override
public Collection<Pool.ModuleData> getClasses() {
List<Pool.ModuleData> all = new ArrayList<>();
public Collection<ModuleEntry> getClasses() {
List<ModuleEntry> all = new ArrayList<>();
visitAllPools((AsmModulePool pool) -> {
for (Pool.ModuleData rf : pool.getClasses()) {
for (ModuleEntry rf : pool.getClasses()) {
all.add(rf);
}
});
@ -186,10 +186,10 @@ public final class AsmPools {
}
@Override
public Collection<Pool.ModuleData> getResourceFiles() {
List<Pool.ModuleData> all = new ArrayList<>();
public Collection<ModuleEntry> getResourceFiles() {
List<ModuleEntry> all = new ArrayList<>();
visitAllPools((AsmModulePool pool) -> {
for (Pool.ModuleData rf : pool.getResourceFiles()) {
for (ModuleEntry rf : pool.getResourceFiles()) {
all.add(rf);
}
});
@ -211,14 +211,14 @@ public final class AsmPools {
}
@Override
public ResourceFile getResourceFile(Pool.ModuleData res) {
public ResourceFile getResourceFile(ModuleEntry res) {
return visitPools((AsmModulePool pool) -> {
return pool.getResourceFile(res);
});
}
@Override
public ClassReader getClassReader(Pool.ModuleData res) {
public ClassReader getClassReader(ModuleEntry res) {
return visitPoolsEx((AsmModulePool pool) -> {
return pool.getClassReader(res);
});
@ -239,7 +239,7 @@ public final class AsmPools {
}
@Override
public void fillOutputResources(Pool outputResources) {
public void fillOutputResources(ModulePool outputResources) {
AsmPools.this.fillOutputResources(outputResources);
}
@ -324,15 +324,15 @@ public final class AsmPools {
*
* @param inputResources The raw resources to build the pool from.
*/
public AsmPools(Pool inputResources) {
public AsmPools(ModulePool inputResources) {
Objects.requireNonNull(inputResources);
Map<String, Pool> resPools = new LinkedHashMap<>();
Map<String, ModulePool> resPools = new LinkedHashMap<>();
Map<String, ModuleDescriptor> descriptors = new HashMap<>();
for (Pool.ModuleData res : inputResources.getContent()) {
Pool p = resPools.get(res.getModule());
inputResources.entries().forEach(res -> {
ModulePool p = resPools.get(res.getModule());
if (p == null) {
p = new PoolImpl(inputResources.getByteOrder(),
((PoolImpl)inputResources).getStringTable());
p = new ModulePoolImpl(inputResources.getByteOrder(),
((ModulePoolImpl)inputResources).getStringTable());
resPools.put(res.getModule(), p);
}
if (res.getPath().endsWith("module-info.class")) {
@ -341,11 +341,11 @@ public final class AsmPools {
descriptors.put(res.getModule(), descriptor);
}
p.add(res);
}
});
poolsArray = new AsmModulePool[resPools.size()];
int i = 0;
for (Entry<String, Pool> entry : resPools.entrySet()) {
for (Entry<String, ModulePool> entry : resPools.entrySet()) {
ModuleDescriptor descriptor = descriptors.get(entry.getKey());
if (descriptor == null) {
throw new PluginException("module-info.class not found for " + entry.getKey() + " module");
@ -405,7 +405,7 @@ public final class AsmPools {
*
* @param outputResources The pool used to fill the jimage.
*/
public void fillOutputResources(Pool outputResources) {
public void fillOutputResources(ModulePool outputResources) {
// First sort modules
List<String> modules = new ArrayList<>();
for (String k : pools.keySet()) {
@ -414,8 +414,8 @@ public final class AsmPools {
if (moduleSorter != null) {
modules = moduleSorter.sort(modules);
}
Pool output = new PoolImpl(outputResources.getByteOrder(),
((PoolImpl)outputResources).getStringTable());
ModulePool output = new ModulePoolImpl(outputResources.getByteOrder(),
((ModulePoolImpl)outputResources).getStringTable());
for (String mn : modules) {
AsmPool pool = pools.get(mn);
pool.fillOutputResources(output);
@ -423,17 +423,17 @@ public final class AsmPools {
sort(outputResources, output, global.sorter);
}
static void sort(Pool outputResources,
Pool transientOutput, Sorter sorter) {
static void sort(ModulePool outputResources,
ModulePool transientOutput, Sorter sorter) {
if (sorter != null) {
List<String> order = sorter.sort(transientOutput);
for (String s : order) {
outputResources.add(transientOutput.get(s));
outputResources.add(transientOutput.findEntry(s).get());
}
} else {
for (ModuleData res : transientOutput.getContent()) {
transientOutput.entries().forEach(res-> {
outputResources.add(res);
}
});
}
}

@ -24,66 +24,41 @@
*/
package jdk.tools.jlink.plugin;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
/**
* An executable runtime image. Instance of this class contains the information
* needed to create image processes.
* An executable runtime image. Contains the information about the executable
* image created.
*/
public abstract class ExecutableImage {
private final Path home;
private final List<String> args;
private final Set<String> modules;
protected ExecutableImage(Path home, Set<String> modules,
List<String> args) {
Objects.requireNonNull(home);
Objects.requireNonNull(args);
if (!Files.exists(home)) {
throw new IllegalArgumentException("Invalid image home");
}
this.home = home;
this.modules = Collections.unmodifiableSet(modules);
this.args = Collections.unmodifiableList(args);
}
public interface ExecutableImage {
/**
* Image home directory,
*
* @return The home directory.
*/
public Path getHome() {
return home;
}
public Path getHome();
/**
* The names of the modules located in the image.
*
* @return The set of modules.
*/
public Set<String> getModules() {
return modules;
}
public Set<String> getModules();
/**
* The list of arguments required to execute the image.
*
* @return The list of arguments.
*/
public List<String> getExecutionArgs() {
return args;
}
public List<String> getExecutionArgs();
/**
* Store new arguments required to execute the image.
*
* @param args Additional arguments
*/
public abstract void storeLaunchArgs(List<String> args);
public void storeLaunchArgs(List<String> args);
}

@ -0,0 +1,87 @@
/*
* 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 jdk.tools.jlink.plugin;
import java.lang.module.ModuleDescriptor;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
/**
* Link-time representation of a Java module.
*/
public interface LinkModule {
/**
* The module name.
*
* @return The name.
*/
public String getName();
/**
* Retrieves a LinkModuleEntry from the given path (e.g:
* /mymodule/com.foo.bar/MyClass.class)
*
* @param path The piece of data path.
* @return A LinkModuleEntry of the given path, if found.
*/
public Optional<ModuleEntry> findEntry(String path);
/**
* The module descriptor of this module.
*
* @return The module descriptor.
*/
public ModuleDescriptor getDescriptor();
/**
* Add a LinkModuleEntry to this module.
*
* @param data The LinkModuleEntry to add.
*/
public void add(ModuleEntry data);
/**
* Retrieves all the packages located in this module.
*
* @return The set of packages.
*/
public Set<String> getAllPackages();
/**
* Retrieves the stream of LinkModuleEntry.
*
* @return The LinkModuleEntry stream.
*/
public Stream<? extends ModuleEntry> entries();
/**
* Return the number of LinkModuleEntry count in this LinkModule.
*
* @return the entry count.
*/
public int getEntryCount();
}

@ -0,0 +1,155 @@
/*
* 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 jdk.tools.jlink.plugin;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Objects;
import jdk.tools.jlink.internal.ImageFileCreator;
import jdk.tools.jlink.internal.ModuleEntryImpl;
/**
* A LinkModuleEntry is the elementary unit of data inside an image. It is
* generally a file. e.g.: a java class file, a resource file, a shared library,
* ...
* <br>
* A LinkModuleEntry is identified by a path of the form:
* <ul>
* <li>For jimage content: /{module name}/{package1}/.../{packageN}/{file
* name}</li>
* <li>For other files (shared lib, launchers, config, ...):/{module name}/
* {@literal bin|conf|native}/{dir1}>/.../{dirN}/{file name}</li>
* </ul>
*/
public interface ModuleEntry {
/**
* Type of module data.
* <li>
* <ul>CLASS_OR_RESOURCE: A java class or resource file.</ul>
* <ul>CONFIG: A configuration file.</ul>
* <ul>NATIVE_CMD: A native process launcher.</ul>
* <ul>NATIVE_LIB: A native library.</ul>
* <ul>OTHER: Other kind of file.</ul>
* </li>
*/
public enum Type {
CLASS_OR_RESOURCE,
CONFIG,
NATIVE_CMD,
NATIVE_LIB,
OTHER
}
/**
* The LinkModuleEntry module name.
*
* @return The module name.
*/
public String getModule();
/**
* The LinkModuleEntry path.
*
* @return The module path.
*/
public String getPath();
/**
* The LinkModuleEntry's type.
*
* @return The data type.
*/
public Type getType();
/**
* The LinkModuleEntry content as an array of byte.
*
* @return An Array of bytes.
*/
public byte[] getBytes();
/**
* The LinkModuleEntry content length.
*
* @return The length.
*/
public long getLength();
/**
* The LinkModuleEntry stream.
*
* @return The module data stream.
*/
public InputStream stream();
/**
* Create a LinkModuleEntry located inside a jimage file. Such
* LinkModuleEntry has a Type being equals to CLASS_OR_RESOURCE.
*
* @param path The complete resource path (contains the module radical).
* @param content The resource content.
* @param size The content size.
* @return A new LinkModuleEntry.
*/
public static ModuleEntry create(String path, InputStream content, long size) {
Objects.requireNonNull(path);
Objects.requireNonNull(content);
String[] split = ImageFileCreator.splitPath(path);
String module = split[0];
return new ModuleEntryImpl(module, path, Type.CLASS_OR_RESOURCE, content, size);
}
/**
* Create a LinkModuleEntry for a file that will be located inside a jimage
* file.
*
* @param path The resource path.
* @param content The resource content.
* @return A new LinkModuleEntry.
*/
public static ModuleEntry create(String path, byte[] content) {
return create(path, new ByteArrayInputStream(content),
content.length);
}
/**
* Create a LinkModuleEntry for a file that will be located outside a jimage
* file.
*
* @param module The module in which this files is located.
* @param path The file path locator (doesn't contain the module name).
* @param type The LinkModuleEntry type.
* @param content The file content.
* @param size The content size.
* @return A new LinkModuleEntry.
*/
public static ModuleEntry create(String module, String path, ModuleEntry.Type type,
InputStream content, long size) {
Objects.requireNonNull(path);
Objects.requireNonNull(content);
return new ModuleEntryImpl(module, path, type, content, size);
}
}

@ -0,0 +1,136 @@
/*
* 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.
*/
package jdk.tools.jlink.plugin;
import java.nio.ByteOrder;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;
/**
* Pool of module data.
*/
public interface ModulePool {
/**
* Is this a read-only ModulePool?
*
* @return true if this is a read-only configuration.
*/
public boolean isReadOnly();
/**
* Add a ModuleEntry.
*
* @param data The ModuleEntry to add.
*/
public void add(ModuleEntry data);
/**
* Retrieves the module for the provided name.
*
* @param name The module name
* @return the module of matching name, if found
*/
public Optional<LinkModule> findModule(String name);
/**
* The stream of modules contained in this ModulePool.
*
* @return The stream of modules.
*/
public Stream<? extends LinkModule> modules();
/**
* Return the number of LinkModule count in this ModulePool.
*
* @return the module count.
*/
public int getModuleCount();
/**
* Get all ModuleEntry contained in this ModulePool instance.
*
* @return The stream of LinkModuleEntries.
*/
public Stream<? extends ModuleEntry> entries();
/**
* Return the number of ModuleEntry count in this ModulePool.
*
* @return the entry count.
*/
public int getEntryCount();
/**
* Get the ModuleEntry for the passed path.
*
* @param path A data path
* @return A ModuleEntry instance or null if the data is not found
*/
public Optional<ModuleEntry> findEntry(String path);
/**
* Check if the ModulePool contains the given ModuleEntry.
*
* @param data The module data to check existence for.
* @return The module data or null if not found.
*/
public boolean contains(ModuleEntry data);
/**
* Check if the ModulePool contains some content at all.
*
* @return True, no content, false otherwise.
*/
public boolean isEmpty();
/**
* Visit each ModuleEntry in this ModulePool to transform it and copy
* the transformed ModuleEntry to the output ModulePool.
*
* @param transform The function called for each ModuleEntry found in the
* ModulePool. The transform function should return a ModuleEntry
* instance which will be added to the output or it should return null if
* the passed ModuleEntry is to be ignored for the output.
*
* @param output The ModulePool to be filled with Visitor returned
* ModuleEntry.
*/
public void transformAndCopy(Function<ModuleEntry, ModuleEntry> transform, ModulePool output);
/**
* The ByteOrder currently in use when generating the jimage file.
*
* @return The ByteOrder.
*/
public ByteOrder getByteOrder();
/**
* Release properties such as OS, CPU name, version etc.
*
* @return the release properties
*/
public Map<String, String> getReleaseProperties();
}

@ -26,7 +26,6 @@ package jdk.tools.jlink.plugin;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jdk.tools.jlink.internal.plugins.PluginsResourceBundle;
@ -36,14 +35,6 @@ import jdk.tools.jlink.internal.plugins.PluginsResourceBundle;
*/
public interface Plugin {
/**
* Type of plugin.
*/
public interface PluginType {
public String getName();
}
/**
* Order of categories:
* <ol>
@ -53,28 +44,29 @@ public interface Plugin {
* <li>MODULEINFO_TRANSFORMER: Transform only module-info.class</li>
* <li>SORTER: Sort resources within the resource container.</li>
* <li>COMPRESSOR: Compress resource within the resouce containers.</li>
* <li>METAINFO_ADDER: Added meta info (like release, copyright etc.)</li>
* <li>VERIFIER: Does some image verification.</li>
* <li>PROCESSOR: Does some post processing on image.</li>
* <li>PACKAGER: Final processing</li>
* </ol>
*/
public enum CATEGORY implements PluginType {
public enum Category {
FILTER("FILTER"),
TRANSFORMER("TRANSFORMER"),
MODULEINFO_TRANSFORMER("MODULEINFO_TRANSFORMER"),
SORTER("SORTER"),
COMPRESSOR("COMPRESSOR"),
METAINFO_ADDER("METAINFO_ADDER"),
VERIFIER("VERIFIER"),
PROCESSOR("PROCESSOR"),
PACKAGER("PACKAGER");
private final String name;
CATEGORY(String name) {
Category(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
@ -91,7 +83,7 @@ public interface Plugin {
* {@link #getStateDescription() getStateDescription} method</li>
* </ul>
*/
public enum STATE {
public enum State {
DISABLED,
AUTO_ENABLED,
FUNCTIONAL
@ -101,7 +93,7 @@ public interface Plugin {
* The Plugin set of types.
* @return The set of types.
*/
public default Set<PluginType> getType() {
public default Set<Category> getType() {
return Collections.emptySet();
}
@ -109,8 +101,8 @@ public interface Plugin {
* The Plugin set of states.
* @return The set of states.
*/
public default Set<STATE> getState() {
return EnumSet.of(STATE.FUNCTIONAL);
public default Set<State> getState() {
return EnumSet.of(State.FUNCTIONAL);
}
/**
@ -191,7 +183,7 @@ public interface Plugin {
* @return A status description.
*/
public default String getStateDescription() {
return getState().contains(STATE.FUNCTIONAL)
return getState().contains(State.FUNCTIONAL)
? PluginsResourceBundle.getMessage("main.status.ok")
: PluginsResourceBundle.getMessage("main.status.not.ok");
}
@ -206,18 +198,4 @@ public interface Plugin {
*/
public default void configure(Map<String, String> config) {
}
/**
* Configure the plugin based on the passed configuration.
* This method is called prior to invoke the plugin.
*
* @param config The plugin configuration.
* @param ctx The plugin context
* @throws IllegalArgumentException if a mandatory argument is missing or
* if an argument has invalid value.
*
*/
public default void configure(Map<String, String> config, PluginContext ctx) {
configure(config);
}
}

Some files were not shown because too many files have changed in this diff Show More