comparison mxtool/mx.py @ 11687:facb442de5db

added support for specifying the JDK version in which a library becomes redundant (e.g., nashorn.jar)
author Doug Simon <doug.simon@oracle.com>
date Tue, 17 Sep 2013 23:28:05 +0200
parents ec7aad9dfc47
children e29743466d00
comparison
equal deleted inserted replaced
11686:13b3c8cd5e52 11687:facb442de5db
458 458
459 def get_path(self, resolve): 459 def get_path(self, resolve):
460 path = self.path 460 path = self.path
461 if not isabs(path): 461 if not isabs(path):
462 path = join(self.suite.dir, path) 462 path = join(self.suite.dir, path)
463 includedInJDK = getattr(self, 'includedInJDK', None)
464 if includedInJDK and java().javaCompliance >= JavaCompliance(includedInJDK):
465 return None
463 if resolve and self.mustExist and not exists(path): 466 if resolve and self.mustExist and not exists(path):
464 assert not len(self.urls) == 0, 'cannot find required library ' + self.name + ' ' + path 467 assert not len(self.urls) == 0, 'cannot find required library ' + self.name + ' ' + path
465 print('Downloading ' + self.name + ' from ' + str(self.urls)) 468 print('Downloading ' + self.name + ' from ' + str(self.urls))
466 download(path, self.urls) 469 download(path, self.urls)
467 return path 470 return path
477 download(path, self.sourceUrls) 480 download(path, self.sourceUrls)
478 return path 481 return path
479 482
480 def append_to_classpath(self, cp, resolve): 483 def append_to_classpath(self, cp, resolve):
481 path = self.get_path(resolve) 484 path = self.get_path(resolve)
482 if exists(path) or not resolve: 485 if path and (exists(path) or not resolve):
483 cp.append(path) 486 cp.append(path)
484 487
485 def all_deps(self, deps, includeLibs, includeSelf=True, includeAnnotationProcessors=False): 488 def all_deps(self, deps, includeLibs, includeSelf=True, includeAnnotationProcessors=False):
486 if not includeLibs or not includeSelf: 489 if not includeLibs or not includeSelf:
487 return deps 490 return deps
1883 if dep.isLibrary(): 1886 if dep.isLibrary():
1884 l = dep 1887 l = dep
1885 # merge library jar into distribution jar 1888 # merge library jar into distribution jar
1886 logv('[' + d.path + ': adding library ' + l.name + ']') 1889 logv('[' + d.path + ': adding library ' + l.name + ']')
1887 lpath = l.get_path(resolve=True) 1890 lpath = l.get_path(resolve=True)
1888 with zipfile.ZipFile(lpath, 'r') as lp: 1891 if lpath:
1889 for arcname in lp.namelist(): 1892 with zipfile.ZipFile(lpath, 'r') as lp:
1890 if arcname.startswith('META-INF/services/'): 1893 for arcname in lp.namelist():
1891 f = arcname[len('META-INF/services/'):].replace('/', os.sep) 1894 if arcname.startswith('META-INF/services/') and not arcname == 'META-INF/services/':
1892 with open(join(services, f), 'a') as outfile: 1895 f = arcname[len('META-INF/services/'):].replace('/', os.sep)
1893 for line in lp.read(arcname).splitlines(): 1896 with open(join(services, f), 'a') as outfile:
1894 outfile.write(line) 1897 for line in lp.read(arcname).splitlines():
1895 else: 1898 outfile.write(line)
1896 overwriteCheck(zf, arcname, lpath + '!' + arcname) 1899 else:
1897 zf.writestr(arcname, lp.read(arcname)) 1900 overwriteCheck(zf, arcname, lpath + '!' + arcname)
1901 zf.writestr(arcname, lp.read(arcname))
1898 else: 1902 else:
1899 p = dep 1903 p = dep
1900 # skip a Java project if its Java compliance level is "higher" than the configured JDK 1904 # skip a Java project if its Java compliance level is "higher" than the configured JDK
1901 if java().javaCompliance < p.javaCompliance: 1905 if java().javaCompliance < p.javaCompliance:
1902 log('Excluding {0} from {2} (Java compliance level {1} required)'.format(p.name, p.javaCompliance, d.path)) 1906 log('Excluding {0} from {2} (Java compliance level {1} required)'.format(p.name, p.javaCompliance, d.path))
2436 elif hasattr(dep, 'eclipse.project'): 2440 elif hasattr(dep, 'eclipse.project'):
2437 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + getattr(dep, 'eclipse.project')}) 2441 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + getattr(dep, 'eclipse.project')})
2438 else: 2442 else:
2439 path = dep.path 2443 path = dep.path
2440 dep.get_path(resolve=True) 2444 dep.get_path(resolve=True)
2441 if not exists(path) and not dep.mustExist: 2445 if not path or (not exists(path) and not dep.mustExist):
2442 continue 2446 continue
2443 2447
2444 if not isabs(path): 2448 if not isabs(path):
2445 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse 2449 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse
2446 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's 2450 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's
2552 update_file(join(settingsDir, name), content) 2556 update_file(join(settingsDir, name), content)
2553 2557
2554 if len(p.annotation_processors()) > 0: 2558 if len(p.annotation_processors()) > 0:
2555 out = XMLDoc() 2559 out = XMLDoc()
2556 out.open('factorypath') 2560 out.open('factorypath')
2557 out.element('factorypathentry', {'kind' : 'PLUGIN', 'id' : 'org.eclipse.jst.ws.annotations.core', 'enabled' : 'true', 'runInBatchMode' : 'false'}) 2561 out.element('factorypathentry', {'kind' : 'PLUGIN', 'id' : 'org.eclipset.ws.annotations.core', 'enabled' : 'true', 'runInBatchMode' : 'false'})
2558 for ap in p.annotation_processors(): 2562 for ap in p.annotation_processors():
2559 for dep in dependency(ap).all_deps([], True): 2563 for dep in dependency(ap).all_deps([], True):
2560 if dep.isLibrary(): 2564 if dep.isLibrary():
2561 if not hasattr(dep, 'eclipse.container') and not hasattr(dep, 'eclipse.project'): 2565 if not hasattr(dep, 'eclipse.container') and not hasattr(dep, 'eclipse.project'):
2562 if dep.mustExist: 2566 if dep.mustExist:
2563 path = dep.get_path(resolve=True) 2567 path = dep.get_path(resolve=True)
2564 if not isabs(path): 2568 if path:
2565 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse 2569 if not isabs(path):
2566 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's 2570 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse
2567 # safest to simply use absolute paths. 2571 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's
2568 path = join(p.suite.dir, path) 2572 # safest to simply use absolute paths.
2569 out.element('factorypathentry', {'kind' : 'EXTJAR', 'id' : path, 'enabled' : 'true', 'runInBatchMode' : 'false'}) 2573 path = join(p.suite.dir, path)
2574 out.element('factorypathentry', {'kind' : 'EXTJAR', 'id' : path, 'enabled' : 'true', 'runInBatchMode' : 'false'})
2570 else: 2575 else:
2571 out.element('factorypathentry', {'kind' : 'WKSPJAR', 'id' : '/' + dep.name + '/' + dep.name + '.jar', 'enabled' : 'true', 'runInBatchMode' : 'false'}) 2576 out.element('factorypathentry', {'kind' : 'WKSPJAR', 'id' : '/' + dep.name + '/' + dep.name + '.jar', 'enabled' : 'true', 'runInBatchMode' : 'false'})
2572 out.close('factorypath') 2577 out.close('factorypath')
2573 update_file(join(p.dir, '.factorypath'), out.xml(indent='\t', newl='\n')) 2578 update_file(join(p.dir, '.factorypath'), out.xml(indent='\t', newl='\n'))
2574 2579
2948 2953
2949 if dep.isLibrary(): 2954 if dep.isLibrary():
2950 if not dep.mustExist: 2955 if not dep.mustExist:
2951 continue 2956 continue
2952 path = dep.get_path(resolve=True) 2957 path = dep.get_path(resolve=True)
2953 if os.sep == '\\': 2958 if path:
2954 path = path.replace('\\', '\\\\') 2959 if os.sep == '\\':
2955 ref = 'file.reference.' + dep.name + '-bin' 2960 path = path.replace('\\', '\\\\')
2956 print >> out, ref + '=' + path 2961 ref = 'file.reference.' + dep.name + '-bin'
2962 print >> out, ref + '=' + path
2957 2963
2958 else: 2964 else:
2959 n = dep.name.replace('.', '_') 2965 n = dep.name.replace('.', '_')
2960 relDepPath = os.path.relpath(dep.dir, p.dir).replace(os.sep, '/') 2966 relDepPath = os.path.relpath(dep.dir, p.dir).replace(os.sep, '/')
2961 ref = 'reference.' + n + '.jar' 2967 ref = 'reference.' + n + '.jar'