continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r654275 - in /continuum/branches/builder/continuum-base/continuum-scm: ./ src/main/java/org/apache/continuum/scm/manager/spring/ src/test/java/org/apache/continuum/scm/manager/ src/test/resources/org/apache/continuum/scm/manager/
Date Wed, 07 May 2008 21:07:30 GMT
Author: carlos
Date: Wed May  7 14:07:26 2008
New Revision: 654275

URL: http://svn.apache.org/viewvc?rev=654275&view=rev
Log:
Automatically inject ScmProvider implementations

Added:
    continuum/branches/builder/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/manager/spring/
    continuum/branches/builder/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/manager/spring/ScmProviderFactoryBean.java
  (with props)
Modified:
    continuum/branches/builder/continuum-base/continuum-scm/pom.xml
    continuum/branches/builder/continuum-base/continuum-scm/src/test/java/org/apache/continuum/scm/manager/ScmManagerTest.java
    continuum/branches/builder/continuum-base/continuum-scm/src/test/resources/org/apache/continuum/scm/manager/ScmManagerTest.xml

Modified: continuum/branches/builder/continuum-base/continuum-scm/pom.xml
URL: http://svn.apache.org/viewvc/continuum/branches/builder/continuum-base/continuum-scm/pom.xml?rev=654275&r1=654274&r2=654275&view=diff
==============================================================================
--- continuum/branches/builder/continuum-base/continuum-scm/pom.xml (original)
+++ continuum/branches/builder/continuum-base/continuum-scm/pom.xml Wed May  7 14:07:26 2008
@@ -26,9 +26,13 @@
       <groupId>org.springframework</groupId>
       <artifactId>spring-context</artifactId>
       <version>${spring.version}</version>
-      <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-spring</artifactId>
+      <scope>test</scope>
+    </dependency>    
+    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
       <version>1.5.0</version>

Added: continuum/branches/builder/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/manager/spring/ScmProviderFactoryBean.java
URL: http://svn.apache.org/viewvc/continuum/branches/builder/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/manager/spring/ScmProviderFactoryBean.java?rev=654275&view=auto
==============================================================================
--- continuum/branches/builder/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/manager/spring/ScmProviderFactoryBean.java
(added)
+++ continuum/branches/builder/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/manager/spring/ScmProviderFactoryBean.java
Wed May  7 14:07:26 2008
@@ -0,0 +1,66 @@
+package org.apache.continuum.scm.manager.spring;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.maven.scm.provider.ScmProvider;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactoryUtils;
+import org.springframework.beans.factory.BeanInitializationException;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+/**
+ * <p>
+ * Factory bean to inject all beans of type {@link ScmProvider}
+ * </p>
+ * <p>
+ * <code>&lt;bean id="scmProviders" class="org.apache.continuum.scm.manager.spring.ScmManagerFactoryBean"/>
+ </code>
+ * </p>
+ * 
+ * @author Carlos Sanchez <carlos@apache.org>
+ */
+public class ScmProviderFactoryBean
+    implements FactoryBean, ApplicationContextAware
+{
+    private ApplicationContext applicationContext;
+
+    public Object getObject()
+        throws Exception
+    {
+        Map<String, ScmProvider> providers = new HashMap<String, ScmProvider>();
+        Map<String, ScmProvider> beans =
+            BeanFactoryUtils.beansOfTypeIncludingAncestors( applicationContext, ScmProvider.class
);
+        for ( ScmProvider provider : beans.values() )
+        {
+            if ( providers.containsKey( provider.getScmType() ) )
+            {
+                throw new BeanInitializationException(
+                                                       "There are to ScmProvider beans in
the appllication context for Scm type " +
+                                                           provider.getScmType() +
+                                                           ". Probably two conflicting scm
implementations are present in the classpath." );
+            }
+            providers.put( provider.getScmType(), provider );
+        }
+        return providers;
+    }
+
+    public Class getObjectType()
+    {
+        return Map.class;
+    }
+
+    public boolean isSingleton()
+    {
+        return true;
+    }
+
+    public void setApplicationContext( ApplicationContext applicationContext )
+        throws BeansException
+    {
+        this.applicationContext = applicationContext;
+    }
+
+}

Propchange: continuum/branches/builder/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/manager/spring/ScmProviderFactoryBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/branches/builder/continuum-base/continuum-scm/src/main/java/org/apache/continuum/scm/manager/spring/ScmProviderFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: continuum/branches/builder/continuum-base/continuum-scm/src/test/java/org/apache/continuum/scm/manager/ScmManagerTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/builder/continuum-base/continuum-scm/src/test/java/org/apache/continuum/scm/manager/ScmManagerTest.java?rev=654275&r1=654274&r2=654275&view=diff
==============================================================================
--- continuum/branches/builder/continuum-base/continuum-scm/src/test/java/org/apache/continuum/scm/manager/ScmManagerTest.java
(original)
+++ continuum/branches/builder/continuum-base/continuum-scm/src/test/java/org/apache/continuum/scm/manager/ScmManagerTest.java
Wed May  7 14:07:26 2008
@@ -19,11 +19,11 @@
  * under the License.
  */
 
+import junit.framework.TestCase;
+
 import org.apache.maven.scm.manager.NoSuchScmProviderException;
+import org.codehaus.plexus.spring.PlexusClassPathXmlApplicationContext;
 import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-import junit.framework.TestCase;
 
 /**
  * @todo replace with a spring integration test
@@ -38,7 +38,8 @@
     public void setUp()
     {
         context =
-            new ClassPathXmlApplicationContext( new String[] { "classpath*:META-INF/spring-context.xml",
+            new PlexusClassPathXmlApplicationContext( new String[] { "classpath*:META-INF/spring-context.xml",
+                "classpath*:META-INF/plexus/components.xml",
                 "classpath*:" + getClass().getName().replace( '.', '/' ) + ".xml" } );
         manager = (ScmManager) context.getBean( "scmManager" );
     }
@@ -47,6 +48,6 @@
         throws NoSuchScmProviderException
     {
         manager.getScmLogger().info( "Hello, World" );
-        assertNotNull( manager.getProviderByType( "svnexe" ) );
+        assertNotNull( manager.getProviderByType( "svn" ) );
     }
 }

Modified: continuum/branches/builder/continuum-base/continuum-scm/src/test/resources/org/apache/continuum/scm/manager/ScmManagerTest.xml
URL: http://svn.apache.org/viewvc/continuum/branches/builder/continuum-base/continuum-scm/src/test/resources/org/apache/continuum/scm/manager/ScmManagerTest.xml?rev=654275&r1=654274&r2=654275&view=diff
==============================================================================
--- continuum/branches/builder/continuum-base/continuum-scm/src/test/resources/org/apache/continuum/scm/manager/ScmManagerTest.xml
(original)
+++ continuum/branches/builder/continuum-base/continuum-scm/src/test/resources/org/apache/continuum/scm/manager/ScmManagerTest.xml
Wed May  7 14:07:26 2008
@@ -6,15 +6,9 @@
 
   <bean id="scmManager"
     class="org.apache.continuum.scm.manager.ScmManager">
-    <!--  TODO: better way to add the providers without having to redeclare all this?
-->
     <property name="scmLogger" ref="scmLogger" />
     <property name="scmProviders">
-      <map>
-        <entry key="svnexe">
-          <bean
-            class="org.apache.maven.scm.provider.svn.svnexe.SvnExeScmProvider" />
-        </entry>
-      </map>
+      <bean class="org.apache.continuum.scm.manager.spring.ScmProviderFactoryBean"/>
     </property>
   </bean>
 </beans>



Mime
View raw message