Skip to content

Commit

Permalink
Make collision detection multi-platform (strimzi#2257)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Scholz <[email protected]>
  • Loading branch information
scholzj authored Dec 2, 2019
1 parent 098fcd5 commit a86f849
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Makefile.os
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ FIND = find
SED = sed
GREP = grep
CP = cp
UNIQ = uniq
SORT = sort

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
FIND = gfind
SED = gsed
GREP = ggrep
CP = gcp
UNIQ = guniq
SORT = gsort
endif
3 changes: 2 additions & 1 deletion docker-images/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -e

source $(dirname $(realpath $0))/../tools/kafka-versions-tools.sh
source $(dirname $(realpath $0))/../multi-platform-support.sh

# Image directories
base_images="base"
Expand Down Expand Up @@ -127,7 +128,7 @@ function fetch_and_unpack_kafka_binaries {
then
unzipped_dir=`mktemp -d`
./extract-jars.sh "$dist_dir/libs" "$unzipped_dir"
./find-colliding-classes.sh "$unzipped_dir" | awk '{print $1}' | sort | uniq > "$whilelist_file" || true
./find-colliding-classes.sh "$unzipped_dir" | awk '{print $1}' | $SORT | $UNIQ > "$whilelist_file" || true
rm -rf $unzipped_dir
fi
done
Expand Down
10 changes: 6 additions & 4 deletions docker-images/find-colliding-classes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
# $1: Directory containing (directories containing) .class files
unzipped_dir=$1

source $(dirname $(realpath $0))/../multi-platform-support.sh

# 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#' | \
$SED -E 's#([a-z0-9]+).*/([^/]*[.]jar)/(.*)#\1\t\2\t\3#' | \
# sort by classname
sort -r -k 3 | \
$SORT -r -k 3 | \
# find duplicate classname
uniq -D -f2 | \
$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
$UNIQ -u -f2
4 changes: 4 additions & 0 deletions multi-platform-support.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ CP=cp
SED=sed
GREP=grep
WC=wc
UNIQ=uniq
SORT=sort

UNAME_S=$(uname -s)
if [ $UNAME_S = "Darwin" ];
Expand All @@ -20,4 +22,6 @@ then
SED=gsed
GREP=ggrep
WC=gwc
UNIQ=guniq
SORT=gsort
fi

0 comments on commit a86f849

Please sign in to comment.