Permalink
Browse files

Initial commit of the Arquillian Maven Plugin. Support for deploy/und…

…eploy and run operations
  • Loading branch information...
0 parents commit 32d6752546583e197930f9558ce16c3b4012ecd8 @aslakknutsen aslakknutsen committed Jul 2, 2011
@@ -0,0 +1,19 @@
+# Eclipse
+.project
+.classpath
+.settings/
+
+# IntelliJ
+*.iml
+*.ipr
+*.iws
+.idea
+
+# Maven
+target/
+
+# TestNG
+test-output/
+
+# JBoss AS
+transaction.log
@@ -0,0 +1,83 @@
+Arquillian Maven Plugin
+=======================
+
+A Maven plugin with support for deploy/undeploy and run operations using the Arquillian Containers.
+
+
+Operations
+----------
+
+* run
+Similar to the famous jetty:run maven plugin. This goal will Setup and Start the Container, Deploy the given Archive, then wait for a JVM shutdown (ctrl+c),
+for so to UnDeploy and Stop the Container.
+
+This should work with all types of containers: Embedded, Managed and Remote.
+
+(note: Remote containers are not actually started, but Archive will be undeployed on shutdown)
+
+* deploy
+
+This goal will Setup and Start the Container and Deploy the Archive, for so to Stop the Container.
+
+(note: This goal makes most sense used with Remote containers)
+
+* undeploy
+
+This goal will Setup and Start the Container and Deploy the Archive, for so to Stop the Container.
+
+(note: This goal makes most sense used with Remote containers)
+
+
+Configuration
+-------------
+
+* targetDir
+
+Parent directory to where the Archive can be found. Default value is: ${project.build.directory}/
+
+* filename
+
+The Archive name as found in 'targetDir'. Default value is: ${project.build.finalName}.${project.packaging}
+
+
+Usage
+-----
+
+```xml
+<properties>
+ <version.arquillian_maven>1.0.0-SNAPSHOT</version.arquillian_maven>
+ <version.arquillian_jetty>1.0.0.CR1</version.arquillian_jetty>
+ <version.jetty>8.0.0.M3</version.jetty>
+</properties>
+
+<build>
+ <plugins>
+ <plugin>
+ <groupId>org.jboss.arquillian.maven</groupId>
+ <artifactId>arquillian-maven-plugin</artifactId>
+ <version>${version.arquillian_maven}</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-jetty-embedded-7</artifactId>
+ <version>${version.arquillian_jetty}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <version>${version.jetty}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-plus</artifactId>
+ <version>${version.jetty}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+</build>
+```
+
+The dependencies needed are the same as described in the [Reference Guide -> Complete Container Reference](https://docs.jboss.org/author/display/ARQ/Complete+Container+Reference).
+
+See the test/ sub module for a complete setup.
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>arquillian-maven-plugin-parent</artifactId>
+ <groupId>org.jboss.arquillian.maven</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>arquillian-maven-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <name>Arquillian Maven Plugin</name>
+ <description>Maven plugin for Deploy/UnDeploy/Run based on the Arquillian Containers</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.core</groupId>
+ <artifactId>arquillian-core-impl-base</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-container-impl-base</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
@@ -0,0 +1,170 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @authors tag. All rights reserved.
+ * 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.arquillian.maven;
+
+import java.io.File;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.jboss.arquillian.container.spi.Container;
+import org.jboss.arquillian.container.spi.ContainerRegistry;
+import org.jboss.arquillian.container.spi.client.container.DeploymentException;
+import org.jboss.arquillian.container.spi.client.deployment.TargetDescription;
+import org.jboss.arquillian.core.impl.loadable.LoadableExtensionLoader;
+import org.jboss.arquillian.core.spi.Manager;
+import org.jboss.arquillian.core.spi.ManagerBuilder;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.GenericArchive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.importer.ZipImporter;
+
+/**
+ * BaseCommand
+ *
+ * @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ *
+ * @requiresDependencyResolution runtime
+ */
+abstract class BaseCommand extends AbstractMojo
+{
+ /**
+ * The target directory the application to be deployed is located.
+ *
+ * @parameter expression="${echo.target}" default-value="${project.build.directory}/"
+ */
+ private File targetDir;
+
+ /**
+ * The file name of the application to be deployed.
+ *
+ * @parameter expression="${echo.filename}" default-value="${project.build.finalName}.${project.packaging}"
+ */
+ private String filename;
+
+ /**
+ * The target directory the archive is located. The default is {@code project.build.directory}.
+ *
+ * @return the target directory the archive is located.
+ */
+ public final File targetDirectory() {
+ return targetDir;
+ }
+
+ /**
+ * The file name of the archive not including the directory. The default is
+ * {@code project.build.finalName + . + project.packaging}
+ *
+ * @return the file name of the archive.
+ */
+ public final String filename() {
+ return filename;
+ }
+
+ /**
+ * The archive file.
+ *
+ * @return the archive file.
+ */
+ public final File file() {
+ return new File(targetDir, filename);
+ }
+
+ /**
+ * The goal of the deployment.
+ *
+ * @return the goal of the deployment.
+ */
+ public abstract String goal();
+
+ /**
+ * Perform the defined goal, e.g. deploy / run / undeploy
+ *
+ * @param container The chosen container to operate on
+ * @param deployment The deployment to operate on
+ */
+ public abstract void perform(Manager manager, Container container, Archive<?> deployment) throws DeploymentException;
+
+ /* (non-Javadoc)
+ * @see org.apache.maven.plugin.Mojo#execute()
+ */
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException
+ {
+ File deploymentFile = file();
+
+ if(!deploymentFile.exists())
+ {
+ throw new IllegalArgumentException("Specified file does not exist:" + deploymentFile + ". Verify 'target' and 'filename' configuration.");
+ }
+
+ getLog().info(goal() + " file: " + deploymentFile.getAbsoluteFile());
+
+ Manager manager = ManagerBuilder.from()
+ .extension(LoadableExtensionLoader.class)
+ .create();
+
+ manager.start();
+
+ GenericArchive deployment = ShrinkWrap.create(ZipImporter.class, deploymentFile.getName())
+ .importFrom(deploymentFile)
+ .as(GenericArchive.class);
+
+ ContainerRegistry registry = manager.resolve(ContainerRegistry.class);
+
+ if(registry == null)
+ {
+ throw new IllegalStateException("No ContainerRegistry found in Context. Something is wrong with the classpath.....");
+ }
+
+ if(registry.getContainers().size() == 0)
+ {
+ throw new IllegalStateException("No Containers in registry. You need to add the Container Adaptor dependencies to the plugin dependency section");
+ }
+
+ // TODO: Add support for multi configuration and arquillian.xml selection
+ Container container = registry.getContainer(TargetDescription.DEFAULT);
+
+ getLog().info("to container: " + container.getName());
+
+ try
+ {
+ Utils.setup(manager, container);
+ Utils.start(manager, container);
+
+ perform(manager, container, deployment);
+ }
+ catch (Exception e)
+ {
+ throw new MojoExecutionException("Could not perform:" + goal(), e);
+ }
+ finally
+ {
+ try
+ {
+ Utils.stop(manager, container);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ manager.shutdown();
+ }
+ }
+}
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @authors tag. All rights reserved.
+ * 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.arquillian.maven;
+
+import org.jboss.arquillian.container.spi.Container;
+import org.jboss.arquillian.container.spi.client.container.DeploymentException;
+import org.jboss.arquillian.core.spi.Manager;
+import org.jboss.shrinkwrap.api.Archive;
+
+/**
+ * Deploy to a Container
+ *
+ * @goal deploy
+ *
+ * @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ *
+ */
+public final class Deploy extends BaseCommand
+{
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.maven.BaseCommand#goal()
+ */
+ @Override
+ public String goal()
+ {
+ return "deploy";
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.arquillian.maven.BaseCommand#perform(org.jboss.arquillian.core.spi.Manager, org.jboss.arquillian.container.spi.Container, org.jboss.shrinkwrap.api.Archive)
+ */
+ @Override
+ public void perform(Manager manager, Container container, Archive<?> deployment) throws DeploymentException
+ {
+ getLog().info("Perform deploy on " + container.getName() + " of deployment " + deployment.getName());
+ Utils.deploy(manager, container, deployment);
+ }
+}
Oops, something went wrong.

0 comments on commit 32d6752

Please sign in to comment.