comparison mxtool/mx.py @ 22023:e942083c0fcc

consolidated logic for querying the source(s) from which an Eclipse settings file is generated
author Doug Simon <doug.simon@oracle.com>
date Fri, 19 Jun 2015 00:45:14 +0200
parents 36a7ec14279d
children 5b4a974d9ae6
comparison
equal deleted inserted replaced
22022:1e72b0915423 22023:e942083c0fcc
456 return join(self.dir, 'jasmin_classes') 456 return join(self.dir, 'jasmin_classes')
457 457
458 def append_to_classpath(self, cp, resolve): 458 def append_to_classpath(self, cp, resolve):
459 if not self.native: 459 if not self.native:
460 cp.append(self.output_dir()) 460 cp.append(self.output_dir())
461
462 def eclipse_settings_sources(self):
463 """
464 Gets a dictionary from the name of an Eclipse settings file to
465 the list of files providing its generated content, in overriding order
466 (i.e., settings from files later in the list override settings from
467 files earlier in the list).
468 """
469 if not hasattr(self, '_eclipse_settings'):
470 esdict = {}
471 hasAps = self.annotation_processors_path() is not None
472 # start with the mxtool defaults
473 defaultEclipseSettingsDir = join(_mx_suite.dir, 'eclipse-settings')
474 if exists(defaultEclipseSettingsDir):
475 for name in os.listdir(defaultEclipseSettingsDir):
476 if isfile(join(defaultEclipseSettingsDir, name)) and name != "org.eclipse.jdt.apt.core.prefs" or hasAps:
477 esdict[name] = [os.path.abspath(join(defaultEclipseSettingsDir, name))]
478
479 # append suite overrides
480 eclipseSettingsDir = join(self.suite.mxDir, 'eclipse-settings')
481 if exists(eclipseSettingsDir):
482 for name in os.listdir(eclipseSettingsDir):
483 if isfile(join(eclipseSettingsDir, name)) and name != "org.eclipse.jdt.apt.core.prefs" or hasAps:
484 esdict.setdefault(name, []).append(os.path.abspath(join(eclipseSettingsDir, name)))
485
486 # check for project overrides
487 projectSettingsDir = join(self.dir, 'eclipse-settings')
488 if exists(projectSettingsDir):
489 for name in os.listdir(projectSettingsDir):
490 if isfile(join(projectSettingsDir, name)) and name != "org.eclipse.jdt.apt.core.prefs" or hasAps:
491 esdict.setdefault(name, []).append(os.path.abspath(join(projectSettingsDir, name)))
492 self._eclipse_settings = esdict
493 return self._eclipse_settings
461 494
462 def find_classes_with_matching_source_line(self, pkgRoot, function, includeInnerClasses=False): 495 def find_classes_with_matching_source_line(self, pkgRoot, function, includeInnerClasses=False):
463 """ 496 """
464 Scan the sources of this project for Java source files containing a line for which 497 Scan the sources of this project for Java source files containing a line for which
465 'function' returns true. A map from class name to source file path for each existing class 498 'function' returns true. A map from class name to source file path for each existing class
2782 '-d', outputDir] 2815 '-d', outputDir]
2783 jdk.javacLibOptions(jdtArgs) 2816 jdk.javacLibOptions(jdtArgs)
2784 jdtArgs += processorArgs 2817 jdtArgs += processorArgs
2785 2818
2786 jdtProperties = join(self.proj.dir, '.settings', 'org.eclipse.jdt.core.prefs') 2819 jdtProperties = join(self.proj.dir, '.settings', 'org.eclipse.jdt.core.prefs')
2787 rootJdtProperties = join(self.proj.suite.mxDir, 'eclipse-settings', 'org.eclipse.jdt.core.prefs') 2820 jdtPropertiesSources = self.proj.eclipse_settings_sources()['org.eclipse.jdt.core.prefs']
2788 if not exists(jdtProperties) or os.path.getmtime(jdtProperties) < os.path.getmtime(rootJdtProperties): 2821 if not exists(jdtProperties) or os.path.getmtime(jdtProperties) < min(map(os.path.getmtime, jdtPropertiesSources)):
2789 # Try to fix a missing properties file by running eclipseinit 2822 # Try to fix a missing or out of date properties file by running eclipseinit
2790 _eclipseinit_project(self.proj) 2823 _eclipseinit_project(self.proj)
2791 if not exists(jdtProperties): 2824 if not exists(jdtProperties):
2792 log('JDT properties file {0} not found'.format(jdtProperties)) 2825 log('JDT properties file {0} not found'.format(jdtProperties))
2793 else: 2826 else:
2794 with open(jdtProperties) as fp: 2827 with open(jdtProperties) as fp:
3960 # Assume that any mx change might imply changes to the generated IDE files 3993 # Assume that any mx change might imply changes to the generated IDE files
3961 if configZip.isOlderThan(__file__): 3994 if configZip.isOlderThan(__file__):
3962 return False 3995 return False
3963 3996
3964 if ide == 'eclipse': 3997 if ide == 'eclipse':
3965 eclipseSettingsDir = join(suite.mxDir, 'eclipse-settings') 3998 for p in suite.projects:
3966 if exists(eclipseSettingsDir): 3999 for _, sources in p.eclipse_settings_sources().iteritems():
3967 for name in os.listdir(eclipseSettingsDir): 4000 for source in sources:
3968 path = join(eclipseSettingsDir, name) 4001 if configZip.isOlderThan(source):
3969 if configZip.isOlderThan(path): 4002 return False
3970 return False
3971 return True 4003 return True
3972 4004
3973 def _eclipseinit_project(p, files=None, libFiles=None): 4005 def _eclipseinit_project(p, files=None, libFiles=None):
3974 assert java(p.javaCompliance) 4006 assert java(p.javaCompliance)
3975 4007
4150 4182
4151 settingsDir = join(p.dir, ".settings") 4183 settingsDir = join(p.dir, ".settings")
4152 if not exists(settingsDir): 4184 if not exists(settingsDir):
4153 os.mkdir(settingsDir) 4185 os.mkdir(settingsDir)
4154 4186
4155 # collect the defaults from mxtool
4156 defaultEclipseSettingsDir = join(dirname(__file__), 'eclipse-settings')
4157 esdict = {}
4158 if exists(defaultEclipseSettingsDir):
4159 for name in os.listdir(defaultEclipseSettingsDir):
4160 if isfile(join(defaultEclipseSettingsDir, name)):
4161 esdict[name] = os.path.abspath(join(defaultEclipseSettingsDir, name))
4162
4163 # check for suite overrides
4164 eclipseSettingsDir = join(p.suite.mxDir, 'eclipse-settings')
4165 if exists(eclipseSettingsDir):
4166 for name in os.listdir(eclipseSettingsDir):
4167 if isfile(join(eclipseSettingsDir, name)):
4168 esdict[name] = os.path.abspath(join(eclipseSettingsDir, name))
4169
4170 # check for project overrides
4171 projectSettingsDir = join(p.dir, 'eclipse-settings')
4172 if exists(projectSettingsDir):
4173 for name in os.listdir(projectSettingsDir):
4174 if isfile(join(projectSettingsDir, name)):
4175 esdict[name] = os.path.abspath(join(projectSettingsDir, name))
4176
4177 # copy a possibly modified file to the project's .settings directory 4187 # copy a possibly modified file to the project's .settings directory
4178 for name, path in esdict.iteritems(): 4188 for name, sources in p.eclipse_settings_sources().iteritems():
4179 # ignore this file altogether if this project has no annotation processors 4189 out = StringIO.StringIO()
4180 if name == "org.eclipse.jdt.apt.core.prefs" and not processorPath: 4190 print >> out, '# GENERATED -- DO NOT EDIT'
4181 continue 4191 for source in sources:
4182 4192 print >> out, '# Source:', source
4183 with open(path) as f: 4193 with open(source) as f:
4184 content = f.read() 4194 print >> out, f.read()
4185 content = content.replace('${javaCompliance}', str(p.javaCompliance)) 4195 content = out.getvalue().replace('${javaCompliance}', str(p.javaCompliance))
4186 if processorPath: 4196 if processorPath:
4187 content = content.replace('org.eclipse.jdt.core.compiler.processAnnotations=disabled', 'org.eclipse.jdt.core.compiler.processAnnotations=enabled') 4197 content = content.replace('org.eclipse.jdt.core.compiler.processAnnotations=disabled', 'org.eclipse.jdt.core.compiler.processAnnotations=enabled')
4188 update_file(join(settingsDir, name), content) 4198 update_file(join(settingsDir, name), content)
4189 if files: 4199 if files:
4190 files.append(join(settingsDir, name)) 4200 files.append(join(settingsDir, name))