BATCH-2144: Removed OSGi ApplicationContextFactory

This commit is contained in:
Michael Minella
2014-04-25 09:36:49 -05:00
parent 97e664bde0
commit 54b3fe0b3a
3 changed files with 10 additions and 196 deletions

View File

@@ -55,16 +55,15 @@ subprojects { subproject ->
springVersionDefault = '4.0.2.RELEASE'
springVersion = project.hasProperty('springVersion') ? getProperty('springVersion') : springVersionDefault
springRetryVersion = '1.0.2.RELEASE'
springRetryVersion = '1.0.3.RELEASE'
springAmqpVersion = '1.1.2.RELEASE'
springDataCommonsVersion = '1.5.0.RELEASE'
springDataGemfireVersion = '1.3.0.RELEASE'
springDataJpaVersion = '1.2.0.RELEASE'
springDataMongodbVersion = '1.1.0.RELEASE'
springDataNeo4jVersion = '2.2.0.RELEASE'
springDataRedisVersion = '1.0.3.RELEASE'
springIntegrationVersion = '4.0.0.RC1'
springOsgiCoreVersion = '1.1.2'
springLdapVersion = '2.0.1.RELEASE'
activemqVersion = '5.1.0'
aspectjVersion = '1.5.4'
@@ -77,7 +76,6 @@ subprojects { subproject ->
derbyVersion = '10.8.2.2'
groovyVersion = '1.6.3'
h2databaseVersion = '1.2.132'
hamcrestVersion = '1.3'
hibernateAnnotationsVersion = '3.3.1.GA'
hibernateVersion = '4.1.9.Final'
hibernateValidatorVersion = '4.3.1.Final'
@@ -94,7 +92,6 @@ subprojects { subproject ->
log4jVersion = '1.2.14'
mysqlVersion = '5.1.6'
mockitoVersion = '1.9.5'
osgiR4CoreVersion = '1.0'
postgresqlVersion = '8.3-603.jdbc3'
quartzVersion = '1.6.1'
servletApiVersion = '2.5'
@@ -215,13 +212,10 @@ project('spring-batch-core') {
testCompile "commons-io:commons-io:$commonsIoVersion"
testCompile "commons-dbcp:commons-dbcp:$commonsDdbcpVersion"
testCompile "junit:junit:$junitVersion"
//testCompile "org.hamcrest:hamcrest-all:$hamcrestVersion"
optional "org.aspectj:aspectjrt:$aspectjVersion"
optional "org.aspectj:aspectjweaver:$aspectjVersion"
optional "org.osgi:osgi_R4_core:$osgiR4CoreVersion"
optional "org.springframework:spring-jdbc:$springVersion"
optional "org.springframework.osgi:spring-osgi-core:$springOsgiCoreVersion"
optional "org.slf4j:slf4j-log4j12:$slf4jVersion"
optional "log4j:log4j:$log4jVersion"
@@ -293,13 +287,15 @@ project('spring-batch-infrastructure') {
optional "org.springframework.data:spring-data-mongodb:$springDataMongodbVersion"
optional "org.springframework.data:spring-data-neo4j:$springDataNeo4jVersion"
optional "org.springframework.data:spring-data-gemfire:$springDataGemfireVersion"
optional "org.springframework.data:spring-data-redis:$springDataRedisVersion"
compile("org.codehaus.woodstox:woodstox-core-asl:$woodstoxVersion") { dep ->
optional dep
exclude group: 'stax', module: 'stax-api'
}
optional "org.springframework.amqp:spring-amqp:$springAmqpVersion"
optional "org.springframework.amqp:spring-rabbit:$springAmqpVersion"
optional "org.springframework.ldap:spring-ldap-core:$springLdapVersion"
optional "org.springframework.ldap:spring-ldap-core-tiger:$springLdapVersion"
optional "org.springframework.ldap:spring-ldap-ldif-core:$springLdapVersion"
}
}
@@ -327,6 +323,9 @@ project('spring-batch-core-tests') {
optional "org.aspectj:aspectjrt:$aspectjVersion"
optional "org.aspectj:aspectjweaver:$aspectjVersion"
optional "cglib:cglib-nodep:$cglibVersion"
optional "org.springframework.ldap:spring-ldap-core:$springLdapVersion"
optional "org.springframework.ldap:spring-ldap-core-tiger:$springLdapVersion"
optional "org.springframework.ldap:spring-ldap-ldif-core:$springLdapVersion"
}
test {
enabled = project.hasProperty('alltests') ? true : false
@@ -412,9 +411,9 @@ project('spring-batch-test') {
compile "org.springframework:spring-test:$springVersion"
compile "org.springframework:spring-jdbc:$springVersion"
compile "commons-io:commons-io:$commonsIoVersion"
compile "commons-dbcp:commons-dbcp:$commonsDdbcpVersion"
compile "commons-collections:commons-collections:$commonsCollectionsVersion"
testCompile "commons-dbcp:commons-dbcp:$commonsDdbcpVersion"
testCompile "org.hsqldb:hsqldb:$hsqldbVersion"
optional "org.aspectj:aspectjrt:$aspectjVersion"
@@ -533,6 +532,7 @@ project('spring-batch-samples') {
optional "org.springframework.data:spring-data-commons:$springDataCommonsVersion"
optional "org.springframework.amqp:spring-amqp:$springAmqpVersion"
optional "org.springframework.amqp:spring-rabbit:$springAmqpVersion"
optional "javax.inject:javax.inject:1"
}
}

View File

@@ -1,120 +0,0 @@
/*
* Copyright 2006-2013 the original author or authors.
*
* Licensed 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.springframework.batch.core.configuration.support;
import org.osgi.framework.BundleContext;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.osgi.context.BundleContextAware;
import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
/**
* {@link ApplicationContextFactory} that can be used to load a context from an
* XML location in a bundle.
*
* @author Dave Syer
*
*/
public class OsgiBundleXmlApplicationContextFactory implements BundleContextAware, ApplicationContextFactory,
ApplicationContextAware {
private BundleContext bundleContext;
private ApplicationContext parent;
private String path;
private String displayName;
/**
* @param path the resource path to the xml to load for the child context.
*/
public void setPath(String path) {
this.path = path;
}
/**
* @param displayName the display name for the application context created.
*/
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
/**
* Setter for the parent application context.
*
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
parent = applicationContext;
}
/**
* Stash the {@link BundleContext} for creating a job application context
* later.
*
* @see org.springframework.osgi.context.BundleContextAware#setBundleContext(org.osgi.framework.BundleContext)
*/
@Override
public void setBundleContext(BundleContext context) {
this.bundleContext = context;
}
/**
* Create an application context from the provided path, using the current
* OSGi {@link BundleContext} and the enclosing Spring
* {@link ApplicationContext} as a parent context.
*
* @see ApplicationContextFactory#createApplicationContext()
*/
@Override
public ConfigurableApplicationContext createApplicationContext() {
OsgiBundleXmlApplicationContext context = new OsgiBundleXmlApplicationContext(new String[] { path }, parent);
String displayName = bundleContext.getBundle().getSymbolicName() + ":" + this.displayName;
context.setDisplayName(displayName);
context.setBundleContext(bundleContext);
context.refresh();
return context;
}
@Override
public String toString() {
String bundleId = bundleContext == null ? null : (bundleContext.getBundle() == null ? bundleContext.toString()
: "" + bundleContext.getBundle().getBundleId());
return "OsgiBundleXmlApplicationContext [path=" + path + ", bundle=" + bundleId + "]";
}
@Override
public int hashCode() {
return toString().hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
return toString().equals(obj.toString());
}
}

View File

@@ -1,66 +0,0 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed 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.springframework.batch.core.configuration.support;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.springframework.util.ClassUtils;
/**
* @author Dave Syer
* @author Will Schipp
*
*/
public class OsgiBundleXmlApplicationContextFactoryTests {
private OsgiBundleXmlApplicationContextFactory factory = new OsgiBundleXmlApplicationContextFactory();
/**
* Test method for {@link org.springframework.batch.core.configuration.support.OsgiBundleXmlApplicationContextFactory#setDisplayName(java.lang.String)}.
*/
@Test
public void testSetDisplayName() {
factory.setDisplayName("foo");
factory.setPath("classpath:"+ClassUtils.addResourcePathToPackagePath(getClass(), "trivial-context.xml"));
BundleContext bundleContext = mock(BundleContext.class);
Bundle bundle = mock(Bundle.class);
when(bundleContext.getBundle()).thenReturn(bundle);
factory.setBundleContext(bundleContext);
// factory.createApplicationContext();
}
@Test
public void testEquals() throws Exception {
factory.setPath("child-context.xml");
OsgiBundleXmlApplicationContextFactory other = new OsgiBundleXmlApplicationContextFactory();
other.setPath("child-context.xml");
assertEquals(other, factory);
assertEquals(other.hashCode(), factory.hashCode());
}
/**
* Test method for {@link org.springframework.batch.core.configuration.support.OsgiBundleXmlApplicationContextFactory#setApplicationContext(org.springframework.context.ApplicationContext)}.
*/
@Test
public void testSetApplicationContext() {
}
}