From 2c869e2018c588021cea6059b30b2ba38b586a9b Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sat, 27 Jun 2009 13:04:30 +0000 Subject: [PATCH] Introduce execution flow generator git-svn-id: https://svn.argeo.org/slc/trunk@2607 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/MANIFEST.MF | 4 +- .../conf/{main.xml => flowGenerator.xml} | 10 +-- .../site/org.argeo.slc.demo.ant/conf/osgi.xml | 3 +- .../AbstractExecutionFlowGenerator.java | 62 +++++++++++++++++++ .../org/argeo/slc/ant/AntFlowGenerator.java | 36 +++++++++++ .../MultipleServiceExporterPostProcessor.java | 21 ++++++- 6 files changed, 126 insertions(+), 10 deletions(-) rename demo/site/org.argeo.slc.demo.ant/conf/{main.xml => flowGenerator.xml} (77%) create mode 100644 runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionFlowGenerator.java create mode 100644 runtime/org.argeo.slc.support.ant/src/main/java/org/argeo/slc/ant/AntFlowGenerator.java diff --git a/demo/site/org.argeo.slc.demo.ant/META-INF/MANIFEST.MF b/demo/site/org.argeo.slc.demo.ant/META-INF/MANIFEST.MF index 4f4943623..f21ac26b4 100644 --- a/demo/site/org.argeo.slc.demo.ant/META-INF/MANIFEST.MF +++ b/demo/site/org.argeo.slc.demo.ant/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 -Require-Bundle: org.argeo.slc.support.equinox, +Require-Bundle: org.argeo.slc.support.osgi, org.argeo.slc.specs, - org.argeo.slc.support.simple, + org.argeo.slc.core, org.argeo.slc.support.ant Bundle-Version: 0.11.4.SNAPSHOT Bundle-Name: Basic Plug-in diff --git a/demo/site/org.argeo.slc.demo.ant/conf/main.xml b/demo/site/org.argeo.slc.demo.ant/conf/flowGenerator.xml similarity index 77% rename from demo/site/org.argeo.slc.demo.ant/conf/main.xml rename to demo/site/org.argeo.slc.demo.ant/conf/flowGenerator.xml index 7546151c6..d25caf9de 100644 --- a/demo/site/org.argeo.slc.demo.ant/conf/main.xml +++ b/demo/site/org.argeo.slc.demo.ant/conf/flowGenerator.xml @@ -7,10 +7,12 @@ http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> - - - + + + + osgibundle:/ant/hello/build.xml + + - \ No newline at end of file diff --git a/demo/site/org.argeo.slc.demo.ant/conf/osgi.xml b/demo/site/org.argeo.slc.demo.ant/conf/osgi.xml index a759f5b5c..a6f9740ef 100644 --- a/demo/site/org.argeo.slc.demo.ant/conf/osgi.xml +++ b/demo/site/org.argeo.slc.demo.ant/conf/osgi.xml @@ -6,8 +6,7 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionFlowGenerator.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionFlowGenerator.java new file mode 100644 index 000000000..a6f0a2cde --- /dev/null +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionFlowGenerator.java @@ -0,0 +1,62 @@ +package org.argeo.slc.core.execution; + +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.SlcException; +import org.springframework.beans.BeansException; +import org.springframework.beans.MutablePropertyValues; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.GenericBeanDefinition; +import org.springframework.core.Ordered; +import org.springframework.core.PriorityOrdered; + +public abstract class AbstractExecutionFlowGenerator implements + BeanFactoryPostProcessor, PriorityOrdered { + private final static Log log = LogFactory + .getLog(AbstractExecutionFlowGenerator.class); + + protected abstract Map createExecutionFlowDefinitions( + ConfigurableListableBeanFactory beanFactory); + + @Override + public void postProcessBeanFactory( + ConfigurableListableBeanFactory beanFactory) throws BeansException { + if (!(beanFactory instanceof BeanDefinitionRegistry)) { + throw new SlcException("Can only work on " + + BeanDefinitionRegistry.class); + } + + Map definitions = createExecutionFlowDefinitions(beanFactory); + + for (String beanName : definitions.keySet()) { + if (log.isDebugEnabled()) + log.debug("Registering execution flow " + beanName); + ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition( + beanName, definitions.get(beanName)); + } + } + + protected GenericBeanDefinition createDefaultFlowDefinition( + List executables) { + GenericBeanDefinition bd = new GenericBeanDefinition(); + bd.setBeanClass(DefaultExecutionFlow.class); + + MutablePropertyValues mpv = new MutablePropertyValues(); + mpv.addPropertyValue("executables", executables); + + bd.setPropertyValues(mpv); + return bd; + } + + @Override + public int getOrder() { + return Ordered.HIGHEST_PRECEDENCE; + } + +} diff --git a/runtime/org.argeo.slc.support.ant/src/main/java/org/argeo/slc/ant/AntFlowGenerator.java b/runtime/org.argeo.slc.support.ant/src/main/java/org/argeo/slc/ant/AntFlowGenerator.java new file mode 100644 index 000000000..1a6f69219 --- /dev/null +++ b/runtime/org.argeo.slc.support.ant/src/main/java/org/argeo/slc/ant/AntFlowGenerator.java @@ -0,0 +1,36 @@ +package org.argeo.slc.ant; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.argeo.slc.core.execution.AbstractExecutionFlowGenerator; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.core.io.Resource; + +public class AntFlowGenerator extends AbstractExecutionFlowGenerator { + private List antFiles = new ArrayList(); + + protected Map createExecutionFlowDefinitions( + ConfigurableListableBeanFactory beanFactory) { + Map definitions = new HashMap(); + + for (Resource antFile : antFiles) { + AntRun antRun = new AntRun(); + antRun.setBuildFile(antFile); + + List executables = new ArrayList(); + executables.add(antRun); + definitions.put("ant." + antFile.getFilename(), + createDefaultFlowDefinition(executables)); + } + return definitions; + } + + public void setAntFiles(List antFiles) { + this.antFiles = antFiles; + } + +} diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/MultipleServiceExporterPostProcessor.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/MultipleServiceExporterPostProcessor.java index b9e39f86c..74f4fb9db 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/MultipleServiceExporterPostProcessor.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/MultipleServiceExporterPostProcessor.java @@ -6,6 +6,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.argeo.slc.SlcException; import org.springframework.beans.BeansException; import org.springframework.beans.MutablePropertyValues; @@ -13,11 +15,16 @@ import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.core.Ordered; +import org.springframework.core.PriorityOrdered; import org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean; @SuppressWarnings(value = { "unchecked" }) public class MultipleServiceExporterPostProcessor implements - BeanFactoryPostProcessor { + BeanFactoryPostProcessor, PriorityOrdered { + private final static Log log = LogFactory + .getLog(MultipleServiceExporterPostProcessor.class); + private List interfaces = new ArrayList(); private Class osgiServiceFactoryClass = OsgiServiceFactoryBean.class; @@ -43,8 +50,13 @@ public class MultipleServiceExporterPostProcessor implements mpv.addPropertyValue("targetBeanName", beanName); RootBeanDefinition bd = new RootBeanDefinition( osgiServiceFactoryClass, mpv); + + String exporterBeanName = "osgiService." + beanName; + if (log.isDebugEnabled()) + log.debug("Registering OSGi service exporter " + + exporterBeanName); ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition( - "osgiService." + beanName, bd); + exporterBeanName, bd); } } @@ -56,4 +68,9 @@ public class MultipleServiceExporterPostProcessor implements this.osgiServiceFactoryClass = osgiServiceFactoryClass; } + @Override + public int getOrder() { + return Ordered.LOWEST_PRECEDENCE; + } + } -- 2.39.2