Skip to content

Commit

Permalink
Addon dir can be specified
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Nov 8, 2012
1 parent c954ec9 commit e35ac2e
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 132 deletions.
Expand Up @@ -3,6 +3,8 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.concurrent.Callable;

import org.jboss.arquillian.container.spi.client.container.DeployableContainer;
import org.jboss.arquillian.container.spi.client.container.DeploymentException;
Expand All @@ -18,9 +20,9 @@
import org.jboss.forge.container.AddonEntry;
import org.jboss.forge.container.AddonRegistry;
import org.jboss.forge.container.AddonUtil;
import org.jboss.forge.container.Bootstrap;
import org.jboss.forge.container.Forge;
import org.jboss.forge.container.Status;
import org.jboss.forge.container.util.ClassLoaders;
import org.jboss.forge.container.util.Files;
import org.jboss.forge.container.util.Streams;
import org.jboss.shrinkwrap.api.Archive;
Expand All @@ -32,16 +34,35 @@ public class ForgeDeployableContainer implements DeployableContainer<ForgeContai
{
private static final int TEST_DEPLOYMENT_TIMEOUT = 60000;
private ForgeRunnable thread;
private File addonDir;
private AddonUtil addonUtil;

private class ForgeRunnable implements Runnable
{
private Forge forge;
private ClassLoader loader;
private File addonDir;

public ForgeRunnable(File addonDir, ClassLoader loader)
{
this.addonDir = addonDir;
this.loader = loader;
}

@Override
public void run()
{
forge = Bootstrap.init();
forge.start();
ClassLoaders.executeIn(loader, new Callable<Object>()
{
@Override
public Object call() throws Exception
{
forge = new Forge();
forge.setAddonDir(addonDir);
forge.start();
return null;
}
});
}

public void stop()
Expand Down Expand Up @@ -73,7 +94,16 @@ public void start() throws LifecycleException
{
try
{
thread = new ForgeRunnable();
this.addonDir = File.createTempFile("forge-test-addon-dir", "");
this.addonUtil = AddonUtil.forAddonDir(addonDir);
}
catch (IOException e1)
{
throw new LifecycleException("Failed to create temporary addon directory", e1);
}
try
{
thread = new ForgeRunnable(addonDir, ClassLoader.getSystemClassLoader());
new Thread(thread).start();
}
catch (Exception e)
Expand All @@ -98,7 +128,7 @@ public ProtocolDescription getDefaultProtocol()
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException
{
AddonEntry addon = getAddonEntry(archive);
File destDir = AddonUtil.getAddonSlotDir(addon);
File destDir = addonUtil.getAddonSlotDir(addon);
destDir.mkdirs();

if (!(archive instanceof ForgeArchive))
Expand All @@ -114,16 +144,16 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException
Asset asset = node.getAsset();
try
{
Streams.write(asset.openStream(), new FileOutputStream(AddonUtil.getAddonDescriptor(addon)));
Streams.write(asset.openStream(), new FileOutputStream(addonUtil.getAddonDescriptor(addon)));
}
catch (FileNotFoundException e)
{
throw new DeploymentException("Could not open addon descriptor [" + AddonUtil.getAddonDescriptor(addon)
throw new DeploymentException("Could not open addon descriptor [" + addonUtil.getAddonDescriptor(addon)
+ "].", e);
}
}

addon = AddonUtil.install(addon);
addon = addonUtil.install(addon);

HTTPContext httpContext = new HTTPContext("localhost", 4141);
httpContext.add(new Servlet("ArquillianServletRunner", "/ArquillianServletRunner"));
Expand Down Expand Up @@ -160,9 +190,9 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException
public void undeploy(Archive<?> archive) throws DeploymentException
{
AddonEntry addon = getAddonEntry(archive);
AddonUtil.remove(addon);
addonUtil.remove(addon);

File dir = AddonUtil.getAddonBaseDir(addon);
File dir = addonUtil.getAddonBaseDir(addon);
boolean deleted = Files.delete(dir, true);
if (!deleted)
throw new IllegalStateException("Could not delete file [" + dir.getAbsolutePath() + "]");
Expand Down
Expand Up @@ -28,6 +28,7 @@ public class ForgeDeployableContainer implements DeployableContainer<ForgeContai
{
private Process process;
private String FORGE_HOME;
private AddonUtil addonUtil;

@Override
public Class<ForgeContainerConfiguration> getConfigurationClass()
Expand All @@ -44,6 +45,7 @@ public void setup(ForgeContainerConfiguration configuration)
@Override
public void start() throws LifecycleException
{
this.addonUtil = AddonUtil.forDefaultAddonDir();
try
{
this.process = NativeSystemCall.exec("java", "-Dforge.logging=false -Dforge.home=" + FORGE_HOME,
Expand Down Expand Up @@ -80,7 +82,7 @@ public ProtocolDescription getDefaultProtocol()
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException
{
AddonEntry addon = getAddonEntry(archive);
File destDir = AddonUtil.getAddonSlotDir(addon);
File destDir = addonUtil.getAddonSlotDir(addon);
destDir.mkdirs();

if (!(archive instanceof ForgeArchive))
Expand All @@ -96,18 +98,18 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException
Asset asset = node.getAsset();
try
{
Streams.write(asset.openStream(), new FileOutputStream(AddonUtil.getAddonDescriptor(addon)));
Streams.write(asset.openStream(), new FileOutputStream(addonUtil.getAddonDescriptor(addon)));
}
catch (FileNotFoundException e)
{
throw new DeploymentException("Could not open addon descriptor [" + AddonUtil.getAddonDescriptor(addon)
throw new DeploymentException("Could not open addon descriptor [" + addonUtil.getAddonDescriptor(addon)
+ "].", e);
}
}

System.out.println("Unzipping " + archive.toString(true));

addon = AddonUtil.install(addon);
addon = addonUtil.install(addon);

HTTPContext httpContext = new HTTPContext("localhost", 4141);
httpContext.add(new Servlet("ArquillianServletRunner", "/ArquillianServletRunner"));
Expand All @@ -120,9 +122,9 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException
public void undeploy(Archive<?> archive) throws DeploymentException
{
AddonEntry addon = getAddonEntry(archive);
AddonUtil.remove(addon);
addonUtil.remove(addon);

File dir = AddonUtil.getAddonBaseDir(addon);
File dir = addonUtil.getAddonBaseDir(addon);
boolean deleted = Files.delete(dir, true);
if (!deleted)
throw new IllegalStateException("Could not delete file [" + dir.getAbsolutePath() + "]");
Expand Down
Expand Up @@ -28,6 +28,7 @@ public class ForgeDeployableContainer implements DeployableContainer<ForgeContai
{
private Process process;
private String FORGE_HOME;
private AddonUtil addonUtil = AddonUtil.forDefaultAddonDir();

@Override
public Class<ForgeContainerConfiguration> getConfigurationClass()
Expand Down Expand Up @@ -80,7 +81,7 @@ public ProtocolDescription getDefaultProtocol()
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException
{
AddonEntry addon = getAddonEntry(archive);
File destDir = AddonUtil.getAddonSlotDir(addon);
File destDir = addonUtil .getAddonSlotDir(addon);
destDir.mkdirs();

if (!(archive instanceof ForgeArchive))
Expand All @@ -96,18 +97,18 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException
Asset asset = node.getAsset();
try
{
Streams.write(asset.openStream(), new FileOutputStream(AddonUtil.getAddonDescriptor(addon)));
Streams.write(asset.openStream(), new FileOutputStream(addonUtil.getAddonDescriptor(addon)));
}
catch (FileNotFoundException e)
{
throw new DeploymentException("Could not open addon descriptor [" + AddonUtil.getAddonDescriptor(addon)
throw new DeploymentException("Could not open addon descriptor [" + addonUtil.getAddonDescriptor(addon)
+ "].", e);
}
}

System.out.println("Unzipping " + archive.toString(true));

addon = AddonUtil.install(addon);
addon = addonUtil.install(addon);

HTTPContext httpContext = new HTTPContext("localhost", 4141);
httpContext.add(new Servlet("ArquillianServletRunner", "/ArquillianServletRunner"));
Expand All @@ -120,9 +121,9 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException
public void undeploy(Archive<?> archive) throws DeploymentException
{
AddonEntry addon = getAddonEntry(archive);
AddonUtil.remove(addon);
addonUtil.remove(addon);

File dir = AddonUtil.getAddonBaseDir(addon);
File dir = addonUtil.getAddonBaseDir(addon);
boolean deleted = Files.delete(dir, true);
if (!deleted)
throw new IllegalStateException("Could not delete file [" + dir.getAbsolutePath() + "]");
Expand Down

0 comments on commit e35ac2e

Please sign in to comment.