tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject svn commit: r1200043 - in /openejb/trunk: openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/deploy/ openejb/assembly/tomee/tomee-catalina/src/tes...
Date Wed, 09 Nov 2011 23:42:16 GMT
Author: jgallimore
Date: Wed Nov  9 23:42:15 2011
New Revision: 1200043

URL: http://svn.apache.org/viewvc?rev=1200043&view=rev
Log:
TOMEE-37 more work on the WebappDeployer. Moved to its own module, and extended to work with
ejb-jars and ears

Added:
    openejb/trunk/sandbox/webdeployer/   (with props)
    openejb/trunk/sandbox/webdeployer/pom.xml
    openejb/trunk/sandbox/webdeployer/src/
    openejb/trunk/sandbox/webdeployer/src/main/
    openejb/trunk/sandbox/webdeployer/src/main/java/
    openejb/trunk/sandbox/webdeployer/src/main/java/org/
    openejb/trunk/sandbox/webdeployer/src/main/java/org/apache/
    openejb/trunk/sandbox/webdeployer/src/main/java/org/apache/tomee/
    openejb/trunk/sandbox/webdeployer/src/main/java/org/apache/tomee/catalina/
    openejb/trunk/sandbox/webdeployer/src/main/java/org/apache/tomee/catalina/deployer/
    openejb/trunk/sandbox/webdeployer/src/main/java/org/apache/tomee/catalina/deployer/WebappDeployer.java
    openejb/trunk/sandbox/webdeployer/src/test/
    openejb/trunk/sandbox/webdeployer/src/test/java/
Removed:
    openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/deploy/
    openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/test/java/org/apache/tomee/deployer/
Modified:
    openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java

Modified: openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java?rev=1200043&r1=1200042&r2=1200043&view=diff
==============================================================================
--- openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
(original)
+++ openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
Wed Nov  9 23:42:15 2011
@@ -886,7 +886,7 @@ public class TomcatWebAppBuilder impleme
      * {@inheritDoc}
      */
     @Override
-    public void checkHost(StandardHost standardHost) {
+    public synchronized void checkHost(StandardHost standardHost) {
         if (standardHost.getAutoDeploy()) {
             // Undeploy any modified application
             for (Iterator<Map.Entry<String, DeployedApplication>> iterator =
deployedApps.entrySet().iterator(); iterator.hasNext();) {

Propchange: openejb/trunk/sandbox/webdeployer/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Nov  9 23:42:15 2011
@@ -0,0 +1,5 @@
+target
+.project
+.settings
+.classpath
+

Added: openejb/trunk/sandbox/webdeployer/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/webdeployer/pom.xml?rev=1200043&view=auto
==============================================================================
--- openejb/trunk/sandbox/webdeployer/pom.xml (added)
+++ openejb/trunk/sandbox/webdeployer/pom.xml Wed Nov  9 23:42:15 2011
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+-->
+<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>
+
+  <groupId>org.apache.openejb</groupId>
+  <artifactId>webdeployer</artifactId>
+  <version>4.0.0-beta-2-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>webdeployer</name>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+  	<dependency>
+  		<groupId>org.apache.openejb</groupId>
+  		<artifactId>tomee-catalina</artifactId>
+  		<version>4.0.0-beta-2-SNAPSHOT</version>
+  		<type>jar</type>
+  		<scope>provided</scope>
+  	</dependency>
+  </dependencies>
+</project>

Added: openejb/trunk/sandbox/webdeployer/src/main/java/org/apache/tomee/catalina/deployer/WebappDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/webdeployer/src/main/java/org/apache/tomee/catalina/deployer/WebappDeployer.java?rev=1200043&view=auto
==============================================================================
--- openejb/trunk/sandbox/webdeployer/src/main/java/org/apache/tomee/catalina/deployer/WebappDeployer.java
(added)
+++ openejb/trunk/sandbox/webdeployer/src/main/java/org/apache/tomee/catalina/deployer/WebappDeployer.java
Wed Nov  9 23:42:15 2011
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.tomee.catalina.deployer;
+
+import static javax.ejb.TransactionManagementType.BEAN;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionManagement;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Service;
+import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.core.StandardServer;
+import org.apache.catalina.util.ContextName;
+import org.apache.openejb.NoSuchApplicationException;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.UndeployException;
+import org.apache.openejb.assembler.Deployer;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.WebAppBuilder;
+import org.apache.openejb.loader.FileUtils;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.tomcat.util.modeler.Registry;
+import org.apache.tomee.catalina.TomcatWebAppBuilder;
+import org.apache.tomee.loader.TomcatHelper;
+
+@Stateless(name = "openejb/WebappDeployer")
+@Remote(Deployer.class)
+@TransactionManagement(BEAN)
+public class WebappDeployer implements Deployer {
+
+	private static final String WEBAPPS = "webapps";
+	private static final String OPENEJB_HOME = "openejb.home";
+	private final TomcatWebAppBuilder webappBuilder;
+	private final Assembler assembler;
+	private final MBeanServer mBeanServer;
+
+	public WebappDeployer() {
+		assembler = (Assembler) SystemInstance.get().getComponent(org.apache.openejb.spi.Assembler.class);
+		webappBuilder = (TomcatWebAppBuilder) SystemInstance.get().getComponent(WebAppBuilder.class);
+		mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
+	}
+
+	public String getUniqueFile() {
+		throw new RuntimeException("This method is not used");
+	}
+
+	public Collection<AppInfo> getDeployedApps() {
+		return assembler.getDeployedApplications();
+	}
+
+	public AppInfo deploy(String location) throws OpenEJBException {
+		return deploy(location, null);
+	}
+
+	public AppInfo deploy(Properties properties) throws OpenEJBException {
+		return deploy(null, properties);
+	}
+
+	public AppInfo deploy(String location, Properties properties) throws OpenEJBException {
+		try {
+			if (location == null && properties == null) {
+				throw new NullPointerException("location and properties are null");
+			}
+			if (location == null) {
+				location = properties.getProperty(FILENAME);
+			}
+			if (properties == null) {
+				properties = new Properties();
+			}
+
+			File source = new File(location);
+			File destination = new File(System.getProperty(OPENEJB_HOME) + File.separator + WEBAPPS
+ File.separator + source.getName());
+			FileUtils.copyFile(destination, source);
+
+			String destinationWithoutExtension = destination.getAbsolutePath();
+			String destinationFilenameWithoutExtension = destination.getName();
+
+			if (destination.getName().contains(".")) {
+				destinationWithoutExtension = destinationWithoutExtension.substring(0, destinationWithoutExtension.lastIndexOf('.'));
+				destinationFilenameWithoutExtension = destinationFilenameWithoutExtension.substring(0,
destinationFilenameWithoutExtension.lastIndexOf('.'));
+			}
+
+			if (destination.getName().toLowerCase().endsWith(".war")) {
+				checkWebapp(destinationFilenameWithoutExtension);
+			} else {
+				check();
+			}
+
+			return findAppInfo(new String[] { destination.getAbsolutePath(), destinationWithoutExtension
});
+		} catch (Exception e) {
+			throw new OpenEJBException(e);
+		}
+	}
+
+	private AppInfo findAppInfo(String... paths) {
+		Collection<AppInfo> deployedApps = getDeployedApps();
+
+		Iterator<AppInfo> iterator = deployedApps.iterator();
+		while (iterator.hasNext()) {
+			AppInfo appInfo = (AppInfo) iterator.next();
+			for (String path : paths) {
+				if (appInfo.path.equals(path)) {
+					return appInfo;
+				}
+			}
+		}
+		
+		return null;
+	}
+
+	private void check() {
+		StandardServer server = TomcatHelper.getServer();
+		for (Service service : server.findServices()) {
+			if (service.getContainer() instanceof Engine) {
+				Engine engine = (Engine) service.getContainer();
+				for (Container engineChild : engine.findChildren()) {
+					if (engineChild instanceof StandardHost) {
+						StandardHost host = (StandardHost) engineChild;
+						webappBuilder.checkHost(host);
+					}
+				}
+			}
+		}
+	}
+
+	private void checkWebapp(String webappName) {
+		try {
+			ContextName cn = new ContextName(webappName);
+
+			String name = "Catalina:type=Deployer,host=localhost";
+			ObjectName oname = new ObjectName(name);
+
+			String[] params = { cn.getName() };
+			String[] signature = { "java.lang.String" };
+			mBeanServer.invoke(oname, "check", params, signature);
+		} catch (Exception e) {
+		}
+	}
+
+	public void undeploy(String moduleId) throws UndeployException, NoSuchApplicationException
{
+		try {
+			AppInfo appInfo = findAppInfo(moduleId);
+			if (appInfo !=  null) {
+				webappBuilder.undeployWebApps(appInfo);
+			}
+			
+			assembler.destroyApplication(moduleId);
+
+			File moduleFile = new File(moduleId);
+			
+			if (moduleFile.getName().contains(".")) {
+				// delete matching directory
+				File dir = new File(moduleFile.getAbsolutePath().substring(0, moduleFile.getAbsolutePath().lastIndexOf('.')));
+				if (dir.exists() && dir.isDirectory()) {
+					delete(dir);
+				}
+			} else {
+				delete(new File(moduleFile + ".war"));
+				delete(new File(moduleFile + ".ear"));
+				delete(new File(moduleFile + ".rar"));
+			}
+			
+			delete(moduleFile);
+
+		} catch (Exception e) {
+			throw new UndeployException(e);
+		}
+	}
+
+	private void delete(File f) {
+		if (f == null || (!f.exists())) {
+			return;
+		}
+		
+		if (f.isFile()) {
+			f.delete();
+			return;
+		}
+		
+		if (f.isDirectory()) {
+			File[] listFiles = f.listFiles();
+			for (File file : listFiles) {
+				if (file.getName().equals(".") || file.getName().equals("..")) continue;
+				delete(file);
+			}
+			
+			f.delete();
+		}
+	}
+
+}



Mime
View raw message