You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2020/06/08 13:16:24 UTC

[james-project] 30/30: JAMES-3179 Drop OSGi

This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 36599ea9739417d88a7023e4f03d8682218c9c07
Author: Gautier DI FOLCO <gd...@linagora.com>
AuthorDate: Wed May 27 17:06:09 2020 +0200

    JAMES-3179 Drop OSGi
---
 mailet/standard/pom.xml                            |   2 +-
 pom.xml                                            |  41 +--
 server/app/pom.xml                                 |   8 -
 server/container/spring/pom.xml                    |   8 -
 .../AbstractOSGIAnnotationBeanPostProcessor.java   | 312 ---------------------
 .../lifecycle/osgi/OSGIConfigurationProvider.java  |  46 ---
 ...PersistenceUnitAnnotationBeanPostProcessor.java |  44 ---
 .../OSGIResourceAnnotationBeanPostProcessor.java   |  42 ---
 .../spring/osgi/AbstractBundleTracker.java         | 198 -------------
 .../container/spring/osgi/DomainListTracker.java   |  35 ---
 .../spring/osgi/RecipientRewriteTableTracker.java  |  35 ---
 .../spring/osgi/UsersRepositoryTracker.java        |  36 ---
 12 files changed, 3 insertions(+), 804 deletions(-)

diff --git a/mailet/standard/pom.xml b/mailet/standard/pom.xml
index 03b890d..1fc19d9 100644
--- a/mailet/standard/pom.xml
+++ b/mailet/standard/pom.xml
@@ -100,7 +100,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
-            <artifactId>httpclient-osgi</artifactId>
+            <artifactId>httpclient</artifactId>
         </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
diff --git a/pom.xml b/pom.xml
index b4de1d8..0e87aae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -611,8 +611,6 @@
         <concurrent.version>1.3.4</concurrent.version>
         <xbean-spring.version>4.9</xbean-spring.version>
         <netty.version>3.10.6.Final</netty.version>
-        <spring-osgi-extender.version>1.2.1</spring-osgi-extender.version>
-        <org.osgi.core.version>5.0.0</org.osgi.core.version>
         <cucumber.version>2.4.0</cucumber.version>
 
         <pax-logging-api.version>1.6.4</pax-logging-api.version>
@@ -627,7 +625,6 @@
         <guava.version>25.1-jre</guava.version>
 
         <jutf7.version>1.0.0</jutf7.version>
-        <httpclient-osgi.version>4.5.1</httpclient-osgi.version>
         <apache.httpcomponents.version>4.5.9</apache.httpcomponents.version>
         <!-- maven-mailetdocs-plugin artifacts -->
         <maven-artifact.version>3.0-alpha-1</maven-artifact.version>
