From 3166c5ace3f00e9fe33fc1b949b2cc9b902098de Mon Sep 17 00:00:00 2001 From: Eduard Dereza Date: Sun, 27 Aug 2017 12:41:15 +0300 Subject: [PATCH 1/5] Replaced cfr decompiler with procyon --- y-decompile | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/y-decompile b/y-decompile index 052977f..1a76bd5 100755 --- a/y-decompile +++ b/y-decompile @@ -6,29 +6,56 @@ CFR_JAR=cfr_0_122.jar CFR_URL="http://www.benf.org/other/cfr/$CFR_JAR" + +PROCYON_JAR="procyon-decompiler-0.5.30.jar" +PROCYON_URL="https://bitbucket.org/mstrobel/procyon/downloads/$PROCYON_JAR" + TMP_DIR="/tmp" HYBRIS_DIR=`y-whereis` +function decompileClass { + local PROCYON_JAR="procyon-decompiler-0.5.30.jar" + local TMP_DIR="/tmp" + local jarPath=$1 + local jarName=$(basename $jarPath) + local jarBaseName="${jarName%.*}" + local jarDirPath=$(dirname $jarPath)/$jarBaseName + java -jar $TMP_DIR/$PROCYON_JAR $classPath -ln -jar $jarPath -o $jarDirPath; + return 0 +} + +export -f decompileClass + if [ $? -ne 0 ]; then echo "FAILURE" exit 1 fi -DECOMPILED_SRC_DIR="$HYBRIS_DIR/../../data/decompiled_src" +RELATIVE_DECOMPILED_SRC_DIR="$HYBRIS_DIR/../../data/decompiled_src" +DECOMPILED_SRC_DIR=$(cd $(dirname $RELATIVE_DECOMPILED_SRC_DIR); pwd)/decompiled_src echo "Getting cfr decompliler" wget -nc -O "$TMP_DIR/$CFR_JAR" $CFR_URL +echo "Getting procyon decompliler" +wget -nc -O "$TMP_DIR/$PROCYON_JAR" $PROCYON_URL + echo "Cleaning directory with decompiled source" rm -rf "$DECOMPILED_SRC_DIR" -echo "Starting jar decompiling" -find "$HYBRIS_DIR/../.." \( \ - -regex ".*bin/[^/]*.jar" \ - -not -path "*tomcat*" \ - -not -path "*atddrunner*" \ - -or \ - -name "*_bof.jar" \) \ - -exec java -jar $TMP_DIR/$CFR_JAR "{}" --outputdir "$DECOMPILED_SRC_DIR"/ \; +rsync -zarvm --exclude="custom/**" \ + --exclude="*tomcat*" \ + --include="*/" \ + --include="**/bin/*.jar" \ + --exclude="*" \ + "$HYBRIS_DIR/.." \ + "$DECOMPILED_SRC_DIR"; + +echo "Starting class files decompiling" +find $DECOMPILED_SRC_DIR -name "*.jar" -exec bash -c 'decompileClass "$1"' _ {} \; + +echo "Starting cleaning up" +find $DECOMPILED_SRC_DIR -name '*.jar' -exec rm "{}" \; + +echo "Finished, decompiled sources available in folder: $DECOMPILED_SRC_DIR" -echo "Finished, decompiled sources available in folder: $DECOMPILED_SRC_DIR" \ No newline at end of file From 5f01f15dd6eec81c670920570d7648ba90fdca0e Mon Sep 17 00:00:00 2001 From: Eduard Dereza Date: Sun, 27 Aug 2017 14:37:54 +0300 Subject: [PATCH 2/5] Added parameter for decompiler selection --- y-decompile | 56 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/y-decompile b/y-decompile index 1a76bd5..ce59ce5 100755 --- a/y-decompile +++ b/y-decompile @@ -1,6 +1,8 @@ #!/usr/bin/env bash -# Decompiles hybris jar files using CFR decompiler +# Decompiles hybris jar files using CFR or PROCYON decompiler +# Decompiler can be specified by argument like - "y-decompile -d cfr" or "y-decompile -d procyon" +# Procyon decompiler is used by default # # source: https://github.com/sergaks/y-scripts @@ -13,24 +15,48 @@ PROCYON_URL="https://bitbucket.org/mstrobel/procyon/downloads/$PROCYON_JAR" TMP_DIR="/tmp" HYBRIS_DIR=`y-whereis` -function decompileClass { - local PROCYON_JAR="procyon-decompiler-0.5.30.jar" - local TMP_DIR="/tmp" - local jarPath=$1 - local jarName=$(basename $jarPath) - local jarBaseName="${jarName%.*}" - local jarDirPath=$(dirname $jarPath)/$jarBaseName - java -jar $TMP_DIR/$PROCYON_JAR $classPath -ln -jar $jarPath -o $jarDirPath; - return 0 +SELECTED_DECOMPILER="procyon" + +function decompileJar { + TMP_DIR="/tmp" + CFR_JAR=cfr_0_122.jar + PROCYON_JAR="procyon-decompiler-0.5.30.jar" + local jarPath=$1 + local decompiler=$2 + local jarName=$(basename $jarPath) + local jarBaseName="${jarName%.*}" + local jarDirPath=$(dirname $jarPath)/$jarBaseName + if [ $decompiler = "cfr" ]; then + java -jar $TMP_DIR/$CFR_JAR $jarPath --outputdir $jarDirPath; + else + java -jar $TMP_DIR/$PROCYON_JAR -ln -jar $jarPath -o $jarDirPath; + fi + return 0 } - -export -f decompileClass +export -f decompileJar if [ $? -ne 0 ]; then echo "FAILURE" exit 1 fi +checkargs () { + if ! [[ $OPTARG =~ ^(procyon|cfr)$ ]] + then + echo "Unknow argument $OPTARG for option $opt. Please specify decompiler 'cfr' or 'procyon'" + exit 1 + fi +} + +# Parse command line argument - d (decompiler) +while getopts "d:" opt +do +case $opt in +d) checkargs +SELECTED_DECOMPILER=$OPTARG;; +esac +done + RELATIVE_DECOMPILED_SRC_DIR="$HYBRIS_DIR/../../data/decompiled_src" DECOMPILED_SRC_DIR=$(cd $(dirname $RELATIVE_DECOMPILED_SRC_DIR); pwd)/decompiled_src @@ -51,11 +77,11 @@ rsync -zarvm --exclude="custom/**" \ "$HYBRIS_DIR/.." \ "$DECOMPILED_SRC_DIR"; -echo "Starting class files decompiling" -find $DECOMPILED_SRC_DIR -name "*.jar" -exec bash -c 'decompileClass "$1"' _ {} \; +echo "Starting class files decompiling by $SELECTED_DECOMPILER" +find $DECOMPILED_SRC_DIR -name "*.jar" -exec bash -c 'decompileJar "$1" "$2"' _ {} $SELECTED_DECOMPILER \; + echo "Starting cleaning up" find $DECOMPILED_SRC_DIR -name '*.jar' -exec rm "{}" \; echo "Finished, decompiled sources available in folder: $DECOMPILED_SRC_DIR" - From 669a2d5100a0b64cf743cf56d43d84de95ae775a Mon Sep 17 00:00:00 2001 From: Eduard Dereza Date: Tue, 12 Dec 2017 12:09:45 +0200 Subject: [PATCH 3/5] Added decompiled lines alignment --- y-decompile | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/y-decompile b/y-decompile index ce59ce5..0fa514e 100755 --- a/y-decompile +++ b/y-decompile @@ -6,14 +6,17 @@ # # source: https://github.com/sergaks/y-scripts -CFR_JAR=cfr_0_122.jar +CFR_JAR=cfr_0_123.jar CFR_URL="http://www.benf.org/other/cfr/$CFR_JAR" PROCYON_JAR="procyon-decompiler-0.5.30.jar" PROCYON_URL="https://bitbucket.org/mstrobel/procyon/downloads/$PROCYON_JAR" TMP_DIR="/tmp" -HYBRIS_DIR=`y-whereis` +HYBRIS_BIN_DIR=$(cd $(dirname `y-whereis`); pwd) +DECOMPILED_SRC_DIR=$(cd $(dirname $HYBRIS_BIN_DIR/../..); pwd)/data/decompiled_src + +echo $DECOMPILED_SRC_DIR SELECTED_DECOMPILER="procyon" @@ -24,13 +27,16 @@ function decompileJar { local jarPath=$1 local decompiler=$2 local jarName=$(basename $jarPath) - local jarBaseName="${jarName%.*}" - local jarDirPath=$(dirname $jarPath)/$jarBaseName + local jarBaseName="${jarName%.*}" + local jarDirPath=$(dirname $jarPath)/$jarBaseName if [ $decompiler = "cfr" ]; then - java -jar $TMP_DIR/$CFR_JAR $jarPath --outputdir $jarDirPath; + java -jar $TMP_DIR/$CFR_JAR $jarPath --outputdir $jarDirPath; else - java -jar $TMP_DIR/$PROCYON_JAR -ln -jar $jarPath -o $jarDirPath; + java -jar $TMP_DIR/$PROCYON_JAR -sl -ln --unicode -jar $jarPath -o $jarDirPath; fi + echo "Packing jar jar cvf $jarBaseName-sources.jar $jarDirPath" + #cd $(dirname $jarPath) + #jar cvf $jarBaseName-sources.jar $jarBaseName return 0 } export -f decompileJar @@ -57,9 +63,6 @@ SELECTED_DECOMPILER=$OPTARG;; esac done -RELATIVE_DECOMPILED_SRC_DIR="$HYBRIS_DIR/../../data/decompiled_src" -DECOMPILED_SRC_DIR=$(cd $(dirname $RELATIVE_DECOMPILED_SRC_DIR); pwd)/decompiled_src - echo "Getting cfr decompliler" wget -nc -O "$TMP_DIR/$CFR_JAR" $CFR_URL @@ -73,8 +76,9 @@ rsync -zarvm --exclude="custom/**" \ --exclude="*tomcat*" \ --include="*/" \ --include="**/bin/*.jar" \ + --include="**/*_bof.jar" \ --exclude="*" \ - "$HYBRIS_DIR/.." \ + "$HYBRIS_BIN_DIR" \ "$DECOMPILED_SRC_DIR"; echo "Starting class files decompiling by $SELECTED_DECOMPILER" @@ -82,6 +86,6 @@ find $DECOMPILED_SRC_DIR -name "*.jar" -exec bash -c 'decompileJar "$1" "$2"' _ echo "Starting cleaning up" -find $DECOMPILED_SRC_DIR -name '*.jar' -exec rm "{}" \; +find $DECOMPILED_SRC_DIR ! -name '*-sources.jar' -name '*.jar' -exec rm "{}" \; echo "Finished, decompiled sources available in folder: $DECOMPILED_SRC_DIR" From ae979500788102d4bb7ca53555f0eb14d54e1102 Mon Sep 17 00:00:00 2001 From: Eduard Dereza Date: Thu, 11 Jan 2018 19:19:46 +0200 Subject: [PATCH 4/5] y-whereis is looking for 'bin/platform' instead of 'hybris' dir --- y-whereis | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/y-whereis b/y-whereis index 32b8e82..e1587ba 100755 --- a/y-whereis +++ b/y-whereis @@ -9,8 +9,8 @@ HYBRIS_PLATFORM_DIR="bin/platform" function purge_hybris_pathes() { for f in "${pathes[@]}"; do - if [ -d "$f/$HYBRIS_PLATFORM_DIR" ]; then - hybris_pathes+=("$f/$HYBRIS_PLATFORM_DIR") + if [[ $f == *$HYBRIS_PLATFORM_DIR ]]; then + hybris_pathes+=("$f") fi done } @@ -18,8 +18,8 @@ function purge_hybris_pathes() function lookup_in_current_dir() { CURRENT_DIR=`pwd` - if [[ $CURRENT_DIR == *"hybris"* ]]; then - pathes+=(`echo $CURRENT_DIR | sed -n 's/hybris.*$/hybris/p'`) + if [[ $CURRENT_DIR == *"platform"* ]]; then + pathes+=(`echo $CURRENT_DIR | sed -n 's/platform.*$/platform/p'`) fi } @@ -27,16 +27,17 @@ function lookup_in_subdirectories() { while IFS= read -r -d $'\0'; do pathes+=("$REPLY") - done < <(find . -maxdepth 3 -type d -name "hybris" -print0) + done < <(find . -maxdepth 4 -type d -name "platform" -print0) } function lookup_nearby() { PARENT=".." - for (( i = 0; i < 5; i++ )); do + for (( i = 0; i < 4; i++ )); do while IFS= read -r -d $'\0'; do pathes+=("$REPLY") - done < <(find $PARENT -maxdepth 3 -type d -name "hybris" -print0) + echo $REPLY + '+' + 'bin' + done < <(find $PARENT -maxdepth 4 -type d -name "platform" -print0) PARENT+="/.." purge_hybris_pathes if [ ${#hybris_pathes[@]} -ne 0 ]; then From 3465c734fbffc8fcbf68ba910e037b6ac5a043a7 Mon Sep 17 00:00:00 2001 From: Eduard Dereza Date: Thu, 19 Nov 2020 19:48:38 +0200 Subject: [PATCH 5/5] Add rebuild command --- y-rebuild | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100755 y-rebuild diff --git a/y-rebuild b/y-rebuild new file mode 100755 index 0000000..fea9c24 --- /dev/null +++ b/y-rebuild @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# Alias for and build with disabled items.xml verification to speed up rebuilding +# +# source: https://github.com/sergaks/y-scripts + +y-ant clean && y-build && y-ant deploy +