You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2012/07/05 15:33:52 UTC
[1/2] git commit: DELTASPIKE-215 user defined property file
configuration
Updated Branches:
refs/heads/master 574570c35 -> 981260158
DELTASPIKE-215 user defined property file configuration
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/98126015
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/98126015
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/98126015
Branch: refs/heads/master
Commit: 981260158ac994268dd160113911b787d19431cc
Parents: ca029be
Author: Mark Struberg <st...@apache.org>
Authored: Thu Jul 5 15:10:51 2012 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Thu Jul 5 15:10:51 2012 +0200
----------------------------------------------------------------------
.../deltaspike/core/api/config/ConfigResolver.java | 3 +-
.../core/api/config/PropertyConfigSource.java | 1 -
.../core/impl/config/ConfigurationExtension.java | 13 +++-
.../services/javax.enterprise.inject.spi.Extension | 1 +
.../MyCustomPropertyConfigSource.java | 15 +++
.../PropertyConfigSourceTest.java | 71 +++++++++++++++
.../impl/src/test/resources/myconfig.properties | 3 +
7 files changed, 104 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/98126015/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
index 1ecb29c..d72ca69 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java
@@ -77,7 +77,8 @@ public final class ConfigResolver
ClassLoader currentClassLoader = ClassUtils.getClassLoader(null);
ConfigSource[] configuredConfigSources = configSources.get(currentClassLoader);
- List<ConfigSource> allConfigSources = Arrays.asList(configuredConfigSources);
+ List<ConfigSource> allConfigSources = new ArrayList<ConfigSource>();
+ allConfigSources.addAll(Arrays.asList(configuredConfigSources));
allConfigSources.addAll(configSourcesToAdd);
// finally put all the configSources back into the map
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/98126015/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/PropertyConfigSource.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/PropertyConfigSource.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/PropertyConfigSource.java
index e8cc243..2de247a 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/PropertyConfigSource.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/PropertyConfigSource.java
@@ -36,7 +36,6 @@ package org.apache.deltaspike.core.api.config;
* after the boot is finished. This means that you cannot use
* this configuration inside a CDI Extension before the boot
* is finished!</p>
- *
*/
public interface PropertyConfigSource extends DeltaSpikeConfig
{
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/98126015/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
index d43dc72..7418629 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/ConfigurationExtension.java
@@ -59,7 +59,18 @@ public class ConfigurationExtension implements Extension, Deactivatable
return;
}
- configSourcesClasses.add(pat.getAnnotatedType().getJavaClass());
+ Class<? extends PropertyConfigSource> pcsClass = pat.getAnnotatedType().getJavaClass();
+ if (pcsClass.isAnnotation() ||
+ pcsClass.isInterface() ||
+ pcsClass.isSynthetic() ||
+ pcsClass.isArray() ||
+ pcsClass.isEnum() )
+ {
+ // we only like to add real classes
+ return;
+ }
+
+ configSourcesClasses.add(pcsClass);
}
@SuppressWarnings("UnusedDeclaration")
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/98126015/deltaspike/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/deltaspike/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
index b251207..bdfba7b 100644
--- a/deltaspike/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
+++ b/deltaspike/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -20,3 +20,4 @@
org.apache.deltaspike.core.impl.exclude.extension.ExcludeExtension
org.apache.deltaspike.core.impl.message.MessageBundleExtension
org.apache.deltaspike.core.impl.exception.control.extension.ExceptionControlExtension
+org.apache.deltaspike.core.impl.config.ConfigurationExtension
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/98126015/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/MyCustomPropertyConfigSource.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/MyCustomPropertyConfigSource.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/MyCustomPropertyConfigSource.java
new file mode 100644
index 0000000..bceea1b
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/MyCustomPropertyConfigSource.java
@@ -0,0 +1,15 @@
+package org.apache.deltaspike.test.core.api.config.propertyconfigsource;
+
+import org.apache.deltaspike.core.api.config.PropertyConfigSource;
+
+/**
+ * Custom
+ */
+public class MyCustomPropertyConfigSource implements PropertyConfigSource
+{
+ @Override
+ public String getPropertyFileName()
+ {
+ return "myconfig.properties";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/98126015/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/PropertyConfigSourceTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/PropertyConfigSourceTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/PropertyConfigSourceTest.java
new file mode 100644
index 0000000..f09f533
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/config/propertyconfigsource/PropertyConfigSourceTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.deltaspike.test.core.api.config.propertyconfigsource;
+
+import org.apache.deltaspike.core.api.config.ConfigResolver;
+import org.apache.deltaspike.test.category.SeCategory;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.Assert;
+import org.junit.Test;
+
+@RunWith(Arquillian.class)
+@Category(SeCategory.class) //X TODO this is only SeCategory as there is currently an Arq problem with properties!
+public class PropertyConfigSourceTest
+{
+ private final static String CONFIG_FILE_NAME = "myconfig.properties";
+
+ /**
+ *X TODO creating a WebArchive is only a workaround because JavaArchive cannot contain other archives.
+ */
+ @Deployment
+ public static WebArchive deploy()
+ {
+ JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "PropertyConfigSourceTest.jar")
+ .addPackage(SeCategory.class.getPackage())
+ .addPackage(PropertyConfigSourceTest.class.getPackage())
+ .addAsResource(CONFIG_FILE_NAME)
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+
+ return ShrinkWrap.create(WebArchive.class, "beanProvider.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addAsLibraries(testJar)
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+
+ @Test
+ public void testCustomPropertyConfigSources() throws Exception
+ {
+ Assert.assertTrue(
+ Thread.currentThread().getContextClassLoader().getResources(CONFIG_FILE_NAME).hasMoreElements());
+
+ String value = ConfigResolver.getPropertyValue("some.propertykey");
+ Assert.assertNotNull(value);
+ Assert.assertEquals("somevalue", value);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/98126015/deltaspike/core/impl/src/test/resources/myconfig.properties
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/resources/myconfig.properties b/deltaspike/core/impl/src/test/resources/myconfig.properties
new file mode 100644
index 0000000..ecdc7ea
--- /dev/null
+++ b/deltaspike/core/impl/src/test/resources/myconfig.properties
@@ -0,0 +1,3 @@
+# a user defined property file
+
+some.propertykey = somevalue