Skip to content

Commit

Permalink
Implemented ForgeArchive for Arquillian
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Sep 13, 2012
1 parent fa51917 commit 7b3d536
Show file tree
Hide file tree
Showing 23 changed files with 270 additions and 136 deletions.
6 changes: 5 additions & 1 deletion arquillian-forge-managed/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>arquillian-forge-managed</artifactId>
<name>Forge - Arquillian Container Adapter</name>
<name>Forge - Arquillian Container Adapter</name>

<dependencies>
<dependency>
Expand Down Expand Up @@ -48,6 +48,10 @@
</dependency>


<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-impl-base</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext;
import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData;
import org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
import org.jboss.forge.arquillian.archive.ForgeArchive;
import org.jboss.forge.arquillian.protocol.ServletProtocolDescription;
import org.jboss.forge.arquillian.util.NativeSystemCall;
import org.jboss.forge.arquillian.util.ShrinkWrapUtil;
Expand All @@ -17,7 +18,6 @@
import org.jboss.forge.container.util.Files;
import org.jboss.forge.container.util.OSUtils;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptor;

public class ForgeDeployableContainer implements DeployableContainer<ForgeContainerConfiguration>
Expand All @@ -42,7 +42,7 @@ public void start() throws LifecycleException
{
try
{
this.process = NativeSystemCall.exec("java", "-Dforge.home=" + FORGE_HOME,
this.process = NativeSystemCall.exec("java", "-Dforge.logging=false -Dforge.home=" + FORGE_HOME,
"-jar", FORGE_HOME + "/jboss-modules.jar", "-modulepath",
FORGE_HOME + "/modules:" + OSUtils.getUserHomePath() + "/.forge/plugins:", "org.jboss.forge");
}
Expand Down Expand Up @@ -76,18 +76,16 @@ public ProtocolDescription getDefaultProtocol()
@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException
{
AddonEntry addon = new AddonEntry(archive.getName(), "2.0.0-SNAPSHOT", "main");
File destDir = AddonUtil.getAddonResourceDir(addon);
AddonEntry addon = getAddonEntry(archive);
File destDir = AddonUtil.getAddonSlotDir(addon);
destDir.mkdirs();

if (archive instanceof WebArchive)
{
ShrinkWrapUtil.unzip(destDir, archive);
}
else
{
throw new DeploymentException("Packaging error - archive was not a container WebArchive");
}
if (!(archive instanceof ForgeArchive))
throw new IllegalArgumentException(
"Invalid Archive type. Ensure that your @Deployment method returns type 'ForgeArchive'.");

ShrinkWrapUtil.toFile(new File(destDir.getAbsolutePath() + "/" + archive.getName()), archive);
ShrinkWrapUtil.unzip(destDir, archive);

addon = AddonUtil.install(addon);

Expand All @@ -101,7 +99,7 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException
@Override
public void undeploy(Archive<?> archive) throws DeploymentException
{
AddonEntry addon = new AddonEntry(archive.getName(), "2.0.0-SNAPSHOT", "main");
AddonEntry addon = getAddonEntry(archive);
AddonUtil.remove(addon);

File dir = AddonUtil.getAddonBaseDir(addon);
Expand All @@ -110,6 +108,11 @@ public void undeploy(Archive<?> archive) throws DeploymentException
throw new IllegalStateException("Could not delete file [" + dir.getAbsolutePath() + "]");
}

private AddonEntry getAddonEntry(Archive<?> archive)
{
return new AddonEntry(archive.getName().replaceFirst("\\.jar$", ""), "2.0.0-SNAPSHOT", "main");
}

@Override
public void deploy(Descriptor descriptor) throws DeploymentException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
import org.jboss.arquillian.container.test.spi.client.deployment.DeploymentPackager;
import org.jboss.arquillian.container.test.spi.client.deployment.ProtocolArchiveProcessor;
import org.jboss.arquillian.core.spi.LoadableExtension;
import org.jboss.forge.arquillian.archive.ForgeArchive;
import org.jboss.forge.arquillian.archive.ForgeArchiveImpl;
import org.jboss.forge.arquillian.runner.BeanManagerProducer;
import org.jboss.forge.arquillian.runner.CDIEnricherRemoteExtensionWorkaround;
import org.jboss.forge.arquillian.runner.ServletLoadableExtension;
import org.jboss.forge.arquillian.runner.ServletTestRunner;
import org.jboss.forge.arquillian.runner.ServletTestServer;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.GenericArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.DependencyResolvers;
import org.jboss.shrinkwrap.resolver.api.maven.MavenDependencyResolver;

Expand All @@ -25,22 +24,25 @@ public class ForgeDeploymentPackager implements DeploymentPackager
@Override
public Archive<?> generateDeployment(TestDeployment testDeployment, Collection<ProtocolArchiveProcessor> processors)
{
if (!(testDeployment.getApplicationArchive() instanceof JavaArchive))
throw new IllegalStateException("Cannot deploy non JavaArchive.");
if (!(testDeployment.getApplicationArchive() instanceof ForgeArchive))
throw new IllegalArgumentException(
"Invalid Archive type. Ensure that your @Deployment method returns type 'ForgeArchive'.");

JavaArchive deployment = JavaArchive.class.cast(testDeployment.getApplicationArchive());
ForgeArchive deployment = ForgeArchive.class.cast(testDeployment.getApplicationArchive());
deployment.addClasses(ServletTestServer.class, ServletTestRunner.class, BeanManagerProducer.class,
CDIEnricherRemoteExtensionWorkaround.class);
deployment.addAsServiceProvider(LoadableExtension.class, ServletLoadableExtension.class);
deployment.addAsServiceProvider(RemoteLoadableExtension.class, CDIEnricherRemoteExtensionWorkaround.class);

WebArchive container = ShrinkWrap.create(WebArchive.class);
container.addAsLibraries(deployment);
container.addAsLibraries(testDeployment.getAuxiliaryArchives());
container.addAsLibraries(resolveDependencies("org.eclipse.jetty:jetty-server:8.1.5.v20120716"));
container.addAsLibraries(resolveDependencies("org.eclipse.jetty:jetty-servlet:8.1.5.v20120716"));
deployment.addAsLibraries(testDeployment.getAuxiliaryArchives());
deployment.addAsLibraries(resolveDependencies("org.jboss.shrinkwrap:shrinkwrap-impl-base:1.0.1"));
deployment.addAsLibraries(resolveDependencies("org.eclipse.jetty:jetty-server:8.1.5.v20120716"));
deployment.addAsLibraries(resolveDependencies("org.eclipse.jetty:jetty-servlet:8.1.5.v20120716"));

return container;
deployment.addClasses(ForgeArchive.class, ForgeArchiveImpl.class);
deployment.addAsServiceProvider(ForgeArchive.class, ForgeArchiveImpl.class);

return deployment;
}

protected static Collection<GenericArchive> resolveDependencies(final String coords)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jboss.forge.arquillian.archive;

import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.container.LibraryContainer;
import org.jboss.shrinkwrap.api.container.ResourceContainer;
import org.jboss.shrinkwrap.api.container.ServiceProviderContainer;

/**
* Traditional WAR (Java Web Archive) structure. Used in construction of web applications.
*
* @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
* @version $Revision: $
*/
public interface ForgeArchive extends Archive<ForgeArchive>, LibraryContainer<ForgeArchive>,
ResourceContainer<ForgeArchive>, ServiceProviderContainer<ForgeArchive>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed 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.jboss.forge.arquillian.archive;

import java.util.logging.Logger;

import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ArchivePath;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.impl.base.container.ContainerBase;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class ForgeArchiveImpl extends ContainerBase<ForgeArchive> implements ForgeArchive
{
// -------------------------------------------------------------------------------------||
// Class Members ----------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

@SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(ForgeArchiveImpl.class.getName());

/**
* Path to the web inside of the Archive.
*/
private static final ArchivePath PATH_ROOT = ArchivePaths.root();

/**
* Path to the classes inside of the Archive.
*/
private static final ArchivePath PATH_CLASSES = ArchivePaths.create(PATH_ROOT, "");

/**
* Path to the libraries inside of the Archive.
*/
private static final ArchivePath PATH_LIBRARY = ArchivePaths.create(PATH_ROOT, "lib");

/**
* Path to the manifests inside of the Archive.
*/
private static final ArchivePath PATH_MANIFEST = ArchivePaths.create("META-INF");

/**
* Path to web archive service providers.
*/
private static final ArchivePath PATH_SERVICE_PROVIDERS = ArchivePaths.create(PATH_CLASSES, "META-INF/services");

// -------------------------------------------------------------------------------------||
// Instance Members -------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

// -------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

/**
* Create a new {@link ForgeArchive} with any type storage engine as backing.
*
* @param delegate The storage backing.
*/
public ForgeArchiveImpl(final Archive<?> delegate)
{
super(ForgeArchive.class, delegate);
}

// -------------------------------------------------------------------------------------||
// Required Implementations -----------------------------------------------------------||
// -------------------------------------------------------------------------------------||

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.impl.base.container.ContainerBase#getManifestPath()
*/
@Override
protected ArchivePath getManifestPath()
{
return PATH_MANIFEST;
}

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.impl.base.container.ContainerBase#getClassesPath()
*/
@Override
protected ArchivePath getClassesPath()
{
return PATH_CLASSES;
}

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.impl.base.container.ContainerBase#getLibraryPath()
*/
@Override
protected ArchivePath getLibraryPath()
{
return PATH_LIBRARY;
}

protected ArchivePath getServiceProvidersPath()
{
return PATH_SERVICE_PROVIDERS;
}

@Override
protected ArchivePath getResourcePath()
{
return PATH_CLASSES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void run()
}
catch (IOException e)
{
throw new RuntimeException("Error reading input from child process", e);
// Don't care right now.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public boolean include(ArchivePath object)
for (Entry<ArchivePath, Node> entry : content.entrySet())
{
ArchivePath path = entry.getKey();
File target = new File(baseDir.getAbsolutePath() + "/" + path.get().replaceFirst("/WEB-INF/lib/", ""));
File target = new File(baseDir.getAbsolutePath() + "/" + path.get().replaceFirst("/lib/", ""));
target.mkdirs();
target.delete();
target.createNewFile();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
implementingClassName=org.jboss.forge.arquillian.archive.ForgeArchiveImpl
extension=.jar
archiveFormat=ZIP
30 changes: 0 additions & 30 deletions control-api/pom.xml

This file was deleted.

2 changes: 0 additions & 2 deletions control-api/src/main/resources/META-INF/beans.xml

This file was deleted.

2 changes: 0 additions & 2 deletions control-api/src/main/resources/META-INF/forge.xml

This file was deleted.

30 changes: 0 additions & 30 deletions control-impl-rest/pom.xml

This file was deleted.

2 changes: 0 additions & 2 deletions control-impl-rest/src/main/resources/META-INF/beans.xml

This file was deleted.

2 changes: 0 additions & 2 deletions control-impl-rest/src/main/resources/META-INF/forge.xml

This file was deleted.

Loading

0 comments on commit 7b3d536

Please sign in to comment.