You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2020/12/30 13:30:21 UTC
[openwebbeans] branch master updated: [OWB-1363] prescanned cdi se
scanner
This is an automated email from the ASF dual-hosted git repository.
rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git
The following commit(s) were added to refs/heads/master by this push:
new a6e47d6 [OWB-1363] prescanned cdi se scanner
a6e47d6 is described below
commit a6e47d6cf5dffb12c92783b25003fd26f2c42883
Author: Romain Manni-Bucau <rm...@gmail.com>
AuthorDate: Wed Dec 30 14:30:15 2020 +0100
[OWB-1363] prescanned cdi se scanner
---
.../webbeans/corespi/scanner/xbean/CdiArchive.java | 2 +-
.../corespi/scanner/xbean/OwbAnnotationFinder.java | 9 ++
.../se/PreScannedCDISeScannerService.java | 96 ++++++++++++++++++++++
3 files changed, 106 insertions(+), 1 deletion(-)
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/CdiArchive.java b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/CdiArchive.java
index b77aaf0..dfb1e11 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/CdiArchive.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/CdiArchive.java
@@ -104,7 +104,7 @@ public class CdiArchive implements Archive
return delegate.iterator();
}
- public final class FoundClasses
+ public static final class FoundClasses
{
private URL url;
private Collection<String> classNames;
diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/OwbAnnotationFinder.java b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/OwbAnnotationFinder.java
index 7dd86f4..1b4b13c 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/OwbAnnotationFinder.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/xbean/OwbAnnotationFinder.java
@@ -20,6 +20,9 @@ package org.apache.webbeans.corespi.scanner.xbean;
import org.apache.xbean.finder.AnnotationFinder;
import org.apache.xbean.finder.archive.Archive;
+import org.apache.xbean.finder.archive.ClassesArchive;
+
+import java.util.stream.Stream;
/**
* We just extend the default AnnotationFinder to get Access to the original ClassInfo
@@ -37,6 +40,12 @@ public class OwbAnnotationFinder extends AnnotationFinder
super(archive);
}
+ public OwbAnnotationFinder(final Class<?>[] classes)
+ {
+ super(new ClassesArchive(/*empty since we want to read from reflection, not form resources*/));
+ Stream.of(classes).forEach(super::readClassDef);
+ }
+
public ClassInfo getClassInfo(String className)
{
return classInfos.get(className);
diff --git a/webbeans-se/src/main/java/org/apache/openwebbeans/se/PreScannedCDISeScannerService.java b/webbeans-se/src/main/java/org/apache/openwebbeans/se/PreScannedCDISeScannerService.java
new file mode 100644
index 0000000..80130b0
--- /dev/null
+++ b/webbeans-se/src/main/java/org/apache/openwebbeans/se/PreScannedCDISeScannerService.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openwebbeans.se;
+
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.corespi.scanner.xbean.CdiArchive;
+import org.apache.webbeans.corespi.scanner.xbean.OwbAnnotationFinder;
+import org.apache.webbeans.spi.BeanArchiveService;
+import org.apache.webbeans.util.WebBeansUtil;
+import org.apache.xbean.finder.AnnotationFinder;
+
+import java.net.URL;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static java.util.Collections.emptyMap;
+import static java.util.stream.Collectors.toList;
+
+public class PreScannedCDISeScannerService extends CDISeScannerService
+{
+ @Override
+ protected AnnotationFinder initFinder()
+ {
+ if (finder != null)
+ {
+ return finder;
+ }
+
+ // todo: support to read beanDeploymentUrls from the conf as well
+ // -> for now we use a full programmatic deployment (single in mem archive)
+ final WebBeansContext webBeansContext = webBeansContext();
+ final OpenWebBeansConfiguration conf = webBeansContext.getOpenWebBeansConfiguration();
+ final String confKeyBase = getClass().getName() + ".";
+ final String classes = conf.getProperty(confKeyBase + "classes");
+ final ClassLoader loader = WebBeansUtil.getCurrentClassLoader();
+ final Class<?>[] reflectClasses = Stream.of(classes.split(",")).map(it ->
+ {
+ try
+ {
+ return loader.loadClass(it);
+ }
+ catch (final ClassNotFoundException e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ }).toArray(Class[]::new);
+ final BeanArchiveService beanArchiveService = webBeansContext.getBeanArchiveService();
+ archive = new CdiArchive(
+ beanArchiveService, WebBeansUtil.getCurrentClassLoader(),
+ emptyMap(), null, getAdditionalArchive());
+ final Map.Entry<String, URL> deplUrl = getBeanDeploymentUrls().entrySet().iterator().next();
+ archive.classesByUrl().put(
+ deplUrl.getKey(),
+ new CdiArchive.FoundClasses(
+ deplUrl.getValue(),
+ Stream.of(classes.split(",")).collect(toList()),
+ beanArchiveService.getBeanArchiveInformation(deplUrl.getValue())));
+ finder = new OwbAnnotationFinder(reflectClasses);
+ return finder;
+ }
+
+ @Override
+ public void classes(final Class<?>[] classes)
+ {
+ // no-op
+ }
+
+ @Override
+ public void packages(final boolean recursive, final Class<?>[] markers)
+ {
+ // no-op
+ }
+
+ @Override
+ public void packages(final boolean recursive, final Package[] packages)
+ {
+ // no-op
+ }
+}