forked from strimzi/strimzi-kafka-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break the build for classpath collisions in Kafka images (strimzi#2253)
This detects when the 3rd-party jars mechanism adds jar dependencies which collide with either other 3rd party jars or with the Kafka jars/dependencies. This is, in essence a regression test for strimzi#2245. Signed-off-by: Tom Bentley <[email protected]>
- Loading branch information
1 parent
598f0ab
commit 8d705ef
Showing
7 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#! /usr/bin/env bash | ||
|
||
jars_dir=$1 | ||
classes_root=$2 | ||
|
||
for jar in $(find $jars_dir -type f -name '*.jar') | ||
do | ||
extracted=$classes_root/$(basename "$jar") | ||
mkdir -p "$extracted" | ||
unzip -qq "$jar" -d "$extracted" >/dev/null | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#! /usr/bin/env bash | ||
image=$1 #strimzi/kafka:latest-kafka-2.2.1 | ||
image_jar_dir=$2 #/opt/kafka/libs | ||
whilelist_file=$3 | ||
|
||
jars_dir=`mktemp -d` | ||
trap "[ -e $jars_dir ] && rm -rf $jars_dir" EXIT | ||
|
||
docker run --name temp-container-name "$image" /bin/true || exit 2 | ||
docker cp "temp-container-name:$image_jar_dir" "$jars_dir" | ||
docker rm temp-container-name > /dev/null | ||
|
||
classes_root=`mktemp -d` | ||
trap "[ -e $classes_root ] && rm -rf $classes_root" EXIT | ||
|
||
$(dirname $0)/extract-jars.sh "$jars_dir" "$classes_root" | ||
|
||
collisions=$($(dirname "$0")/find-colliding-classes.sh "$classes_root" | awk '{printf("%s\t%s\n",$1,$2);}' | \ | ||
grep -vFf "$whilelist_file") | ||
|
||
if [ "$collisions" != "" ] ; then | ||
echo "ERROR: Different class files with same name from different jars found!" | ||
echo "$collisions" | ||
echo "(Ignoring jars from Kafka distribution containing different class files with same name:" | ||
sed -e 's/^/ /' "$whilelist_file" | ||
echo ")" | ||
echo "It's likely that either two third party jars are using different versions " | ||
echo "of a common (transitive) dependency or a single third party jar is using a" | ||
echo "dependency which is also a (transitive) dependency of Kafka." | ||
echo "In either case the solution is a judicious <exclude> of the dependency." | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#! /usr/bin/env bash | ||
# $1: Directory containing (directories containing) .class files | ||
unzipped_dir=$1 | ||
|
||
# compute list of <md5> <classfile> | ||
find $unzipped_dir ! -empty -type f -name '*.class' -a ! -name 'module-info.class' -exec md5sum {} + | \ | ||
# split into <md5> <jarname> <classname> | ||
sed -E 's#([a-z0-9]+).*/([^/]*[.]jar)/(.*)#\1\t\2\t\3#' | \ | ||
# sort by classname | ||
sort -r -k 3 | \ | ||
# find duplicate classname | ||
uniq -D -f2 | \ | ||
# swap column order => <classname> <jarname> <md5> | ||
awk '{printf("%s\t%s\t%s\n",$2,$3,$1);}' | \ | ||
# find unique md5 (i.e. classfiles differ) | ||
uniq -u -f2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters