Author: struberg
Date: Sun Feb 11 13:04:52 2018
New Revision: 1823838
URL: http://svn.apache.org/viewvc?rev=1823838&view=rev
Log:
OWB-1230 add way to exclude CDI Extensions via config
Added:
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/java/org/apache/webbeans/test/spi/configuration/ExcludeExtensionsTest.java
(with props)
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/resources/META-INF/services/
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Modified:
openwebbeans/trunk/webbeans-impl/src/it/properties/pom.xml
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/java/org/apache/webbeans/test/spi/configuration/ConfigurationTest.java
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/boot/Bootstrap.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ExtensionLoader.java
openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Modified: openwebbeans/trunk/webbeans-impl/src/it/properties/pom.xml
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/it/properties/pom.xml?rev=1823838&r1=1823837&r2=1823838&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/it/properties/pom.xml (original)
+++ openwebbeans/trunk/webbeans-impl/src/it/properties/pom.xml Sun Feb 11
13:04:52 2018
@@ -52,6 +52,16 @@
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.3_spec</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-interceptor_1.2_spec</artifactId>
+ <optional>true</optional>
+ </dependency>
</dependencies>
</project>
Modified:
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/java/org/apache/webbeans/test/spi/configuration/ConfigurationTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/java/org/apache/webbeans/test/spi/configuration/ConfigurationTest.java?rev=1823838&r1=1823837&r2=1823838&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/java/org/apache/webbeans/test/spi/configuration/ConfigurationTest.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/java/org/apache/webbeans/test/spi/configuration/ConfigurationTest.java
Sun Feb 11 13:04:52 2018
@@ -32,14 +32,14 @@ public class ConfigurationTest
OpenWebBeansConfiguration cfg =
WebBeansContext.getInstance().getOpenWebBeansConfiguration();
// not overloaded
- String ts =
cfg.getProperty("org.apache.webbeans.spi.TransactionService");
- Assert.assertNotNull(ts);
-
Assert.assertEquals("org.apache.webbeans.corespi.ee.TransactionServiceJndiImpl",
ts);
-
+ String esi =
cfg.getProperty("org.apache.webbeans.web.eagerSessionInitialisation");
+ Assert.assertNotNull(esi);
+ Assert.assertEquals("false", esi);
+
// overloaded version 1
String wbf = cfg.getProperty("org.apache.webbeans.spi.JNDIService");
Assert.assertNotNull(wbf);
-
Assert.assertEquals("org.apache.webbeans.corespi.ee.JNDIServiceEnterpriseImpl",
wbf);
+
Assert.assertEquals("org.apache.webbeans.corespi.se.DefaultJndiService", wbf);
// property which is only in the specialised openwebbeans.properties
String testProperty = cfg.getProperty("test.property");
Added:
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/java/org/apache/webbeans/test/spi/configuration/ExcludeExtensionsTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/java/org/apache/webbeans/test/spi/configuration/ExcludeExtensionsTest.java?rev=1823838&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/java/org/apache/webbeans/test/spi/configuration/ExcludeExtensionsTest.java
(added)
+++
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/java/org/apache/webbeans/test/spi/configuration/ExcludeExtensionsTest.java
Sun Feb 11 13:04:52 2018
@@ -0,0 +1,87 @@
+/*
+ * 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.webbeans.test.spi.configuration;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import java.util.HashSet;
+import java.util.Set;
+
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.spi.ContainerLifecycle;
+import org.junit.Test;
+import org.junit.Assert;
+
+/**
+ * Test the feature to exclude extensions which are not needed.
+ *
+ * @see org.apache.webbeans.config.OpenWebBeansConfiguration#IGNORED_EXTENSIONS
+ */
+public class ExcludeExtensionsTest
+{
+ public static Set<String> EXT_CALLS = new HashSet<>();
+
+
+ @Test
+ public void testExtensionExclusion() throws Exception
+ {
+ EXT_CALLS.clear();
+
+ ContainerLifecycle containerLifecycle =
WebBeansContext.getInstance().getService(ContainerLifecycle.class);
+ containerLifecycle.startApplication(null);
+
+ try
+ {
+ Assert.assertEquals(1, EXT_CALLS.size());
+ Assert.assertTrue(EXT_CALLS.contains("B"));
+ }
+ finally
+ {
+ containerLifecycle.stopApplication(null);
+ }
+
+ }
+
+
+ public static class ExtensionA implements Extension
+ {
+ public void bbd(@Observes BeforeBeanDiscovery bbd)
+ {
+ EXT_CALLS.add("A");
+ }
+ }
+
+ public static class ExtensionB implements Extension
+ {
+ public void bbd(@Observes BeforeBeanDiscovery bbd)
+ {
+ EXT_CALLS.add("B");
+ }
+ }
+
+ public static class ExtensionC implements Extension
+ {
+ public void bbd(@Observes BeforeBeanDiscovery bbd)
+ {
+ EXT_CALLS.add("C");
+ }
+ }
+}
Propchange:
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/java/org/apache/webbeans/test/spi/configuration/ExcludeExtensionsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1823838&r1=1823837&r2=1823838&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/resources/META-INF/openwebbeans/openwebbeans.properties
Sun Feb 11 13:04:52 2018
@@ -29,7 +29,8 @@ test.property=true
# TODO these are currently only preliminary values for testing the mechanism!
# use the real EE server JNDI implementation for storing objects in JNDI
-org.apache.webbeans.spi.JNDIService=org.apache.webbeans.corespi.ee.JNDIServiceEnterpriseImpl
-org.apache.webbeans.spi.JPAService=org.apache.webbeans.corespi.ee.geronimo.JPAServiceOpenEjb
-org.apache.webbeans.spi.TransactionService=org.apache.webbeans.corespi.ee.TransactionServiceJndiImpl
+org.apache.webbeans.spi.JNDIService=org.apache.webbeans.corespi.se.DefaultJndiService
+
+
+org.apache.webbeans.ignoredExtensions=org.apache.webbeans.test.spi.configuration.ExcludeExtensionsTest$ExtensionA,org.apache.webbeans.test.spi.configuration.ExcludeExtensionsTest$ExtensionC
Added:
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension?rev=1823838&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension
(added)
+++
openwebbeans/trunk/webbeans-impl/src/it/properties/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Sun Feb 11 13:04:52 2018
@@ -0,0 +1,20 @@
+#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.
+
+org.apache.webbeans.test.spi.configuration.ExcludeExtensionsTest$ExtensionA
+org.apache.webbeans.test.spi.configuration.ExcludeExtensionsTest$ExtensionB
+org.apache.webbeans.test.spi.configuration.ExcludeExtensionsTest$ExtensionC
\ No newline at end of file
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/boot/Bootstrap.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/boot/Bootstrap.java?rev=1823838&r1=1823837&r2=1823838&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/boot/Bootstrap.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/boot/Bootstrap.java
Sun Feb 11 13:04:52 2018
@@ -44,6 +44,8 @@ public class Bootstrap
log.info(OWBLogConst.INFO_0006);
//this relies on DefaultSingletonService to instantiate the
WebBeansContext
containerLifecycle =
WebBeansContext.getInstance().getService(ContainerLifecycle.class);
+
+ this.properties = properties;
}
public void start() throws InterruptedException
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java?rev=1823838&r1=1823837&r2=1823838&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
Sun Feb 11 13:04:52 2018
@@ -159,7 +159,10 @@ public class OpenWebBeansConfiguration
/**
* Flag which indicates that only jars with an explicit META-INF/beans.xml
marker file shall get parsed.
- * Default is {@code false}
+ * Default is {@code false}.
+ *
+ * This might be switched on to improve boot time in cases where you
always have beans.xml in
+ * your jars or classpath entries.
*/
public static final String SCAN_ONLY_BEANS_XML_JARS =
"org.apache.webbeans.scanBeansXmlOnly";
@@ -171,6 +174,13 @@ public class OpenWebBeansConfiguration
public static final String IGNORED_INTERFACES =
"org.apache.webbeans.ignoredDecoratorInterfaces";
/**
+ * A comma-separated list of fully qualified class names of CDI Extensions
that should be ignored.
+ *
+ *
+ */
+ public static final String IGNORED_EXTENSIONS =
"org.apache.webbeans.ignoredExtensions";
+
+ /**
* By default we do _not_ force session creation in our
WebBeansConfigurationListener. We only create the
* Session if we really need the SessionContext. E.g. when we create a
Contextual Instance in it.
* Sometimes this creates a problem as the HttpSession can only be created
BEFORE anything got written back
@@ -205,9 +215,17 @@ public class OpenWebBeansConfiguration
private final Properties configProperties = new Properties();
+ /**
+ * @see #IGNORED_INTERFACES
+ */
private Set<String> ignoredInterfaces;
/**
+ * @see #IGNORED_EXTENSIONS
+ */
+ private Set<String> ignoredExtensions;
+
+ /**
* All configured lists per key.
*
* For a single key the following configuration sources will get parsed:
@@ -414,19 +432,30 @@ public class OpenWebBeansConfiguration
{
if (ignoredInterfaces == null)
{
- String ignoredInterfacesString = getProperty(IGNORED_INTERFACES);
- if (ignoredInterfacesString != null)
- {
- ignoredInterfaces = new
HashSet<>(Arrays.asList(ignoredInterfacesString.split("[,\\p{javaWhitespace}]")));
- }
- else
- {
- ignoredInterfaces = Collections.emptySet();
- }
+ ignoredInterfaces = getPropertyList(IGNORED_INTERFACES);
}
return ignoredInterfaces;
}
+ public synchronized Set<String> getIgnoredExtensions()
+ {
+ if (ignoredExtensions == null)
+ {
+ ignoredExtensions = getPropertyList(IGNORED_EXTENSIONS);
+ }
+ return ignoredExtensions;
+ }
+
+ private Set<String> getPropertyList(String configKey)
+ {
+ String configValue = getProperty(configKey);
+ if (configValue != null)
+ {
+ return new
HashSet<>(Arrays.asList(configValue.split("[,\\p{javaWhitespace}]")));
+ }
+ return Collections.emptySet();
+ }
+
/**
* Scan all openwebbeans.properties files + system properties +
* syste.env for the given key.
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ExtensionLoader.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ExtensionLoader.java?rev=1823838&r1=1823837&r2=1823838&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ExtensionLoader.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ExtensionLoader.java
Sun Feb 11 13:04:52 2018
@@ -23,15 +23,18 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.DefinitionException;
import javax.enterprise.inject.spi.DeploymentException;
import javax.enterprise.inject.spi.Extension;
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
import org.apache.webbeans.util.ExceptionUtil;
import org.apache.webbeans.util.WebBeansUtil;
@@ -44,6 +47,9 @@ import org.apache.webbeans.util.WebBeans
*/
public class ExtensionLoader
{
+ /**Logger instance*/
+ private static final Logger logger =
WebBeansLoggerFacade.getLogger(ExtensionLoader.class);
+
/**Map of extensions*/
private final Map<Class<?>, Object> extensions = new
ConcurrentHashMap<>();
private final Set<Class<? extends Extension>> extensionClasses = new
HashSet<>();
@@ -76,9 +82,22 @@ public class ExtensionLoader
*/
public void loadExtensionServices(ClassLoader classLoader)
{
+ Set<String> ignoredExtensions =
webBeansContext.getOpenWebBeansConfiguration().getIgnoredExtensions();
+ if (!ignoredExtensions.isEmpty())
+ {
+ logger.info("Ignoring the following CDI Extensions. See " +
OpenWebBeansConfiguration.IGNORED_EXTENSIONS +
+ " " + ignoredExtensions.toString());
+ }
+
List<Extension> loader =
webBeansContext.getLoaderService().load(Extension.class, classLoader);
for (Extension extension : loader)
{
+ if (ignoredExtensions.contains(extension.getClass().getName()))
+ {
+ logger.info("Skipping CDI Extension due to exclusion: " +
extension.getClass().getName());
+ continue;
+ }
+
if (!extensionClasses.contains(extension.getClass()))
{
extensionClasses.add(extension.getClass());
Modified:
openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1823838&r1=1823837&r2=1823838&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Sun Feb 11 13:04:52 2018
@@ -143,6 +143,12 @@ org.apache.webbeans.web.eagerSessionInit
# org.apache.webbeans.generator.javaVersion=1.6
################################################################################################
+############################# Ignored CDI Extension class names
################################
+# A comma separated list of CDI Extension class names which should get ignored.
+# Each listed class name must be fully qualified.
+# org.apache.webbeans.ignoredExtensions=org.acme.FooExtension
+################################################################################################
+
######################### Bean Scanning
########################################################
# A list of known JARs/paths which should not be scanned for beans