[jbosstools-commits] JBoss Tools SVN: r30522 - in workspace/adietish: org.jboss.ide.eclipse.as7.deployment.tests and 3 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Tue Apr 12 13:26:49 EDT 2011
Author: adietish
Date: 2011-04-12 13:26:48 -0400 (Tue, 12 Apr 2011)
New Revision: 30522
Added:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/as/demos/war/runner/StandaloneDeployerIntegrationTest.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneDeployer.java
Removed:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/as/demos/war/runner/DeploymentUtilsIntegrationTest.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/DeploymentUtils.java
Modified:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/.classpath
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/META-INF/MANIFEST.MF
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/build.properties
Log:
Copied: workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneDeployer.java (from rev 30521, workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/DeploymentUtils.java)
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneDeployer.java (rev 0)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneDeployer.java 2011-04-12 17:26:48 UTC (rev 30522)
@@ -0,0 +1,163 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as7.deployment;
+
+import static org.jboss.as.protocol.StreamUtils.safeClose;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.as.controller.client.helpers.standalone.DeploymentPlan;
+import org.jboss.as.controller.client.helpers.standalone.DeploymentPlanBuilder;
+import org.jboss.as.controller.client.helpers.standalone.DuplicateDeploymentNameException;
+import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentManager;
+
+/**
+ * Used to deploy/undeploy deployments to a running <b>standalone</b> application server
+ *
+ * TODO Use the real deployment API once that is complete
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class StandaloneDeployer implements Closeable {
+
+ public static final long DEFAULT_TIMEOUT = 15000;
+
+ private final List<AbstractDeployable> deployments = new ArrayList<AbstractDeployable>();
+ private final ModelControllerClient client;
+ private final ServerDeploymentManager manager;
+ private long timeout = DEFAULT_TIMEOUT;
+
+ public StandaloneDeployer() throws UnknownHostException {
+ client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999);
+ manager = ServerDeploymentManager.Factory.create(client);
+ }
+
+ public synchronized void addWarFileDeployment(File file) {
+ deployments.add(new WarDeployable(file));
+ }
+
+ public synchronized void deploy() throws DuplicateDeploymentNameException, IOException, ExecutionException, InterruptedException, TimeoutException {
+ DeploymentPlanBuilder builder = manager.newDeploymentPlan();
+ for (AbstractDeployable deployment : deployments) {
+ builder = deployment.addDeployment(builder);
+ }
+
+ try {
+ manager.execute(builder.build()).get(timeout, TimeUnit.MILLISECONDS);
+ } finally {
+ markDeploymentsDeployed();
+ }
+ }
+
+ private void markDeploymentsDeployed() {
+ for (AbstractDeployable deployment : deployments) {
+ deployment.deployed = true;
+ }
+ }
+
+ public synchronized void undeploy() throws ExecutionException, InterruptedException, TimeoutException {
+ DeploymentPlanBuilder builder = manager.newDeploymentPlan();
+ for (AbstractDeployable deployment : deployments) {
+ builder = deployment.removeDeployment(builder);
+ }
+ DeploymentPlan plan = builder.build();
+ if (plan.getDeploymentActions().size() > 0) {
+ manager.execute(builder.build()).get(timeout, TimeUnit.MILLISECONDS);
+ }
+ }
+
+ public MBeanServerConnection getConnection() throws Exception {
+ return JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi"),
+ new HashMap<String, Object>()).getMBeanServerConnection();
+ }
+
+ public String showJndi() throws Exception {
+ return (String)getConnection().invoke(new ObjectName("jboss:type=JNDIView"), "list", new Object[] {true}, new String[] {"boolean"});
+ }
+
+ public long getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(long timeout) {
+ this.timeout = timeout;
+ }
+
+ @Override
+ public void close() throws IOException {
+ safeClose(client);
+ }
+
+ private abstract class AbstractDeployable{
+
+ private boolean deployed;
+ private String name;
+
+ public synchronized DeploymentPlanBuilder addDeployment(DeploymentPlanBuilder builder) throws DuplicateDeploymentNameException, IOException, ExecutionException, InterruptedException {
+ this.name = getFile().getName();
+ return builder.add(name, getFile()).deploy(name);
+ }
+
+ public synchronized DeploymentPlanBuilder removeDeployment(DeploymentPlanBuilder builder) {
+ if (deployed) {
+ return builder.undeploy(name).remove(name);
+ }
+ else {
+ return builder;
+ }
+ }
+
+ protected abstract File getFile();
+ }
+
+ private class WarDeployable extends AbstractDeployable {
+
+ private File file;
+
+ public WarDeployable(File file) {
+ this.file = file;
+ }
+
+ @Override
+ protected File getFile() {
+ return file;
+ }
+
+ }
+}
Property changes on: workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneDeployer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/.classpath
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/.classpath 2011-04-12 16:23:19 UTC (rev 30521)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/.classpath 2011-04-12 17:26:48 UTC (rev 30522)
@@ -10,6 +10,5 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="wars"/>
- <classpathentry kind="lib" path="jboss-servlet-api_3.0_spec-1.0.0.Final.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/META-INF/MANIFEST.MF
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/META-INF/MANIFEST.MF 2011-04-12 16:23:19 UTC (rev 30521)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/META-INF/MANIFEST.MF 2011-04-12 17:26:48 UTC (rev 30522)
@@ -14,5 +14,4 @@
shrinkwrap-impl-base-1.0.0-alpha-12-sources.jar,
shrinkwrap-impl-base-1.0.0-alpha-12.jar,
shrinkwrap-spi-1.0.0-alpha-12-sources.jar,
- shrinkwrap-spi-1.0.0-alpha-12.jar,
- jboss-servlet-api_3.0_spec-1.0.0.Final.jar
+ shrinkwrap-spi-1.0.0-alpha-12.jar
Modified: workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/build.properties
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/build.properties 2011-04-12 16:23:19 UTC (rev 30521)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/build.properties 2011-04-12 17:26:48 UTC (rev 30522)
@@ -8,5 +8,4 @@
shrinkwrap-impl-base-1.0.0-alpha-12-sources.jar,\
shrinkwrap-impl-base-1.0.0-alpha-12.jar,\
shrinkwrap-spi-1.0.0-alpha-12-sources.jar,\
- shrinkwrap-spi-1.0.0-alpha-12.jar,\
- jboss-servlet-api_3.0_spec-1.0.0.Final.jar
+ shrinkwrap-spi-1.0.0-alpha-12.jar
Deleted: workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/as/demos/war/runner/DeploymentUtilsIntegrationTest.java
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/as/demos/war/runner/DeploymentUtilsIntegrationTest.java 2011-04-12 16:23:19 UTC (rev 30521)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/as/demos/war/runner/DeploymentUtilsIntegrationTest.java 2011-04-12 17:26:48 UTC (rev 30522)
@@ -1,113 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.as.demos.war.runner;
-
-import static org.jboss.as.protocol.StreamUtils.safeClose;
-import static org.junit.Assert.assertTrue;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.net.HttpURLConnection;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.text.MessageFormat;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
-import org.jboss.ide.eclipse.as7.deployment.tests.DeploymentUtils;
-import org.junit.Test;
-import org.osgi.framework.Bundle;
-
-/**
- *
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision: 1.1 $
- */
-public class DeploymentUtilsIntegrationTest {
-
- private static final String WAR_FOLDER = "/wars/";
- private static final String BUNDLE_ID = "org.jboss.ide.eclipse.as7.deployment.tests";
-
- private static final int WEBAPP_RESPONSE_TIMEOUT = 10 * 1024;
-
- private static final String HOST = "localhost";
- private static final int WEB_PORT = 8080;
-
- @Test
- public void canDeployUsingDeploymentUtils() throws Exception {
- DeploymentUtils utils = null;
- try {
- utils = new DeploymentUtils();
-// File warFile = nonOsgiGetWarFile("minimalistic.war");
- File warFile = osgiGetWarFile("minimalistic.war");
- utils.addWarFileDeployment(warFile);
- utils.deploy();
-
- String response = getServerResponse(new URL(
- MessageFormat.format("http://{0}:{1}/{2}",
- HOST,
- String.valueOf(WEB_PORT),
- "minimalistic")));
- assertTrue(response.indexOf("minimalistic") >= 0);
-
- } finally {
- utils.undeploy();
- safeClose(utils);
- }
- }
-
- private File osgiGetWarFile(String name) throws URISyntaxException, IOException {
- Bundle bundle = Platform.getBundle(BUNDLE_ID);
- URL entryUrl = bundle.getEntry(WAR_FOLDER + name);
- return new File(FileLocator.resolve(entryUrl).toURI());
- }
-
- private static File nonOsgiGetWarFile(String path) {
- URL url = Thread.currentThread().getContextClassLoader().getResource(path);
- return new File(url.getFile());
- }
-
- private String getServerResponse(URL url) throws IOException {
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setUseCaches(false);
- connection.setDoInput(true);
- connection.setAllowUserInteraction(false);
- connection.setConnectTimeout(WEBAPP_RESPONSE_TIMEOUT);
- connection.setInstanceFollowRedirects(true);
- connection.setDoOutput(false);
- BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
- return toString(in);
- }
-
- private String toString(BufferedInputStream in) throws IOException {
- StringWriter writer = new StringWriter();
- for (int data = -1; ((data = in.read()) != -1);) {
- writer.write(data);
- }
- return writer.toString();
- }
-
-
-}
-
Copied: workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/as/demos/war/runner/StandaloneDeployerIntegrationTest.java (from rev 30521, workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/as/demos/war/runner/DeploymentUtilsIntegrationTest.java)
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/as/demos/war/runner/StandaloneDeployerIntegrationTest.java (rev 0)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/as/demos/war/runner/StandaloneDeployerIntegrationTest.java 2011-04-12 17:26:48 UTC (rev 30522)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.as.demos.war.runner;
+
+import static org.jboss.as.protocol.StreamUtils.safeClose;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.HttpURLConnection;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.ide.eclipse.as7.deployment.StandaloneDeployer;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class StandaloneDeployerIntegrationTest {
+
+ private static final String WAR_FOLDER = "/wars/";
+ private static final String BUNDLE_ID = "org.jboss.ide.eclipse.as7.deployment.tests";
+
+ private static final int WEBAPP_RESPONSE_TIMEOUT = 10 * 1024;
+
+ private static final String HOST = "localhost";
+ private static final int WEB_PORT = 8080;
+
+ @Test
+ public void canDeployUsingDeploymentUtils() throws Exception {
+ StandaloneDeployer utils = null;
+ try {
+ utils = new StandaloneDeployer();
+ File warFile = getWarFile("minimalistic.war");
+ utils.addWarFileDeployment(warFile);
+ utils.deploy();
+
+ String response = getServerResponse(new URL(
+ MessageFormat.format("http://{0}:{1}/{2}",
+ HOST, String.valueOf(WEB_PORT), "minimalistic")));
+ assertTrue(response.indexOf("minimalistic") >= 0);
+
+ } finally {
+ utils.undeploy();
+ safeClose(utils);
+ }
+ }
+
+ private File getWarFile(String name) throws URISyntaxException, IOException {
+ Bundle bundle = Platform.getBundle(BUNDLE_ID);
+ URL entryUrl = bundle.getEntry(WAR_FOLDER + name);
+ return new File(FileLocator.resolve(entryUrl).toURI());
+ }
+
+ private String getServerResponse(URL url) throws IOException {
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setUseCaches(false);
+ connection.setDoInput(true);
+ connection.setAllowUserInteraction(false);
+ connection.setConnectTimeout(WEBAPP_RESPONSE_TIMEOUT);
+ connection.setInstanceFollowRedirects(true);
+ connection.setDoOutput(false);
+ BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
+ return toString(in);
+ }
+
+ private String toString(InputStream in) throws IOException {
+ StringWriter writer = new StringWriter();
+ for (int data = -1; ((data = in.read()) != -1);) {
+ writer.write(data);
+ }
+ return writer.toString();
+ }
+}
Property changes on: workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/as/demos/war/runner/StandaloneDeployerIntegrationTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted: workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/DeploymentUtils.java
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/DeploymentUtils.java 2011-04-12 16:23:19 UTC (rev 30521)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/DeploymentUtils.java 2011-04-12 17:26:48 UTC (rev 30522)
@@ -1,345 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ide.eclipse.as7.deployment.tests;
-
-import static org.jboss.as.protocol.StreamUtils.safeClose;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
-import org.jboss.as.controller.client.ModelControllerClient;
-import org.jboss.as.controller.client.helpers.standalone.DeploymentPlan;
-import org.jboss.as.controller.client.helpers.standalone.DeploymentPlanBuilder;
-import org.jboss.as.controller.client.helpers.standalone.DuplicateDeploymentNameException;
-import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentManager;
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ArchivePath;
-import org.jboss.shrinkwrap.api.ArchivePaths;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.container.ResourceContainer;
-import org.jboss.shrinkwrap.api.exporter.ZipExporter;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-
-/**
- * Used to deploy/undeploy deployments to a running <b>standalone</b> application server
- *
- * TODO Use the real deployment API once that is complete
- *
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision: 1.1 $
- */
-public class DeploymentUtils implements Closeable {
-
- public static final long DEFAULT_TIMEOUT = 15000;
-
- private final List<AbstractDeployment> deployments = new ArrayList<AbstractDeployment>();
- private final ModelControllerClient client;
- private final ServerDeploymentManager manager;
- private long timeout = DEFAULT_TIMEOUT;
-
- public DeploymentUtils() throws UnknownHostException {
- client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999);
- manager = ServerDeploymentManager.Factory.create(client);
- }
-
- public DeploymentUtils(String archiveName, Package... pkg) throws UnknownHostException {
- this();
- addDeployment(archiveName, pkg);
- }
-
- public DeploymentUtils(Archive<?> archive) throws UnknownHostException {
- this();
- deployments.add(new ArbitraryDeployment(archive,false));
- }
-
- public DeploymentUtils(String archiveName, boolean show, Package... pkgs) throws UnknownHostException {
- this();
- addDeployment(archiveName, show, pkgs);
- }
-
- public synchronized void addDeployment(String archiveName, Package... pkgs) {
- addDeployment(archiveName, false, pkgs);
- }
-
- public synchronized void addDeployment(String archiveName, boolean show, Package... pkgs) {
- deployments.add(new Deployment(archiveName, pkgs, show));
- }
-
- public synchronized void addWarDeployment(String archiveName, Package... pkgs) {
- addWarDeployment(archiveName, false, pkgs);
- }
-
- public synchronized void addWarDeployment(String archiveName, boolean show, Package... pkgs) {
- deployments.add(new WarDeployment(archiveName, pkgs, show));
- }
-
- public synchronized void addWarFileDeployment(File file) {
- deployments.add(new WarFileDeployment(file));
- }
-
- public synchronized void deploy() throws DuplicateDeploymentNameException, IOException, ExecutionException, InterruptedException, TimeoutException {
- DeploymentPlanBuilder builder = manager.newDeploymentPlan().withRollback();
- for (AbstractDeployment deployment : deployments) {
- builder = deployment.addDeployment(manager, builder);
- }
-
- try {
- manager.execute(builder.build()).get(timeout, TimeUnit.MILLISECONDS);
- } finally {
- markDeploymentsDeployed();
- }
- }
-
- private void markDeploymentsDeployed() {
- for (AbstractDeployment deployment : deployments) {
- deployment.deployed = true;
- }
- }
-
- public synchronized void undeploy() throws ExecutionException, InterruptedException, TimeoutException {
- DeploymentPlanBuilder builder = manager.newDeploymentPlan();
- for (AbstractDeployment deployment : deployments) {
- builder = deployment.removeDeployment(builder);
- }
- DeploymentPlan plan = builder.build();
- if (plan.getDeploymentActions().size() > 0) {
- manager.execute(builder.build()).get(timeout, TimeUnit.MILLISECONDS);
- }
- }
-
- public MBeanServerConnection getConnection() throws Exception {
- return JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi"),
- new HashMap<String, Object>()).getMBeanServerConnection();
- }
-
- public String showJndi() throws Exception {
- return (String)getConnection().invoke(new ObjectName("jboss:type=JNDIView"), "list", new Object[] {true}, new String[] {"boolean"});
- }
-
- public long getTimeout() {
- return timeout;
- }
-
- public void setTimeout(long timeout) {
- this.timeout = timeout;
- }
-
- @Override
- public void close() throws IOException {
- safeClose(client);
- }
-
- private abstract class AbstractDeployment{
-
- boolean deployed;
- String deployment;
-
- public synchronized DeploymentPlanBuilder addDeployment(ServerDeploymentManager manager, DeploymentPlanBuilder builder) throws DuplicateDeploymentNameException, IOException, ExecutionException, InterruptedException {
- deployment = getRealArchive().getName();
- System.out.println("Deploying " + deployment);
- return builder.add(deployment, getRealArchive()).deploy(deployment);
- }
-
- public synchronized DeploymentPlanBuilder removeDeployment(DeploymentPlanBuilder builder) {
- if (deployed) {
- System.out.println("Undeploying " + deployment);
- return builder.undeploy(deployment).remove(deployment);
- }
- else {
- return builder;
- }
- }
-
- protected void addFiles(ResourceContainer<?> archive, File dir, ArchivePath dest) {
- for (String name : dir.list()) {
- File file = new File(dir, name);
- if (file.isDirectory()) {
- addFiles(archive, file, ArchivePaths.create(dest, name));
- } else {
- archive.addAsResource(file, ArchivePaths.create(dest, name));
- }
- }
- }
-
- protected File getSourceMetaInfDir(String archiveName) {
- String name = "archives/" + archiveName + "/META-INF/MANIFEST.MF";
-
- URL url = Thread.currentThread().getContextClassLoader().getResource(name);
- if (url == null) {
- throw new IllegalArgumentException("No resource called " + name);
- }
- try {
- File file = new File(url.toURI());
- return file.getParentFile();
- } catch (URISyntaxException e) {
- throw new RuntimeException("Could not get file for " + url);
- }
- }
-
- protected File getSourceWebInfDir(String archiveName) {
- String name = "archives/" + archiveName + "/WEB-INF";
-
- URL url = Thread.currentThread().getContextClassLoader().getResource(name);
- if (url == null) {
- return null;
- }
- try {
- return new File(url.toURI());
- } catch (URISyntaxException e) {
- throw new RuntimeException("Could not get file for " + url);
- }
- }
-
- protected File getOutputDir() {
- File file = new File("target");
- if (!file.exists()) {
- throw new IllegalStateException("target/ does not exist");
- }
- if (!file.isDirectory()) {
- throw new IllegalStateException("target/ is not a directory");
- }
- file = new File(file, "archives");
- if (file.exists()) {
- if (!file.isDirectory()) {
- throw new IllegalStateException("target/archives/ already exists and is not a directory");
- }
- } else {
- file.mkdir();
- }
- return file.getAbsoluteFile();
- }
-
- protected File createArchive(Archive<?> archive) {
- File realArchive = new File(getOutputDir(), archive.getName());
- archive.as(ZipExporter.class).exportZip(realArchive, true);
- return realArchive;
- }
-
- protected abstract File getRealArchive();
- }
-
- private class Deployment extends AbstractDeployment {
- final File realArchive;
-
- public Deployment(String archiveName, Package[] pkgs, boolean show) {
-
- ArchivePath metaInf = ArchivePaths.create("META-INF");
-
- JavaArchive archive = ShrinkWrap.create(JavaArchive.class, archiveName);
- for(Package pkg : pkgs) {
- archive.addPackage(pkg);
- }
-
- File sourceMetaInf = getSourceMetaInfDir(archiveName);
- addFiles(archive, sourceMetaInf, metaInf);
-
- System.out.println(archive.toString(show));
- realArchive = createArchive(archive);
- }
-
- @Override
- protected File getRealArchive() {
- return realArchive;
- }
- }
-
-
- private class WarDeployment extends AbstractDeployment {
- final File realArchive;
-
- public WarDeployment(String archiveName, Package[] pkgs, boolean show) {
-
- ArchivePath metaInf = ArchivePaths.create("META-INF");
-
-
- WebArchive archive = ShrinkWrap.create(WebArchive.class, archiveName);
- for(Package pkg : pkgs) {
- archive.addPackage(pkg);
- }
-
- File sourceMetaInf = getSourceMetaInfDir(archiveName);
- addFiles(archive, sourceMetaInf, metaInf);
-
- File sourceWebInf = getSourceWebInfDir(archiveName);
- if (sourceWebInf != null) {
- addFiles(archive, sourceWebInf, ArchivePaths.create("WEB-INF"));
- }
-
- System.out.println(archive.toString(show));
- realArchive = createArchive(archive);
- }
-
- @Override
- protected File getRealArchive() {
- return realArchive;
- }
- }
-
- private class ArbitraryDeployment extends AbstractDeployment {
- final File realArchive;
-
- public ArbitraryDeployment(Archive archive, boolean show) {
-
- ArchivePath metaInf = ArchivePaths.create("META-INF");
-
- System.out.println(archive.toString(show));
- realArchive = createArchive(archive);
- }
-
- @Override
- protected File getRealArchive() {
- return realArchive;
- }
- }
-
- private class WarFileDeployment extends AbstractDeployment {
-
- private File file;
-
- public WarFileDeployment(File file) {
- this.file = file;
- }
-
- @Override
- protected File getRealArchive() {
- return file;
- }
-
- }
-}
More information about the jbosstools-commits
mailing list