@@ -2345,14 +2342,8 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.httpcomponents</groupId>
-                <artifactId>httpclient-osgi</artifactId>
-                <version>${apache.httpcomponents.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>commons-logging</groupId>
-                        <artifactId>commons-logging</artifactId>
-                    </exclusion>
-                </exclusions>
+                <artifactId>httpclient</artifactId>
+                <version>4.5.10</version>
             </dependency>
             <dependency>
                 <groupId>org.apache.james.jspf</groupId>
@@ -2575,11 +2566,6 @@
                 <version>3.0.0</version>
             </dependency>
             <dependency>
-                <groupId>org.osgi</groupId>
-                <artifactId>org.osgi.core</artifactId>
-                <version>${org.osgi.core.version}</version>
-            </dependency>
-            <dependency>
                 <groupId>org.scala-lang</groupId>
                 <artifactId>scala-library</artifactId>
                 <version>${scala.version}</version>
@@ -2678,29 +2664,6 @@
                 <version>${spring.version}</version>
             </dependency>
             <dependency>
-                <groupId>org.springframework.osgi</groupId>
-                <artifactId>spring-osgi-extender</artifactId>
-                <version>${spring-osgi-extender.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>org.springframework</groupId>
-                        <artifactId>org.springframework.core</artifactId>
-                    </exclusion>
-                    <exclusion>
-                        <groupId>org.springframework</groupId>
-                        <artifactId>org.springframework.aop</artifactId>
-                    </exclusion>
-                    <exclusion>
-                        <groupId>org.springframework</groupId>
-                        <artifactId>org.springframework.context</artifactId>
-                    </exclusion>
-                    <exclusion>
-                        <groupId>org.springframework</groupId>
-                        <artifactId>org.springframework.beans</artifactId>
-                    </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
                 <groupId>org.subethamail</groupId>
                 <artifactId>subethasmtp</artifactId>
                 <version>3.1.7</version>
diff --git a/server/app/pom.xml b/server/app/pom.xml
index 00ab3f0..0be80fd 100644
--- a/server/app/pom.xml
+++ b/server/app/pom.xml
@@ -457,14 +457,6 @@
             <artifactId>james-server-spring</artifactId>
             <exclusions>
                 <exclusion>
-                    <groupId>org.springframework.osgi</groupId>
-                    <artifactId>spring-osgi-extender</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.osgi</groupId>
-                    <artifactId>org.osgi.core</artifactId>
-                </exclusion>
-                <exclusion>
                     <groupId>javax.mail</groupId>
                     <artifactId>mail</artifactId>
                 </exclusion>
diff --git a/server/container/spring/pom.xml b/server/container/spring/pom.xml
index 5e7551e..dcb87f5 100644
--- a/server/container/spring/pom.xml
+++ b/server/container/spring/pom.xml
@@ -157,10 +157,6 @@
             <artifactId>log4j-slf4j-impl</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>jcl-over-slf4j</artifactId>
         </dependency>
@@ -208,10 +204,6 @@
             <artifactId>spring-web</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.springframework.osgi</groupId>
-            <artifactId>spring-osgi-extender</artifactId>
-        </dependency>
-        <dependency>
             <groupId>pl.pragmatists</groupId>
             <artifactId>JUnitParams</artifactId>
             <scope>test</scope>
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java b/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java
deleted file mode 100644
index 4bad5f5..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/AbstractOSGIAnnotationBeanPostProcessor.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.lifecycle.osgi;
-
-import java.beans.PropertyDescriptor;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
-import org.osgi.framework.BundleContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.FatalBeanException;
-import org.springframework.beans.MutablePropertyValues;
-import org.springframework.beans.PropertyValues;
-import org.springframework.beans.factory.BeanClassLoaderAware;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
-import org.springframework.core.annotation.AnnotationUtils;
-import org.springframework.osgi.context.BundleContextAware;
-import org.springframework.osgi.service.importer.support.Cardinality;
-import org.springframework.osgi.service.importer.support.OsgiServiceCollectionProxyFactoryBean;
-import org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean;
-import org.springframework.util.ReflectionUtils;
-
-/**
- * Abstract base class for {@link BeanPostProcessor} implementations which need to wire stuff via annotations and need to be functional via OSGI.
- * 
- * Many of this code is borrowed from the spring-dm's class <code>org.springframework.osgi.extensions.annotation.ServiceReferenceInjectionBeanPostProcessor.</code>
- *  * 
- * 
- *
- * @param <A>
- */
-public abstract class AbstractOSGIAnnotationBeanPostProcessor<A extends Annotation> extends InstantiationAwareBeanPostProcessorAdapter implements BundleContextAware, BeanClassLoaderAware, BeanFactoryAware {
-
-    public static final long DEFAULT_TIMEOUT = 60 * 1000 * 5;
-    private BundleContext bundleContext;
-
-    private static final Logger logger = LoggerFactory.getLogger(AbstractOSGIAnnotationBeanPostProcessor.class);
-
-    protected BeanFactory beanFactory;
-
-    private ClassLoader classLoader;
-
-    private boolean lookupBeanFactory = true;
-
-    private long timeout = DEFAULT_TIMEOUT;
-
-
-    /**
-     * Set the timeout in milliseconds. The default is 5 minutes
-     * 
-     * @param timeout
-     */
-    public void setTimeout(long timeout) {
-        this.timeout = timeout;
-    }
-    
-    public void setLookupBeanFactory(boolean lookupBeanFactory) {
-        this.lookupBeanFactory = lookupBeanFactory;
-    }
-    
-    private abstract static class ImporterCallAdapter {
-
-        @SuppressWarnings("rawtypes")
-        static void setInterfaces(Object importer, Class[] classes) {
-            if (importer instanceof OsgiServiceProxyFactoryBean) {
-                ((OsgiServiceProxyFactoryBean) importer).setInterfaces(classes);
-            } else {
-                ((OsgiServiceCollectionProxyFactoryBean) importer).setInterfaces(classes);
-            }
-        }
-
-        static void setBundleContext(Object importer, BundleContext context) {
-            ((BundleContextAware) importer).setBundleContext(context);
-        }
-
-        static void setBeanClassLoader(Object importer, ClassLoader cl) {
-            ((BeanClassLoaderAware) importer).setBeanClassLoader(cl);
-        }
-
-        static void setCardinality(Object importer, Cardinality cardinality) {
-            if (importer instanceof OsgiServiceProxyFactoryBean) {
-                ((OsgiServiceProxyFactoryBean) importer).setCardinality(cardinality);
-            } else {
-                ((OsgiServiceCollectionProxyFactoryBean) importer).setCardinality(cardinality);
-            }
-        }
-
-
-        static void afterPropertiesSet(Object importer) throws Exception {
-            ((InitializingBean) importer).afterPropertiesSet();
-        }
-
-        static void setFilter(Object importer, String filter) {
-            if (importer instanceof OsgiServiceProxyFactoryBean) {
-                ((OsgiServiceProxyFactoryBean) importer).setFilter(filter);
-            } else {
-                ((OsgiServiceCollectionProxyFactoryBean) importer).setFilter(filter);
-            }
-        }
-
-
-        @SuppressWarnings("unused")
-        static void setServiceBean(Object importer, String name) {
-            if (importer instanceof OsgiServiceProxyFactoryBean) {
-                ((OsgiServiceProxyFactoryBean) importer).setServiceBeanName(name);
-            } else {
-                ((OsgiServiceCollectionProxyFactoryBean) importer).setServiceBeanName(name);
-            }
-        }
-    }
-
-    @Override
-    public void setBeanClassLoader(ClassLoader classLoader) {
-        this.classLoader = classLoader;
-    }
-
-    /**
-     * process FactoryBean created objects, since these will not have had
-     * services injected.
-     * 
-     * @param bean
-     * @param beanName
-     */
-    @Override
-    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
-        logger.debug("processing [{}, {}]", bean.getClass().getName(), beanName);
-        // Catch FactoryBean created instances.
-        if (!(bean instanceof FactoryBean) && beanFactory.containsBean(BeanFactory.FACTORY_BEAN_PREFIX + beanName)) {
-            injectServices(bean, beanName);
-        }
-        return bean;
-    }
-
-    /* private version of the injector can use */
-    private void injectServices(final Object bean, final String beanName) {
-        ReflectionUtils.doWithMethods(bean.getClass(),
-            method -> {
-                A s = AnnotationUtils.getAnnotation(method, getAnnotation());
-                if (s != null && method.getParameterTypes().length == 1) {
-                    try {
-                        logger.debug("Processing annotation [{}] for [{}.{}()] on bean [{}]", s, bean.getClass().getName(), method.getName(), beanName);
-                        method.invoke(bean, getServiceImporter(s, method, beanName).getObject());
-                    } catch (Exception e) {
-                        throw new IllegalArgumentException("Error processing annotation " + s, e);
-                    }
-                }
-            });
-    }
-
-    @Override
-    @SuppressWarnings("rawtypes")
-    public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean,
-            String beanName) throws BeansException {
-
-        MutablePropertyValues newprops = new MutablePropertyValues(pvs);
-        for (PropertyDescriptor pd : pds) {
-            A s = findAnnotatedProperty(pd);
-            if (s != null && !pvs.contains(pd.getName())) {
-                try {
-                    logger.debug("Processing annotation [{}] for [{}.{}]", s, beanName, pd.getName());
-                    FactoryBean importer = getServiceImporter(s, pd.getWriteMethod(), beanName);
-                    // BPPs are created in stageOne(), even though they are run in stageTwo(). This check means that
-                    // the call to getObject() will not fail with ServiceUnavailable. This is safe to do because
-                    // ServiceReferenceDependencyBeanFactoryPostProcessor will ensure that mandatory services are
-                    // satisfied before stageTwo() is run.
-                    if (bean instanceof BeanPostProcessor) {
-                        ImporterCallAdapter.setCardinality(importer, Cardinality.C_0__1);
-                    }
-                    newprops.addPropertyValue(pd.getName(), importer.getObject());
-                } catch (Exception e) {
-                    throw new FatalBeanException("Could not create service reference", e);
-                }
-            }
-        }
-        return newprops;
-    }
-
-    @SuppressWarnings("rawtypes")
-    private FactoryBean getServiceImporter(A s, Method writeMethod, String beanName) throws Exception {
-        // Invocations will block here, so although the ApplicationContext is
-        // created nothing will
-        // proceed until all the dependencies are satisfied.
-        Class<?>[] params = writeMethod.getParameterTypes();
-        if (params.length != 1) {
-            throw new IllegalArgumentException("Setter for [" + beanName + "] must have only one argument");
-        }
-
-        if (lookupBeanFactory) {
-            logger.debug("Lookup the bean via the BeanFactory");
-
-            final Class<?> clazz = writeMethod.getParameterTypes()[0];
-            Object bean;
-            try {
-                bean = getBeanFromFactory(s, clazz);
-            } catch (NoSuchBeanDefinitionException e) {
-                // We was not able to find the bean in the factory so fallback to the osgi registry
-                bean = null;
-            }
-            
-            if (bean != null) {
-                final Object fBean = bean;
-                
-                // Create a new FactoryBean which just return the found beab
-                return new FactoryBean() {
-
-                    @Override
-                    public Object getObject() throws Exception {
-                        return fBean;
-                    }
-
-                    @Override
-                    public Class getObjectType() {
-                        return fBean.getClass();
-                    }
-
-                    @Override
-                    public boolean isSingleton() {
-                        return true;
-                    }
-                };
-            }
-        }
-        // The bean was not found in the BeanFactory. Its time to lookup it via the OSGI-Registry
-        return getResourceProperty(new OsgiServiceProxyFactoryBean(), getFilter(s), writeMethod, beanName);
-    }
-
-    
-
-    @SuppressWarnings("rawtypes")
-    private FactoryBean getResourceProperty(OsgiServiceProxyFactoryBean pfb,  String filter, Method writeMethod, String beanName) throws Exception {
-        pfb.setTimeout(timeout);
-        
-        // check if the we have a name for the requested bean. If so we set the filter for it
-        if (filter != null) {
-            ImporterCallAdapter.setFilter(pfb, filter);
-        }
-        ImporterCallAdapter.setInterfaces(pfb, writeMethod.getParameterTypes());
-        
-        ImporterCallAdapter.setBundleContext(pfb, bundleContext);
-        ImporterCallAdapter.setBeanClassLoader(pfb, classLoader);
-        ImporterCallAdapter.afterPropertiesSet(pfb);
-        return pfb;
-    }
-
-
-    private A findAnnotatedProperty(PropertyDescriptor propertyDescriptor) {
-        Method setter = propertyDescriptor.getWriteMethod();
-        return setter != null ? AnnotationUtils.getAnnotation(setter, getAnnotation()) : null;
-    }
-
-    @Override
-    public void setBundleContext(BundleContext context) {
-        this.bundleContext = context;
-    }
-
-    @Override
-    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
-        this.beanFactory = beanFactory;
-    }
-    
-
-    /**
-     * Return the class of the {@link Annotation}
-     * 
-     * @return clazz
-     */
-    protected abstract Class<A> getAnnotation();
-    
-    /**
-     * Return the filter which should get used to lookup the service in the osgi registry.
-     * If no special filter should be used, just return null
-     * 
-     * @param annotation
-     * @return filter
-     */
-    protected abstract String getFilter(A annotation);
-    
-    /**
-     * Return the Bean lookup-ed from the {@link BeanFactory}. If non can be found just return null
-     * 
-     * @param a
-     * @param clazz
-     * @return bean
-     */
-    protected abstract Object getBeanFromFactory(A a, Class<?> clazz);
-    
-}
-
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIConfigurationProvider.java b/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIConfigurationProvider.java
deleted file mode 100644
index 426e37d..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIConfigurationProvider.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.lifecycle.osgi;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import org.apache.commons.configuration2.HierarchicalConfiguration;
-import org.apache.commons.configuration2.ex.ConfigurationException;
-import org.apache.commons.configuration2.tree.ImmutableNode;
-import org.apache.james.server.core.configuration.FileConfigurationProvider;
-
-public class OSGIConfigurationProvider implements org.apache.james.container.spring.lifecycle.ConfigurationProvider {
-
-    @Override
-    public void registerConfiguration(String beanName, HierarchicalConfiguration<ImmutableNode> conf) {
-        
-    }
-
-    @Override
-    public HierarchicalConfiguration<ImmutableNode> getConfiguration(String beanName) throws ConfigurationException {
-        try (FileInputStream fis = new FileInputStream("/tmp/" + beanName + ".xml")) {
-            return FileConfigurationProvider.getConfig(fis);
-        } catch (IOException e) {
-            throw new ConfigurationException("Bean " + beanName);
-        }
-        // Left empty on purpose
-    }
-
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java b/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java
deleted file mode 100644
index 56ca90c..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIPersistenceUnitAnnotationBeanPostProcessor.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.lifecycle.osgi;
-
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceUnit;
-
-/**
- * Inject the {@link EntityManagerFactory} if an method is marked with the {@link PersistenceUnit} annotation
- */
-public class OSGIPersistenceUnitAnnotationBeanPostProcessor extends AbstractOSGIAnnotationBeanPostProcessor<PersistenceUnit> {
-
-    @Override
-    protected Class<PersistenceUnit> getAnnotation() {
-        return PersistenceUnit.class;
-    }
-
-    @Override
-    protected String getFilter(PersistenceUnit a) {
-        return null;
-    }
-
-    @Override
-    protected Object getBeanFromFactory(PersistenceUnit a, Class<?> clazz) {
-        return beanFactory.getBean(clazz);
-    }
-
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java b/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java
deleted file mode 100644
index cd8b485..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/lifecycle/osgi/OSGIResourceAnnotationBeanPostProcessor.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.lifecycle.osgi;
-
-import javax.annotation.Resource;
-
-import org.springframework.osgi.service.exporter.OsgiServicePropertiesResolver;
-
-public class OSGIResourceAnnotationBeanPostProcessor extends AbstractOSGIAnnotationBeanPostProcessor<Resource> {
-
-    @Override
-    protected Class<Resource> getAnnotation() {
-        return Resource.class;
-    }
-
-    @Override
-    protected String getFilter(Resource a) {
-        return  "(" + OsgiServicePropertiesResolver.BEAN_NAME_PROPERTY_KEY + "=" + a.name() + ")";
-    }
-    
-    @Override
-    protected Object getBeanFromFactory(Resource a, Class<?> clazz) {
-        return beanFactory.getBean(a.name(), clazz);
-    }
-    
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/AbstractBundleTracker.java b/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/AbstractBundleTracker.java
deleted file mode 100644
index 637aeb0..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/AbstractBundleTracker.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.osgi;
-
-import java.net.URL;
-import java.util.Enumeration;
-
-import org.apache.commons.configuration2.HierarchicalConfiguration;
-import org.apache.commons.configuration2.tree.ImmutableNode;
-import org.apache.james.container.spring.lifecycle.ConfigurationProvider;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.context.ApplicationContext;
-import org.springframework.osgi.context.BundleContextAware;
-import org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext;
-import org.springframework.osgi.service.exporter.OsgiServicePropertiesResolver;
-import org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean;
-
-/**
- * This {@link BundleListener} use the extender pattern to scan all loaded
- * bundles if a class name with a given name is present. If so it register in
- * the {@link BeanDefinitionRegistry} and also register it to the OSG-Registry via an {@link OsgiServiceFactoryBean}
- * 
- */
-public abstract class AbstractBundleTracker implements BeanFactoryAware, BundleListener, BundleContextAware, InitializingBean, DisposableBean {
-
-    private BundleContext context;
-    private String configuredClass;
-    private volatile OsgiServiceFactoryBean osgiFactoryBean;
-    private BeanFactory factory;
-    private final Logger logger = LoggerFactory.getLogger(AbstractBundleTracker.class);
-    
-    @Override
-    public void setBeanFactory(BeanFactory factory) throws BeansException {
-        this.factory = factory;
-    }
-
-    @Override
-    public void setBundleContext(BundleContext context) {
-        this.context = context;
-    }
-
-    @Override
-    public void bundleChanged(BundleEvent event) {
-        Bundle b = event.getBundle();
-
-        // Check if the event was fired for this class
-        if (b.equals(this.context.getBundle())) {
-            return;
-        }
-
-        switch (event.getType()) {
-        case BundleEvent.STARTED:
-            Enumeration<?> entrs = b.findEntries("/", "*.class", true);
-            if (entrs != null) {
-
-                // Loop over all the classes
-                while (entrs.hasMoreElements()) {
-                    URL e = (URL) entrs.nextElement();
-                    String file = e.getFile();
-
-                    String className = file.replaceAll("/", ".").replaceAll("\\.class", "").replaceFirst("\\.", "");
-                    if (className.equals(configuredClass)) {
-                        try {
-
-                            BeanFactory bFactory = getBeanFactory(b.getBundleContext());
-                            Class<?> clazz = getServiceClass();
-
-                            // Create the definition and register it
-                            BeanDefinitionRegistry registry = (BeanDefinitionRegistry) bFactory;
-                            BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(className).getBeanDefinition();
-                            registry.registerBeanDefinition(getComponentName(), def);
-
-                            // register the bean as service in the OSGI-Registry
-                            osgiFactoryBean = new OsgiServiceFactoryBean();
-                            osgiFactoryBean.setTargetBeanName(getComponentName());
-                            osgiFactoryBean.setBeanFactory(bFactory);
-                            osgiFactoryBean.setBundleContext(b.getBundleContext());
-                            osgiFactoryBean.setInterfaces(new Class[] { clazz });
-                            osgiFactoryBean.afterPropertiesSet();
-                            logger.debug("Registered {} in the OSGI-Registry with interface {}", configuredClass, clazz.getName());
-                        } catch (Exception e1) {
-                            logger.error("Unable to register {} in the OSGI-Registry", configuredClass, e1);
-                        }
-                    }
-                }
-            }
-            break;
-        case BundleEvent.STOPPED:
-            // check if we need to destroy the OsgiFactoryBean. This also include the unregister from the OSGI-Registry
-            if (osgiFactoryBean != null) {
-                osgiFactoryBean.destroy();
-                osgiFactoryBean = null;
-                logger.debug("Unregistered {} in the OSGI-Registry with interface {}", configuredClass, getServiceClass().getName());
-
-            }
-            break;
-        default:
-            break;
-        }
-
-    }
-
-    
-    /**
-     * Return the {@link BeanFactory} for the given {@link BundleContext}. If none can be found we just create a new {@link AbstractDelegatedExecutionApplicationContext} and return the {@link BeanFactory} of it
-     * 
-     * 
-     * @param bundleContext
-     * @return factory
-     * @throws Exception
-     */
-    private BeanFactory getBeanFactory(BundleContext bundleContext) throws Exception {
-        final String filter = "(" + OsgiServicePropertiesResolver.BEAN_NAME_PROPERTY_KEY + "=" + bundleContext.getBundle().getSymbolicName() + ")";
-        final ServiceReference<?>[] applicationContextRefs = bundleContext.getServiceReferences(ApplicationContext.class.getName(), filter);
-        
-        // Check if we found an ApplicationContext. If not create one
-        if (applicationContextRefs == null || applicationContextRefs.length != 1) {
-            
-            // Create a new context which just serve as registry later
-            AbstractDelegatedExecutionApplicationContext context = new AbstractDelegatedExecutionApplicationContext() {
-            };
-            context.setBundleContext(bundleContext);
-            context.setPublishContextAsService(true);
-            context.refresh();
-            return context.getBeanFactory();
-        } else {
-            return ((ApplicationContext) bundleContext.getService(applicationContextRefs[0])).getAutowireCapableBeanFactory();
-        }
-       
-       
-    }
-
-    @Override
-    public void afterPropertiesSet() throws Exception {
-        ConfigurationProvider confProvider = factory.getBean(ConfigurationProvider.class);
-        HierarchicalConfiguration<ImmutableNode> config = confProvider.getConfiguration(getComponentName());
-
-        // Get the configuration for the class
-        configuredClass = config.getString("[@class]");
-        if (context != null) {
-            context.addBundleListener(this);
-        }
-    }
-
-    @Override
-    public void destroy() throws Exception {
-        // Its time to unregister the listener so we are sure resources are released
-        if (context != null) {
-            context.removeBundleListener(this);
-        }
-    }
-
-    /**
-     * Return the name of the component
-     * 
-     * @return name
-     */
-    protected abstract String getComponentName();
-
-    /**
-     * Return the class which will be used to expose the service in the OSGI
-     * registry
-     * 
-     * @return sClass
-     */
-    protected abstract Class<?> getServiceClass();
-
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/DomainListTracker.java b/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/DomainListTracker.java
deleted file mode 100644
index 9d94886..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/DomainListTracker.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.osgi;
-
-import org.apache.james.domainlist.api.DomainList;
-
-public class DomainListTracker extends AbstractBundleTracker {
-
-    @Override
-    protected String getComponentName() {
-        return "domainlist";
-    }
-
-    @Override
-    protected Class<?> getServiceClass() {
-        return DomainList.class;
-    }
-
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/RecipientRewriteTableTracker.java b/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/RecipientRewriteTableTracker.java
deleted file mode 100644
index 3126604..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/RecipientRewriteTableTracker.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.osgi;
-
-import org.apache.james.rrt.api.RecipientRewriteTable;
-
-public class RecipientRewriteTableTracker extends AbstractBundleTracker {
-
-    @Override
-    protected String getComponentName() {
-        return "recipientrewritetable";
-    }
-
-    @Override
-    protected Class<?> getServiceClass() {
-        return RecipientRewriteTable.class;
-    }
-
-}
diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/UsersRepositoryTracker.java b/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/UsersRepositoryTracker.java
deleted file mode 100644
index e956e47..0000000
--- a/server/container/spring/src/main/java/org/apache/james/container/spring/osgi/UsersRepositoryTracker.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/****************************************************************
- * 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.james.container.spring.osgi;
-
-import org.apache.james.user.api.UsersRepository;
-
-public class UsersRepositoryTracker extends AbstractBundleTracker {
-
-    
-    @Override
-    protected String getComponentName() {
-        return "usersrepository";
-    }
-    
-    @Override
-    protected Class<?> getServiceClass() {
-        return UsersRepository.class;
-    }
-
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org