Skip to content

Commit

Permalink
Added support for multiple wars in ears with the servlet protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpanzer committed Jun 12, 2012
1 parent 624eb04 commit a39a45c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class DeploymentDescription
private boolean managed = true;
private int order = 0;
private boolean testable = true;
private String archiveForEnrichment;

private TargetDescription target = TargetDescription.DEFAULT;
private ProtocolDescription protocol= ProtocolDescription.DEFAULT;
Expand Down Expand Up @@ -132,6 +133,19 @@ public DeploymentDescription shouldBeManaged(boolean startup)
return this;
}


public String getArchiveForEnrichment() {
if ("".equals(archiveForEnrichment)) {
return null;
}
return archiveForEnrichment;
}

public DeploymentDescription archiveForEnrichment(String archiveForEnrichment) {
this.archiveForEnrichment = archiveForEnrichment;
return this;
}

/**
* @return the startup
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@
* @return
*/
boolean testable() default true;


String archiveForEnrichment() default "";


}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ else if(Descriptor.class.isAssignableFrom(deploymentMethod.getReturnType()))
{
deployment.setProtocol(protocol);
}

if (!"".equals(deploymentAnnotation.archiveForEnrichment())) {
deployment.archiveForEnrichment(deploymentAnnotation.archiveForEnrichment());
}
if(deploymentMethod.isAnnotationPresent(ShouldThrowException.class))
{
deployment.setExpectedException(deploymentMethod.getAnnotation(ShouldThrowException.class).value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.jboss.arquillian.container.spi.client.deployment.TargetDescription;
import org.jboss.arquillian.container.spi.client.protocol.ProtocolDescription;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.Node;
import org.jboss.shrinkwrap.api.asset.ArchiveAsset;
import org.jboss.shrinkwrap.api.asset.Asset;

/**
* Value object that contains the {@link Archive}s needed for deployment. <br/>
Expand Down Expand Up @@ -87,12 +90,19 @@ public String getDeploymentName()

/**
* Convenience method to lookup the user tagged archive for enriching.
* @return The tagged Archive or ApplicationArchive if none are tagged
* @return The tagged Archive or null if none are tagged
*/
public Archive<?> getArchiveForEnrichment()
{
// TODO: lookup 'tagged' archive. return applicationArchive if none found
return applicationArchive;
if (deploymentDescription.getArchiveForEnrichment() != null) {
if (!applicationArchive.contains(deploymentDescription.getArchiveForEnrichment())) {
throw new IllegalArgumentException("Application does not contain the archive "+deploymentDescription.getArchiveForEnrichment()+" that is to be enriched.");
}
Node n = applicationArchive.get(deploymentDescription.getArchiveForEnrichment());
ArchiveAsset asset = (ArchiveAsset) n.getAsset();
return asset.getArchive();
}
return null;
}

public Archive<?> getApplicationArchive()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Archive<?> generateDeployment(TestDeployment testDeployment, Collection<P

if(EnterpriseArchive.class.isInstance(applicationArchive))
{
return handleArchive(EnterpriseArchive.class.cast(applicationArchive), auxiliaryArchives, protocol, processor);
return handleArchive(EnterpriseArchive.class.cast(applicationArchive), auxiliaryArchives, protocol, processor, testDeployment);
}

if(WebArchive.class.isInstance(applicationArchive))
Expand Down Expand Up @@ -104,7 +104,7 @@ private Archive<?> handleArchive(JavaArchive applicationArchive, Collection<Arch
processor);
}

private Archive<?> handleArchive(EnterpriseArchive applicationArchive, Collection<Archive<?>> auxiliaryArchives, JavaArchive protocol, Processor processor)
private Archive<?> handleArchive(EnterpriseArchive applicationArchive, Collection<Archive<?>> auxiliaryArchives, JavaArchive protocol, Processor processor, TestDeployment testDeployment)
{
Map<ArchivePath, Node> applicationArchiveWars = applicationArchive.getContent(Filters.include(".*\\.war"));
if(applicationArchiveWars.size() == 1)
Expand All @@ -125,8 +125,26 @@ private Archive<?> handleArchive(EnterpriseArchive applicationArchive, Collectio
}
else if(applicationArchiveWars.size() > 1)
{
// TODO: fetch the TestDeployment.getArchiveForEnrichment
throw new UnsupportedOperationException("Multiple WebArchives found in " + applicationArchive.getName() + ". Can not determine which to enrich");
Archive<?> archive = testDeployment.getArchiveForEnrichment();
if (archive == null) {
throw new UnsupportedOperationException("Multiple WebArchives found in " + applicationArchive.getName() + ". Can not determine which to enrich");
}
try
{
handleArchive(
(WebArchive)archive,
new ArrayList<Archive<?>>(), // reuse the War handling, but Auxiliary Archives should be added to the EAR, not the WAR
protocol,
processor);
}
catch (ClassCastException e)
{
throw new IllegalArgumentException("Can not manipulate war's that are not of type " + WebArchive.class, e);
}
catch (IllegalArgumentException e)
{
throw new IllegalArgumentException("Can not manipulate war's that are not of type " + WebArchive.class, e);
}
}
else
{
Expand Down

0 comments on commit a39a45c

Please sign in to comment.