changeset 9857:719a290b8a23

added optional annotationProcessorForDependents attribute for a project to inject itself as an annotation processor for all dependents
author Doug Simon <doug.simon@oracle.com>
date Tue, 04 Jun 2013 15:22:10 +0200
parents fbeda9df497d
children 538ac2cf3383
files mx/projects mxtool/mx.py
diffstat 2 files changed, 32 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/mx/projects	Tue Jun 04 12:21:32 2013 +0200
+++ b/mx/projects	Tue Jun 04 15:22:10 2013 +0200
@@ -100,7 +100,7 @@
 project@com.oracle.graal.hotspot@sourceDirs=src
 project@com.oracle.graal.hotspot@dependencies=com.oracle.graal.replacements,com.oracle.graal.printer
 project@com.oracle.graal.hotspot@checkstyle=com.oracle.graal.graph
-project@com.oracle.graal.hotspot@annotationProcessors=com.oracle.graal.replacements.verifier
+project@com.oracle.graal.hotspot@annotationProcessors=com.oracle.graal.replacements.verifier,com.oracle.graal.service.processor
 project@com.oracle.graal.hotspot@javaCompliance=1.7
 
 # graal.hotspot.amd64
@@ -143,6 +143,7 @@
 project@com.oracle.graal.options@sourceDirs=src
 project@com.oracle.graal.options@checkstyle=com.oracle.graal.graph
 project@com.oracle.graal.options@javaCompliance=1.7
+project@com.oracle.graal.options@annotationProcessorForDependents=true
 
 # graal.graph
 project@com.oracle.graal.graph@subDir=graal
@@ -254,7 +255,6 @@
 project@com.oracle.graal.phases@dependencies=com.oracle.graal.nodes,com.oracle.graal.options
 project@com.oracle.graal.phases@checkstyle=com.oracle.graal.graph
 project@com.oracle.graal.phases@javaCompliance=1.7
-project@com.oracle.graal.phases@annotationProcessors=com.oracle.graal.options
 
 # graal.phases.common
 project@com.oracle.graal.phases.common@subDir=graal
--- a/mxtool/mx.py	Tue Jun 04 12:21:32 2013 +0200
+++ b/mxtool/mx.py	Tue Jun 04 15:22:10 2013 +0200
@@ -146,6 +146,7 @@
 _libs = dict()
 _dists = dict()
 _suites = dict()
+_annotationProcessors = None
 _mainSuite = None
 _opts = None
 _java = None
@@ -409,16 +410,18 @@
         return self._imported_java_packages
 
     def annotation_processors(self):
-        if not hasattr(self, '_transitiveAnnotationProcessors'):
+        if not hasattr(self, '_annotationProcessors'):
             ap = set()
-            if hasattr(self, '_annotationProcessors'):
-                ap = set(self._annotationProcessors)
-            for name in self.deps:
-                dep = _projects.get(name, None)
-                if dep is not None:
-                    ap.update(dep.annotation_processors())
-            self._transitiveAnnotationProcessors = list(ap)
-        return self._transitiveAnnotationProcessors
+            if hasattr(self, '_declaredAnnotationProcessors'):
+                ap = set(self._declaredAnnotationProcessors)
+
+            # find dependencies that auto-inject themselves as annotation processors to all dependents                
+            allDeps = self.all_deps([], includeLibs=False, includeSelf=False, includeAnnotationProcessors=False)
+            for p in allDeps:
+                if hasattr(p, 'annotationProcessorForDependents') and p.annotationProcessorForDependents.lower() == 'true':
+                    ap.add(p.name)
+            self._annotationProcessors = list(ap)
+        return self._annotationProcessors
 
 class Library(Dependency):
     def __init__(self, suite, name, path, mustExist, urls, sourcePath, sourceUrls):
@@ -538,7 +541,7 @@
             if not p.native and p.javaCompliance is None:
                 abort('javaCompliance property required for non-native project ' + name)
             if len(ap) > 0:
-                p._annotationProcessors = ap
+                p._declaredAnnotationProcessors = ap
             p.__dict__.update(attrs)
             self.projects.append(p)
 
@@ -742,6 +745,18 @@
     """
     return _projects.values()
 
+def annotation_processors():
+    """
+    Get the list of all loaded projects that define an annotation processor.
+    """
+    global _annotationProcessors
+    if _annotationProcessors is None:
+        ap = set()
+        for p in projects():
+            ap.update(p.annotation_processors())
+        _annotationProcessors = list(ap)
+    return _annotationProcessors
+
 def distribution(name, fatalIfMissing=True):
     """
     Get the distribution for a given name. This will abort if the named distribution does
@@ -1684,16 +1699,16 @@
     return 0
 
 def processorjars():
-    projects = set()
     
+    projs = set()
     for p in sorted_deps():
         if _isAnnotationProcessorDependency(p):
-            projects.add(p)
+            projs.add(p)
             
-    if len(projects) <= 0:
+    if len(projs) < 0:
         return
     
-    pnames = [p.name for p in projects]
+    pnames = [p.name for p in projs]
     build(['--projects', ",".join(pnames)])
     archive(pnames)
 
@@ -2348,22 +2363,7 @@
     """
     Determines if a given project is part of an annotation processor.
     """
-    processors = set()
-    
-    for otherProject in projects():
-        if len(p.annotation_processors()) > 0:
-            for processorName in otherProject.annotation_processors():
-                processors.add(project(processorName, fatalIfMissing=True))
-                 
-    if p in processors:
-        return True
-    
-    for otherProject in processors:
-        deps = otherProject.all_deps([], True)
-        if p in deps:
-            return True
-    
-    return False
+    return p in sorted_deps(annotation_processors())
 
 def _genEclipseBuilder(dotProjectDoc, p, name, mxCommand, refresh=True, async=False, logToConsole=False, xmlIndent='\t', xmlStandalone=None):
     launchOut = XMLDoc();