comparison mxtool/mx.py @ 9009:1eb16dbb31a7

changed 'mx javap' command to accept class name patterns instead of fully qualified class names
author Doug Simon <doug.simon@oracle.com>
date Thu, 11 Apr 2013 21:38:09 +0200
parents 7844a36d0216
children 025448743177
comparison
equal deleted inserted replaced
9008:c6d4a69d5129 9009:1eb16dbb31a7
3016 3016
3017 finally: 3017 finally:
3018 if exists(tmpbase): 3018 if exists(tmpbase):
3019 shutil.rmtree(tmpbase) 3019 shutil.rmtree(tmpbase)
3020 3020
3021 def findclass(args): 3021 def findclass(args, logToConsole=True):
3022 """find all classes matching a given substring""" 3022 """find all classes matching a given substring"""
3023 3023
3024 matches = []
3024 for entry, filename in classpath_walk(includeBootClasspath=True): 3025 for entry, filename in classpath_walk(includeBootClasspath=True):
3025 if filename.endswith('.class'): 3026 if filename.endswith('.class'):
3026 if isinstance(entry, zipfile.ZipFile): 3027 if isinstance(entry, zipfile.ZipFile):
3027 classname = filename.replace('/', '.') 3028 classname = filename.replace('/', '.')
3028 else: 3029 else:
3029 classname = filename.replace(os.sep, '.') 3030 classname = filename.replace(os.sep, '.')
3030 classname = classname[:-len('.class')] 3031 classname = classname[:-len('.class')]
3031 for a in args: 3032 for a in args:
3032 if a in classname: 3033 if a in classname:
3033 log(classname) 3034 matches.append(classname)
3035 if logToConsole:
3036 log(classname)
3037 return matches
3034 3038
3035 def javap(args): 3039 def javap(args):
3036 """launch javap with a -classpath option denoting all available classes 3040 """disassemble classes matching given pattern with javap"""
3037
3038 Run the JDK javap class file disassembler with the following prepended options:
3039
3040 -private -verbose -classpath <path to project classes>"""
3041 3041
3042 javap = java().javap 3042 javap = java().javap
3043 if not exists(javap): 3043 if not exists(javap):
3044 abort('The javap executable does not exists: ' + javap) 3044 abort('The javap executable does not exists: ' + javap)
3045 else: 3045 else:
3046 run([javap, '-private', '-verbose', '-classpath', classpath()] + args) 3046 run([javap, '-private', '-verbose', '-classpath', classpath()] + findclass(args, logToConsole=False))
3047 3047
3048 def show_projects(args): 3048 def show_projects(args):
3049 """show all loaded projects""" 3049 """show all loaded projects"""
3050 for s in suites(): 3050 for s in suites():
3051 projectsFile = join(s.dir, 'mx', 'projects') 3051 projectsFile = join(s.dir, 'mx', 'projects')
3079 'help': [help_, '[command]'], 3079 'help': [help_, '[command]'],
3080 'ideclean': [ideclean, ''], 3080 'ideclean': [ideclean, ''],
3081 'ideinit': [ideinit, ''], 3081 'ideinit': [ideinit, ''],
3082 'archive': [archive, '[options]'], 3082 'archive': [archive, '[options]'],
3083 'projectgraph': [projectgraph, ''], 3083 'projectgraph': [projectgraph, ''],
3084 'javap': [javap, ''], 3084 'javap': [javap, '<class name patterns>'],
3085 'javadoc': [javadoc, '[options]'], 3085 'javadoc': [javadoc, '[options]'],
3086 'site': [site, '[options]'], 3086 'site': [site, '[options]'],
3087 'netbeansinit': [netbeansinit, ''], 3087 'netbeansinit': [netbeansinit, ''],
3088 'projects': [show_projects, ''], 3088 'projects': [show_projects, ''],
3089 } 3089 }