Skip to content

Commit

Permalink
ARQ-1513 Multicontainer extension should not log warnings about its p…
Browse files Browse the repository at this point in the history
…roperty
  • Loading branch information
Stefan Miklosovic committed Oct 5, 2013
1 parent 3e10025 commit 6c0177f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 23 deletions.
Expand Up @@ -44,9 +44,9 @@
/**
* This class registers all adapters which are specified in the arquillian.xml.
*
* In the case there is only one adapter implementation on the classpath, it is not necessary to specify it in the
* container configuration since it will be used automatically. You have to specify it only in the case you are going to
* use more than one container.
* In the case there is only one adapter implementation on the classpath, it is not necessary to specify it in the container
* configuration since it will be used automatically. You have to specify it only in the case you are going to use more than one
* container.
*
* @author Dominik Pospisil <dpospisi@redhat.com>
* @author Stefan Miklosovic <smikloso@redhat.com>
Expand Down Expand Up @@ -83,20 +83,44 @@ public Container create(ContainerDef definition, ServiceLoader loader) {
}

if (services.size() == 1) {
// just one container on cp
dcService = services.iterator().next();
} else {
Map<String, String> props = definition.getContainerProperties();
if (!props.containsKey("adapterImplClass")) {
throw new ConfigurationException("Container adapter implementation class must be provided via "
+ ADAPTER_IMPL_CONFIG_STRING + " property.");
dcService = guessDeployableContainer(definition, services);

// there are two containers but we failed to guess the current one, we are
// pretty sure it is not android or any one we can guess
if (dcService == null && services.size() == 2 && isAndroidContainerRegistered()) {
for (DeployableContainer<?> service : services) {
if (!service.getClass().getName().equals("org.arquillian.droidium.container.AndroidDeployableContainer")) {
dcService = service;
}
}
}

Class<?> dcImplClass = Class.forName(props.get(ADAPTER_IMPL_CONFIG_STRING));
// >= 2 containers and none of them is Android, we just stick to adapterImplClass property
if (dcService == null) {
Map<String, String> props = definition.getContainerProperties();
if (!props.containsKey(ADAPTER_IMPL_CONFIG_STRING)) {
logger.log(Level.WARNING, "Unable to get container adapter class for container with "
+ "qualifier {0}. It is expected that you pass {1} property with class name which implements "
+ "DeployableContainer interface for given container definition. It is not necessary to "
+ "specify adapterImplClass property in case your container qualifier name in arquillian.xml, "
+ "after lowercasing, contains or is equal to string: android, jboss, glassfish, tomee, openshift. "
+ "It is expected that when you name your container like that, you put Arquillian container "
+ "adapter for that container on the classpath.",
new Object[] { definition.getContainerName(), ADAPTER_IMPL_CONFIG_STRING });
throw new ConfigurationException("Container adapter implementation class must be provided via "
+ ADAPTER_IMPL_CONFIG_STRING + " property.");
}

for (DeployableContainer<?> dc : services) {
if (dcImplClass.isInstance(dc)) {
dcService = dc;
break;
Class<?> dcImplClass = Class.forName(props.get(ADAPTER_IMPL_CONFIG_STRING));

for (DeployableContainer<?> dc : services) {
if (dcImplClass.isInstance(dc)) {
dcService = dc;
break;
}
}
}
}
Expand All @@ -112,9 +136,50 @@ public Container create(ContainerDef definition, ServiceLoader loader) {
}
}

@Override
public Container getContainer(String name) {
return findMatchingContainer(name);
@SuppressWarnings("rawtypes")
private DeployableContainer<?> guessDeployableContainer(ContainerDef definition, Collection<DeployableContainer> services) {

Map<String, String> properties = definition.getContainerProperties();
String containerName = definition.getContainerName().toLowerCase();
DeployableContainer<?> container = null;

if (containerName.contains("android")
|| properties.containsKey("avdName")
|| properties.containsKey("serialId")
|| properties.containsKey("consolePort")
|| properties.containsKey("emulatorOptions")) {
container = parseContainer("org.arquillian.droidium.container.AndroidDeployableContainer", services);
} else if (containerName.contains("jboss")) {
container = parseContainer("org.jboss.as.arquillian.container", services);
} else if (containerName.contains("glassfish")) {
container = parseContainer("org.jboss.arquillian.container.glassfish", services);
} else if (containerName.contains("tomee")) {
container = parseContainer("org.apache.openejb.arquillian", services);
} else if (containerName.contains("openshift")) {
container = parseContainer("org.jboss.arquillian.container.openshift", services);
}

return container;
}

@SuppressWarnings("rawtypes")
private DeployableContainer<?> parseContainer(String className, Collection<DeployableContainer> services) {
for (DeployableContainer<?> container : services) {
if (container.getClass().getName().startsWith(className)) {
return container;
}
}
return null;
}

private boolean isAndroidContainerRegistered() {
for (Container container : containers) {
if (container.getDeployableContainer().getConfigurationClass().getName().equals(
"org.arquillian.droidium.container.configuration.AndroidContainerConfiguration")) {
return true;
}
}
return false;
}

@Override
Expand Down Expand Up @@ -157,4 +222,9 @@ private Container findMatchingContainer(String name) {
return null;
}

@Override
public Container getContainer(String name) {
return findMatchingContainer(name);
}

}
Expand Up @@ -14,15 +14,12 @@
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<!-- Container configuration -->
<!-- Since more then one container adapter is on classpath, you have to specify
adapterImplClass for each container manually. -->
<group qualifier="containers" default="true">
<container qualifier="android" default="true">
<configuration>
<!-- Name of Android container to start or use during tests. This property is filtered
meaning it is set in profile in pom.xml under the same name of the property. -->
<property name="avdName">${android.avd.name}</property>
<property name="adapterImplClass">org.arquillian.droidium.container.AndroidDeployableContainer</property>
<property name="emulatorOptions">${android.emulator.options}</property>
<property name="emulatorBootupTimeoutInSeconds">600</property>
<property name="logType">disable</property>
Expand All @@ -33,7 +30,6 @@
<container qualifier="jbossas">
<configuration>
<property name="jbossHome">${basedir}/target/jboss-as-7.1.1.Final</property>
<property name="adapterImplClass">org.jboss.as.arquillian.container.managed.ManagedDeployableContainer</property>
</configuration>
</container>
</group>
Expand Down
4 changes: 0 additions & 4 deletions tests/droidium-web-01/src/test/resources/arquillian.xml
Expand Up @@ -14,8 +14,6 @@
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<!-- Container configuration -->
<!-- Since more then one container adapter is on classpath, you have to specify
adapterImplClass for each container manually. -->
<group qualifier="containers" default="true">
<container qualifier="android" default="true">
<configuration>
Expand All @@ -27,7 +25,6 @@
<property name="logType">disable</property>
<property name="droneGuestPort">8080</property>
<property name="droneHostPort">8080</property>
<property name="adapterImplClass">org.arquillian.droidium.container.AndroidDeployableContainer</property>
</configuration>
</container>

Expand All @@ -36,7 +33,6 @@
<configuration>
<property name="jbossHome">${basedir}/target/jboss-as-7.1.1.Final</property>
<property name="javaVmArguments">-Xmx512m -XX:MaxPermSize=128m -Djboss.bind.address=${as.bind.ip}</property>
<property name="adapterImplClass">org.jboss.as.arquillian.container.managed.ManagedDeployableContainer</property>
</configuration>
</container>
</group>
Expand Down

0 comments on commit 6c0177f

Please sign in to comment.