You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2020/09/20 05:43:50 UTC
[karaf-winegrower] branch master updated: dont require
osgi-annotation in cp for @Header
This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf-winegrower.git
The following commit(s) were added to refs/heads/master by this push:
new fbcfbb7 dont require osgi-annotation in cp for @Header
new 9487180 Merge pull request #8 from rmannibucau/rmannibucau/avoid-to-require-osgi-annotation-in-cp-for-implicit-headers
fbcfbb7 is described below
commit fbcfbb703b2730121efcc92a033f567a6e470a2d
Author: Romain Manni-Bucau <rm...@gmail.com>
AuthorDate: Sat Sep 19 17:02:34 2020 +0200
dont require osgi-annotation in cp for @Header
---
pom.xml | 4 +--
.../winegrower/scanner/StandaloneScanner.java | 3 ++-
.../manifest/HeaderManifestContributor.java | 29 +++++++++-------------
.../scanner/manifest/ManifestContributor.java | 25 ++++++++++++++++++-
4 files changed, 40 insertions(+), 21 deletions(-)
diff --git a/pom.xml b/pom.xml
index b89db6a..0995c29 100644
--- a/pom.xml
+++ b/pom.xml
@@ -116,8 +116,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
- <source>11</source>
- <target>11</target>
+ <source>8</source>
+ <target>8</target>
</configuration>
</plugin>
diff --git a/winegrower-core/src/main/java/org/apache/winegrower/scanner/StandaloneScanner.java b/winegrower-core/src/main/java/org/apache/winegrower/scanner/StandaloneScanner.java
index 8505805..9b3cfb2 100644
--- a/winegrower-core/src/main/java/org/apache/winegrower/scanner/StandaloneScanner.java
+++ b/winegrower-core/src/main/java/org/apache/winegrower/scanner/StandaloneScanner.java
@@ -40,6 +40,7 @@ import java.util.jar.Manifest;
import java.util.stream.Stream;
import org.apache.winegrower.Ripener;
+import org.apache.winegrower.scanner.manifest.ManifestContributor;
import org.apache.winegrower.scanner.manifest.ManifestCreator;
import org.apache.xbean.finder.AnnotationFinder;
import org.apache.xbean.finder.ClassLoaders;
@@ -192,7 +193,7 @@ public class StandaloneScanner {
}
private Manifest tryLoadManifest(final Archive archive, final String name) {
- final AnnotationFinder archiveFinder = new AnnotationFinder(archive, false);
+ final AnnotationFinder archiveFinder = new ManifestContributor.WinegrowerAnnotationFinder(archive, false);
final ManifestCreator manifestCreator = new ManifestCreator(name);
configuration.getManifestContributors()
.forEach(c -> c.contribute(archiveFinder, manifestCreator));
diff --git a/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/HeaderManifestContributor.java b/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/HeaderManifestContributor.java
index cae4442..ef1ef5d 100644
--- a/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/HeaderManifestContributor.java
+++ b/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/HeaderManifestContributor.java
@@ -13,14 +13,12 @@
*/
package org.apache.winegrower.scanner.manifest;
-import static java.util.stream.Collectors.toMap;
-import static org.apache.xbean.asm8.ClassReader.SKIP_CODE;
-import static org.apache.xbean.asm8.ClassReader.SKIP_DEBUG;
-import static org.apache.xbean.asm8.ClassReader.SKIP_FRAMES;
-import static org.apache.xbean.asm8.Opcodes.ASM8;
+import org.apache.xbean.asm8.AnnotationVisitor;
+import org.apache.xbean.asm8.ClassReader;
+import org.apache.xbean.asm8.ClassVisitor;
+import org.apache.xbean.finder.AnnotationFinder;
import java.io.InputStream;
-import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -31,10 +29,11 @@ import java.util.function.Supplier;
import java.util.jar.Manifest;
import java.util.stream.Stream;
-import org.apache.xbean.asm8.AnnotationVisitor;
-import org.apache.xbean.asm8.ClassReader;
-import org.apache.xbean.asm8.ClassVisitor;
-import org.apache.xbean.finder.AnnotationFinder;
+import static java.util.stream.Collectors.toMap;
+import static org.apache.xbean.asm8.ClassReader.SKIP_CODE;
+import static org.apache.xbean.asm8.ClassReader.SKIP_DEBUG;
+import static org.apache.xbean.asm8.ClassReader.SKIP_FRAMES;
+import static org.apache.xbean.asm8.Opcodes.ASM8;
public class HeaderManifestContributor implements ManifestContributor {
@@ -44,13 +43,9 @@ public class HeaderManifestContributor implements ManifestContributor {
final List<Class<?>> headerClasses;
final List<Class<?>> headersClasses;
try {
- final Class<? extends Annotation> headerAnnotation = (Class<? extends Annotation>)
- loader.loadClass("org.osgi.annotation.bundle.Header");
- final Class<? extends Annotation> headersAnnotation = (Class<? extends Annotation>)
- loader.loadClass("org.osgi.annotation.bundle.Headers");
-
- headerClasses = finder.findAnnotatedClasses(headerAnnotation);
- headersClasses = finder.findAnnotatedClasses(headersAnnotation);
+ final WinegrowerAnnotationFinder waf = WinegrowerAnnotationFinder.class.cast(finder); // temp, see impl
+ headerClasses = waf.findAnnotatedClasses("org.osgi.annotation.bundle.Header");
+ headersClasses = waf.findAnnotatedClasses("org.osgi.annotation.bundle.Headers");
if (headerClasses.isEmpty() && headersClasses.isEmpty()) { // reuse the finder to ensure it exists
return;
}
diff --git a/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/ManifestContributor.java b/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/ManifestContributor.java
index 6de3311..6d2f98f 100644
--- a/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/ManifestContributor.java
+++ b/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/ManifestContributor.java
@@ -13,11 +13,34 @@
*/
package org.apache.winegrower.scanner.manifest;
+import org.apache.xbean.finder.AnnotationFinder;
+import org.apache.xbean.finder.archive.Archive;
+
+import java.util.List;
import java.util.function.Supplier;
import java.util.jar.Manifest;
-import org.apache.xbean.finder.AnnotationFinder;
+import static java.util.stream.Collectors.toList;
public interface ManifestContributor {
void contribute(final AnnotationFinder finder, final Supplier<Manifest> manifest);
+
+ class WinegrowerAnnotationFinder extends AnnotationFinder {
+ public WinegrowerAnnotationFinder(final Archive archive, final boolean checkRuntimeAnnotation) {
+ super(archive, checkRuntimeAnnotation);
+ }
+
+ // todo: port over xbean
+ public List<Class<?>> findAnnotatedClasses(final String annotation) {
+ return this.getAnnotationInfos(annotation).stream()
+ .map(it -> {
+ try {
+ return AnnotationFinder.ClassInfo.class.cast(it).get();
+ } catch (final ClassNotFoundException var8) {
+ // skip
+ return null;
+ }
+ }).collect(toList());
+ }
+ }
}