Skip to content

Commit

Permalink
[AS7-2824] Bundles directory not resolved correctly with multi folder…
Browse files Browse the repository at this point in the history
… module-path definition
  • Loading branch information
Thomas Diesler authored and kabir committed Jan 25, 2012
1 parent 0ffd5ec commit cdb3b1d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
Expand Up @@ -16,8 +16,9 @@
*/
package org.jboss.as.arquillian.container.managed;

import static org.jboss.as.arquillian.container.Authentication.password;
import static org.jboss.as.arquillian.container.Authentication.username;
import org.jboss.arquillian.container.spi.client.container.LifecycleException;
import org.jboss.as.arquillian.container.CommonDeployableContainer;
import org.jboss.sasl.util.UsernamePasswordHashUtil;

import java.io.BufferedReader;
import java.io.File;
Expand All @@ -33,9 +34,8 @@
import java.util.concurrent.TimeoutException;
import java.util.logging.Logger;

import org.jboss.arquillian.container.spi.client.container.LifecycleException;
import org.jboss.as.arquillian.container.CommonDeployableContainer;
import org.jboss.sasl.util.UsernamePasswordHashUtil;
import static org.jboss.as.arquillian.container.Authentication.password;
import static org.jboss.as.arquillian.container.Authentication.username;

/**
* JBossAsManagedContainer
Expand Down Expand Up @@ -72,8 +72,8 @@ private static boolean processHasDied(final Process process) {
protected void startInternal() throws LifecycleException {
ManagedContainerConfiguration config = getContainerConfiguration();

if(isServerRunning()) {
if(config.isAllowConnectingToRunningServer()) {
if (isServerRunning()) {
if (config.isAllowConnectingToRunningServer()) {
return;
} else {
failDueToRunning();
Expand All @@ -82,12 +82,19 @@ protected void startInternal() throws LifecycleException {

try {
final String jbossHomeDir = config.getJbossHome();
final String modulePath;
if(config.getModulePath() != null && !config.getModulePath().isEmpty()) {
modulePath = config.getModulePath();
} else {
modulePath = jbossHomeDir + File.separatorChar + "modules";
String modulesPath = config.getModulePath();
if (modulesPath == null || modulesPath.isEmpty()) {
modulesPath = jbossHomeDir + File.separatorChar + "modules";
}
File modulesDir = new File(modulesPath);
if (modulesDir.isDirectory() == false)
throw new IllegalStateException("Cannot find: " + modulesDir);

String bundlesPath = modulesDir.getParent() + File.separator + "bundles";
File bundlesDir = new File(bundlesPath);
if (bundlesDir.isDirectory() == false)
throw new IllegalStateException("Cannot find: " + bundlesDir);

final String additionalJavaOpts = config.getJavaVmArguments();

File modulesJar = new File(jbossHomeDir + File.separatorChar + "jboss-modules.jar");
Expand All @@ -108,18 +115,19 @@ protected void startInternal() throws LifecycleException {
}
}

if(config.isEnableAssertions()) {
if (config.isEnableAssertions()) {
cmd.add("-ea");
}

cmd.add("-Djboss.home.dir=" + jbossHomeDir);
cmd.add("-Dorg.jboss.boot.log.file=" + jbossHomeDir + "/standalone/log/boot.log");
cmd.add("-Dlogging.configuration=file:" + jbossHomeDir + CONFIG_PATH + "logging.properties");
cmd.add("-Djboss.modules.dir=" + modulePath);
cmd.add("-Djboss.modules.dir=" + modulesDir.getCanonicalPath());
cmd.add("-Djboss.bundles.dir=" + bundlesDir.getCanonicalPath());
cmd.add("-jar");
cmd.add(modulesJar.getAbsolutePath());
cmd.add("-mp");
cmd.add(modulePath);
cmd.add(modulesPath);
cmd.add("-jaxpmodule");
cmd.add("javax.xml.jaxp-provider");
cmd.add("org.jboss.as.standalone");
Expand Down Expand Up @@ -158,7 +166,7 @@ public void run() {
break;
Thread.sleep(sleep);
timeout -= sleep;
sleep = Math.max(sleep/2, 100);
sleep = Math.max(sleep / 2, 100);
}
}
if (!serverAvailable) {
Expand All @@ -185,8 +193,7 @@ protected void stopInternal() throws LifecycleException {
}
} catch (Exception e) {
throw new LifecycleException("Could not stop container", e);
}
finally {
} finally {
removeTempAuthConfigurationIfAuthNotDefined();
}
}
Expand Down Expand Up @@ -270,10 +277,10 @@ private void createTempAuthConfigurationIfAuthNotDefined(ManagedContainerConfigu

File usersFile = new File(jbossHomeDir + CONFIG_PATH + MGMT_USERS_FILE);

if(config.getUsername() == null) {
if (config.getUsername() == null) {
File tmpUsersFile = new File(jbossHomeDir + CONFIG_PATH + MGMT_USERS_TMP_FILE);
if(usersFile.exists()) {
if(!usersFile.renameTo(tmpUsersFile)) {
if (usersFile.exists()) {
if (!usersFile.renameTo(tmpUsersFile)) {
throw new IllegalStateException("Could not rename " + usersFile + " to " + tmpUsersFile + ". " +
"Unable to start server with custom security. " +
"Please setup a management user manually and provide username/password in the Arquillian configuration.");
Expand All @@ -290,7 +297,7 @@ private void createTempAuthConfigurationIfAuthNotDefined(ManagedContainerConfigu
private void removeTempAuthConfigurationIfAuthNotDefined() {
final String jbossHomeDir = getContainerConfiguration().getJbossHome();
File tmpUsersFile = new File(jbossHomeDir, CONFIG_PATH + MGMT_USERS_TMP_FILE);
if(tmpUsersFile.exists() && getContainerConfiguration().getUsername() == null) {
if (tmpUsersFile.exists() && getContainerConfiguration().getUsername() == null) {
File usersFile = new File(jbossHomeDir, CONFIG_PATH + MGMT_USERS_FILE);
tmpUsersFile.renameTo(usersFile);
}
Expand Down
Expand Up @@ -116,8 +116,9 @@ public synchronized void start(StartContext context) throws StartException {
final ServiceContainer serviceContainer = serviceController.getServiceContainer();
serviceTarget = context.getChildTarget();

modulesDir = injectedEnvironment.getValue().getModulesDir();
bundlesDir = new File(modulesDir.getPath() + "/../bundles").getCanonicalFile();
ServerEnvironment serverEnvironment = injectedEnvironment.getValue();
modulesDir = serverEnvironment.getModulesDir();
bundlesDir = serverEnvironment.getBundlesDir();

if (bundlesDir.isDirectory() == false)
throw MESSAGES.cannotFindBundleDir(bundlesDir);
Expand Down
19 changes: 19 additions & 0 deletions server/src/main/java/org/jboss/as/server/ServerEnvironment.java
Expand Up @@ -93,6 +93,14 @@ public ProcessType getProcessType() {
*/
public static final String MODULES_DIR = "jboss.modules.dir";

