comparison mxtool/mx.py @ 21472:c190ed6b84bf

added checkcopyrights command (from mxtool2)
author Doug Simon <doug.simon@oracle.com>
date Fri, 22 May 2015 23:11:17 +0200
parents e3438899928c
children 12e3d0dfffeb
comparison
equal deleted inserted replaced
21471:a64d09dc4590 21472:c190ed6b84bf
2316 if _opts.java_dbg_port is not None: 2316 if _opts.java_dbg_port is not None:
2317 self.java_args += ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(_opts.java_dbg_port)] 2317 self.java_args += ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(_opts.java_dbg_port)]
2318 2318
2319 def _init_classpaths(self): 2319 def _init_classpaths(self):
2320 if not self._classpaths_initialized: 2320 if not self._classpaths_initialized:
2321 myDir = dirname(__file__) 2321 _, binDir = _compile_mx_class('ClasspathDump', jdk=self)
2322 outDir = join(dirname(__file__), '.jdk' + str(self.version)) 2322 self._bootclasspath, self._extdirs, self._endorseddirs = [x if x != 'null' else None for x in subprocess.check_output([self.java, '-cp', _cygpathU2W(binDir), 'ClasspathDump'], stderr=subprocess.PIPE).split('|')]
2323 if not exists(outDir):
2324 os.makedirs(outDir)
2325 javaSource = join(myDir, 'ClasspathDump.java')
2326 javaClass = join(outDir, 'ClasspathDump.class')
2327 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource):
2328 subprocess.check_call([self.javac, '-d', _cygpathU2W(outDir), _cygpathU2W(javaSource)], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
2329 self._bootclasspath, self._extdirs, self._endorseddirs = [x if x != 'null' else None for x in subprocess.check_output([self.java, '-cp', _cygpathU2W(outDir), 'ClasspathDump'], stderr=subprocess.PIPE).split('|')]
2330 if self.javaCompliance <= JavaCompliance('1.8'): 2323 if self.javaCompliance <= JavaCompliance('1.8'):
2331 # All 3 system properties accessed by ClasspathDump are expected to exist 2324 # All 3 system properties accessed by ClasspathDump are expected to exist
2332 if not self._bootclasspath or not self._extdirs or not self._endorseddirs: 2325 if not self._bootclasspath or not self._extdirs or not self._endorseddirs:
2333 warn("Could not find all classpaths: boot='" + str(self._bootclasspath) + "' extdirs='" + str(self._extdirs) + "' endorseddirs='" + str(self._endorseddirs) + "'") 2326 warn("Could not find all classpaths: boot='" + str(self._bootclasspath) + "' extdirs='" + str(self._extdirs) + "' endorseddirs='" + str(self._endorseddirs) + "'")
2334 self._bootclasspath = _filter_non_existant_paths(self._bootclasspath) 2327 self._bootclasspath = _filter_non_existant_paths(self._bootclasspath)
2535 if d != '' and not exists(d): 2528 if d != '' and not exists(d):
2536 os.makedirs(d) 2529 os.makedirs(d)
2537 2530
2538 assert not path.endswith(os.sep) 2531 assert not path.endswith(os.sep)
2539 2532
2540 myDir = dirname(__file__) 2533 _, binDir = _compile_mx_class('URLConnectionDownload')
2541 javaSource = join(myDir, 'URLConnectionDownload.java') 2534
2542 javaClass = join(myDir, 'URLConnectionDownload.class')
2543 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource):
2544 subprocess.check_call([java().javac, '-d', _cygpathU2W(myDir), _cygpathU2W(javaSource)])
2545 verbose = [] 2535 verbose = []
2546 if sys.stderr.isatty(): 2536 if sys.stderr.isatty():
2547 verbose.append("-v") 2537 verbose.append("-v")
2548 if run([java().java, '-cp', _cygpathU2W(myDir), 'URLConnectionDownload', _cygpathU2W(path)] + verbose + urls, nonZeroIsFatal=False) == 0: 2538 if run([java().java, '-cp', _cygpathU2W(binDir), 'URLConnectionDownload', _cygpathU2W(path)] + verbose + urls, nonZeroIsFatal=False) == 0:
2549 return 2539 return
2550 2540
2551 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + 2541 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' +
2552 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually') 2542 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually')
2553 2543
5440 _show_section('libraries', s.libs) 5430 _show_section('libraries', s.libs)
5441 _show_section('jrelibraries', s.jreLibs) 5431 _show_section('jrelibraries', s.jreLibs)
5442 _show_section('projects', s.projects) 5432 _show_section('projects', s.projects)
5443 _show_section('distributions', s.dists) 5433 _show_section('distributions', s.dists)
5444 5434
5435 def _compile_mx_class(javaClassName, classpath=None, jdk=None):
5436 myDir = dirname(__file__)
5437 binDir = join(myDir, 'bin' if not jdk else '.jdk' + str(jdk.version))
5438 javaSource = join(myDir, javaClassName + '.java')
5439 javaClass = join(binDir, javaClassName + '.class')
5440 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource):
5441 if not exists(binDir):
5442 os.mkdir(binDir)
5443 javac = jdk.javac if jdk else java().javac
5444 cmd = [javac, '-d', _cygpathU2W(binDir)]
5445 if classpath:
5446 cmd += ['-cp', _separatedCygpathU2W(binDir + os.pathsep + classpath)]
5447 cmd += [_cygpathU2W(javaSource)]
5448 try:
5449 subprocess.check_call(cmd)
5450 except subprocess.CalledProcessError:
5451 abort('failed to compile:' + javaSource)
5452
5453 return (myDir, binDir)
5454
5455 def checkcopyrights(args):
5456 '''run copyright check on the sources'''
5457 class CP(ArgumentParser):
5458 def format_help(self):
5459 return ArgumentParser.format_help(self) + self._get_program_help()
5460
5461 def _get_program_help(self):
5462 help_output = subprocess.check_output([java().java, '-cp', _cygpathU2W(binDir), 'CheckCopyright', '--help'])
5463 return '\nother argumemnts preceded with --\n' + help_output
5464
5465 myDir, binDir = _compile_mx_class('CheckCopyright')
5466
5467 parser = CP(prog='mx checkcopyrights')
5468
5469 parser.add_argument('--primary', action='store_true', help='limit checks to primary suite')
5470 parser.add_argument('remainder', nargs=REMAINDER, metavar='...')
5471 args = parser.parse_args(args)
5472 remove_doubledash(args.remainder)
5473
5474
5475 # ensure compiled form of code is up to date
5476
5477 result = 0
5478 # copyright checking is suite specific as each suite may have different overrides
5479 for s in suites(True):
5480 if args.primary and not s.primary:
5481 continue
5482 custom_copyrights = _cygpathU2W(join(s.mxDir, 'copyrights'))
5483 custom_args = []
5484 if exists(custom_copyrights):
5485 custom_args = ['--custom-copyright-dir', custom_copyrights]
5486 rc = run([java().java, '-cp', _cygpathU2W(binDir), 'CheckCopyright', '--copyright-dir', _cygpathU2W(myDir)] + custom_args + args.remainder, cwd=s.dir, nonZeroIsFatal=False)
5487 result = result if rc == 0 else rc
5488 return result
5489
5490 def remove_doubledash(args):
5491 if '--' in args:
5492 args.remove('--')
5493
5445 def ask_yes_no(question, default=None): 5494 def ask_yes_no(question, default=None):
5446 """""" 5495 """"""
5447 assert not default or default == 'y' or default == 'n' 5496 assert not default or default == 'y' or default == 'n'
5448 if not is_interactive(): 5497 if not is_interactive():
5449 if default: 5498 if default:
5483 _commands = { 5532 _commands = {
5484 'about': [about, ''], 5533 'about': [about, ''],
5485 'build': [build, '[options]'], 5534 'build': [build, '[options]'],
5486 'checkstyle': [checkstyle, ''], 5535 'checkstyle': [checkstyle, ''],
5487 'canonicalizeprojects': [canonicalizeprojects, ''], 5536 'canonicalizeprojects': [canonicalizeprojects, ''],
5537 'checkcopyrights': [checkcopyrights, '[options]'],
5488 'clean': [clean, ''], 5538 'clean': [clean, ''],
5489 'eclipseinit': [eclipseinit, ''], 5539 'eclipseinit': [eclipseinit, ''],
5490 'eclipseformat': [eclipseformat, ''], 5540 'eclipseformat': [eclipseformat, ''],
5491 'exportlibs': [exportlibs, ''], 5541 'exportlibs': [exportlibs, ''],
5492 'findclass': [findclass, ''], 5542 'findclass': [findclass, ''],