You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gn...@apache.org on 2018/01/16 07:34:00 UTC
svn commit: r1821218 - in /aries/trunk/blueprint:
blueprint-spring-extender/src/main/java/org/apache/aries/blueprint/spring/extender/
blueprint-spring-extender/src/test/ blueprint-spring-extender/src/test/java/
blueprint-spring-extender/src/test/java/o...
Author: gnodet
Date: Tue Jan 16 07:34:00 2018
New Revision: 1821218
URL: http://svn.apache.org/viewvc?rev=1821218&view=rev
Log:
[ARIES-1717] Untie Aries Blueprint Spring (extender) to specific Spring version
Added:
aries/trunk/blueprint/blueprint-spring-extender/src/main/java/org/apache/aries/blueprint/spring/extender/SpringXsdVersionResolver.java
aries/trunk/blueprint/blueprint-spring-extender/src/test/
aries/trunk/blueprint/blueprint-spring-extender/src/test/java/
aries/trunk/blueprint/blueprint-spring-extender/src/test/java/org/
aries/trunk/blueprint/blueprint-spring-extender/src/test/java/org/apache/
aries/trunk/blueprint/blueprint-spring-extender/src/test/java/org/apache/aries/
aries/trunk/blueprint/blueprint-spring-extender/src/test/java/org/apache/aries/blueprint/
aries/trunk/blueprint/blueprint-spring-extender/src/test/java/org/apache/aries/blueprint/spring/
aries/trunk/blueprint/blueprint-spring-extender/src/test/java/org/apache/aries/blueprint/spring/extender/
aries/trunk/blueprint/blueprint-spring-extender/src/test/java/org/apache/aries/blueprint/spring/extender/SpringXsdVersionResolverTest.java
Modified:
aries/trunk/blueprint/blueprint-spring-extender/src/main/java/org/apache/aries/blueprint/spring/extender/SpringOsgiExtension.java
aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BeansNamespaceHandler.java
aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java
Modified: aries/trunk/blueprint/blueprint-spring-extender/src/main/java/org/apache/aries/blueprint/spring/extender/SpringOsgiExtension.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring-extender/src/main/java/org/apache/aries/blueprint/spring/extender/SpringOsgiExtension.java?rev=1821218&r1=1821217&r2=1821218&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-spring-extender/src/main/java/org/apache/aries/blueprint/spring/extender/SpringOsgiExtension.java (original)
+++ aries/trunk/blueprint/blueprint-spring-extender/src/main/java/org/apache/aries/blueprint/spring/extender/SpringOsgiExtension.java Tue Jan 16 07:34:00 2018
@@ -99,7 +99,7 @@ public class SpringOsgiExtension impleme
writer.write("<blueprint xmlns=\"http://www.osgi.org/xmlns/blueprint/v1.0.0\"\n");
writer.write("\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
writer.write("\txmlns:bean=\"http://www.springframework.org/schema/beans\"\n");
- writer.write("\txsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\">\n");
+ writer.write("\txsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-" + SpringXsdVersionResolver.resolve() + ".xsd\">\n");
for (URL url : paths) {
writer.write("\t<bean:import resource=\"" + url.toString() + "\"/>\n");
}
Added: aries/trunk/blueprint/blueprint-spring-extender/src/main/java/org/apache/aries/blueprint/spring/extender/SpringXsdVersionResolver.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring-extender/src/main/java/org/apache/aries/blueprint/spring/extender/SpringXsdVersionResolver.java?rev=1821218&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-spring-extender/src/main/java/org/apache/aries/blueprint/spring/extender/SpringXsdVersionResolver.java (added)
+++ aries/trunk/blueprint/blueprint-spring-extender/src/main/java/org/apache/aries/blueprint/spring/extender/SpringXsdVersionResolver.java Tue Jan 16 07:34:00 2018
@@ -0,0 +1,54 @@
+/**
+ * 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.aries.blueprint.spring.extender;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.SpringVersion;
+
+/**
+ * Resolves spring xsd version.
+ *
+ */
+public class SpringXsdVersionResolver {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(SpringXsdVersionResolver.class);
+ private static final String DEFAULT_VERSION = "4.3"; // latest version
+ private static final Pattern PATTERN = Pattern.compile("^\\d*\\.\\d*");
+
+ /**
+ * It will call a Spring method that returns the full version. Expects
+ * format 4.2.2.RELEASE and 4.2 will be returned.
+ *
+ * @return String containing the xsd version.
+ */
+ public static String resolve() {
+ final String fullVersion = SpringVersion.getVersion();
+ if (fullVersion != null) {
+ final Matcher matcher = PATTERN.matcher(fullVersion);
+ if (matcher.find()) {
+ return matcher.group(0);
+ }
+ }
+ LOGGER.trace("Could not resolve xsd version from Spring's version {}", fullVersion);
+
+ return DEFAULT_VERSION;
+
+ }
+}
Added: aries/trunk/blueprint/blueprint-spring-extender/src/test/java/org/apache/aries/blueprint/spring/extender/SpringXsdVersionResolverTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring-extender/src/test/java/org/apache/aries/blueprint/spring/extender/SpringXsdVersionResolverTest.java?rev=1821218&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-spring-extender/src/test/java/org/apache/aries/blueprint/spring/extender/SpringXsdVersionResolverTest.java (added)
+++ aries/trunk/blueprint/blueprint-spring-extender/src/test/java/org/apache/aries/blueprint/spring/extender/SpringXsdVersionResolverTest.java Tue Jan 16 07:34:00 2018
@@ -0,0 +1,35 @@
+/**
+ * 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.aries.blueprint.spring.extender;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Resolves spring xsd version.
+ *
+ */
+public class SpringXsdVersionResolverTest {
+
+ @Test
+ public void testResolve() {
+ final String xsdVersion = SpringXsdVersionResolver.resolve();
+
+ Assert.assertThat(xsdVersion, equalTo("4.2"));
+ }
+}
Modified: aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BeansNamespaceHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BeansNamespaceHandler.java?rev=1821218&r1=1821217&r2=1821218&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BeansNamespaceHandler.java (original)
+++ aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BeansNamespaceHandler.java Tue Jan 16 07:34:00 2018
@@ -155,7 +155,7 @@ public class BeansNamespaceHandler imple
if (StringUtils.hasText(profileSpec)) {
String[] specifiedProfiles = StringUtils.tokenizeToStringArray(
profileSpec, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
- if (!getReaderContext().getEnvironment().acceptsProfiles(specifiedProfiles)) {
+ if (!getReaderContext().getReader().getEnvironment().acceptsProfiles(specifiedProfiles)) {
return;
}
}
@@ -230,7 +230,7 @@ public class BeansNamespaceHandler imple
}
// Resolve system properties: e.g. "${user.dir}"
- location = getReaderContext().getEnvironment().resolveRequiredPlaceholders(location);
+ location = getReaderContext().getReader().getEnvironment().resolveRequiredPlaceholders(location);
Set<Resource> actualResources = new LinkedHashSet<Resource>(4);
Modified: aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java?rev=1821218&r1=1821217&r2=1821218&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java (original)
+++ aries/trunk/blueprint/blueprint-spring/src/main/java/org/apache/aries/blueprint/spring/BlueprintNamespaceHandler.java Tue Jan 16 07:34:00 2018
@@ -42,6 +42,7 @@ import org.springframework.beans.factory
import org.springframework.beans.factory.parsing.ProblemReporter;
import org.springframework.beans.factory.parsing.ReaderEventListener;
import org.springframework.beans.factory.parsing.SourceExtractor;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
import org.springframework.beans.factory.xml.NamespaceHandlerResolver;
@@ -247,7 +248,7 @@ public class BlueprintNamespaceHandler i
private org.springframework.beans.factory.xml.ParserContext createSpringParserContext(ParserContext parserContext, DefaultListableBeanFactory registry) {
try {
- XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(registry);
+ SpringVersionBridgeXmlBeanDefinitionReader xbdr = new SpringVersionBridgeXmlBeanDefinitionReader(registry);
Resource resource = new UrlResource(parserContext.getSourceNode().getOwnerDocument().getDocumentURI());
ProblemReporter problemReporter = new FailFastProblemReporter();
ReaderEventListener listener = new EmptyReaderEventListener();
@@ -265,5 +266,20 @@ public class BlueprintNamespaceHandler i
}
}
+ /**
+ * Some methods are protected in Spring 3.x, hence overridden methods in this class to make them available.
+ */
+ private class SpringVersionBridgeXmlBeanDefinitionReader extends XmlBeanDefinitionReader {
+
+ public SpringVersionBridgeXmlBeanDefinitionReader(final BeanDefinitionRegistry registry) {
+ super(registry);
+ }
+
+ @Override
+ public XmlReaderContext createReaderContext(final Resource resource) {
+ return super.createReaderContext(resource);
+ }
+ }
+
}