/**
* Constant that holds the name of the environment property for specifying the directory from which JBoss will read OSGi bundles.
*
* <p>
* Defaults to <tt><em>HOME_DIR</em>/bundles</tt>/
*/
public static final String BUNDLES_DIR = "jboss.bundles.dir";

/**
* VFS module identifier
*/
Expand Down Expand Up @@ -208,6 +216,7 @@ public ProcessType getProcessType() {

private final File homeDir;
private final File modulesDir;
private final File bundlesDir;
private final File serverBaseDir;
private final File serverConfigurationDir;
private final ConfigurationFile serverConfigurationFile;
Expand Down Expand Up @@ -308,6 +317,12 @@ public ServerEnvironment(final String hostControllerName, final Properties props
}
modulesDir = tmp;

tmp = getFileFromProperty(BUNDLES_DIR, props);
if (tmp == null) {
tmp = new File(homeDir, "bundles");
}
bundlesDir = tmp;

tmp = getFileFromProperty(SERVER_BASE_DIR, props);
if (tmp == null) {
tmp = new File(homeDir, standalone ? "standalone" : "domain/servers/" + serverName);
Expand Down Expand Up @@ -453,6 +468,10 @@ public File getModulesDir() {
return modulesDir;
}

public File getBundlesDir() {
return bundlesDir;
}

public File getServerBaseDir() {
return serverBaseDir;
}
Expand Down

0 comments on commit cdb3b1d

Please sign in to comment.