Author: rmannibucau Date: Wed Mar 20 10:21:43 2013 New Revision: 1458720 URL: http://svn.apache.org/r1458720 Log: TOMEE-137 more logic to not override properties set through arquillian.xml - otherwise dynamic port feature is totally broken
Modified: tomee/tomee/trunk/arquillian/arquillian-tck/src/test/resources/arquillian.xml tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ConfigurationOverrides.java tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/test/java/org/apache/openejb/arquillian/common/ConfigurationOverridesTest.java tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/main/resources/default.arquillian-tomee-remote.properties Modified: tomee/tomee/trunk/arquillian/arquillian-tck/src/test/resources/arquillian.xml URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tck/src/test/resources/arquillian.xml?rev=1458720&r1=1458719&r2=1458720&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tck/src/test/resources/arquillian.xml (original) +++ tomee/tomee/trunk/arquillian/arquillian-tck/src/test/resources/arquillian.xml Wed Mar 20 10:21:43 2013 @@ -27,6 +27,7 @@ <property name="dir">target/apache-tomee-remote</property> <property name="appWorkingDir">target/arquillian-test-working-dir</property> <property name="cleanOnStartUp">true</property> + <property name="simpleLog">true</property> </configuration> </container> </arquillian> Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ConfigurationOverrides.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ConfigurationOverrides.java?rev=1458720&r1=1458719&r2=1458720&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ConfigurationOverrides.java (original) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ConfigurationOverrides.java Wed Mar 20 10:21:43 2013 @@ -32,13 +32,18 @@ import java.util.logging.Logger; public class ConfigurationOverrides { protected static final Logger LOGGER = Logger.getLogger(TomEEContainer.class.getName()); - public static void apply(Object configuration, final Properties systemProperties, String... prefixes) { - final List<URL> urls = findPropertiesFiles(prefixes); + public static List<URL> apply(Object configuration, final Properties systemProperties, String... prefixes) { + final List<URL> propertiesFiles = findPropertiesFiles("default.arquillian-%s.properties", prefixes); + apply(configuration, systemProperties, propertiesFiles, false, prefixes); - apply(configuration, systemProperties, urls, prefixes); + final List<URL> overridePropFiles = findPropertiesFiles("arquillian-%s.properties", prefixes); + apply(configuration, systemProperties, overridePropFiles, true, prefixes); + + propertiesFiles.addAll(overridePropFiles); + return propertiesFiles; } - public static void apply(final Object configuration, final Properties systemProperties, final List<URL> urls, final String... prefixes) { + public static void apply(final Object configuration, final Properties systemProperties, final List<URL> urls, final boolean overrideNotNull, final String... prefixes) { final List<Properties> propertiesList = read(urls); final Properties defaults = new Properties(); @@ -52,7 +57,7 @@ public class ConfigurationOverrides { for (Map.Entry<Object, Object> entry : defaults.entrySet()) { final String key = entry.getKey().toString(); final String value = entry.getValue().toString(); - setProperty(map, key, key, value, Level.FINE); + setProperty(map, key, key, value, Level.FINE, overrideNotNull); } // @@ -63,7 +68,7 @@ public class ConfigurationOverrides { final String property = prefix + "." + key; final String value = systemProperties.getProperty(property); - setProperty(map, key, property, value, Level.INFO); + setProperty(map, key, property, value, Level.INFO, overrideNotNull); } } } @@ -80,20 +85,16 @@ public class ConfigurationOverrides { return propertiesList; } - public static List<URL> findPropertiesFiles(String... prefixes) { + public static List<URL> findPropertiesFiles(final String name, final String... prefixes) { final List<URL> urls = new ArrayList<URL>(); final ClassLoader loader = Thread.currentThread().getContextClassLoader(); for (String prefix : prefixes) { - final String resourceName = String.format("default.arquillian-%s.properties", prefix.replace('.', '-')); + final String resourceName = String.format(name, prefix.replace('.', '-')); addResources(urls, loader, resourceName); } - for (String prefix : prefixes) { - final String resourceName = String.format("arquillian-%s.properties", prefix.replace('.', '-')); - addResources(urls, loader, resourceName); - } return urls; } @@ -108,12 +109,17 @@ public class ConfigurationOverrides { } } - private static void setProperty(ObjectMap map, String key, String property, String value, final Level info) { + private static void setProperty(ObjectMap map, String key, String property, String value, final Level info, final boolean overrideNotNull) { if (value == null) { LOGGER.log(Level.FINE, String.format("Unset '%s'", property)); return; } + if (!overrideNotNull && !isNull(map.get(key))) { + LOGGER.log(Level.FINE, String.format("Unset '%s' because already set", property)); + return; + } + try { LOGGER.log(info, String.format("Applying override '%s=%s'", property, value)); map.put(key, value); @@ -129,4 +135,11 @@ public class ConfigurationOverrides { } } } + + private static boolean isNull(final Object o) { + if (Number.class.isInstance(o)) { + return Number.class.cast(o).intValue() == 0; + } + return o == null; + } } Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/test/java/org/apache/openejb/arquillian/common/ConfigurationOverridesTest.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/test/java/org/apache/openejb/arquillian/common/ConfigurationOverridesTest.java?rev=1458720&r1=1458719&r2=1458720&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/test/java/org/apache/openejb/arquillian/common/ConfigurationOverridesTest.java (original) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/test/java/org/apache/openejb/arquillian/common/ConfigurationOverridesTest.java Wed Mar 20 10:21:43 2013 @@ -19,6 +19,7 @@ package org.apache.openejb.arquillian.co import junit.framework.TestCase; import java.net.URL; +import java.util.Collection; import java.util.List; import java.util.Properties; @@ -33,10 +34,15 @@ public class ConfigurationOverridesTest * * Do not change the order * + * Note: the order is guaranteed by org.apache.openejb.arquillian.common.ConfigurationOverrides#apply(java.lang.Object, java.util.Properties, java.lang.String...) + * because it needs to know if we work on a default or not property file + * to be able to not override already set properties with defaults ones + * * @throws Exception */ public void testFindPropertiesFiles() throws Exception { - final List<URL> color = ConfigurationOverrides.findPropertiesFiles("color", "color.orange"); + String[] prefixes = { "color", "color.orange" }; + final List<URL> color = ConfigurationOverrides.apply(new Color(), new Properties(), prefixes); assertEquals(4, color.size()); assertTrue(color.get(0).toExternalForm().endsWith("/default.arquillian-color.properties")); Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/main/resources/default.arquillian-tomee-remote.properties URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/main/resources/default.arquillian-tomee-remote.properties?rev=1458720&r1=1458719&r2=1458720&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/main/resources/default.arquillian-tomee-remote.properties (original) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/main/resources/default.arquillian-tomee-remote.properties Wed Mar 20 10:21:43 2013 @@ -14,16 +14,21 @@ # See the License for the specific language governing permissions and # limitations under the License. # -ajpPort=8009 artifactId=apache-tomee classifier=webprofile cleanOnStartUp=false -debugPort=5005 exportConfAsSystemProperty=false groupId=${pom.groupId} host=localhost -httpPort=8080 stopHost=localhost -stopPort=8005 type=zip version=${pom.version} + +# PLEASE NEVER SET IT +# Otherwise arquillian.xml is totally broken +# +# ajpPort=8009 +# debugPort=5005 +# httpPort=8080 +# stopPort=8005 +