]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java
Make sure Spring context will be properly closed
[gpl/argeo-slc.git] / org.argeo.slc.agent / src / main / java / org / argeo / slc / ant / AntSlcApplication.java
index 7c85fc2397ca9d921ccb148ba55951648521208e..b6c98ebbc3e44f6c571783fd190c05a0c8ce0872 100644 (file)
@@ -32,7 +32,6 @@ import org.springframework.beans.factory.BeanFactoryUtils;
 import org.springframework.beans.factory.ListableBeanFactory;
 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.context.ApplicationContext;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.support.GenericApplicationContext;
 import org.springframework.core.io.DefaultResourceLoader;
@@ -68,29 +67,32 @@ public class AntSlcApplication {
                        log.debug("workDir=" + workDir);
                }
 
-               // Spring initialization
-               ConfigurableApplicationContext ctx = createExecutionContext(slcExecution);
-
                // Ant coordinates
                String scriptRelativePath = findAntScript(slcExecution);
                List<String> targets = findAntTargets(slcExecution);
 
+               // Spring initialization
+               ConfigurableApplicationContext ctx = createExecutionContext(slcExecution);
+
                // Ant project initialization
                Project project = new Project();
                AntExecutionContext executionContext = new AntExecutionContext(project);
                project.addReference(AntConstants.REF_ROOT_CONTEXT, ctx);
                project.addReference(AntConstants.REF_SLC_EXECUTION, slcExecution);
-               initProject(project, properties, references);
-               parseProject(project, scriptRelativePath);
 
-               // Execute project
-               initStructure(project, scriptRelativePath);
-               runProject(project, targets);
+               try {
+                       initProject(project, properties, references);
+                       parseProject(project, scriptRelativePath);
 
-               if (executionOutput != null)
-                       executionOutput.postExecution(executionContext);
+                       // Execute project
+                       initStructure(project, scriptRelativePath);
+                       runProject(project, targets);
 
-               ctx.close();
+                       if (executionOutput != null)
+                               executionOutput.postExecution(executionContext);
+               } finally {
+                       ctx.close();
+               }
        }
 
        protected void initSystemProperties(Properties userProperties) {