Mercurial > hg > truffle
comparison mxtool/mx.py @ 18890:f5cee3a0496c
mx: support annotation processors in libraries
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Wed, 21 Jan 2015 13:55:37 +0100 |
parents | 4dc7b1f66de3 |
children | 8e8b4a6a85f5 |
comparison
equal
deleted
inserted
replaced
18889:4dc7b1f66de3 | 18890:f5cee3a0496c |
---|---|
1 #!/usr/bin/env python2.7 | 1 #!/usr/bin/env python2.7 |
2 # | 2 # |
3 # ---------------------------------------------------------------------------------------------------- | 3 # ---------------------------------------------------------------------------------------------------- |
4 # | 4 # |
5 # Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. | 5 # Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. |
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7 # | 7 # |
8 # This code is free software; you can redistribute it and/or modify it | 8 # This code is free software; you can redistribute it and/or modify it |
9 # under the terms of the GNU General Public License version 2 only, as | 9 # under the terms of the GNU General Public License version 2 only, as |
10 # published by the Free Software Foundation. | 10 # published by the Free Software Foundation. |
552 Gets the class path composed of the distribution jars containing the | 552 Gets the class path composed of the distribution jars containing the |
553 annotation processors that will be applied when compiling this project. | 553 annotation processors that will be applied when compiling this project. |
554 """ | 554 """ |
555 def annotation_processors_path(self): | 555 def annotation_processors_path(self): |
556 aps = [project(ap) for ap in self.annotation_processors()] | 556 aps = [project(ap) for ap in self.annotation_processors()] |
557 if len(aps): | 557 libAps = [dep for dep in self.all_deps([], includeLibs=True, includeSelf=False) if dep.isLibrary() and hasattr(dep, 'annotationProcessor') and getattr(dep, 'annotationProcessor').lower() == 'true'] |
558 return os.pathsep.join([ap.definedAnnotationProcessorsDist.path for ap in aps if ap.definedAnnotationProcessorsDist]) | 558 if len(aps) + len(libAps): |
559 return os.pathsep.join([ap.definedAnnotationProcessorsDist.path for ap in aps if ap.definedAnnotationProcessorsDist] + [lib.get_path(False) for lib in libAps]) | |
559 return None | 560 return None |
561 | |
562 def uses_annotation_processor_library(self): | |
563 for dep in self.all_deps([], includeLibs=True, includeSelf=False): | |
564 if dep.isLibrary() and hasattr(dep, 'annotationProcessor'): | |
565 return True | |
566 return False | |
560 | 567 |
561 def update_current_annotation_processors_file(self): | 568 def update_current_annotation_processors_file(self): |
562 aps = self.annotation_processors() | 569 aps = self.annotation_processors() |
563 outOfDate = False | 570 outOfDate = False |
564 currentApsFile = join(self.suite.mxDir, 'currentAnnotationProcessors', self.name) | 571 currentApsFile = join(self.suite.mxDir, 'currentAnnotationProcessors', self.name) |
2442 log('JDT properties file {0} not found'.format(jdtProperties)) | 2449 log('JDT properties file {0} not found'.format(jdtProperties)) |
2443 else: | 2450 else: |
2444 with open(jdtProperties) as fp: | 2451 with open(jdtProperties) as fp: |
2445 origContent = fp.read() | 2452 origContent = fp.read() |
2446 content = origContent | 2453 content = origContent |
2447 if args.jdt_warning_as_error: | 2454 if self.proj.uses_annotation_processor_library(): |
2455 # unfortunately, the command line compiler doesn't let us ignore warnings for generated files only | |
2456 content = content.replace('=warning', '=ignore') | |
2457 elif args.jdt_warning_as_error: | |
2448 content = content.replace('=warning', '=error') | 2458 content = content.replace('=warning', '=error') |
2449 if not args.jdt_show_task_tags: | 2459 if not args.jdt_show_task_tags: |
2450 content = content + '\norg.eclipse.jdt.core.compiler.problem.tasks=ignore' | 2460 content = content + '\norg.eclipse.jdt.core.compiler.problem.tasks=ignore' |
2451 if origContent != content: | 2461 if origContent != content: |
2452 jdtPropertiesTmp = jdtProperties + '.tmp' | 2462 jdtPropertiesTmp = jdtProperties + '.tmp' |
3589 srcDir = join(p.dir, src) | 3599 srcDir = join(p.dir, src) |
3590 if not exists(srcDir): | 3600 if not exists(srcDir): |
3591 os.mkdir(srcDir) | 3601 os.mkdir(srcDir) |
3592 out.element('classpathentry', {'kind' : 'src', 'path' : src}) | 3602 out.element('classpathentry', {'kind' : 'src', 'path' : src}) |
3593 | 3603 |
3594 if len(p.annotation_processors()) > 0: | 3604 processorPath = p.annotation_processors_path() |
3605 if processorPath: | |
3595 genDir = p.source_gen_dir() | 3606 genDir = p.source_gen_dir() |
3596 if not exists(genDir): | 3607 if not exists(genDir): |
3597 os.mkdir(genDir) | 3608 os.mkdir(genDir) |
3598 out.element('classpathentry', {'kind' : 'src', 'path' : 'src_gen'}) | 3609 out.open('classpathentry', {'kind' : 'src', 'path' : 'src_gen'}) |
3610 if p.uses_annotation_processor_library(): | |
3611 # ignore warnings produced by third-party annotation processors | |
3612 out.open('attributes') | |
3613 out.element('attribute', {'name' : 'ignore_optional_problems', 'value' : 'true'}) | |
3614 out.close('attributes') | |
3615 out.close('classpathentry') | |
3616 | |
3599 if files: | 3617 if files: |
3600 files.append(genDir) | 3618 files.append(genDir) |
3601 | 3619 |
3602 # Every Java program depends on a JRE | 3620 # Every Java program depends on a JRE |
3603 out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-' + str(p.javaCompliance)}) | 3621 out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-' + str(p.javaCompliance)}) |
3773 esdict[name] = os.path.abspath(join(projectSettingsDir, name)) | 3791 esdict[name] = os.path.abspath(join(projectSettingsDir, name)) |
3774 | 3792 |
3775 # copy a possibly modified file to the project's .settings directory | 3793 # copy a possibly modified file to the project's .settings directory |
3776 for name, path in esdict.iteritems(): | 3794 for name, path in esdict.iteritems(): |
3777 # ignore this file altogether if this project has no annotation processors | 3795 # ignore this file altogether if this project has no annotation processors |
3778 if name == "org.eclipse.jdt.apt.core.prefs" and not len(p.annotation_processors()) > 0: | 3796 if name == "org.eclipse.jdt.apt.core.prefs" and not processorPath: |
3779 continue | 3797 continue |
3780 | 3798 |
3781 with open(path) as f: | 3799 with open(path) as f: |
3782 content = f.read() | 3800 content = f.read() |
3783 content = content.replace('${javaCompliance}', str(p.javaCompliance)) | 3801 content = content.replace('${javaCompliance}', str(p.javaCompliance)) |
3784 if len(p.annotation_processors()) > 0: | 3802 if processorPath: |
3785 content = content.replace('org.eclipse.jdt.core.compiler.processAnnotations=disabled', 'org.eclipse.jdt.core.compiler.processAnnotations=enabled') | 3803 content = content.replace('org.eclipse.jdt.core.compiler.processAnnotations=disabled', 'org.eclipse.jdt.core.compiler.processAnnotations=enabled') |
3786 update_file(join(settingsDir, name), content) | 3804 update_file(join(settingsDir, name), content) |
3787 if files: | 3805 if files: |
3788 files.append(join(settingsDir, name)) | 3806 files.append(join(settingsDir, name)) |
3789 | 3807 |
3790 processorPath = p.annotation_processors_path() | |
3791 if processorPath: | 3808 if processorPath: |
3792 out = XMLDoc() | 3809 out = XMLDoc() |
3793 out.open('factorypath') | 3810 out.open('factorypath') |
3794 out.element('factorypathentry', {'kind' : 'PLUGIN', 'id' : 'org.eclipse.jst.ws.annotations.core', 'enabled' : 'true', 'runInBatchMode' : 'false'}) | 3811 out.element('factorypathentry', {'kind' : 'PLUGIN', 'id' : 'org.eclipse.jst.ws.annotations.core', 'enabled' : 'true', 'runInBatchMode' : 'false'}) |
3795 for e in processorPath.split(os.pathsep): | 3812 for e in processorPath.split(os.pathsep): |