comparison mxtool/mx.py @ 11374:9cdf7a9d3475

Enable library as annotation processor Add a dependency(name) method Implement all_deps for Library
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 20 Aug 2013 13:22:15 +0200
parents 345bce66c04a
children 2d228d304247
comparison
equal deleted inserted replaced
11373:6675167d52b6 11374:9cdf7a9d3475
200 def __hash__(self): 200 def __hash__(self):
201 return hash(self.name) 201 return hash(self.name)
202 202
203 def isLibrary(self): 203 def isLibrary(self):
204 return isinstance(self, Library) 204 return isinstance(self, Library)
205
206 def isProject(self):
207 return isinstance(self, Project)
205 208
206 class Project(Dependency): 209 class Project(Dependency):
207 def __init__(self, suite, name, srcDirs, deps, javaCompliance, workingSets, d): 210 def __init__(self, suite, name, srcDirs, deps, javaCompliance, workingSets, d):
208 Dependency.__init__(self, suite, name) 211 Dependency.__init__(self, suite, name)
209 self.srcDirs = srcDirs 212 self.srcDirs = srcDirs
231 childDeps = self.annotation_processors() + childDeps 234 childDeps = self.annotation_processors() + childDeps
232 if self in deps: 235 if self in deps:
233 return deps 236 return deps
234 for name in childDeps: 237 for name in childDeps:
235 assert name != self.name 238 assert name != self.name
236 dep = _libs.get(name, None) 239 dep = dependency(name)
237 if dep is not None: 240 if not dep in deps and (includeLibs or not dep.isLibrary()):
238 if includeLibs and not dep in deps: 241 dep.all_deps(deps, includeLibs=includeLibs, includeAnnotationProcessors=includeAnnotationProcessors)
239 deps.append(dep)
240 else:
241 dep = _projects.get(name, None)
242 if dep is None:
243 if name in _opts.ignored_projects:
244 abort('project named ' + name + ' required by ' + self.name + ' is ignored')
245 abort('dependency named ' + name + ' required by ' + self.name + ' is not found')
246 if not dep in deps:
247 dep.all_deps(deps, includeLibs=includeLibs, includeAnnotationProcessors=includeAnnotationProcessors)
248 if not self in deps and includeSelf: 242 if not self in deps and includeSelf:
249 deps.append(self) 243 deps.append(self)
250 return deps 244 return deps
251 245
252 def _compute_max_dep_distances(self, name, distances, dist): 246 def _compute_max_dep_distances(self, name, distances, dist):
466 460
467 def append_to_classpath(self, cp, resolve): 461 def append_to_classpath(self, cp, resolve):
468 path = self.get_path(resolve) 462 path = self.get_path(resolve)
469 if exists(path) or not resolve: 463 if exists(path) or not resolve:
470 cp.append(path) 464 cp.append(path)
465
466 def all_deps(self, deps, includeLibs, includeSelf=True, includeAnnotationProcessors=False):
467 if not includeLibs or not includeSelf:
468 return deps
469 deps.append(self)
470 return deps
471 471
472 class Suite: 472 class Suite:
473 def __init__(self, d, primary): 473 def __init__(self, d, primary):
474 self.dir = d 474 self.dir = d
475 self.projects = [] 475 self.projects = []
760 """ 760 """
761 Get the list of all loaded projects that define an annotation processor. 761 Get the list of all loaded projects that define an annotation processor.
762 """ 762 """
763 global _annotationProcessors 763 global _annotationProcessors
764 if _annotationProcessors is None: 764 if _annotationProcessors is None:
765 ap = set() 765 aps = set()
766 for p in projects(): 766 for p in projects():
767 ap.update(p.annotation_processors()) 767 for ap in p.annotation_processors():
768 _annotationProcessors = list(ap) 768 if project(ap, False):
769 aps.add(ap)
770 _annotationProcessors = list(aps)
769 return _annotationProcessors 771 return _annotationProcessors
770 772
771 def distribution(name, fatalIfMissing=True): 773 def distribution(name, fatalIfMissing=True):
772 """ 774 """
773 Get the distribution for a given name. This will abort if the named distribution does 775 Get the distribution for a given name. This will abort if the named distribution does
774 not exist and 'fatalIfMissing' is true. 776 not exist and 'fatalIfMissing' is true.
775 """ 777 """
776 d = _dists.get(name) 778 d = _dists.get(name)
777 if d is None and fatalIfMissing: 779 if d is None and fatalIfMissing:
778 abort('distribution named ' + name + ' not found') 780 abort('distribution named ' + name + ' not found')
781 return d
782
783 def dependency(name, fatalIfMissing=True):
784 """
785 Get the project or library for a given name. This will abort if a project or library does
786 not exist for 'name' and 'fatalIfMissing' is true.
787 """
788 d = _projects.get(name)
789 if d is None:
790 d = _libs.get(name)
791 if d is None and fatalIfMissing:
792 if name in _opts.ignored_projects:
793 abort('project named ' + name + ' is ignored')
794 abort('project or library named ' + name + ' not found')
779 return d 795 return d
780 796
781 def project(name, fatalIfMissing=True): 797 def project(name, fatalIfMissing=True):
782 """ 798 """
783 Get the project for a given name. This will abort if the named project does 799 Get the project for a given name. This will abort if the named project does
810 cp += [_opts.cp_suffix] 826 cp += [_opts.cp_suffix]
811 return os.pathsep.join(cp) 827 return os.pathsep.join(cp)
812 828
813 def classpath(names=None, resolve=True, includeSelf=True, includeBootClasspath=False): 829 def classpath(names=None, resolve=True, includeSelf=True, includeBootClasspath=False):
814 """ 830 """
815 Get the class path for a list of given projects, resolving each entry in the 831 Get the class path for a list of given dependencies, resolving each entry in the
816 path (e.g. downloading a missing library) if 'resolve' is true. 832 path (e.g. downloading a missing library) if 'resolve' is true.
817 """ 833 """
818 if names is None: 834 if names is None:
819 result = _as_classpath(sorted_deps(includeLibs=True), resolve) 835 result = _as_classpath(sorted_deps(includeLibs=True), resolve)
820 else: 836 else:
821 deps = [] 837 deps = []
822 if isinstance(names, types.StringTypes): 838 if isinstance(names, types.StringTypes):
823 project(names).all_deps(deps, True, includeSelf) 839 names = [names]
824 else: 840 for n in names:
825 for n in names: 841 dependency(n).all_deps(deps, True, includeSelf)
826 project(n).all_deps(deps, True, includeSelf)
827 result = _as_classpath(deps, resolve) 842 result = _as_classpath(deps, resolve)
828 if includeBootClasspath: 843 if includeBootClasspath:
829 result = os.pathsep.join([java().bootclasspath(), result]) 844 result = os.pathsep.join([java().bootclasspath(), result])
830 return result 845 return result
831 846
2443 if len(p.annotation_processors()) > 0: 2458 if len(p.annotation_processors()) > 0:
2444 out = XMLDoc() 2459 out = XMLDoc()
2445 out.open('factorypath') 2460 out.open('factorypath')
2446 out.element('factorypathentry', {'kind' : 'PLUGIN', 'id' : 'org.eclipse.jst.ws.annotations.core', 'enabled' : 'true', 'runInBatchMode' : 'false'}) 2461 out.element('factorypathentry', {'kind' : 'PLUGIN', 'id' : 'org.eclipse.jst.ws.annotations.core', 'enabled' : 'true', 'runInBatchMode' : 'false'})
2447 for ap in p.annotation_processors(): 2462 for ap in p.annotation_processors():
2448 apProject = project(ap) 2463 for dep in dependency(ap).all_deps([], True):
2449 for dep in apProject.all_deps([], True):
2450 if dep.isLibrary(): 2464 if dep.isLibrary():
2451 if not hasattr(dep, 'eclipse.container') and not hasattr(dep, 'eclipse.project'): 2465 if not hasattr(dep, 'eclipse.container') and not hasattr(dep, 'eclipse.project'):
2452 if dep.mustExist: 2466 if dep.mustExist:
2453 path = dep.get_path(resolve=True) 2467 path = dep.get_path(resolve=True)
2454 if not isabs(path): 2468 if not isabs(path):
2815 2829
2816 deps = p.all_deps([], True) 2830 deps = p.all_deps([], True)
2817 annotationProcessorOnlyDeps = [] 2831 annotationProcessorOnlyDeps = []
2818 if len(p.annotation_processors()) > 0: 2832 if len(p.annotation_processors()) > 0:
2819 for ap in p.annotation_processors(): 2833 for ap in p.annotation_processors():
2820 apProject = project(ap) 2834 apDep = dependency(ap)
2821 if not apProject in deps: 2835 if not apDep in deps:
2822 deps.append(apProject) 2836 deps.append(apDep)
2823 annotationProcessorOnlyDeps.append(apProject) 2837 annotationProcessorOnlyDeps.append(apDep)
2824 2838
2825 annotationProcessorReferences = []; 2839 annotationProcessorReferences = [];
2826 2840
2827 for dep in deps: 2841 for dep in deps:
2828 if dep == p: 2842 if dep == p: