-
-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved to plugin, allow annotations without parenthesis
--- Signed-off-by: Peter Kriens <Peter.Kriens@aQute.biz> Signed-off-by: Peter Kriens <Peter.Kriens@aQute.biz>
- Loading branch information
Showing
5 changed files
with
90 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
biz.aQute.bndlib/src/aQute/bnd/osgi/metainf/MetaInfServiceParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package aQute.bnd.osgi.metainf; | ||
|
||
import java.lang.annotation.RetentionPolicy; | ||
import java.util.Map; | ||
|
||
import aQute.bnd.header.Attrs; | ||
import aQute.bnd.osgi.Analyzer; | ||
import aQute.bnd.osgi.Annotation; | ||
import aQute.bnd.osgi.Annotation.ElementType; | ||
import aQute.bnd.osgi.Descriptors.TypeRef; | ||
import aQute.bnd.osgi.Processor; | ||
import aQute.bnd.osgi.metainf.MetaInfService.Implementation; | ||
import aQute.bnd.service.AnalyzerPlugin; | ||
|
||
/** | ||
* process the META-INF/services/* files. These files can contain bnd | ||
* annotations. | ||
*/ | ||
|
||
public class MetaInfServiceParser implements AnalyzerPlugin { | ||
|
||
/** | ||
* Iterate over the the file in META-INF/services and process them for | ||
* annotations. | ||
*/ | ||
@Override | ||
public boolean analyzeJar(Analyzer analyzer) throws Exception { | ||
MetaInfService.getServiceFiles(analyzer.getJar()) | ||
.values() | ||
.stream() | ||
.flatMap(mis -> mis.getImplementations() | ||
.values() | ||
.stream()) | ||
.forEach(impl -> { | ||
impl.getAnnotations() | ||
.forEach((annotationName, attrs) -> { | ||
doAnnotationsforMetaInf(analyzer, impl, Processor.removeDuplicateMarker(annotationName), attrs); | ||
}); | ||
}); | ||
return false; | ||
} | ||
|
||
/* | ||
* Process 1 annotation | ||
*/ | ||
private void doAnnotationsforMetaInf(Analyzer analyzer, Implementation impl, String annotationName, Attrs attrs) { | ||
try { | ||
Map<String, Object> properties = attrs.toTyped(); | ||
properties.putIfAbsent("value", impl.getServiceName()); // default | ||
TypeRef implementation = analyzer.getTypeRefFromFQN(impl.getImplementationName()); | ||
assert implementation != null; | ||
Annotation ann = new Annotation(analyzer.getTypeRefFromFQN(annotationName), properties, ElementType.TYPE, | ||
RetentionPolicy.CLASS); | ||
analyzer.addAnnotation(ann, implementation); | ||
} catch (Exception e) { | ||
analyzer.exception(e, "failed to process %s=%v due to %s", annotationName, attrs, e); | ||
} | ||
} | ||
|
||
} |