comparison mxtool/mx.py @ 7313:570d8e4c6dfb

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 07 Jan 2013 13:04:04 +0100
parents 57edf6b07d36
children 442668d41bc2
comparison
equal deleted inserted replaced
7312:46f945023189 7313:570d8e4c6dfb
186 os.mkdir(dir) 186 os.mkdir(dir)
187 for s in self.source_dirs(): 187 for s in self.source_dirs():
188 if not exists(s): 188 if not exists(s):
189 os.mkdir(s) 189 os.mkdir(s)
190 190
191 def all_deps(self, deps, includeLibs, includeSelf=True): 191 def all_deps(self, deps, includeLibs, includeSelf=True, includeAnnotationProcessors=False):
192 """ 192 """
193 Add the transitive set of dependencies for this project, including 193 Add the transitive set of dependencies for this project, including
194 libraries if 'includeLibs' is true, to the 'deps' list. 194 libraries if 'includeLibs' is true, to the 'deps' list.
195 """ 195 """
196 childDeps = list(self.deps)
197 if includeAnnotationProcessors and hasattr(self, 'annotationProcessors') and len(self.annotationProcessors) > 0:
198 childDeps = self.annotationProcessors + childDeps
196 if self in deps: 199 if self in deps:
197 return deps 200 return deps
198 for name in self.deps: 201 for name in childDeps:
199 assert name != self.name 202 assert name != self.name
200 dep = _libs.get(name, None) 203 dep = _libs.get(name, None)
201 if dep is not None: 204 if dep is not None:
202 if includeLibs and not dep in deps: 205 if includeLibs and not dep in deps:
203 deps.append(dep) 206 deps.append(dep)
206 if dep is None: 209 if dep is None:
207 if name in _opts.ignored_projects: 210 if name in _opts.ignored_projects:
208 abort('project named ' + name + ' required by ' + self.name + ' is ignored') 211 abort('project named ' + name + ' required by ' + self.name + ' is ignored')
209 abort('dependency named ' + name + ' required by ' + self.name + ' is not found') 212 abort('dependency named ' + name + ' required by ' + self.name + ' is not found')
210 if not dep in deps: 213 if not dep in deps:
211 dep.all_deps(deps, includeLibs) 214 dep.all_deps(deps, includeLibs=includeLibs, includeAnnotationProcessors=includeAnnotationProcessors)
212 if not self in deps and includeSelf: 215 if not self in deps and includeSelf:
213 deps.append(self) 216 deps.append(self)
214 return deps 217 return deps
215 218
216 def _compute_max_dep_distances(self, name, distances, dist): 219 def _compute_max_dep_distances(self, name, distances, dist):
462 465
463 for name, attrs in projsMap.iteritems(): 466 for name, attrs in projsMap.iteritems():
464 srcDirs = pop_list(attrs, 'sourceDirs') 467 srcDirs = pop_list(attrs, 'sourceDirs')
465 deps = pop_list(attrs, 'dependencies') 468 deps = pop_list(attrs, 'dependencies')
466 ap = pop_list(attrs, 'annotationProcessors') 469 ap = pop_list(attrs, 'annotationProcessors')
467 deps += ap 470 #deps += ap
468 javaCompliance = attrs.pop('javaCompliance', None) 471 javaCompliance = attrs.pop('javaCompliance', None)
469 subDir = attrs.pop('subDir', None); 472 subDir = attrs.pop('subDir', None);
470 if subDir is None: 473 if subDir is None:
471 dir = join(self.dir, name) 474 dir = join(self.dir, name)
472 else: 475 else:
476 p.native = attrs.pop('native', '') == 'true' 479 p.native = attrs.pop('native', '') == 'true'
477 if not p.native and p.javaCompliance is None: 480 if not p.native and p.javaCompliance is None:
478 abort('javaCompliance property required for non-native project ' + name) 481 abort('javaCompliance property required for non-native project ' + name)
479 if len(ap) > 0: 482 if len(ap) > 0:
480 p.annotationProcessors = ap 483 p.annotationProcessors = ap
481 apc = pop_list(attrs, 'annotationProcessorClasses')
482 if len(apc) > 0:
483 p.annotationProcessorClasses = apc
484 p.__dict__.update(attrs) 484 p.__dict__.update(attrs)
485 self.projects.append(p) 485 self.projects.append(p)
486 486
487 for name, attrs in libsMap.iteritems(): 487 for name, attrs in libsMap.iteritems():
488 path = attrs.pop('path') 488 path = attrs.pop('path')
727 with zipfile.ZipFile(entry, 'r') as zf: 727 with zipfile.ZipFile(entry, 'r') as zf:
728 for zi in zf.infolist(): 728 for zi in zf.infolist():
729 entryPath = zi.filename 729 entryPath = zi.filename
730 yield zf, entryPath 730 yield zf, entryPath
731 731
732 def sorted_deps(projectNames=None, includeLibs=False): 732 def sorted_deps(projectNames=None, includeLibs=False, includeAnnotationProcessors=False):
733 """ 733 """
734 Gets projects and libraries sorted such that dependencies 734 Gets projects and libraries sorted such that dependencies
735 are before the projects that depend on them. Unless 'includeLibs' is 735 are before the projects that depend on them. Unless 'includeLibs' is
736 true, libraries are omitted from the result. 736 true, libraries are omitted from the result.
737 """ 737 """
740 projects = _projects.values() 740 projects = _projects.values()
741 else: 741 else:
742 projects = [project(name) for name in projectNames] 742 projects = [project(name) for name in projectNames]
743 743
744 for p in projects: 744 for p in projects:
745 p.all_deps(deps, includeLibs) 745 p.all_deps(deps, includeLibs=includeLibs, includeAnnotationProcessors=includeAnnotationProcessors)
746 return deps 746 return deps
747 747
748 class ArgParser(ArgumentParser): 748 class ArgParser(ArgumentParser):
749 749
750 # Override parent to append the list of available commands 750 # Override parent to append the list of available commands
1294 projects = args.projects.split(',') 1294 projects = args.projects.split(',')
1295 1295
1296 if args.only is not None: 1296 if args.only is not None:
1297 sortedProjects = [project(name) for name in args.only.split(',')] 1297 sortedProjects = [project(name) for name in args.only.split(',')]
1298 else: 1298 else:
1299 sortedProjects = sorted_deps(projects) 1299 sortedProjects = sorted_deps(projects, includeAnnotationProcessors=True)
1300 1300
1301 for p in sortedProjects: 1301 for p in sortedProjects:
1302 if p.native: 1302 if p.native:
1303 if args.native: 1303 if args.native:
1304 log('Calling GNU make {0}...'.format(p.dir)) 1304 log('Calling GNU make {0}...'.format(p.dir))
1378 1378
1379 else: 1379 else:
1380 log('could not file .class directive in Jasmin source: ' + src) 1380 log('could not file .class directive in Jasmin source: ' + src)
1381 else: 1381 else:
1382 dst = join(outputDir, src[len(sourceDir) + 1:]) 1382 dst = join(outputDir, src[len(sourceDir) + 1:])
1383 if exists(dirname(dst)) and (not exists(dst) or os.path.getmtime(dst) != os.path.getmtime(src)): 1383 if not exists(dirname(dst)):
1384 os.makedirs(dirname(dst))
1385 if exists(dirname(dst)) and (not exists(dst) or os.path.getmtime(dst) < os.path.getmtime(src)):
1384 shutil.copyfile(src, dst) 1386 shutil.copyfile(src, dst)
1385 1387
1386 if not mustBuild: 1388 if not mustBuild:
1387 for javafile in javafiles: 1389 for javafile in javafiles:
1388 classfile = outputDir + javafile[len(sourceDir):-len('java')] + 'class' 1390 classfile = outputDir + javafile[len(sourceDir):-len('java')] + 'class'
1408 javacArgs = [] 1410 javacArgs = []
1409 if java().debug_port is not None: 1411 if java().debug_port is not None:
1410 javacArgs += ['-J-Xdebug', '-J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(java().debug_port)] 1412 javacArgs += ['-J-Xdebug', '-J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(java().debug_port)]
1411 1413
1412 if hasattr(p, 'annotationProcessors') and len(p.annotationProcessors) > 0: 1414 if hasattr(p, 'annotationProcessors') and len(p.annotationProcessors) > 0:
1413 annotationProcessors = [] 1415 processorPath = classpath(p.annotationProcessors, resolve=True)
1414 for apProject in p.annotationProcessors:
1415 apClasses = project(apProject).annotationProcessorClasses
1416 if len(apClasses) == 0:
1417 abort("Project " + p + " specifies " + apProject + " as an annotation processor but " + apProject + " does not specifiy any annotation processor class")
1418 annotationProcessors += apClasses
1419
1420 genDir = p.source_gen_dir(); 1416 genDir = p.source_gen_dir();
1421 if exists(genDir): 1417 if exists(genDir):
1422 shutil.rmtree(genDir) 1418 shutil.rmtree(genDir)
1423 os.mkdir(genDir) 1419 os.mkdir(genDir)
1424 javacArgs += ['-processor', ",".join(annotationProcessors), "-s", genDir] 1420 javacArgs += ['-processorpath', join(processorPath), '-s', genDir]
1425 else: 1421 else:
1426 javacArgs += ['-proc:none'] 1422 javacArgs += ['-proc:none']
1427 1423
1428 toBeDeleted = [argfileName] 1424 toBeDeleted = [argfileName]
1429 try: 1425 try:
1440 '-cp', cp, '-g', '-enableJavadoc', 1436 '-cp', cp, '-g', '-enableJavadoc',
1441 '-d', outputDir] + javacArgs 1437 '-d', outputDir] + javacArgs
1442 jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs') 1438 jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs')
1443 if not exists(jdtProperties): 1439 if not exists(jdtProperties):
1444 # Try to fix a missing properties file by running eclipseinit 1440 # Try to fix a missing properties file by running eclipseinit
1445 eclipseinit([]) 1441 eclipseinit([], buildProcessorJars=False)
1446 if not exists(jdtProperties): 1442 if not exists(jdtProperties):
1447 log('JDT properties file {0} not found'.format(jdtProperties)) 1443 log('JDT properties file {0} not found'.format(jdtProperties))
1448 else: 1444 else:
1449 # convert all warnings to errors 1445 # convert all warnings to errors
1450 if args.jdt_warning_as_error: 1446 if args.jdt_warning_as_error:
1465 1461
1466 if suppliedParser: 1462 if suppliedParser:
1467 return args 1463 return args
1468 return None 1464 return None
1469 1465
1470 def processorjars(args): 1466 def processorjars():
1471 hasProcessorJars = [] 1467 projects = set([])
1472 1468
1473 for p in sorted_deps(): 1469 for p in sorted_deps():
1474 if hasattr(p, 'annotationProcessorClasses') and len(p.annotationProcessorClasses) > 0: 1470 if _needsEclipseJarBuild(p):
1475 hasProcessorJars.append(p) 1471 projects.add(p)
1476 1472
1477 if len(hasProcessorJars) <= 0: 1473 if len(projects) <= 0:
1478 return 1474 return
1479 1475
1480 build(['--projects', ",".join(map(lambda p: p.name, hasProcessorJars))]) 1476 build(['--projects', ",".join(map(lambda p: p.name, projects))])
1481 1477
1482 for p in hasProcessorJars: 1478 for p in projects:
1483 spDir = join(p.output_dir(), 'META-INF', 'services') 1479 targetJar = join(p.dir, p.name + '.jar')
1484 if not exists(spDir): 1480 jar(targetJar, [p.output_dir()])
1485 os.makedirs(spDir)
1486 spFile = join(spDir, 'javax.annotation.processing.Processor')
1487 with open(spFile, 'w') as fp:
1488 fp.writelines(p.annotationProcessorClasses)
1489 created = False
1490 for dep in p.all_deps([], False):
1491 if created:
1492 cmd = 'uf'
1493 else:
1494 cmd = 'cf'
1495 created = True
1496 jarCmd = [java().jar, cmd, join(p.dir, p.name + 'AnnotationProcessor.jar'), '-C', dep.output_dir(), '.']
1497 subprocess.check_call(jarCmd)
1498 log('added ' + dep.name + ' to ' + p.name + '.jar');
1499 1481
1482
1483 def jar(destFileName, dirs):
1484 latestMod = _latestModification(dirs)
1485
1486 if exists(destFileName):
1487 mod = os.path.getmtime(destFileName)
1488 if int(round(latestMod*1000)) == int(round(mod*1000)):
1489 # nothing todo
1490 return
1491
1492 if latestMod is None and exists(destFileName):
1493 return
1494
1495 jarCmd = [java().jar, 'cf', destFileName]
1496
1497 for directory in dirs:
1498 jarCmd += ['-C', directory, '.']
1499
1500 subprocess.check_call(jarCmd)
1501 log('Written jar file {0}'.format(destFileName))
1502
1503 atime = os.path.getatime(destFileName)
1504 os.utime(destFileName, (atime, latestMod))
1505
1506 def _latestModification(directories):
1507 latestMod = None
1508 for directory in directories:
1509 if not os.path.exists (directory):
1510 continue
1511 for root, _, files in os.walk(directory):
1512 for names in files:
1513 filepath = os.path.join(root, names)
1514 mod = os.path.getmtime(filepath)
1515 if latestMod is None:
1516 latestMod = mod
1517 elif mod > latestMod:
1518 latestMod = mod
1519 return latestMod
1500 1520
1501 def canonicalizeprojects(args): 1521 def canonicalizeprojects(args):
1502 """process all project files to canonicalize the dependencies 1522 """process all project files to canonicalize the dependencies
1503 1523
1504 The exit code of this command reflects how many files were updated.""" 1524 The exit code of this command reflects how many files were updated."""
1858 eclipseLaunches = join('mx', 'eclipse-launches') 1878 eclipseLaunches = join('mx', 'eclipse-launches')
1859 if not exists(eclipseLaunches): 1879 if not exists(eclipseLaunches):
1860 os.makedirs(eclipseLaunches) 1880 os.makedirs(eclipseLaunches)
1861 return update_file(join(eclipseLaunches, name + '.launch'), launch) 1881 return update_file(join(eclipseLaunches, name + '.launch'), launch)
1862 1882
1863 def eclipseinit(args, suite=None): 1883 def eclipseinit(args, suite=None, buildProcessorJars=True):
1864 """(re)generate Eclipse project configurations""" 1884 """(re)generate Eclipse project configurations"""
1865 1885
1866 if suite is None: 1886 if suite is None:
1867 suite = _mainSuite 1887 suite = _mainSuite
1868 1888
1869 processorjars([]) 1889 if buildProcessorJars:
1890 processorjars()
1870 1891
1871 for p in projects(): 1892 for p in projects():
1872 if p.native: 1893 if p.native:
1873 continue 1894 continue
1874 1895
1881 for src in p.srcDirs: 1902 for src in p.srcDirs:
1882 srcDir = join(p.dir, src) 1903 srcDir = join(p.dir, src)
1883 if not exists(srcDir): 1904 if not exists(srcDir):
1884 os.mkdir(srcDir) 1905 os.mkdir(srcDir)
1885 out.element('classpathentry', {'kind' : 'src', 'path' : src}) 1906 out.element('classpathentry', {'kind' : 'src', 'path' : src})
1907
1908 if hasattr(p, 'annotationProcessors') and len(p.annotationProcessors) > 0:
1909 genDir = p.source_gen_dir();
1910 if not exists(genDir):
1911 os.mkdir(genDir)
1912 out.element('classpathentry', {'kind' : 'src', 'path' : 'src_gen'})
1886 1913
1887 # Every Java program depends on the JRE 1914 # Every Java program depends on the JRE
1888 out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER'}) 1915 out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER'})
1889 1916
1890 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project 1917 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project
1973 for buildCommand in ['org.eclipse.pde.ManifestBuilder', 'org.eclipse.pde.SchemaBuilder']: 2000 for buildCommand in ['org.eclipse.pde.ManifestBuilder', 'org.eclipse.pde.SchemaBuilder']:
1974 out.open('buildCommand') 2001 out.open('buildCommand')
1975 out.element('name', data=buildCommand) 2002 out.element('name', data=buildCommand)
1976 out.element('arguments', data='') 2003 out.element('arguments', data='')
1977 out.close('buildCommand') 2004 out.close('buildCommand')
2005
2006 if (_needsEclipseJarBuild(p)):
2007 out.open('buildCommand')
2008 out.element('name', data='org.eclipse.ui.externaltools.ExternalToolBuilder')
2009 out.element('triggers', data='auto,full,incremental,')
2010 out.open('arguments')
2011 out.open('dictionary')
2012 out.element('key', data = 'LaunchConfigHandle')
2013 out.element('value', data = _genEclipseJarBuild(p))
2014 out.close('dictionary')
2015 out.open('dictionary')
2016 out.element('key', data = 'incclean')
2017 out.element('value', data = 'true')
2018 out.close('dictionary')
2019 out.close('arguments')
2020 out.close('buildCommand')
2021
1978 out.close('buildSpec') 2022 out.close('buildSpec')
1979 out.open('natures') 2023 out.open('natures')
1980 out.element('nature', data='org.eclipse.jdt.core.javanature') 2024 out.element('nature', data='org.eclipse.jdt.core.javanature')
1981 if exists(csConfig): 2025 if exists(csConfig):
1982 out.element('nature', data='net.sf.eclipsecs.core.CheckstyleNature') 2026 out.element('nature', data='net.sf.eclipsecs.core.CheckstyleNature')
2008 out = XMLDoc() 2052 out = XMLDoc()
2009 out.open('factorypath') 2053 out.open('factorypath')
2010 out.element('factorypathentry', {'kind' : 'PLUGIN', 'id' : 'org.eclipse.jst.ws.annotations.core', 'enabled' : 'true', 'runInBatchMode' : 'false'}) 2054 out.element('factorypathentry', {'kind' : 'PLUGIN', 'id' : 'org.eclipse.jst.ws.annotations.core', 'enabled' : 'true', 'runInBatchMode' : 'false'})
2011 for ap in p.annotationProcessors: 2055 for ap in p.annotationProcessors:
2012 apProject = project(ap) 2056 apProject = project(ap)
2013 out.element('factorypathentry', {'kind' : 'WKSPJAR', 'id' : '/' + apProject.name + '/' + apProject.name + 'AnnotationProcessor.jar', 'enabled' : 'true', 'runInBatchMode' : 'false'})
2014 for dep in apProject.all_deps([], True): 2057 for dep in apProject.all_deps([], True):
2015 if dep.isLibrary(): 2058 if dep.isLibrary():
2016 if not hasattr(dep, 'eclipse.container') and not hasattr(dep, 'eclipse.project'): 2059 if not hasattr(dep, 'eclipse.container') and not hasattr(dep, 'eclipse.project'):
2017 if dep.mustExist: 2060 if dep.mustExist:
2018 path = dep.get_path(resolve=True) 2061 path = dep.get_path(resolve=True)
2020 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse 2063 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse
2021 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's 2064 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's
2022 # safest to simply use absolute paths. 2065 # safest to simply use absolute paths.
2023 path = join(suite.dir, path) 2066 path = join(suite.dir, path)
2024 out.element('factorypathentry', {'kind' : 'EXTJAR', 'id' : path, 'enabled' : 'true', 'runInBatchMode' : 'false'}) 2067 out.element('factorypathentry', {'kind' : 'EXTJAR', 'id' : path, 'enabled' : 'true', 'runInBatchMode' : 'false'})
2068 else:
2069 out.element('factorypathentry', {'kind' : 'WKSPJAR', 'id' : '/' + dep.name + '/' + dep.name + '.jar', 'enabled' : 'true', 'runInBatchMode' : 'false'})
2025 out.close('factorypath') 2070 out.close('factorypath')
2026 update_file(join(p.dir, '.factorypath'), out.xml(indent='\t', newl='\n')) 2071 update_file(join(p.dir, '.factorypath'), out.xml(indent='\t', newl='\n'))
2027 2072
2028 make_eclipse_attach('localhost', '8000', deps=projects()) 2073 make_eclipse_attach('localhost', '8000', deps=projects())
2074
2075
2076 def _needsEclipseJarBuild(p):
2077 processors = set([])
2078
2079 for otherProject in projects():
2080 if hasattr(otherProject, 'annotationProcessors') and len(otherProject.annotationProcessors) > 0:
2081 for processorName in otherProject.annotationProcessors:
2082 processors.add(project(processorName, fatalIfMissing=True))
2083
2084 if p in processors:
2085 return True
2086
2087 for otherProject in processors:
2088 deps = otherProject.all_deps([], True)
2089 if p in deps:
2090 return True
2091
2092 return False
2093
2094 def _genEclipseJarBuild(p):
2095 launchOut = XMLDoc();
2096 launchOut.open('launchConfiguration', {'type' : 'org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType'})
2097 launchOut.element('stringAttribute', {'key' : 'org.eclipse.debug.core.ATTR_REFRESH_SCOPE', 'value': '${project}'})
2098 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.core.capture_output', 'value': 'false'})
2099 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_CONSOLE_OUTPUT_ON', 'value': 'false'})
2100 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND', 'value': 'true'})
2101
2102 baseDir = dirname(dirname(os.path.abspath(__file__)))
2103
2104 cmd = 'mx.sh'
2105 if get_os() == 'windows':
2106 cmd = 'mx.cmd'
2107 launchOut.element('stringAttribute', {'key' : 'org.eclipse.ui.externaltools.ATTR_LOCATION', 'value': join(baseDir, cmd) })
2108 launchOut.element('stringAttribute', {'key' : 'org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS', 'value': 'auto,full,incremental'})
2109 launchOut.element('stringAttribute', {'key' : 'org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS', 'value': ''.join(['jar', ' ', p.name])})
2110 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED','value': 'true'})
2111 launchOut.element('stringAttribute', {'key' : 'org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY', 'value': baseDir})
2112
2113
2114 launchOut.close('launchConfiguration')
2115
2116 externalToolDir = join(p.dir, '.externalToolBuilders')
2117
2118 if not exists(externalToolDir):
2119 os.makedirs(externalToolDir)
2120 update_file(join(externalToolDir, 'Jar.launch'), launchOut.xml(indent='\t', newl='\n'))
2121
2122 return "<project>/.externalToolBuilders/Jar.launch"
2123
2124
2125
2029 2126
2030 def netbeansinit(args, suite=None): 2127 def netbeansinit(args, suite=None):
2031 """(re)generate NetBeans project configurations""" 2128 """(re)generate NetBeans project configurations"""
2032 2129
2033 if suite is None: 2130 if suite is None:
2061 out.open('data', {'xmlns' : 'http://www.netbeans.org/ns/j2se-project/3'}) 2158 out.open('data', {'xmlns' : 'http://www.netbeans.org/ns/j2se-project/3'})
2062 out.element('name', data=p.name) 2159 out.element('name', data=p.name)
2063 out.element('explicit-platform', {'explicit-source-supported' : 'true'}) 2160 out.element('explicit-platform', {'explicit-source-supported' : 'true'})
2064 out.open('source-roots') 2161 out.open('source-roots')
2065 out.element('root', {'id' : 'src.dir'}) 2162 out.element('root', {'id' : 'src.dir'})
2163 if hasattr(p, 'annotationProcessors') and len(p.annotationProcessors) > 0:
2164 out.element('root', {'id' : 'src.ap-source-output.dir'})
2066 out.close('source-roots') 2165 out.close('source-roots')
2067 out.open('test-roots') 2166 out.open('test-roots')
2068 out.element('root', {'id' : 'test.src.dir'})
2069 out.close('test-roots') 2167 out.close('test-roots')
2070 out.close('data') 2168 out.close('data')
2071 2169
2072 firstDep = True 2170 firstDep = True
2073 for dep in p.all_deps([], True): 2171 for dep in p.all_deps([], True):
2097 updated = update_file(join(p.dir, 'nbproject', 'project.xml'), out.xml(indent=' ', newl='\n')) or updated 2195 updated = update_file(join(p.dir, 'nbproject', 'project.xml'), out.xml(indent=' ', newl='\n')) or updated
2098 2196
2099 out = StringIO.StringIO() 2197 out = StringIO.StringIO()
2100 jdkPlatform = 'JDK_' + java().version 2198 jdkPlatform = 'JDK_' + java().version
2101 2199
2200 annotationProcessorEnabled = "false"
2201 annotationProcessorReferences = ""
2202 annotationProcessorSrcFolder = ""
2203 if hasattr(p, 'annotationProcessors') and len(p.annotationProcessors) > 0:
2204 annotationProcessorEnabled = "true"
2205 annotationProcessorSrcFolder = "src.ap-source-output.dir=${build.generated.sources.dir}/ap-source-output"
2206
2102 content = """ 2207 content = """
2103 annotation.processing.enabled=false 2208 annotation.processing.enabled=""" + annotationProcessorEnabled + """
2104 annotation.processing.enabled.in.editor=false 2209 annotation.processing.enabled.in.editor=""" + annotationProcessorEnabled + """
2105 annotation.processing.processors.list= 2210 annotation.processing.processors.list=
2106 annotation.processing.run.all.processors=true 2211 annotation.processing.run.all.processors=true
2107 annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
2108 application.title=""" + p.name + """ 2212 application.title=""" + p.name + """
2109 application.vendor=mx 2213 application.vendor=mx
2110 build.classes.dir=${build.dir} 2214 build.classes.dir=${build.dir}
2111 build.classes.excludes=**/*.java,**/*.form 2215 build.classes.excludes=**/*.java,**/*.form
2112 # This directory is removed when the project is cleaned: 2216 # This directory is removed when the project is cleaned:
2132 includes=** 2236 includes=**
2133 jar.compress=false 2237 jar.compress=false
2134 # Space-separated list of extra javac options 2238 # Space-separated list of extra javac options
2135 javac.compilerargs= 2239 javac.compilerargs=
2136 javac.deprecation=false 2240 javac.deprecation=false
2137 javac.processorpath=\\
2138 ${javac.classpath}
2139 javac.source=1.7 2241 javac.source=1.7
2140 javac.target=1.7 2242 javac.target=1.7
2141 javac.test.classpath=\\ 2243 javac.test.classpath=\\
2142 ${javac.classpath}:\\ 2244 ${javac.classpath}:\\
2143 ${build.classes.dir} 2245 ${build.classes.dir}
2144 javac.test.processorpath=\\
2145 ${javac.test.classpath}
2146 javadoc.additionalparam= 2246 javadoc.additionalparam=
2147 javadoc.author=false 2247 javadoc.author=false
2148 javadoc.encoding=${source.encoding} 2248 javadoc.encoding=${source.encoding}
2149 javadoc.noindex=false 2249 javadoc.noindex=false
2150 javadoc.nonavbar=false 2250 javadoc.nonavbar=false
2168 # or test-sys-prop.name=value to set system properties for unit tests): 2268 # or test-sys-prop.name=value to set system properties for unit tests):
2169 run.jvmargs= 2269 run.jvmargs=
2170 run.test.classpath=\\ 2270 run.test.classpath=\\
2171 ${javac.test.classpath}:\\ 2271 ${javac.test.classpath}:\\
2172 ${build.test.classes.dir} 2272 ${build.test.classes.dir}
2173 test.src.dir= 2273 test.src.dir=./test
2274 """ + annotationProcessorSrcFolder + """
2174 source.encoding=UTF-8""".replace(':', os.pathsep).replace('/', os.sep) 2275 source.encoding=UTF-8""".replace(':', os.pathsep).replace('/', os.sep)
2175 print >> out, content 2276 print >> out, content
2176 2277
2177 mainSrc = True 2278 mainSrc = True
2178 for src in p.srcDirs: 2279 for src in p.srcDirs:
2186 mainSrc = False 2287 mainSrc = False
2187 else: 2288 else:
2188 print >> out, 'src.' + src + '.dir=${' + ref + '}' 2289 print >> out, 'src.' + src + '.dir=${' + ref + '}'
2189 2290
2190 javacClasspath = [] 2291 javacClasspath = []
2191 for dep in p.all_deps([], True): 2292
2293 deps = p.all_deps([], True)
2294 annotationProcessorOnlyDeps = []
2295 if hasattr(p, 'annotationProcessors') and len(p.annotationProcessors) > 0:
2296 for ap in p.annotationProcessors:
2297 apProject = project(ap)
2298 if not apProject in deps:
2299 deps.append(apProject)
2300 annotationProcessorOnlyDeps.append(apProject)
2301
2302 annotationProcessorReferences = [];
2303
2304 for dep in deps:
2192 if dep == p: 2305 if dep == p:
2193 continue; 2306 continue;
2194 2307
2195 if dep.isLibrary(): 2308 if dep.isLibrary():
2196 if not dep.mustExist: 2309 if not dep.mustExist:
2206 relDepPath = os.path.relpath(dep.dir, p.dir).replace(os.sep, '/') 2319 relDepPath = os.path.relpath(dep.dir, p.dir).replace(os.sep, '/')
2207 ref = 'reference.' + n + '.jar' 2320 ref = 'reference.' + n + '.jar'
2208 print >> out, 'project.' + n + '=' + relDepPath 2321 print >> out, 'project.' + n + '=' + relDepPath
2209 print >> out, ref + '=${project.' + n + '}/dist/' + dep.name + '.jar' 2322 print >> out, ref + '=${project.' + n + '}/dist/' + dep.name + '.jar'
2210 2323
2211 javacClasspath.append('${' + ref + '}') 2324 if not dep in annotationProcessorOnlyDeps:
2325 javacClasspath.append('${' + ref + '}')
2326 else:
2327 annotationProcessorReferences.append('${' + ref + '}')
2328 annotationProcessorReferences += ":\\\n ${" + ref + "}"
2212 2329
2213 print >> out, 'javac.classpath=\\\n ' + (os.pathsep + '\\\n ').join(javacClasspath) 2330 print >> out, 'javac.classpath=\\\n ' + (os.pathsep + '\\\n ').join(javacClasspath)
2214 2331 print >> out, 'javac.test.processorpath=${javac.test.classpath}\\\n ' + (os.pathsep + '\\\n ').join(annotationProcessorReferences)
2215 2332 print >> out, 'javac.processorpath=${javac.classpath}\\\n ' + (os.pathsep + '\\\n ').join(annotationProcessorReferences)
2333
2216 updated = update_file(join(p.dir, 'nbproject', 'project.properties'), out.getvalue()) or updated 2334 updated = update_file(join(p.dir, 'nbproject', 'project.properties'), out.getvalue()) or updated
2217 out.close() 2335 out.close()
2218 2336
2219 if updated: 2337 if updated:
2220 log('If using NetBeans:') 2338 log('If using NetBeans:')
2221 log(' 1. Ensure that a platform named "JDK ' + java().version + '" is defined (Tools -> Java Platforms)') 2339 log(' 1. Ensure that a platform named "JDK ' + java().version + '" is defined (Tools -> Java Platforms)')
2222 log(' 2. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)') 2340 log(' 2. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)')
2223 2341
2224 def ideclean(args, suite=None): 2342 def ideclean(args, suite=None):
2225 """remove all Eclipse and NetBeans project configurations""" 2343 """remove all Eclipse and NetBeans project configurations"""
2226
2227 def rm(path): 2344 def rm(path):
2228 if exists(path): 2345 if exists(path):
2229 os.remove(path) 2346 os.remove(path)
2230 2347
2231 for p in projects(): 2348 for p in projects():
2232 if p.native: 2349 if p.native:
2233 continue 2350 continue
2234 2351
2235 shutil.rmtree(join(p.dir, '.settings'), ignore_errors=True) 2352 shutil.rmtree(join(p.dir, '.settings'), ignore_errors=True)
2353 shutil.rmtree(join(p.dir, '.externalToolBuilders'), ignore_errors=True)
2236 shutil.rmtree(join(p.dir, 'nbproject'), ignore_errors=True) 2354 shutil.rmtree(join(p.dir, 'nbproject'), ignore_errors=True)
2237 rm(join(p.dir, '.classpath')) 2355 rm(join(p.dir, '.classpath'))
2238 rm(join(p.dir, '.project')) 2356 rm(join(p.dir, '.project'))
2239 rm(join(p.dir, 'build.xml')) 2357 rm(join(p.dir, 'build.xml'))
2358 rm(join(p.dir, 'eclipse-build.xml'))
2359 try:
2360 rm(join(p.dir, p.name + '.jar'))
2361 except:
2362 log("Error removing {0}".format(p.name + '.jar'))
2363
2240 2364
2241 def ideinit(args, suite=None): 2365 def ideinit(args, suite=None):
2242 """(re)generate Eclipse and NetBeans project configurations""" 2366 """(re)generate Eclipse and NetBeans project configurations"""
2243 eclipseinit(args, suite) 2367 eclipseinit(args, suite)
2244 netbeansinit(args, suite) 2368 netbeansinit(args, suite)