You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streams.apache.org by sb...@apache.org on 2018/02/06 17:17:49 UTC
[streams] branch STREAMS-580 updated: support class hierarchy and
package hierarchy resolution
This is an automated email from the ASF dual-hosted git repository.
sblackmon pushed a commit to branch STREAMS-580
in repository https://gitbox.apache.org/repos/asf/streams.git
The following commit(s) were added to refs/heads/STREAMS-580 by this push:
new 5753828 support class hierarchy and package hierarchy resolution
5753828 is described below
commit 57538281f957e56bb43cc33fc6c054bac68bf9c9
Author: Steve Blackmon @steveblackmon <sb...@apache.org>
AuthorDate: Tue Feb 6 11:17:41 2018 -0600
support class hierarchy and package hierarchy resolution
---
.../streams/config/ComponentConfigurator.java | 23 +++++++++++++++++-
streams-config/src/main/resources/reference.conf | 4 ++++
.../config/test/ComponentConfiguratorTest.java | 27 ++++++++++++++++++++--
.../{ancestry.conf => classHierarchy.conf} | 0
.../src/test/resources/componentTest.conf | 11 ++-------
.../{ancestry.conf => packageHierarchy.conf} | 6 ++---
6 files changed, 56 insertions(+), 15 deletions(-)
diff --git a/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java b/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
index e60f087..aa17d36 100644
--- a/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
+++ b/streams-config/src/main/java/org/apache/streams/config/ComponentConfigurator.java
@@ -61,7 +61,9 @@ public class ComponentConfigurator<T extends Serializable> {
* the entire object, or fragments of it, will be collected and merged from:
* - the simple class name of the configured class
* - the fully qualified class name of the configured class
- * - any of the ancestor packages of the configured class
+ * - any of the ancestor classes of the configured class
+ * - the configured class's package
+ * - any of the parent packages of the configured class's package
*
* @return result
*/
@@ -87,6 +89,25 @@ public class ComponentConfigurator<T extends Serializable> {
}
}
+ String[] canonicalNameParts = StringUtils.split(configClass.getCanonicalName(), '.');
+
+ for( int partIndex = 1; partIndex < canonicalNameParts.length; partIndex++) {
+ String[] partialPathParts = ArrayUtils.subarray(canonicalNameParts, 0, partIndex);
+ String partialPath = StringUtils.join(partialPathParts, '.');
+
+ if( rootConfig.hasPath(partialPath) ) {
+ Config partialPathConfig = rootConfig.getConfig(partialPath).withoutPath(canonicalNameParts[partIndex]);
+ if( !partialPathConfig.root().isEmpty()) {
+ if (cascadeConfig == null) {
+ cascadeConfig = partialPathConfig;
+ } else {
+ cascadeConfig = partialPathConfig.withFallback(cascadeConfig);
+ }
+ }
+ }
+
+ }
+
if( rootConfig.hasPath(configClass.getSimpleName()) ) {
Config simpleNameConfig = rootConfig.getConfig(configClass.getSimpleName());
if( cascadeConfig == null ) {
diff --git a/streams-config/src/main/resources/reference.conf b/streams-config/src/main/resources/reference.conf
index 67e36af..6e83394 100644
--- a/streams-config/src/main/resources/reference.conf
+++ b/streams-config/src/main/resources/reference.conf
@@ -9,3 +9,7 @@ queueSize = 1000
shutdownCheckDelay = 1000
shutdownCheckInterval = 1000
startedAt = -1
+defaultComponent {
+ inClasses = [ "java.lang.Object" ]
+ outClasses = [ "java.lang.Object" ]
+}
diff --git a/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java b/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
index 1903652..765758a 100644
--- a/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
+++ b/streams-config/src/test/java/org/apache/streams/config/test/ComponentConfiguratorTest.java
@@ -195,9 +195,9 @@ public class ComponentConfiguratorTest {
}
@Test
- public void testDetectConfigurationAncestory() throws Exception {
+ public void testDetectConfigurationClassHierarchy() throws Exception {
- Config testConfig = ConfigFactory.parseResourcesAnySyntax("ancestry.conf");
+ Config testConfig = ConfigFactory.parseResourcesAnySyntax("classHierarchy.conf");
StreamsConfigurator.setConfig(testConfig);
@@ -217,4 +217,27 @@ public class ComponentConfiguratorTest {
}
+ @Test
+ public void testDetectConfigurationPackageHierarchy() throws Exception {
+
+ Config testConfig = ConfigFactory.parseResourcesAnySyntax("packageHierarchy.conf");
+
+ StreamsConfigurator.setConfig(testConfig);
+
+ ComponentConfigurator<ComponentConfiguration> configurator = new ComponentConfigurator(ComponentConfiguration.class);
+
+ ComponentConfiguration configuredPojo = configurator.detectConfiguration();
+
+ Assert.assertThat(configuredPojo, is(notNullValue()));
+
+ Assert.assertThat(configuredPojo.getInClasses(), is(notNullValue()));
+ Assert.assertThat(configuredPojo.getInClasses().size(), is(greaterThan(0)));
+ Assert.assertThat(configuredPojo.getInClasses().get(0), equalTo("java.lang.Integer"));
+
+ Assert.assertThat(configuredPojo.getOutClasses(), is(notNullValue()));
+ Assert.assertThat(configuredPojo.getOutClasses().size(), is(greaterThan(0)));
+ Assert.assertThat(configuredPojo.getOutClasses().get(0), equalTo("java.lang.Float"));
+
+ }
+
}
\ No newline at end of file
diff --git a/streams-config/src/test/resources/ancestry.conf b/streams-config/src/test/resources/classHierarchy.conf
similarity index 100%
copy from streams-config/src/test/resources/ancestry.conf
copy to streams-config/src/test/resources/classHierarchy.conf
diff --git a/streams-config/src/test/resources/componentTest.conf b/streams-config/src/test/resources/componentTest.conf
index 83b1155..ec864dc 100644
--- a/streams-config/src/test/resources/componentTest.conf
+++ b/streams-config/src/test/resources/componentTest.conf
@@ -13,14 +13,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-defaultComponent {
-
-}
configuredComponent {
- inClasses = [
- java.lang.String
- ]
- outClasses = [
- java.lang.String
- ]
+ inClasses = [ "java.lang.Object" ]
+ outClasses = [ "java.lang.Object" ]
}
diff --git a/streams-config/src/test/resources/ancestry.conf b/streams-config/src/test/resources/packageHierarchy.conf
similarity index 52%
rename from streams-config/src/test/resources/ancestry.conf
rename to streams-config/src/test/resources/packageHierarchy.conf
index d95176a..a765833 100644
--- a/streams-config/src/test/resources/ancestry.conf
+++ b/streams-config/src/test/resources/packageHierarchy.conf
@@ -1,4 +1,4 @@
-org.apache.streams.config.ComponentConfiguration = {
+org.apache = {
inClasses = [
"java.lang.Object"
]
@@ -6,7 +6,7 @@ org.apache.streams.config.ComponentConfiguration = {
"java.lang.Object"
]
}
-org.apache.streams.config.test.ComponentConfigurationForTestingNumberOne = {
+org.apache.streams = {
inClasses = [
"java.lang.Integer"
]
@@ -14,7 +14,7 @@ org.apache.streams.config.test.ComponentConfigurationForTestingNumberOne = {
"java.lang.Integer"
]
}
-org.apache.streams.config.test.ComponentConfigurationForTestingNumberTwo = {
+org.apache.streams.config = {
outClasses = [
"java.lang.Float"
]
--
To stop receiving notification emails like this one, please contact
sblackmon@apache.org.