# HG changeset patch # User Doug Simon # Date 1387748041 -3600 # Node ID 69f3251332c9a6d82881a6cab13a685be438b098 # Parent 72e2ec923b7bd3ff312dec836c282bed7aa25599 modified eclipseinit and netbeansinit to save all created/copied/downloaded project related files in zip files diff -r 72e2ec923b7b -r 69f3251332c9 mxtool/mx.py --- a/mxtool/mx.py Sat Dec 21 13:47:36 2013 +0100 +++ b/mxtool/mx.py Sun Dec 22 22:34:01 2013 +0100 @@ -2195,11 +2195,11 @@ projs.add(p) if len(projs) <= 0: - return + return [] pnames = [p.name for p in projs] build(['--projects', ",".join(pnames)]) - archive(pnames) + return archive(pnames) def pylint(args): """run pylint (if available) over Python source files (found by 'hg locate' or by tree walk with -walk)""" @@ -2275,6 +2275,7 @@ parser.add_argument('names', nargs=REMAINDER, metavar='[|@]...') args = parser.parse_args(args) + archives = [] for name in args.names: if name.startswith('@'): dname = name[1:] @@ -2341,6 +2342,7 @@ shutil.rmtree(services) # Atomic on Unix shutil.move(tmp, d.path) + archives.append(d.path) # print time.time(), 'move:', tmp, '->', d.path d.notify_updated() finally: @@ -2363,10 +2365,13 @@ zf.close() os.close(fd) # Atomic on Unix - shutil.move(tmp, join(p.dir, p.name + '.jar')) + jarFile = join(p.dir, p.name + '.jar') + shutil.move(tmp, jarFile) + archives.append(jarFile) finally: if exists(tmp): os.remove(tmp) + return archives def canonicalizeprojects(args): """process all project files to canonicalize the dependencies @@ -2620,6 +2625,11 @@ log('Removing {0}...'.format(outputDir)) shutil.rmtree(outputDir) + for configName in ['netbeans-config.zip', 'eclipse-config.zip']: + config = TimeStampFile(join(p.suite.mxDir, configName)) + if config.exists(): + os.unlink(config.path) + if suppliedParser: return args @@ -2771,7 +2781,8 @@ eclipseLaunches = join(suite.mxDir, 'eclipse-launches') if not exists(eclipseLaunches): os.makedirs(eclipseLaunches) - return update_file(join(eclipseLaunches, name + '.launch'), launch) + launchFile = join(eclipseLaunches, name + '.launch') + return update_file(launchFile, launch), launchFile def make_eclipse_launch(javaArgs, jre, name=None, deps=None): """ @@ -2867,16 +2878,17 @@ return True def _eclipseinit_suite(args, suite, buildProcessorJars=True, refreshOnly=False): - timestamp = TimeStampFile(join(suite.mxDir, 'eclipseinit.timestamp')) - if refreshOnly and not timestamp.exists(): + configZip = TimeStampFile(join(suite.mxDir, 'eclipse-config.zip')) + if refreshOnly and not configZip.exists(): return - if _check_ide_timestamp(suite, timestamp): + if _check_ide_timestamp(suite, configZip): logv('[Eclipse configurations are up to date - skipping]') return + files = [] if buildProcessorJars: - _processorjars_suite(suite) + files += _processorjars_suite(suite) projToDist = dict() for dist in _dists.values(): @@ -2905,6 +2917,7 @@ if not exists(genDir): os.mkdir(genDir) out.element('classpathentry', {'kind' : 'src', 'path' : 'src_gen'}) + files.append(genDir) # Every Java program depends on the JRE out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-' + str(p.javaCompliance)}) @@ -2939,12 +2952,15 @@ if sourcePath is not None: attributes['sourcepath'] = sourcePath out.element('classpathentry', attributes) + files.append(path) else: out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + dep.name}) out.element('classpathentry', {'kind' : 'output', 'path' : getattr(p, 'eclipse.output', 'bin')}) out.close('classpath') - update_file(join(p.dir, '.classpath'), out.xml(indent='\t', newl='\n')) + classpathFile = join(p.dir, '.classpath') + update_file(classpathFile, out.xml(indent='\t', newl='\n')) + files.append(classpathFile) csConfig = join(project(p.checkstyleProj).dir, '.checkstyle_checks.xml') if exists(csConfig): @@ -2977,6 +2993,7 @@ out.close('fileset-config') update_file(dotCheckstyle, out.xml(indent=' ', newl='\n')) + files.append(dotCheckstyle) out = XMLDoc() out.open('projectDescription') @@ -3022,7 +3039,9 @@ out.element('nature', data='org.eclipse.pde.PluginNature') out.close('natures') out.close('projectDescription') - update_file(join(p.dir, '.project'), out.xml(indent='\t', newl='\n')) + projectFile = join(p.dir, '.project') + update_file(projectFile, out.xml(indent='\t', newl='\n')) + files.append(projectFile) settingsDir = join(p.dir, ".settings") if not exists(settingsDir): @@ -3041,6 +3060,7 @@ if len(p.annotation_processors()) > 0: content = content.replace('org.eclipse.jdt.core.compiler.processAnnotations=disabled', 'org.eclipse.jdt.core.compiler.processAnnotations=enabled') update_file(join(settingsDir, name), content) + files.append(join(settingsDir, name)) if len(p.annotation_processors()) > 0: out = XMLDoc() @@ -3059,13 +3079,33 @@ # safest to simply use absolute paths. path = join(p.suite.dir, path) out.element('factorypathentry', {'kind' : 'EXTJAR', 'id' : path, 'enabled' : 'true', 'runInBatchMode' : 'false'}) + files.append(path) else: out.element('factorypathentry', {'kind' : 'WKSPJAR', 'id' : '/' + dep.name + '/' + dep.name + '.jar', 'enabled' : 'true', 'runInBatchMode' : 'false'}) out.close('factorypath') update_file(join(p.dir, '.factorypath'), out.xml(indent='\t', newl='\n')) - - make_eclipse_attach(suite, 'localhost', '8000', deps=projects()) - timestamp.touch() + files.append(join(p.dir, '.factorypath')) + + _, launchFile = make_eclipse_attach(suite, 'localhost', '8000', deps=projects()) + files.append(launchFile) + + _zip_files(files, suite.dir, configZip.path) + +def _zip_files(files, baseDir, zipPath): + fd, tmp = tempfile.mkstemp(suffix='', prefix=basename(zipPath), dir=baseDir) + try: + zf = zipfile.ZipFile(tmp, 'w') + for f in sorted(set(files)): + relpath = os.path.relpath(f, baseDir) + arcname = relpath.replace(os.sep, '/') + zf.write(f, arcname) + zf.close() + os.close(fd) + # Atomic on Unix + shutil.move(tmp, zipPath) + finally: + if exists(tmp): + os.remove(tmp) def _isAnnotationProcessorDependency(p): """ @@ -3295,15 +3335,16 @@ _netbeansinit_suite(args, suite, refreshOnly, buildProcessorJars) def _netbeansinit_suite(args, suite, refreshOnly=False, buildProcessorJars=True): - timestamp = TimeStampFile(join(suite.mxDir, 'netbeansinit.timestamp')) - if refreshOnly and not timestamp.exists(): + configZip = TimeStampFile(join(suite.mxDir, 'netbeans-config.zip')) + if refreshOnly and not configZip.exists(): return - if _check_ide_timestamp(suite, timestamp): + if _check_ide_timestamp(suite, configZip): logv('[NetBeans configurations are up to date - skipping]') return updated = False + files = [] for p in suite.projects: if p.native: continue @@ -3328,6 +3369,7 @@ out.close('target') out.close('project') updated = update_file(join(p.dir, 'build.xml'), out.xml(indent='\t', newl='\n')) or updated + files.append(join(p.dir, 'build.xml')) out = XMLDoc() out.open('project', {'xmlns' : 'http://www.netbeans.org/ns/project/1'}) @@ -3371,6 +3413,7 @@ out.close('configuration') out.close('project') updated = update_file(join(p.dir, 'nbproject', 'project.xml'), out.xml(indent=' ', newl='\n')) or updated + files.append(join(p.dir, 'nbproject', 'project.xml')) out = StringIO.StringIO() jdkPlatform = 'JDK_' + str(java().version) @@ -3492,6 +3535,7 @@ path = path.replace('\\', '\\\\') ref = 'file.reference.' + dep.name + '-bin' print >> out, ref + '=' + path + files.append(path) else: n = dep.name.replace('.', '_') @@ -3512,13 +3556,14 @@ updated = update_file(join(p.dir, 'nbproject', 'project.properties'), out.getvalue()) or updated out.close() + files.append(join(p.dir, 'nbproject', 'project.properties')) if updated: log('If using NetBeans:') log(' 1. Ensure that a platform named "JDK_' + str(java().version) + '" is defined (Tools -> Java Platforms)') log(' 2. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)') - timestamp.touch() + _zip_files(files, suite.dir, configZip.path) def ideclean(args): """remove all Eclipse and NetBeans project configurations""" @@ -3527,8 +3572,8 @@ os.remove(path) for s in suites(): - rm(join(s.mxDir, 'eclipseinit.timestamp')) - rm(join(s.mxDir, 'netbeansinit.timestamp')) + rm(join(s.mxDir, 'eclipse-config.zip')) + rm(join(s.mxDir, 'netbeans-config.zip')) for p in projects(): if p.native: