Skip to content

Commit

Permalink
infras: decoupling multiDeclRefactor with checkstyle backend. Add con…
Browse files Browse the repository at this point in the history
…troller of checkstyle as a middleware.
  • Loading branch information
CharlesZ-Chen committed Dec 16, 2016
1 parent 5daa44b commit 8043286
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
25 changes: 25 additions & 0 deletions controller_checkstyle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
import json

import multiDeclRefactor

### key: issue name in checkstyle,
### value: refactor method main entry
REFACTOR_DICT = {
"HackedMultipleVariableDeclarations" : multiDeclRefactor.refactor_decls
}

def main():
try:
data = json.load(sys.stdin)

for issue, refactor in REFACTOR_DICT.iteritems():
refactor(data[issue])

except ValueError:
for line in sys.stdin:
print line
sys.exit(1)

if __name__ == '__main__':
main()
16 changes: 8 additions & 8 deletions multiDeclRefactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
import shutil, tempfile
import json

REFACTOR_ISSUE_NAME = "HackedMultipleVariableDeclarations"

def main():
try:
data = json.load(sys.stdin)
total_multi_decls = data[REFACTOR_ISSUE_NAME]
file_based_multi_decls = collect_by_file(total_multi_decls)
for refactor_file, multi_decls in file_based_multi_decls.iteritems():
refactor_decls(refactor_file, multi_decls)
total_multi_decls = json.load(sys.stdin)
refactor_decls(total_multi_decls)
except ValueError:
for line in sys.stdin:
print line
sys.exit(1)

def refactor_decls(refactor_file, multi_decls):
def refactor_decls(total_multi_decls):
file_based_multi_decls = collect_by_file(total_multi_decls)
for refactor_file, multi_decls in file_based_multi_decls.iteritems():
refactor_decls_in_single_file(refactor_file, multi_decls)

def refactor_decls_in_single_file(refactor_file, multi_decls):
# print multi_decls
backup = refactor_file + ".origin"
shutil.copyfile(refactor_file, backup)
Expand Down
4 changes: 2 additions & 2 deletions run-refactor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ CHECK_STYLE_DIR=$SCRIPT_DIR/checkstyle

CHECK_STYLE_ALL_JAR=$CHECK_STYLE_DIR/target/checkstyle-7.4-SNAPSHOT-all.jar

java -jar $CHECK_STYLE_ALL_JAR -c $SCRIPT_DIR/multiDeclChecks.xml -f json "$@" | python $SCRIPT_DIR/multiDeclRefactor.py
java -jar $CHECK_STYLE_ALL_JAR -c $SCRIPT_DIR/multiDeclChecks.xml -f json "$@" | python $SCRIPT_DIR/controller_checkstyle.py

##develop version call: using eclipse output of checkstyle, running refactor frontend
# java -cp $ROOT_DIR/checkstyle/target/classes:$(ls $ROOT_DIR/checkstyle/target/dependency/*.jar | tr '\n' : | rev | cut -c 2- | rev) com.puppycrawl.tools.checkstyle.Main -c $SCRIPT_DIR/multiDeclChecks.xml -f json "$@" | python $SCRIPT_DIR/multiDeclRefactor.py
# java -cp $ROOT_DIR/checkstyle/target/classes:$(ls $ROOT_DIR/checkstyle/target/dependency/*.jar | tr '\n' : | rev | cut -c 2- | rev) com.puppycrawl.tools.checkstyle.Main -c $SCRIPT_DIR/multiDeclChecks.xml -f json "$@" | python $SCRIPT_DIR/controller_checkstyle.py

## develop version call: using eclipse output of checkstyle, print AST tree
# java -cp $ROOT_DIR/checkstyle/target/classes:$(ls $ROOT_DIR/checkstyle/target/dependency/*.jar | tr '\n' : | rev | cut -c 2- | rev) com.puppycrawl.tools.checkstyle.Main -t "$@"

0 comments on commit 8043286

Please sign in to comment.