diff options
| -rw-r--r-- | README | 10 | ||||
| -rw-r--r-- | bin/flycheck-android-java.py | 117 | ||||
| -rw-r--r-- | flycheck-android-experimental.el | 7 | ||||
| -rw-r--r-- | src/main/groovy/FlycheckAndroidJavaTask.groovy | 47 |
4 files changed, 114 insertions, 67 deletions
@@ -52,6 +52,16 @@ apply plugin: org.thejk.FlycheckAndroidExperimentalInitPlugin That should be it. += If you have product flavors you might want to specify which += variant should be used. + +(add-to-list + 'java-mode-hook + '(lambda () + (progn + (require 'flycheck-android-experimental) + (setq flycheck-android-java-variant "devArm7Debug")))) + = If you use checkstyle, you can expand the java-mode-hook: (add-to-list 'java-mode-hook diff --git a/bin/flycheck-android-java.py b/bin/flycheck-android-java.py index d4a54ca..9bbb31a 100644 --- a/bin/flycheck-android-java.py +++ b/bin/flycheck-android-java.py @@ -121,7 +121,7 @@ Otherwise return None.""" return None def figure_out_java_compilation(sessiondir, sourcefile, tempfile, checkstyle, - force=False): + variant, force=False): """Get options for Java compilation from gradle project and run javac.""" (cmd, mtime, projectdir) = get_gradle_command_and_project_mtime( os.path.dirname(sourcefile)) @@ -158,40 +158,26 @@ def figure_out_java_compilation(sessiondir, sourcefile, tempfile, checkstyle, output = output.split('\n') - generate = None - all_generate = [] - - for line in output: - if line == '***' or line == '!!!': - if generate: - all_generate.extend(generate) - - generate = [] if line == '!!!' else None - elif generate != None: - generate.append(line) - - if all_generate: - subprocess.call(cmd + ['-q'] + all_generate) - data = None - first = None + data_type = None + variants = [] + gen = [] ret = 0 compiled = False for line in output: if line == '***' or line == '!!!': - if data: - if not first: - first = data - files = file_in_list(sourcefile, data['files']) - if files: - ret = run_javac(data['encoding'], data['source'], - data['target'], data['bootcp'], - data['cp'], files, data['output'], - data['args'], tempfile, outdir) - compiled = True - break - data = {} if line == '***' else None - elif data != None: + if data_type == '*': + variants.append({'data': data, 'gen': len(gen)}) + elif data_type == '!' and variants: + gen.append(data) + data_type = line[0] + if data_type == '*': + data = {} + else: + data = [] + elif data_type == '*': + if line.startswith('variant='): + data['variant'] = line[8:] if line.startswith('args='): data['args'] = line[6:-1].split(', ') elif line.startswith('encoding='): @@ -208,28 +194,68 @@ def figure_out_java_compilation(sessiondir, sourcefile, tempfile, checkstyle, data['files'] = line[6:].split(':') elif line.startswith('output='): data['output'] = line[7:] + elif data_type == '!': + data.append(line) - if not compiled and data: - if not first: - first = data - files = file_in_list(sourcefile, data['files']) - if files: - ret = run_javac(data['encoding'], data['source'], data['target'], - data['bootcp'], data['cp'], files, data['output'], - data['args'], tempfile, outdir) - compiled = True + if data_type == '*': + variants.append({'data': data, 'gen': len(gen)}) + elif data_type == '!' and variants: + gen.append(data) + + fallback = None + + if variant: + for v in variants: + data = v['data'] + if 'variant' in data and data['variant'] == variant: + if not fallback: + fallback = data + files = file_in_list(sourcefile, data['files']) + if files: + if v['gen'] < len(gen): + subprocess.call(cmd + ['-q'] + gen[v['gen']]) + + ret = run_javac(data['encoding'], data['source'], + data['target'], data['bootcp'], + data['cp'], files, data['output'], + data['args'], tempfile, outdir) + compiled = True + break + + if not compiled and variants: + data = variants[0]['data'] + first = data['variant'] if 'variant' in data else None + for v in variants: + data = v['data'] + if first and 'variant' in data and data['variant'] == first: + if not fallback: + fallback = data + files = file_in_list(sourcefile, data['files']) + if files: + if v['gen'] < len(gen): + subprocess.call(cmd + ['-q'] + gen[v['gen']]) + + ret = run_javac(data['encoding'], data['source'], + data['target'], data['bootcp'], + data['cp'], files, data['output'], + data['args'], tempfile, outdir) + compiled = True + break if not compiled: # Probably need to rerun gradle to find group for sourcefile if cached and os.path.exists(sourcefile): return figure_out_java_compilation(sessiondir, sourcefile, - tempfile, checkstyle, force=True) + tempfile, checkstyle, variant, + force=True) # OK, perhaps file doesn't exist yet or not yet added to gradle, # whatever, assume the first group is good enough - if first: - ret = run_javac(first['encoding'], first['source'], first['target'], - first['bootcp'], first['cp'], first['files'], - first['output'], first['args'], tempfile, outdir) + if fallback: + ret = run_javac(fallback['encoding'], fallback['source'], + fallback['target'], fallback['bootcp'], + fallback['cp'], fallback['files'], + fallback['output'], fallback['args'], + tempfile, outdir) compiled = True if not ret and checkstyle: @@ -263,6 +289,7 @@ def main(argv): parser.add_argument('--checkstyle-path') parser.add_argument('--checkstyle-config') parser.add_argument('--checkstyle-properties') + parser.add_argument('--variant') parser.add_argument('sessiondir', nargs='?') parser.add_argument('sourcefile') parser.add_argument('tempfile', nargs='?') @@ -280,6 +307,6 @@ def main(argv): sourcefile = os.path.abspath(sourcefile) return figure_out_java_compilation(args.sessiondir, sourcefile, tempfile, - checkstyle) + checkstyle, args.variant) sys.exit(main(sys.argv)) diff --git a/flycheck-android-experimental.el b/flycheck-android-experimental.el index 87cde62..34d01f0 100644 --- a/flycheck-android-experimental.el +++ b/flycheck-android-experimental.el @@ -34,6 +34,11 @@ :safe #'stringp) (make-variable-buffer-local 'flycheck-android-java-checkstyle-properties) +(flycheck-def-option-var flycheck-android-java-variant nil android-java + "Variant to select instead of first." + :safe #'stringp) +(make-variable-buffer-local 'flycheck-android-java-variant) + (flycheck-define-checker android-java "Java syntax checker using javac." :command ("python" @@ -46,6 +51,8 @@ flycheck-android-java-checkstyle-config concat) (option "--checkstyle-properties=" flycheck-android-java-checkstyle-properties concat) + (option "--variant=" + flycheck-android-java-variant concat) (eval (flycheck-android-get-sessiondir)) (eval buffer-file-name) source) diff --git a/src/main/groovy/FlycheckAndroidJavaTask.groovy b/src/main/groovy/FlycheckAndroidJavaTask.groovy index 633c445..558981d 100644 --- a/src/main/groovy/FlycheckAndroidJavaTask.groovy +++ b/src/main/groovy/FlycheckAndroidJavaTask.groovy @@ -32,30 +32,33 @@ class FlycheckAndroidJavaTask extends DefaultTask { } variants = variants.sort() def configurations = ['', 'UnitTest'] - configurations.each { configuration -> - def name = 'compile' - name += variants.first().capitalize() - name += configuration.capitalize() + 'JavaWithJavac' - def compile = project.tasks.findByName(name) - if (compile) { - println '***' - println 'args=' + compile.options.compilerArgs - println 'encoding=' + compile.options.encoding - println 'bootcp=' + (compile.options.bootClasspath ?: '') - println 'cp=' + compile.classpath.asPath - println 'source=' + compile.sourceCompatibility - println 'target=' + compile.targetCompatibility - println 'files=' + compile.inputs.files.asPath - println 'output=' + compile.destinationDir + variants.each { variant -> + configurations.each { configuration -> + def name = 'compile' + name += variant.capitalize() + name += configuration.capitalize() + 'JavaWithJavac' + def compile = project.tasks.findByName(name) + if (compile) { + println '***' + println 'variant=' + variant + println 'args=' + compile.options.compilerArgs + println 'encoding=' + compile.options.encoding + println 'bootcp=' + (compile.options.bootClasspath ?: '') + println 'cp=' + compile.classpath.asPath + println 'source=' + compile.sourceCompatibility + println 'target=' + compile.targetCompatibility + println 'files=' + compile.inputs.files.asPath + println 'output=' + compile.destinationDir + } } - } - def name = 'generate' - name += variants.first().capitalize() + 'Sources' - def generate = project.tasks.findByName(name) - if (generate != null) { - println '!!!' - println generate.path + def name = 'generate' + name += variant.capitalize() + 'Sources' + def generate = project.tasks.findByName(name) + if (generate != null) { + println '!!!' + println generate.path + } } } } |
