Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Horrible scripts to make JD's output recompileable (for Spiral Knights, circa 2011. I'm not allowed regexes anymore.)
#!/bin/bash
#find possibly broken source files that will need to be manually fixed
( \
find ../code -type f -iname "*.java" -print0 | xargs --null grep -l '// Byte code:' && \
find ../code -type f -iname "*.java" -size 0 \
) | uniq
#!/bin/bash
#JD doesn't generate valid code under certain circumstances, try to clean it up
SCRIPT=$(readlink -f $0)
BASEDIR=`dirname $SCRIPT`
#directories in which to look for files to fix
FIXDIRS="${BASEDIR}/../code/com/threerings/projectx/ ${BASEDIR}/../code/com/threerings/coin/ ${BASEDIR}/../code/com/threerings/hemiptera/ ${BASEDIR}/../code/com/threerings/pulse/"
#fix duplicate equals operators
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l "= =" | xargs --null perl -pi -e "s/= =/=/g"
#fix max float / double vals
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '\-3.402824E+38F' | xargs --null perl -pi -e 's/\-3\.402824E\+38F/\Float\.MIN_VALUE/g'
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '3.4028235E+38F' | xargs --null perl -pi -e 's/3\.4028235E\+38F/Float\.MAX_VALUE/g'
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '\-1.797693134862316E+308D' | xargs --null perl -pi -e 's/\-1\.797693134862316E\+308D/Double\.MIN_VALUE/g'
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '1.7976931348623157E+308D' | xargs --null perl -pi -e 's/1\.7976931348623157E\+308D/Double\.MAX_VALUE/g'
#unscrew references to the class of arrays of objects
#non-base types
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l -P '\[L([a-zA-Z0-9\.]+)\.class' | xargs --null perl -pi -e 's/\[L([a-zA-Z0-9\.]+)\.class/$1\[\]\.class/g'
#base types
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '\[I.class' | xargs --null perl -pi -e 's/\[I.class/int\[\]\.class/g'
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '\[J.class' | xargs --null perl -pi -e 's/\[J.class/long\[\]\.class/g'
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '\[F.class' | xargs --null perl -pi -e 's/\[F.class/float\[\]\.class/g'
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '\[Z.class' | xargs --null perl -pi -e 's/\[Z.class/boolean\[\]\.class/g'
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '\[B.class' | xargs --null perl -pi -e 's/\[B.class/byte\[\]\.class/g'
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '\[C.class' | xargs --null perl -pi -e 's/\[C.class/char\[\]\.class/g'
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '\[D.class' | xargs --null perl -pi -e 's/\[D.class/double\[\]\.class/g'
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l '\[S.class' | xargs --null perl -pi -e 's/\[S.class/short\[\]\.class/g'
#why would you import one of the base classes? fix it anyways...
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l -P 'import (I|J|F|Z|B|C|D|S);' | xargs --null perl -pi -e 's/import (I|J|F|Z|B|C|D|S);//g'
#cast to long ends up empty? bah. bet this breaks something random.
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l -F '()(' | xargs --null perl -pi -e 's/\(\)\(/(long)(/g'
#sort of fix switches on enums
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l -P '\(([A-Za-z0-9\.]+\.)?[0-9]+\.\$SwitchMap\$.*?\[' | xargs --null perl -pi -e 's/\(([A-Za-z0-9\.]+\.)?[0-9]+\.\$SwitchMap\$.*?\[(.*?ordinal\(\))\]\)/($2)/g'
#try to unscrew all references to this
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l -P '([0-9\.]+\.)?this(\.)?(val\$)?' | xargs --null perl -pi -e 's/([0-9\.]+\.)?this(\.)?(val\$)?/this$2/g'
#now unbreak all of those package-info.java files (if I ever needed proof that perl one-liners are evil, this is it)
find $FIXDIRS -type f -iname "package-info.java" -print0 | xargs --null grep --null -l -F 'abstract interface package-info' | xargs --null perl -pi -e 'BEGIN{undef $/;} s/(.*)(\@EditorMessageBundle\(.*?\)).*/$2\n$1/gms'
#don't import the inner class (oh god, I think this happens for a lot of imports, this isn't good)
find $FIXDIRS -type f -iname "*.java" -print0 | xargs --null grep --null -l -F 'import com.threerings.presents.dobj.DSet.Entry;' | xargs --null perl -pi -e 's/import com\.threerings\.presents\.dobj\.DSet\.Entry;/import com.threerings.presents.dobj.DSet;/g'
#!/bin/bash
javac -classpath ../jars/ehcache-1.2.4.jar:$HOME/spiral/code/config.jar:$HOME/spiral/code/projectx-config.jar:$HOME/spiral/code/projectx-pcode.jar:$HOME/spiral/code/lwjgl.jar:$HOME/spiral/code/lwjgl_util.jar:$HOME/spiral/code/jinput.jar:$HOME/spiral/code/jshortcut.jar:$HOME/spiral/code/commons-beanutils.jar:$HOME/spiral/code/commons-digester.jar:$HOME/spiral/code/commons-logging.jar -Xmaxerrs 3000 -g -sourcepath ../code/ -d . `find ../code/ -name "*.java" |sed 's/ /\\ /' | tr '\n' ' '` 2>&1
#!/bin/bash
javac -sourcepath . -classpath ../jars/ehcache-1.2.4.jar:$HOME/spiral/code/projectx-pcode.jar:$HOME/spiral/code/config.jar:$HOME/spiral/code/projectx-config.jar:$HOME/spiral/code/projectx-pcode.jar:$HOME/spiral/code/lwjgl.jar:$HOME/spiral/code/lwjgl_util.jar:$HOME/spiral/code/jinput.jar:$HOME/spiral/code/jshortcut.jar:$HOME/spiral/code/commons-beanutils.jar:$HOME/spiral/code/commons-digester.jar:$HOME/spiral/code/commons-logging.jar -Xmaxerrs 3000 -g -d ../classes $@ 2>&1
#!/bin/bash
./recompile.sh 2>&1 | grep -F '..' | cut -d ':' -f 1,1 | sort | uniq -c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.