openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1800506 - in /openwebbeans/meecrowave/trunk: ./ meecrowave-core/ meecrowave-core/src/main/java/org/apache/meecrowave/ meecrowave-core/src/main/java/org/apache/meecrowave/cdi/ meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans...
Date Sat, 01 Jul 2017 13:31:24 GMT
Author: rmannibucau
Date: Sat Jul  1 13:31:23 2017
New Revision: 1800506

URL: http://svn.apache.org/viewvc?rev=1800506&view=rev
Log:
MEECROWAVE-48 CDI SE support

Added:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveProvider.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerInitializer.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerSelector.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/resources/META-INF/services/javax.enterprise.inject.se.SeContainerInitializer
    openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/cdi/
    openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerInitializerTest.java
Modified:
    openwebbeans/meecrowave/trunk/meecrowave-core/pom.xml
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java
    openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/meecrowave-core/configuration.adoc
    openwebbeans/meecrowave/trunk/pom.xml

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/pom.xml?rev=1800506&r1=1800505&r2=1800506&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/pom.xml (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/pom.xml Sat Jul  1 13:31:23 2017
@@ -31,12 +31,12 @@
   <dependencies>
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
-      <artifactId>geronimo-annotation_1.2_spec</artifactId>
+      <artifactId>geronimo-annotation_1.3_spec</artifactId>
       <version>1.0</version>
     </dependency>
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
-      <artifactId>geronimo-jcdi_1.1_spec</artifactId>
+      <artifactId>geronimo-jcdi_2.0_spec</artifactId>
       <version>1.0</version>
     </dependency>
     <dependency>
@@ -87,7 +87,7 @@
     </dependency>
     <dependency>
       <groupId>org.apache.openwebbeans</groupId>
-      <artifactId>openwebbeans-impl</artifactId>
+      <artifactId>openwebbeans-se</artifactId>
       <version>${openwebbeans.version}</version>
     </dependency>
     <dependency>

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java?rev=1800506&r1=1800505&r2=1800506&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
Sat Jul  1 13:31:23 2017
@@ -296,6 +296,7 @@ public class Meecrowave implements AutoC
                     break;
                 case Lifecycle.BEFORE_INIT_EVENT:
                     ctx.getServletContext().setAttribute("meecrowave.configuration", configuration);
+                    ctx.getServletContext().setAttribute("meecrowave.instance", Meecrowave.this);
                     if (configuration.loginConfig != null) {
                         ctx.setLoginConfig(configuration.loginConfig.build());
                     }

Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveProvider.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveProvider.java?rev=1800506&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveProvider.java
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveProvider.java
Sat Jul  1 13:31:23 2017
@@ -0,0 +1,6 @@
+package org.apache.meecrowave.cdi;
+
+import org.apache.webbeans.container.OwbCDIProvider;
+
+public class MeecrowaveProvider extends OwbCDIProvider {
+}

Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerInitializer.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerInitializer.java?rev=1800506&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerInitializer.java
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerInitializer.java
Sat Jul  1 13:31:23 2017
@@ -0,0 +1,113 @@
+/*
+ * 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.meecrowave.cdi;
+
+import org.apache.meecrowave.Meecrowave;
+import org.apache.meecrowave.logging.jul.Log4j2Logger;
+import org.apache.meecrowave.logging.openwebbeans.Log4j2LoggerFactory;
+import org.apache.meecrowave.logging.tomcat.Log4j2Log;
+import org.apache.meecrowave.openwebbeans.KnowClassesFilter;
+import org.apache.meecrowave.openwebbeans.OWBTomcatWebScannerService;
+import org.apache.openwebbeans.se.OWBContainer;
+import org.apache.openwebbeans.se.OWBInitializer;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.spi.ScannerService;
+import org.apache.xbean.finder.filter.Filter;
+
+import javax.enterprise.inject.se.SeContainer;
+import javax.enterprise.inject.se.SeContainerInitializer;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import static java.util.stream.Collectors.toSet;
+
+public class MeecrowaveSeContainerInitializer extends OWBInitializer {
+    static { // todo: see if we can not do it statically but also means we lazy load OWB
which can require some OWB rework
+        System.setProperty("java.util.logging.manager",
+                System.getProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager"));
+        System.setProperty("openwebbeans.logging.factory",
+                System.getProperty("openwebbeans.logging.factory", Log4j2LoggerFactory.class.getName()));
+        System.setProperty("org.apache.cxf.Logger",
+                System.getProperty("org.apache.cxf.Logger", Log4j2Logger.class.getName()));
+        System.setProperty("org.apache.tomcat.Logger",
+                System.getProperty("org.apache.tomcat.Logger", Log4j2Log.class.getName()));
+    }
+
+    private Meecrowave.Builder builder = new Meecrowave.Builder();
+
+    @Override
+    public SeContainerInitializer addProperty(final String s, final Object o) {
+        if (Meecrowave.Builder.class.isInstance(o)) {
+            builder = Meecrowave.Builder.class.cast(o);
+            return this;
+        }
+
+        final String setter = "set" + Character.toUpperCase(s.charAt(0)) + s.substring(1);
+        final Optional<Method> setterOpt = Stream.of(builder.getClass().getMethods())
+                .filter(m -> m.getName().equals(setter) && m.getParameterCount()
== 1)
+                .findFirst();
+        if (!setterOpt.isPresent()) {
+            super.addProperty(s, o);
+            // todo: log or do we assume delegate will ?
+            return this;
+        }
+
+        try {
+            builder.getClass().getMethod(setter, o.getClass()).invoke(builder, o);
+        } catch (final IllegalAccessException | NoSuchMethodException | InvocationTargetException
ex) {
+            throw new IllegalArgumentException(ex);
+        }
+        return this;
+    }
+
+    @Override
+    protected void addCustomServices(final Map<String, Object> services) {
+        final Set<String> forced = this.scannerService.configuredClasses().stream().map(Class::getName).collect(toSet());
+        services.put(Filter.class.getName(), new KnowClassesFilter() { // override it to
make programmatic configuration working OOTB
+            @Override
+            public boolean accept(final String name) {
+                return forced.contains(name) || super.accept(name);
+            }
+        });
+    }
+
+    @Override
+    protected SeContainer newContainer(final WebBeansContext context) {
+        final Meecrowave meecrowave = new Meecrowave(builder);
+        return new OWBContainer(context, meecrowave) {
+            {
+                meecrowave.bake();
+            }
+
+            @Override
+            protected void doClose() {
+                meecrowave.close();
+            }
+        };
+    }
+
+    @Override
+    protected ScannerService getScannerService() {
+        return new OWBTomcatWebScannerService(scannerService);
+    }
+}

Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerSelector.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerSelector.java?rev=1800506&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerSelector.java
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerSelector.java
Sat Jul  1 13:31:23 2017
@@ -0,0 +1,30 @@
+/*
+ * 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.meecrowave.cdi;
+
+import org.apache.openwebbeans.se.SeContainerSelector;
+
+import javax.enterprise.inject.se.SeContainerInitializer;
+
+public class MeecrowaveSeContainerSelector implements SeContainerSelector {
+    @Override
+    public SeContainerInitializer find() {
+        return new MeecrowaveSeContainerInitializer();
+    }
+}

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java?rev=1800506&r1=1800505&r2=1800506&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java
Sat Jul  1 13:31:23 2017
@@ -20,54 +20,49 @@ package org.apache.meecrowave.openwebbea
 
 import org.apache.meecrowave.Meecrowave;
 import org.apache.meecrowave.cxf.JAXRSFieldInjectionInterceptor;
-import org.apache.webbeans.annotation.AnyLiteral;
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.configurator.BeanConfiguratorImpl;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.intercept.InterceptorsManager;
 import org.apache.webbeans.servlet.WebBeansConfigurationListener;
 import org.apache.webbeans.web.context.WebConversationFilter;
 
 import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.configurator.BeanConfigurator;
 import javax.servlet.DispatcherType;
 import javax.servlet.FilterRegistration;
 import javax.servlet.ServletContainerInitializer;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletException;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collections;
 import java.util.EnumSet;
-import java.util.HashSet;
 import java.util.Set;
-
-import static java.util.Arrays.asList;
+import java.util.function.Consumer;
 
 public class OWBAutoSetup implements ServletContainerInitializer {
     @Override
     public void onStartup(final Set<Class<?>> c, final ServletContext ctx) throws
ServletException {
         final Meecrowave.Builder builder = Meecrowave.Builder.class.cast(ctx.getAttribute("meecrowave.configuration"));
+        final Meecrowave instance = Meecrowave.class.cast(ctx.getAttribute("meecrowave.instance"));
         if (builder.isCdiConversation()) {
             final FilterRegistration.Dynamic filter = ctx.addFilter("owb-conversation", WebConversationFilter.class);
             filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
         }
 
         // eager boot to let injections work in listeners
-        final EagerBootListener bootListener = new EagerBootListener(builder);
+        final EagerBootListener bootListener = new EagerBootListener(instance);
         bootListener.doContextInitialized(new ServletContextEvent(ctx));
         ctx.addListener(bootListener);
     }
 
     public static class EagerBootListener extends WebBeansConfigurationListener implements
Extension {
-        private final Meecrowave.Builder config;
+        private final Meecrowave meecrowave;
 
-        private EagerBootListener(final Meecrowave.Builder builder) {
-            this.config = builder;
+        private EagerBootListener(final Meecrowave meecrowave) {
+            this.meecrowave = meecrowave;
         }
 
         @Override
@@ -89,75 +84,27 @@ public class OWBAutoSetup implements Ser
             final BeanManagerImpl beanManager = instance.getBeanManagerImpl();
             final InterceptorsManager interceptorsManager = instance.getInterceptorsManager();
 
-            beanManager.addInternalBean(new ConfigBean(config));
+            beanManager.addInternalBean(newBean(instance, configurator ->
+                    configurator.beanClass(Meecrowave.Builder.class)
+                            .scope(ApplicationScoped.class)
+                            .qualifiers(DefaultLiteral.INSTANCE)
+                            .types(Meecrowave.Builder.class, Object.class)
+                            .createWith(cc -> meecrowave.getConfiguration())));
+            beanManager.addInternalBean(newBean(instance, configurator ->
+                    configurator.beanClass(Meecrowave.class)
+                            .scope(ApplicationScoped.class)
+                            .qualifiers(DefaultLiteral.INSTANCE)
+                            .types(Meecrowave.class, AutoCloseable.class, Object.class)
+                            .createWith(cc -> meecrowave)));
 
             interceptorsManager.addInterceptorBindingType(JAXRSFieldInjectionInterceptor.Binding.class);
             beanManager.addAdditionalAnnotatedType(this, beanManager.createAnnotatedType(JAXRSFieldInjectionInterceptor.class));
         }
 
-        private static class ConfigBean implements Bean<Meecrowave.Builder> {
-            private final Meecrowave.Builder value;
-            private final Set<Type> types = new HashSet<>(asList(Meecrowave.Builder.class,
Object.class));
-            private final Set<Annotation> qualifiers = new HashSet<>(asList(DefaultLiteral.INSTANCE,
AnyLiteral.INSTANCE));
-
-            private ConfigBean(final Meecrowave.Builder config) {
-                this.value = config;
-            }
-
-            @Override
-            public Set<InjectionPoint> getInjectionPoints() {
-                return Collections.emptySet();
-            }
-
-            @Override
-            public Class<?> getBeanClass() {
-                return Meecrowave.Builder.class;
-            }
-
-            @Override
-            public boolean isNullable() {
-                return false;
-            }
-
-            @Override
-            public Meecrowave.Builder create(final CreationalContext<Meecrowave.Builder>
context) {
-                return value;
-            }
-
-            @Override
-            public void destroy(final Meecrowave.Builder instance, final CreationalContext<Meecrowave.Builder>
context) {
-
-            }
-
-            @Override
-            public Set<Type> getTypes() {
-                return types;
-            }
-
-            @Override
-            public Set<Annotation> getQualifiers() {
-                return qualifiers;
-            }
-
-            @Override
-            public Class<? extends Annotation> getScope() {
-                return ApplicationScoped.class;
-            }
-
-            @Override
-            public String getName() {
-                return null;
-            }
-
-            @Override
-            public Set<Class<? extends Annotation>> getStereotypes() {
-                return Collections.emptySet();
-            }
-
-            @Override
-            public boolean isAlternative() {
-                return false;
-            }
+        private <T> Bean<?> newBean(final WebBeansContext instance, final Consumer<BeanConfigurator<T>>
configurer) {
+            final BeanConfiguratorImpl<T> meecrowaveBeanBuilder = new BeanConfiguratorImpl<>(instance);
+            configurer.accept(meecrowaveBeanBuilder);
+            return meecrowaveBeanBuilder.getBean();
         }
     }
 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java?rev=1800506&r1=1800505&r2=1800506&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java
Sat Jul  1 13:31:23 2017
@@ -20,9 +20,11 @@ package org.apache.meecrowave.openwebbea
 
 import org.apache.meecrowave.Meecrowave;
 import org.apache.meecrowave.logging.tomcat.LogFacade;
+import org.apache.openwebbeans.se.CDISeScannerService;
 import org.apache.tomcat.JarScanFilter;
 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.webbeans.web.scanner.WebScannerService;
@@ -30,9 +32,7 @@ import org.apache.xbean.finder.Annotatio
 import org.apache.xbean.finder.filter.Filter;
 
 import javax.servlet.ServletContext;
-import java.io.Closeable;
 import java.io.File;
-import java.io.IOException;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -41,6 +41,7 @@ import java.net.URI;
 import java.net.URL;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 import java.util.function.Consumer;
 import java.util.stream.Stream;
@@ -50,10 +51,11 @@ import static java.util.Optional.ofNulla
 import static java.util.stream.Collectors.toSet;
 import static org.apache.tomcat.JarScanType.PLUGGABILITY;
 
-public class OWBTomcatWebScannerService extends WebScannerService implements Closeable {
+public class OWBTomcatWebScannerService extends WebScannerService {
     private final LogFacade logger = new LogFacade(OWBTomcatWebScannerService.class.getName());
+    private final CDISeScannerService delegate;
 
-    private JarScanFilter filter;
+    protected JarScanFilter filter;
     private String jreBase;
 
     // just for logging (== temp)
@@ -62,16 +64,70 @@ public class OWBTomcatWebScannerService
     private String shared;
     private Consumer<File> fileVisitor;
 
+    public OWBTomcatWebScannerService() {
+        this(null);
+    }
+
+
+    public OWBTomcatWebScannerService(final CDISeScannerService delegate) {
+        this.delegate = delegate;
+    }
+
     @Override
     public void init(final Object context) {
-        // no-op
+        if (delegate != null) {
+            delegate.init(context);
+        }
+    }
+
+    @Override
+    public OwbAnnotationFinder getFinder() {
+        if (delegate != null) {
+            return delegate.getFinder();
+        }
+        return super.getFinder();
+    }
+
+    @Override
+    public Map<BeanArchiveService.BeanArchiveInformation, Set<Class<?>>>
getBeanClassesPerBda() {
+        if (delegate != null) {
+            return delegate.getBeanClassesPerBda();
+        }
+        return super.getBeanClassesPerBda();
+    }
+
+    @Override
+    public void release() {
+        if (delegate != null) {
+            delegate.release();
+        } else {
+            super.release();
+        }
+    }
+
+    @Override
+    public Set<Class<?>> getBeanClasses() {
+        if (delegate != null) {
+            return delegate.getBeanClasses();
+        }
+        return super.getBeanClasses();
     }
 
     @Override
     public void scan() {
+        if (delegate != null) {
+            if (getFinder() == null) {
+                delegate.scan();
+            }
+            if (finder == null) {
+                finder = getFinder();
+            }
+        }
+
         if (finder != null) {
             return;
         }
+
         super.scan();
         scanGroovy(WebBeansUtil.getCurrentClassLoader());
         if (!urls.isEmpty()) {
@@ -269,11 +325,6 @@ public class OWBTomcatWebScannerService
         this.docBase = docBase;
     }
 
-    @Override
-    public void close() throws IOException {
-
-    }
-
     public void setFileVisitor(final Consumer<File> fileVisitor) {
         this.fileVisitor = fileVisitor;
     }

Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/resources/META-INF/services/javax.enterprise.inject.se.SeContainerInitializer
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/resources/META-INF/services/javax.enterprise.inject.se.SeContainerInitializer?rev=1800506&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/resources/META-INF/services/javax.enterprise.inject.se.SeContainerInitializer
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/resources/META-INF/services/javax.enterprise.inject.se.SeContainerInitializer
Sat Jul  1 13:31:23 2017
@@ -0,0 +1 @@
+org.apache.meecrowave.cdi.MeecrowaveSeContainerInitializer

Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerInitializerTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerInitializerTest.java?rev=1800506&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerInitializerTest.java
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/cdi/MeecrowaveSeContainerInitializerTest.java
Sat Jul  1 13:31:23 2017
@@ -0,0 +1,63 @@
+/*
+ * 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.meecrowave.cdi;
+
+import org.apache.meecrowave.Meecrowave;
+import org.junit.Test;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.se.SeContainer;
+import javax.enterprise.inject.se.SeContainerInitializer;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.MediaType;
+
+import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class MeecrowaveSeContainerInitializerTest {
+    @Test
+    public void run() {
+        try (final SeContainer container = SeContainerInitializer.newInstance()
+                .disableDiscovery()
+                .addBeanClasses(Configured.class)
+                .initialize()) {
+            final Client client = ClientBuilder.newClient();
+            assertNotNull(container.select(Meecrowave.class).get());
+            assertEquals("configured", client
+                    .target(String.format("http://localhost:%d/configured", container.select(Meecrowave.Builder.class).get().getHttpPort()))
+                    .request(TEXT_PLAIN_TYPE)
+                    .get(String.class));
+        }
+    }
+
+    @ApplicationScoped
+    @Path("configured")
+    public static class Configured {
+        @GET
+        @Produces(MediaType.TEXT_PLAIN)
+        public String get() {
+            return "configured";
+        }
+    }
+}

Modified: openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/meecrowave-core/configuration.adoc
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/meecrowave-core/configuration.adoc?rev=1800506&r1=1800505&r2=1800506&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/meecrowave-core/configuration.adoc
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/meecrowave-core/configuration.adoc
Sat Jul  1 13:31:23 2017
@@ -34,6 +34,64 @@ new Meecrowave(new Builder() {{
     .await();
 ----
 
+== CDI SE API
+
+CDI 2.0 introduces a "SE API" for CDI. It looks like:
+
+[source,java]
+----
+try (final SeContainer container = SeContainerInitializer.newInstance()
+        .disableDiscovery()
+        .addBeanClasses(Configured.class)
+        .initialize()) {
+    // your main
+}
+----
+
+Meecrowave inherits from OpenWebBeans SE API implementation and therefore this SE API will
work out of the box.
+
+It is implemented as a `bake()` and you can still access the `Builder` configuration or even
`Meecrowave` itself if needed:
+
+[source,java]
+----
+try (final SeContainer container = SeContainerInitializer.newInstance()
+        .disableDiscovery()
+        .addBeanClasses(Configured.class)
+        .initialize()) {
+
+    // use the configuration to access extensions, custom config or even server port
+    Meecrowave.Builder config = container.select(Meecrowave.Builder.class).get();
+    int port = config.getHttpPort();
+
+    // default wait implementation relying on tomcat one
+    container.select(Meecrowave.class).get().await(); // wait for the program to be killed
(tomcat.await() equivalent)
+
+}
+----
+
+All the configuration of meecrowave is still available using properties:
+
+[source,java]
+----
+try (final SeContainer container = SeContainerInitializer.newInstance()
+     .addProperty("nameOfTheProperty", instanceInTheRightType)
+     .initialize()) {
+    container.select(Meecrowave.class).get().await();
+}
+----
+
+The type should match the type expected by the `Builder` instance. Note you can also just
pass directly a `Builder` instance as value
+(the property name is not important) if you want something preconfigured:
+
+[source,java]
+----
+try (final SeContainer container = SeContainerInitializer.newInstance()
+     .addProperty("meecrowaveConfiguration", new Meecrowave.Builder().randomPort())
+     .initialize()) {
+    container.select(Meecrowave.class).get().await();
+}
+----
+
 == Automatic configuration
 
 The `org.apache.meecrowave.Meecrowave$Builder` class also provides `loadFromProperties(Properties)`

Modified: openwebbeans/meecrowave/trunk/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/pom.xml?rev=1800506&r1=1800505&r2=1800506&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/pom.xml (original)
+++ openwebbeans/meecrowave/trunk/pom.xml Sat Jul  1 13:31:23 2017
@@ -50,7 +50,7 @@
 
     <junit.version>4.12</junit.version>
     <tomcat.version>9.0.0.M22</tomcat.version>
-    <openwebbeans.version>1.7.3</openwebbeans.version>
+    <openwebbeans.version>2.0.0-SNAPSHOT</openwebbeans.version>
     <cxf.version>3.1.12</cxf.version>
     <johnzon.version>1.1.1</johnzon.version>
     <log4j2.version>2.8.2</log4j2.version>



Mime
View raw message