comparison mxtool/mx.py @ 13473:69f3251332c9

modified eclipseinit and netbeansinit to save all created/copied/downloaded project related files in zip files
author Doug Simon <doug.simon@oracle.com>
date Sun, 22 Dec 2013 22:34:01 +0100
parents 020099961eb4
children 4a3628c79ff9
comparison
equal deleted inserted replaced
13472:72e2ec923b7b 13473:69f3251332c9
2193 for p in candidates: 2193 for p in candidates:
2194 if _isAnnotationProcessorDependency(p): 2194 if _isAnnotationProcessorDependency(p):
2195 projs.add(p) 2195 projs.add(p)
2196 2196
2197 if len(projs) <= 0: 2197 if len(projs) <= 0:
2198 return 2198 return []
2199 2199
2200 pnames = [p.name for p in projs] 2200 pnames = [p.name for p in projs]
2201 build(['--projects', ",".join(pnames)]) 2201 build(['--projects', ",".join(pnames)])
2202 archive(pnames) 2202 return archive(pnames)
2203 2203
2204 def pylint(args): 2204 def pylint(args):
2205 """run pylint (if available) over Python source files (found by 'hg locate' or by tree walk with -walk)""" 2205 """run pylint (if available) over Python source files (found by 'hg locate' or by tree walk with -walk)"""
2206 2206
2207 parser = ArgumentParser(prog='mx pylint') 2207 parser = ArgumentParser(prog='mx pylint')
2273 """create jar files for projects and distributions""" 2273 """create jar files for projects and distributions"""
2274 parser = ArgumentParser(prog='mx archive') 2274 parser = ArgumentParser(prog='mx archive')
2275 parser.add_argument('names', nargs=REMAINDER, metavar='[<project>|@<distribution>]...') 2275 parser.add_argument('names', nargs=REMAINDER, metavar='[<project>|@<distribution>]...')
2276 args = parser.parse_args(args) 2276 args = parser.parse_args(args)
2277 2277
2278 archives = []
2278 for name in args.names: 2279 for name in args.names:
2279 if name.startswith('@'): 2280 if name.startswith('@'):
2280 dname = name[1:] 2281 dname = name[1:]
2281 d = distribution(dname) 2282 d = distribution(dname)
2282 fd, tmp = tempfile.mkstemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path)) 2283 fd, tmp = tempfile.mkstemp(suffix='', prefix=basename(d.path) + '.', dir=dirname(d.path))
2339 zf.close() 2340 zf.close()
2340 os.close(fd) 2341 os.close(fd)
2341 shutil.rmtree(services) 2342 shutil.rmtree(services)
2342 # Atomic on Unix 2343 # Atomic on Unix
2343 shutil.move(tmp, d.path) 2344 shutil.move(tmp, d.path)
2345 archives.append(d.path)
2344 # print time.time(), 'move:', tmp, '->', d.path 2346 # print time.time(), 'move:', tmp, '->', d.path
2345 d.notify_updated() 2347 d.notify_updated()
2346 finally: 2348 finally:
2347 if exists(tmp): 2349 if exists(tmp):
2348 os.remove(tmp) 2350 os.remove(tmp)
2361 arcname = join(relpath, f).replace(os.sep, '/') 2363 arcname = join(relpath, f).replace(os.sep, '/')
2362 zf.write(join(root, f), arcname) 2364 zf.write(join(root, f), arcname)
2363 zf.close() 2365 zf.close()
2364 os.close(fd) 2366 os.close(fd)
2365 # Atomic on Unix 2367 # Atomic on Unix
2366 shutil.move(tmp, join(p.dir, p.name + '.jar')) 2368 jarFile = join(p.dir, p.name + '.jar')
2369 shutil.move(tmp, jarFile)
2370 archives.append(jarFile)
2367 finally: 2371 finally:
2368 if exists(tmp): 2372 if exists(tmp):
2369 os.remove(tmp) 2373 os.remove(tmp)
2374 return archives
2370 2375
2371 def canonicalizeprojects(args): 2376 def canonicalizeprojects(args):
2372 """process all project files to canonicalize the dependencies 2377 """process all project files to canonicalize the dependencies
2373 2378
2374 The exit code of this command reflects how many files were updated.""" 2379 The exit code of this command reflects how many files were updated."""
2617 2622
2618 outputDir = p.output_dir() 2623 outputDir = p.output_dir()
2619 if outputDir != '' and exists(outputDir): 2624 if outputDir != '' and exists(outputDir):
2620 log('Removing {0}...'.format(outputDir)) 2625 log('Removing {0}...'.format(outputDir))
2621 shutil.rmtree(outputDir) 2626 shutil.rmtree(outputDir)
2627
2628 for configName in ['netbeans-config.zip', 'eclipse-config.zip']:
2629 config = TimeStampFile(join(p.suite.mxDir, configName))
2630 if config.exists():
2631 os.unlink(config.path)
2622 2632
2623 if suppliedParser: 2633 if suppliedParser:
2624 return args 2634 return args
2625 2635
2626 def about(args): 2636 def about(args):
2769 suitePrefix = suite.name + '-' 2779 suitePrefix = suite.name + '-'
2770 name = suitePrefix + 'attach-' + hostname + '-' + port 2780 name = suitePrefix + 'attach-' + hostname + '-' + port
2771 eclipseLaunches = join(suite.mxDir, 'eclipse-launches') 2781 eclipseLaunches = join(suite.mxDir, 'eclipse-launches')
2772 if not exists(eclipseLaunches): 2782 if not exists(eclipseLaunches):
2773 os.makedirs(eclipseLaunches) 2783 os.makedirs(eclipseLaunches)
2774 return update_file(join(eclipseLaunches, name + '.launch'), launch) 2784 launchFile = join(eclipseLaunches, name + '.launch')
2785 return update_file(launchFile, launch), launchFile
2775 2786
2776 def make_eclipse_launch(javaArgs, jre, name=None, deps=None): 2787 def make_eclipse_launch(javaArgs, jre, name=None, deps=None):
2777 """ 2788 """
2778 Creates an Eclipse launch configuration file for running/debugging a Java command. 2789 Creates an Eclipse launch configuration file for running/debugging a Java command.
2779 """ 2790 """
2865 if timestamp.isOlderThan(path): 2876 if timestamp.isOlderThan(path):
2866 return False 2877 return False
2867 return True 2878 return True
2868 2879
2869 def _eclipseinit_suite(args, suite, buildProcessorJars=True, refreshOnly=False): 2880 def _eclipseinit_suite(args, suite, buildProcessorJars=True, refreshOnly=False):
2870 timestamp = TimeStampFile(join(suite.mxDir, 'eclipseinit.timestamp')) 2881 configZip = TimeStampFile(join(suite.mxDir, 'eclipse-config.zip'))
2871 if refreshOnly and not timestamp.exists(): 2882 if refreshOnly and not configZip.exists():
2872 return 2883 return
2873 2884
2874 if _check_ide_timestamp(suite, timestamp): 2885 if _check_ide_timestamp(suite, configZip):
2875 logv('[Eclipse configurations are up to date - skipping]') 2886 logv('[Eclipse configurations are up to date - skipping]')
2876 return 2887 return
2877 2888
2889 files = []
2878 if buildProcessorJars: 2890 if buildProcessorJars:
2879 _processorjars_suite(suite) 2891 files += _processorjars_suite(suite)
2880 2892
2881 projToDist = dict() 2893 projToDist = dict()
2882 for dist in _dists.values(): 2894 for dist in _dists.values():
2883 distDeps = sorted_deps(dist.deps) 2895 distDeps = sorted_deps(dist.deps)
2884 for p in distDeps: 2896 for p in distDeps:
2903 if len(p.annotation_processors()) > 0: 2915 if len(p.annotation_processors()) > 0:
2904 genDir = p.source_gen_dir() 2916 genDir = p.source_gen_dir()
2905 if not exists(genDir): 2917 if not exists(genDir):
2906 os.mkdir(genDir) 2918 os.mkdir(genDir)
2907 out.element('classpathentry', {'kind' : 'src', 'path' : 'src_gen'}) 2919 out.element('classpathentry', {'kind' : 'src', 'path' : 'src_gen'})
2920 files.append(genDir)
2908 2921
2909 # Every Java program depends on the JRE 2922 # Every Java program depends on the JRE
2910 out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-' + str(p.javaCompliance)}) 2923 out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-' + str(p.javaCompliance)})
2911 2924
2912 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project 2925 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project
2937 2950
2938 sourcePath = dep.get_source_path(resolve=True) 2951 sourcePath = dep.get_source_path(resolve=True)
2939 if sourcePath is not None: 2952 if sourcePath is not None:
2940 attributes['sourcepath'] = sourcePath 2953 attributes['sourcepath'] = sourcePath
2941 out.element('classpathentry', attributes) 2954 out.element('classpathentry', attributes)
2955 files.append(path)
2942 else: 2956 else:
2943 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + dep.name}) 2957 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + dep.name})
2944 2958
2945 out.element('classpathentry', {'kind' : 'output', 'path' : getattr(p, 'eclipse.output', 'bin')}) 2959 out.element('classpathentry', {'kind' : 'output', 'path' : getattr(p, 'eclipse.output', 'bin')})
2946 out.close('classpath') 2960 out.close('classpath')
2947 update_file(join(p.dir, '.classpath'), out.xml(indent='\t', newl='\n')) 2961 classpathFile = join(p.dir, '.classpath')
2962 update_file(classpathFile, out.xml(indent='\t', newl='\n'))
2963 files.append(classpathFile)
2948 2964
2949 csConfig = join(project(p.checkstyleProj).dir, '.checkstyle_checks.xml') 2965 csConfig = join(project(p.checkstyleProj).dir, '.checkstyle_checks.xml')
2950 if exists(csConfig): 2966 if exists(csConfig):
2951 out = XMLDoc() 2967 out = XMLDoc()
2952 2968
2975 out.element('filter-data', {'value' : line}) 2991 out.element('filter-data', {'value' : line})
2976 out.close('filter') 2992 out.close('filter')
2977 2993
2978 out.close('fileset-config') 2994 out.close('fileset-config')
2979 update_file(dotCheckstyle, out.xml(indent=' ', newl='\n')) 2995 update_file(dotCheckstyle, out.xml(indent=' ', newl='\n'))
2996 files.append(dotCheckstyle)
2980 2997
2981 out = XMLDoc() 2998 out = XMLDoc()
2982 out.open('projectDescription') 2999 out.open('projectDescription')
2983 out.element('name', data=p.name) 3000 out.element('name', data=p.name)
2984 out.element('comment', data='') 3001 out.element('comment', data='')
3020 out.element('nature', data='net.sf.eclipsecs.core.CheckstyleNature') 3037 out.element('nature', data='net.sf.eclipsecs.core.CheckstyleNature')
3021 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project 3038 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project
3022 out.element('nature', data='org.eclipse.pde.PluginNature') 3039 out.element('nature', data='org.eclipse.pde.PluginNature')
3023 out.close('natures') 3040 out.close('natures')
3024 out.close('projectDescription') 3041 out.close('projectDescription')
3025 update_file(join(p.dir, '.project'), out.xml(indent='\t', newl='\n')) 3042 projectFile = join(p.dir, '.project')
3043 update_file(projectFile, out.xml(indent='\t', newl='\n'))
3044 files.append(projectFile)
3026 3045
3027 settingsDir = join(p.dir, ".settings") 3046 settingsDir = join(p.dir, ".settings")
3028 if not exists(settingsDir): 3047 if not exists(settingsDir):
3029 os.mkdir(settingsDir) 3048 os.mkdir(settingsDir)
3030 3049
3039 content = f.read() 3058 content = f.read()
3040 content = content.replace('${javaCompliance}', str(p.javaCompliance)) 3059 content = content.replace('${javaCompliance}', str(p.javaCompliance))
3041 if len(p.annotation_processors()) > 0: 3060 if len(p.annotation_processors()) > 0:
3042 content = content.replace('org.eclipse.jdt.core.compiler.processAnnotations=disabled', 'org.eclipse.jdt.core.compiler.processAnnotations=enabled') 3061 content = content.replace('org.eclipse.jdt.core.compiler.processAnnotations=disabled', 'org.eclipse.jdt.core.compiler.processAnnotations=enabled')
3043 update_file(join(settingsDir, name), content) 3062 update_file(join(settingsDir, name), content)
3063 files.append(join(settingsDir, name))
3044 3064
3045 if len(p.annotation_processors()) > 0: 3065 if len(p.annotation_processors()) > 0:
3046 out = XMLDoc() 3066 out = XMLDoc()
3047 out.open('factorypath') 3067 out.open('factorypath')
3048 out.element('factorypathentry', {'kind' : 'PLUGIN', 'id' : 'org.eclipse.jst.ws.annotations.core', 'enabled' : 'true', 'runInBatchMode' : 'false'}) 3068 out.element('factorypathentry', {'kind' : 'PLUGIN', 'id' : 'org.eclipse.jst.ws.annotations.core', 'enabled' : 'true', 'runInBatchMode' : 'false'})
3057 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse 3077 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse
3058 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's 3078 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's
3059 # safest to simply use absolute paths. 3079 # safest to simply use absolute paths.
3060 path = join(p.suite.dir, path) 3080 path = join(p.suite.dir, path)
3061 out.element('factorypathentry', {'kind' : 'EXTJAR', 'id' : path, 'enabled' : 'true', 'runInBatchMode' : 'false'}) 3081 out.element('factorypathentry', {'kind' : 'EXTJAR', 'id' : path, 'enabled' : 'true', 'runInBatchMode' : 'false'})
3082 files.append(path)
3062 else: 3083 else:
3063 out.element('factorypathentry', {'kind' : 'WKSPJAR', 'id' : '/' + dep.name + '/' + dep.name + '.jar', 'enabled' : 'true', 'runInBatchMode' : 'false'}) 3084 out.element('factorypathentry', {'kind' : 'WKSPJAR', 'id' : '/' + dep.name + '/' + dep.name + '.jar', 'enabled' : 'true', 'runInBatchMode' : 'false'})
3064 out.close('factorypath') 3085 out.close('factorypath')
3065 update_file(join(p.dir, '.factorypath'), out.xml(indent='\t', newl='\n')) 3086 update_file(join(p.dir, '.factorypath'), out.xml(indent='\t', newl='\n'))
3066 3087 files.append(join(p.dir, '.factorypath'))
3067 make_eclipse_attach(suite, 'localhost', '8000', deps=projects()) 3088
3068 timestamp.touch() 3089 _, launchFile = make_eclipse_attach(suite, 'localhost', '8000', deps=projects())
3090 files.append(launchFile)
3091
3092 _zip_files(files, suite.dir, configZip.path)
3093
3094 def _zip_files(files, baseDir, zipPath):
3095 fd, tmp = tempfile.mkstemp(suffix='', prefix=basename(zipPath), dir=baseDir)
3096 try:
3097 zf = zipfile.ZipFile(tmp, 'w')
3098 for f in sorted(set(files)):
3099 relpath = os.path.relpath(f, baseDir)
3100 arcname = relpath.replace(os.sep, '/')
3101 zf.write(f, arcname)
3102 zf.close()
3103 os.close(fd)
3104 # Atomic on Unix
3105 shutil.move(tmp, zipPath)
3106 finally:
3107 if exists(tmp):
3108 os.remove(tmp)
3069 3109
3070 def _isAnnotationProcessorDependency(p): 3110 def _isAnnotationProcessorDependency(p):
3071 """ 3111 """
3072 Determines if a given project is part of an annotation processor. 3112 Determines if a given project is part of an annotation processor.
3073 """ 3113 """
3293 3333
3294 for suite in suites(True): 3334 for suite in suites(True):
3295 _netbeansinit_suite(args, suite, refreshOnly, buildProcessorJars) 3335 _netbeansinit_suite(args, suite, refreshOnly, buildProcessorJars)
3296 3336
3297 def _netbeansinit_suite(args, suite, refreshOnly=False, buildProcessorJars=True): 3337 def _netbeansinit_suite(args, suite, refreshOnly=False, buildProcessorJars=True):
3298 timestamp = TimeStampFile(join(suite.mxDir, 'netbeansinit.timestamp')) 3338 configZip = TimeStampFile(join(suite.mxDir, 'netbeans-config.zip'))
3299 if refreshOnly and not timestamp.exists(): 3339 if refreshOnly and not configZip.exists():
3300 return 3340 return
3301 3341
3302 if _check_ide_timestamp(suite, timestamp): 3342 if _check_ide_timestamp(suite, configZip):
3303 logv('[NetBeans configurations are up to date - skipping]') 3343 logv('[NetBeans configurations are up to date - skipping]')
3304 return 3344 return
3305 3345
3306 updated = False 3346 updated = False
3347 files = []
3307 for p in suite.projects: 3348 for p in suite.projects:
3308 if p.native: 3349 if p.native:
3309 continue 3350 continue
3310 3351
3311 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project 3352 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project
3326 out.element('arg', {'value' : '@GRAAL'}) 3367 out.element('arg', {'value' : '@GRAAL'})
3327 out.close('exec') 3368 out.close('exec')
3328 out.close('target') 3369 out.close('target')
3329 out.close('project') 3370 out.close('project')
3330 updated = update_file(join(p.dir, 'build.xml'), out.xml(indent='\t', newl='\n')) or updated 3371 updated = update_file(join(p.dir, 'build.xml'), out.xml(indent='\t', newl='\n')) or updated
3372 files.append(join(p.dir, 'build.xml'))
3331 3373
3332 out = XMLDoc() 3374 out = XMLDoc()
3333 out.open('project', {'xmlns' : 'http://www.netbeans.org/ns/project/1'}) 3375 out.open('project', {'xmlns' : 'http://www.netbeans.org/ns/project/1'})
3334 out.element('type', data='org.netbeans.modules.java.j2seproject') 3376 out.element('type', data='org.netbeans.modules.java.j2seproject')
3335 out.open('configuration') 3377 out.open('configuration')
3369 out.close('references') 3411 out.close('references')
3370 3412
3371 out.close('configuration') 3413 out.close('configuration')
3372 out.close('project') 3414 out.close('project')
3373 updated = update_file(join(p.dir, 'nbproject', 'project.xml'), out.xml(indent=' ', newl='\n')) or updated 3415 updated = update_file(join(p.dir, 'nbproject', 'project.xml'), out.xml(indent=' ', newl='\n')) or updated
3416 files.append(join(p.dir, 'nbproject', 'project.xml'))
3374 3417
3375 out = StringIO.StringIO() 3418 out = StringIO.StringIO()
3376 jdkPlatform = 'JDK_' + str(java().version) 3419 jdkPlatform = 'JDK_' + str(java().version)
3377 3420
3378 annotationProcessorEnabled = "false" 3421 annotationProcessorEnabled = "false"
3490 if path: 3533 if path:
3491 if os.sep == '\\': 3534 if os.sep == '\\':
3492 path = path.replace('\\', '\\\\') 3535 path = path.replace('\\', '\\\\')
3493 ref = 'file.reference.' + dep.name + '-bin' 3536 ref = 'file.reference.' + dep.name + '-bin'
3494 print >> out, ref + '=' + path 3537 print >> out, ref + '=' + path
3538 files.append(path)
3495 3539
3496 else: 3540 else:
3497 n = dep.name.replace('.', '_') 3541 n = dep.name.replace('.', '_')
3498 relDepPath = os.path.relpath(dep.dir, p.dir).replace(os.sep, '/') 3542 relDepPath = os.path.relpath(dep.dir, p.dir).replace(os.sep, '/')
3499 ref = 'reference.' + n + '.jar' 3543 ref = 'reference.' + n + '.jar'
3510 print >> out, 'javac.test.processorpath=${javac.test.classpath}\\\n ' + (os.pathsep + '\\\n ').join(annotationProcessorReferences) 3554 print >> out, 'javac.test.processorpath=${javac.test.classpath}\\\n ' + (os.pathsep + '\\\n ').join(annotationProcessorReferences)
3511 print >> out, 'javac.processorpath=${javac.classpath}\\\n ' + (os.pathsep + '\\\n ').join(annotationProcessorReferences) 3555 print >> out, 'javac.processorpath=${javac.classpath}\\\n ' + (os.pathsep + '\\\n ').join(annotationProcessorReferences)
3512 3556
3513 updated = update_file(join(p.dir, 'nbproject', 'project.properties'), out.getvalue()) or updated 3557 updated = update_file(join(p.dir, 'nbproject', 'project.properties'), out.getvalue()) or updated
3514 out.close() 3558 out.close()
3559 files.append(join(p.dir, 'nbproject', 'project.properties'))
3515 3560
3516 if updated: 3561 if updated:
3517 log('If using NetBeans:') 3562 log('If using NetBeans:')
3518 log(' 1. Ensure that a platform named "JDK_' + str(java().version) + '" is defined (Tools -> Java Platforms)') 3563 log(' 1. Ensure that a platform named "JDK_' + str(java().version) + '" is defined (Tools -> Java Platforms)')
3519 log(' 2. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)') 3564 log(' 2. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)')
3520 3565
3521 timestamp.touch() 3566 _zip_files(files, suite.dir, configZip.path)
3522 3567
3523 def ideclean(args): 3568 def ideclean(args):
3524 """remove all Eclipse and NetBeans project configurations""" 3569 """remove all Eclipse and NetBeans project configurations"""
3525 def rm(path): 3570 def rm(path):
3526 if exists(path): 3571 if exists(path):
3527 os.remove(path) 3572 os.remove(path)
3528 3573
3529 for s in suites(): 3574 for s in suites():
3530 rm(join(s.mxDir, 'eclipseinit.timestamp')) 3575 rm(join(s.mxDir, 'eclipse-config.zip'))
3531 rm(join(s.mxDir, 'netbeansinit.timestamp')) 3576 rm(join(s.mxDir, 'netbeans-config.zip'))
3532 3577
3533 for p in projects(): 3578 for p in projects():
3534 if p.native: 3579 if p.native:
3535 continue 3580 continue
3536 3581