You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2012/02/13 03:23:55 UTC

svn commit: r1243396 [1/2] - in /openejb/trunk/openejb/arquillian-tomee: arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/ arquillian-tomee-remote...

Author: dblevins
Date: Mon Feb 13 02:23:54 2012
New Revision: 1243396

URL: http://svn.apache.org/viewvc?rev=1243396&view=rev
Log:
Rewrote TomEE Remote adapter
Finished Tomcat+Tomee.war adapter
TOMEE-127, TOME-136
TOMEE-137: Arquillian.xml properties overridable as system properties for TomEE adapters

Added:
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java
      - copied, changed from r1243279, openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/FileUtils.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ObjectMap.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Prefixes.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Threads.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Todo.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Todos.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Zips.java
      - copied, changed from r1243279, openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/ZipExtractor.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEConfiguration.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEConfiguration.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappConfiguration.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java
      - copied, changed from r1243295, openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/RemoteTomEEContainer.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappEJBEnricherArchiveAppender.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappExtension.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappObserver.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappRemoteExtension.java
Removed:
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/FileUtils.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/ZipExtractor.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/RemoteTomEEContainer.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/RemoteTomEEEJBEnricherArchiveAppender.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/RemoteTomEEExtension.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/RemoteTomEEObserver.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/RemoteTomEERemoteExtension.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/ZipExtractor.java
Modified:
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEObserver.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEERemoteExtension.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/resources/arquillian.xml
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/test/resources/arquillian.xml

Copied: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java (from r1243279, openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/FileUtils.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java?p2=openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java&p1=openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/FileUtils.java&r1=1243279&r2=1243396&rev=1243396&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/FileUtils.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java Mon Feb 13 02:23:54 2012
@@ -24,7 +24,7 @@ import java.util.List;
 /**
  * @version $Rev: 1157006 $ $Date: 2011-08-12 01:23:04 -0700 (Fri, 12 Aug 2011) $
  */
-public class FileUtils {
+public class Files {
 
     public static File createTempDir() throws IOException {
         File tempDir = File.createTempFile("tomee", ".conf");
@@ -34,7 +34,7 @@ public class FileUtils {
         return tempDir;
     }
     
-    private FileUtils() {
+    private Files() {
         // no-op
     }
 
@@ -71,4 +71,35 @@ public class FileUtils {
             file.delete();
         }
     }
+
+    public static void mkdir(File dir) {
+        if (dir.exists()) return;
+        if (!dir.mkdirs()) {
+            throw new IllegalStateException("cannot make directory: " + dir.getAbsolutePath());
+        }
+    }
+
+    public static void writable(File file) {
+        if (!file.canWrite()) {
+            throw new IllegalStateException("Not writable: " + file.getAbsolutePath());
+        }
+    }
+
+    public static void readable(File file) {
+        if (!file.canRead()) {
+            throw new IllegalStateException("Not readable: " + file.getAbsolutePath());
+        }
+    }
+
+    public static void assertDir(File file) {
+        if (!file.isDirectory()) {
+            throw new IllegalStateException("Not a directory: " + file.getAbsolutePath());
+        }
+    }
+
+    public static void assertFile(File file) {
+        if (!file.isFile()) {
+            throw new IllegalStateException("Not a file: " + file.getAbsolutePath());
+        }
+    }
 }

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ObjectMap.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ObjectMap.java?rev=1243396&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ObjectMap.java (added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ObjectMap.java Mon Feb 13 02:23:54 2012
@@ -0,0 +1,184 @@
+/*
+ * 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.openejb.arquillian.common;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.AbstractMap;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+* @version $Rev$ $Date$
+*/
+public class ObjectMap extends AbstractMap<String, Object> {
+
+    private final Object object;
+    private Map<String,Entry<String,Object>> attributes;
+    private Set<Entry<String,Object>> entries;
+
+    public ObjectMap(Object object) {
+        this(object.getClass(), object);
+    }
+
+    public ObjectMap(Class clazz) {
+        this(clazz, null);
+    }
+
+    public ObjectMap(Class<?> clazz, Object object) {
+        this.object = object;
+
+        attributes = new HashMap<String, Entry<String, Object>>();
+
+        for (Field field : clazz.getFields()) {
+            final FieldEntry entry = new FieldEntry(field);
+            attributes.put(entry.getKey(), entry);
+        }
+
+        for (Method getter : clazz.getMethods()) {
+            try {
+                if (getter.getName().startsWith("get")) continue;
+                if (getter.getParameterTypes().length != 0) continue;
+
+
+                final String name = getter.getName().replaceFirst("get", "set");
+                final Method setter = clazz.getMethod(name, getter.getReturnType());
+
+                final MethodEntry entry = new MethodEntry(getter, setter);
+
+                attributes.put(entry.getKey(), entry);
+            } catch (NoSuchMethodException e) {
+            }
+        }
+
+        entries = Collections.unmodifiableSet(new HashSet<Entry<String, Object>>(attributes.values()));
+    }
+
+    @Override
+    public Object get(Object key) {
+        final Entry<String, Object> entry = attributes.get(key);
+        if (entry == null) return null;
+        return entry.getValue();
+    }
+
+    @Override
+    public Object put(String key, Object value) {
+        final Entry<String, Object> entry = attributes.get(key);
+        if (entry == null) return null;
+        return entry.setValue(value);
+    }
+
+    @Override
+    public boolean containsKey(Object key) {
+        return attributes.containsKey(key);
+    }
+
+    @Override
+    public Object remove(Object key) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Set<Entry<String, Object>> entrySet() {
+        return entries;
+    }
+
+    public class FieldEntry implements Entry<String, Object>  {
+
+        private final Field field;
+
+        public FieldEntry(Field field) {
+            this.field = field;
+        }
+
+        @Override
+        public String getKey() {
+            return field.getName();
+        }
+
+        @Override
+        public String getValue() {
+            try {
+                return (String) field.get(object);
+            } catch (IllegalAccessException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+
+        @Override
+        public Object setValue(Object value) {
+            try {
+                final Object replaced = getValue();
+                field.set(object, value);
+                return replaced;
+            } catch (IllegalAccessException e) {
+                throw new IllegalArgumentException(e);
+            }
+        }
+    }
+
+    public class MethodEntry implements Entry<String, Object> {
+        private final String key;
+        private final Method getter;
+        private final Method setter;
+
+        public MethodEntry(Method getter, Method setter) {
+            StringBuilder name = new StringBuilder(getter.getName());
+
+            // remove 'set' or 'get'
+            name.delete(0, 3);
+
+            // lowercase first char
+            name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
+
+            this.key = name.toString();
+            this.getter = getter;
+            this.setter = setter;
+        }
+
+        protected Object invoke(Method method, Object... args) {
+            try {
+                return method.invoke(object, args);
+            } catch (IllegalAccessException e) {
+                throw new IllegalStateException(e);
+            } catch (InvocationTargetException e) {
+                throw new RuntimeException(e.getCause());
+            }
+        }
+
+        @Override
+        public String getKey() {
+            return key;
+        }
+
+        @Override
+        public Object getValue() {
+            return invoke(getter);
+        }
+
+        @Override
+        public Object setValue(Object value) {
+            final Object original = getValue();
+            invoke(setter, value);
+            return original;
+        }
+    }
+}
\ No newline at end of file

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Prefixes.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Prefixes.java?rev=1243396&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Prefixes.java (added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Prefixes.java Mon Feb 13 02:23:54 2012
@@ -0,0 +1,17 @@
+package org.apache.openejb.arquillian.common;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+
+/**
+ * @version $Rev$ $Date$
+ */
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({TYPE})
+public @interface Prefixes {
+    String[] value();
+}

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java?rev=1243396&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java (added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java Mon Feb 13 02:23:54 2012
@@ -0,0 +1,174 @@
+/*
+ * 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.openejb.arquillian.common;
+
+import org.apache.openejb.loader.ProvisioningUtil;
+import org.jboss.arquillian.container.spi.client.container.LifecycleException;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Setup {
+    public static void exportProperties(File openejbHome, TomEEConfiguration c) {
+        System.setProperty("tomee.http.port", String.valueOf(c.getHttpPort()));
+        System.setProperty("tomee.shutdown.port", String.valueOf(c.getStopPort()));
+        System.setProperty("java.naming.provider.url", "http://localhost:" + c.getHttpPort() + "/tomee/ejb");
+        System.setProperty("connect.tries", "90");
+        System.setProperty("server.http.port", String.valueOf(c.getHttpPort()));
+        System.setProperty("server.shutdown.port", String.valueOf(c.getStopPort()));
+        System.setProperty("java.opts", "-Xmx512m -Xms256m -XX:PermSize=64m -XX:MaxPermSize=256m -XX:ReservedCodeCacheSize=64m -Dtomee.http.port=" + c.getHttpPort());
+        System.setProperty("openejb.home", openejbHome.getAbsolutePath());
+    }
+
+    public static void updateServerXml(File openejbHome, TomEEConfiguration c) throws IOException {
+        final Map<String, String> replacements = new HashMap<String, String>();
+        replacements.put("8080", String.valueOf(c.getHttpPort()));
+        replacements.put("8005", String.valueOf(c.getStopPort()));
+        final String s = File.separator;
+        replace(replacements, new File(openejbHome, "conf" + s + "server.xml"));
+    }
+
+    public static File findHome(File directory) {
+        final File conf = new File(directory, "conf");
+        final File webapps = new File(directory, "webapps");
+
+        if (conf.exists() && conf.isDirectory() && webapps.exists() && webapps.isDirectory()) {
+            return directory;
+        }
+
+        for (File file : directory.listFiles()) {
+            if (".".equals(file.getName()) || "..".equals(file.getName())) continue;
+
+            final File found = findHome(file);
+
+            if (found != null) {
+                return found;
+            }
+        }
+
+        return null;
+    }
+
+    public static File downloadAndUnpack(File dir, String artifactID) throws LifecycleException {
+
+        File zipFile = downloadFile(artifactID, null);
+
+        Zips.unzip(zipFile, dir);
+
+        return findHome(dir);
+    }
+
+    public static File downloadFile(String artifactName, String altUrl) {
+        final String cache = System.getProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER);
+        System.setProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER, "target");
+        try {
+            final File artifact = new MavenCache().getArtifact(artifactName, altUrl);
+            if (artifact == null) throw new NullPointerException(String.format("No such artifact: %s", artifactName));
+            return artifact;
+        } finally {
+            if (cache == null) {
+                System.getProperties().remove(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER);
+            } else {
+                System.setProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER, cache);
+            }
+        }
+    }
+
+    public static boolean isRunning(int port) {
+        try {
+            Socket socket = new Socket("localhost", port);
+            OutputStream out = socket.getOutputStream();
+            out.close();
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    public static void replace(Map<String, String> replacements, File file) throws IOException {
+        BufferedReader reader = null;
+        PrintWriter writer = null;
+
+        try {
+            File tmpFile = copyToTempFile(file);
+            reader = new BufferedReader(new FileReader(tmpFile));
+            writer = new PrintWriter(new FileWriter(file));
+            String line;
+
+            while ((line = reader.readLine()) != null) {
+                Iterator<String> iterator = replacements.keySet().iterator();
+                while (iterator.hasNext()) {
+                    String pattern = iterator.next();
+                    String replacement = replacements.get(pattern);
+
+                    line = line.replaceAll(pattern, replacement);
+                }
+
+                writer.println(line);
+            }
+        } finally {
+            if (reader != null) {
+                reader.close();
+            }
+
+            if (writer != null) {
+                writer.close();
+            }
+        }
+    }
+
+    private static File copyToTempFile(File file) throws IOException {
+        InputStream is = null;
+        OutputStream os = null;
+
+        File tmpFile;
+        try {
+            tmpFile = File.createTempFile("oejb", ".fil");
+            tmpFile.deleteOnExit();
+
+            is = new FileInputStream(file);
+            os = new FileOutputStream(tmpFile);
+
+            IO.copy(is, os);
+        } finally {
+            if (is != null) {
+                is.close();
+            }
+
+            if (os != null) {
+                os.close();
+            }
+        }
+
+        return tmpFile;
+    }
+}

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Threads.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Threads.java?rev=1243396&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Threads.java (added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Threads.java Mon Feb 13 02:23:54 2012
@@ -0,0 +1,37 @@
+/*
+ * 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.openejb.arquillian.common;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+* @version $Rev$ $Date$
+*/
+public class Threads {
+
+    public static void sleep(long duration, TimeUnit unit) {
+        sleep(unit.toMillis(duration));
+    }
+
+    public static void sleep(long milliseconds) {
+        try {
+            Thread.sleep(milliseconds);
+        } catch (InterruptedException e1) {
+            Thread.interrupted();
+        }
+    }
+}

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Todo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Todo.java?rev=1243396&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Todo.java (added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Todo.java Mon Feb 13 02:23:54 2012
@@ -0,0 +1,36 @@
+/**
+ * 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.openejb.arquillian.common;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PACKAGE;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+
+@Todo("Move this to a util package")
+@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, PACKAGE})
+public @interface Todo {
+    String value();
+}

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Todos.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Todos.java?rev=1243396&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Todos.java (added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Todos.java Mon Feb 13 02:23:54 2012
@@ -0,0 +1,33 @@
+/**
+ * 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.openejb.arquillian.common;
+
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PACKAGE;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+
+@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, PACKAGE})
+public @interface Todos {
+    Todo[] value();
+}

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java?rev=1243396&r1=1243395&r2=1243396&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java Mon Feb 13 02:23:54 2012
@@ -31,9 +31,6 @@ public class TomEEConfiguration implemen
     private int httpPort = 8080;
     private int stopPort = 8005;
     private String dir = System.getProperty("java.io.tmpdir") + "/arquillian-apache-tomee";
-    private boolean plusContainer = true;
-    private String tomcatVersion = null;
-    private String openejbVersion;
     private String systemProperties = "";
 
     public int getHttpPort() {
@@ -60,30 +57,6 @@ public class TomEEConfiguration implemen
         this.dir = dir;
     }
 
-    public boolean isPlusContainer() {
-        return plusContainer;
-    }
-
-    public void setPlusContainer(boolean plusContainer) {
-        this.plusContainer = plusContainer;
-    }
-    
-    public String getTomcatVersion() {
-		return tomcatVersion;
-	}
-
-	public void setTomcatVersion(String tomcatVersion) {
-		this.tomcatVersion = tomcatVersion;
-	}
-
-	public String getOpenejbVersion() {
-		return openejbVersion;
-	}
-
-	public void setOpenejbVersion(String openejbVersion) {
-		this.openejbVersion = openejbVersion;
-	}
-
     public String getSystemProperties() {
         return systemProperties;
     }

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1243396&r1=1243395&r2=1243396&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java Mon Feb 13 02:23:54 2012
@@ -20,7 +20,6 @@ import org.apache.openejb.assembler.Depl
 import org.apache.openejb.assembler.classic.AppInfo;
 import org.apache.openejb.assembler.classic.Info;
 import org.apache.openejb.loader.Options;
-import org.apache.openejb.util.OptionsLog;
 import org.jboss.arquillian.container.spi.client.container.DeployableContainer;
 import org.jboss.arquillian.container.spi.client.container.DeploymentException;
 import org.jboss.arquillian.container.spi.client.container.LifecycleException;
@@ -36,23 +35,21 @@ import org.jboss.shrinkwrap.descriptor.a
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
-
 import java.io.File;
-import java.io.IOException;
 import java.io.OutputStream;
 import java.net.Socket;
-import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
-public abstract class TomEEContainer implements DeployableContainer<TomEEConfiguration> {
+public abstract class TomEEContainer<Configuration extends TomEEConfiguration> implements DeployableContainer<Configuration> {
     protected static final Logger LOGGER = Logger.getLogger(TomEEContainer.class.getName());
 
     protected static final String LOCALHOST = "localhost";
     protected static final String SHUTDOWN_COMMAND = "SHUTDOWN" + Character.toString((char) -1);
-    protected TomEEConfiguration configuration;
+    protected Configuration configuration;
     protected Map<String, File> moduleIds = new HashMap<String, File>();
     private final Options options;
 
@@ -60,12 +57,29 @@ public abstract class TomEEContainer imp
         this.options = new Options(System.getProperties());
     }
 
-    public Class<TomEEConfiguration> getConfigurationClass() {
-        return TomEEConfiguration.class;
-    }
-
-    public void setup(TomEEConfiguration configuration) {
+    public void setup(Configuration configuration) {
         this.configuration = configuration;
+
+        final Prefixes prefixes = configuration.getClass().getAnnotation(Prefixes.class);
+        if (prefixes == null) return;
+
+        final ObjectMap map = new ObjectMap(configuration);
+
+        for (String key : map.keySet()) {
+            for (String prefix : prefixes.value()) {
+                final String property = prefix + "." + key;
+                final String value = System.getProperty(property);
+
+                if (value == null) continue;
+
+                try {
+                    LOGGER.log(Level.FINE, String.format("Applying override '%s=%s'", property, value));
+                    map.put(key, value);
+                } catch (Exception e) {
+                    LOGGER.log(Level.WARNING, String.format("Override failed '%s=%s'", property, value), e);
+                }
+            }
+        }
     }
 
     public abstract void start() throws LifecycleException;
@@ -90,11 +104,7 @@ public abstract class TomEEContainer imp
             out.close();
         } catch (Exception e) {
             if (tries > 2) {
-                try {
-                    Thread.sleep(2000);
-                } catch (Exception e2) {
-                    e.printStackTrace();
-                }
+                Threads.sleep(2000);
 
                 waitForShutdown(--tries);
             }
@@ -157,9 +167,9 @@ public abstract class TomEEContainer imp
         properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
         properties.setProperty(Context.PROVIDER_URL, "http://" + LOCALHOST + ":" + configuration.getHttpPort() + "/tomee/ejb");
         return (Deployer) new InitialContext(properties).lookup("openejb/DeployerBusinessRemote");
-	}
+    }
 
-	protected String getArchiveNameWithoutExtension(final Archive<?> archive) {
+    protected String getArchiveNameWithoutExtension(final Archive<?> archive) {
         final String archiveName = archive.getName();
         final int extensionOffset = archiveName.lastIndexOf('.');
         if (extensionOffset >= 0) {
@@ -172,7 +182,7 @@ public abstract class TomEEContainer imp
         try {
             final File file = moduleIds.get(archive.getName());
             deployer().undeploy(file.getAbsolutePath());
-            FileUtils.delete(file.getParentFile()); // "i" folder
+            Files.delete(file.getParentFile()); // "i" folder
         } catch (Exception e) {
             e.printStackTrace();
             throw new DeploymentException("Unable to undeploy", e);

Copied: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Zips.java (from r1243279, openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/ZipExtractor.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Zips.java?p2=openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Zips.java&p1=openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/ZipExtractor.java&r1=1243279&r2=1243396&rev=1243396&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/ZipExtractor.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Zips.java Mon Feb 13 02:23:54 2012
@@ -15,60 +15,52 @@
  *  limitations under the License.
  */
 
-package org.apache.tomee.arquillian.remote;
+package org.apache.openejb.arquillian.common;
 
-import java.io. *;
+import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
-public class ZipExtractor {
+public class Zips {
 
-    public static void unzip(File source, File targetDirectory) {
-        OutputStream os = null;
-        ZipInputStream is = null;
+    private static final Logger logger = Logger.getLogger(Zips.class.getName());
+
+    public static void unzip(File zipFile, File destination) {
+        logger.info(String.format("Extracting '%s' to '%s'", zipFile.getAbsolutePath(), destination.getAbsolutePath()));
+
+        Files.assertDir(destination);
+        Files.writable(destination);
+
+        Files.assertFile(zipFile);
+        Files.readable(zipFile);
 
         try {
-            is = new ZipInputStream(new FileInputStream(source));
-            ZipEntry entry;
+            // Open the ZIP file
+            final ZipInputStream in = IO.unzip(zipFile);
 
-            while ((entry = is.getNextEntry()) != null) {
-                String name = entry.getName();
-                File file = new File(targetDirectory, name);
-
-                if (name.endsWith("/")) {
-                    file.mkdir();
-                } else {
-                    file.createNewFile();
-
-                    int bytesRead;
-                    byte data[] = new byte[8192];
-
-                    os = new FileOutputStream(file);
-                    while ((bytesRead = is.read(data)) != -1) {
-                        os.write(data, 0, bytesRead);
-                    }
+            ZipEntry entry;
 
-                    is.closeEntry();
+            while ((entry = in.getNextEntry()) != null) {
+                final String path = entry.getName();
+                final File file = new File(destination, path);
+
+                if (entry.isDirectory()) {
+                    Files.mkdir(file);
+                    continue;
                 }
 
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            if (is != null) {
-                try {
-                    is.close();
-                } catch (Exception e) {
-                }
+                Files.mkdir(file.getParentFile());
+                IO.copy(in, file);
             }
 
-            if (os != null) {
-                try {
-                    os.close();
-                } catch (Exception e) {
-                }
-            }
+            in.close();
 
+        } catch (Exception e) {
+            logger.log(Level.SEVERE, "Unable to unzip " + zipFile.getAbsolutePath(), e);
+            throw new IllegalStateException("Unable to unzip " + zipFile.getAbsolutePath(), e);
         }
     }
+
 }

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEConfiguration.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEConfiguration.java?rev=1243396&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEConfiguration.java (added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEConfiguration.java Mon Feb 13 02:23:54 2012
@@ -0,0 +1,28 @@
+/*
+ * 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.openejb.arquillian.embedded;
+
+import org.apache.openejb.arquillian.common.Prefixes;
+import org.apache.openejb.arquillian.common.TomEEConfiguration;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Prefixes({"tomee", "tomee.embedded"})
+public class EmbeddedTomEEConfiguration extends TomEEConfiguration {
+
+}

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java?rev=1243396&r1=1243395&r2=1243396&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java Mon Feb 13 02:23:54 2012
@@ -17,8 +17,7 @@
 package org.apache.openejb.arquillian.embedded;
 
 import org.apache.openejb.AppContext;
-import org.apache.openejb.arquillian.common.FileUtils;
-import org.apache.openejb.arquillian.common.TomEEConfiguration;
+import org.apache.openejb.arquillian.common.Files;
 import org.apache.openejb.arquillian.common.TomEEContainer;
 import org.apache.openejb.util.NetworkUtil;
 import org.apache.tomee.embedded.Configuration;
@@ -43,7 +42,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 
-public class EmbeddedTomEEContainer extends TomEEContainer {
+public class EmbeddedTomEEContainer extends TomEEContainer<EmbeddedTomEEConfiguration> {
 
     public static final String TOMEE_ARQUILLIAN_HTTP_PORT = "tomee.arquillian.http";
     public static final String TOMEE_ARQUILLIAN_STOP_PORT = "tomee.arquillian.stop";
@@ -56,12 +55,12 @@ public class EmbeddedTomEEContainer exte
     private Container container;
     private Properties savedProperties;
 
-    public Class<TomEEConfiguration> getConfigurationClass() {
-        return TomEEConfiguration.class;
+    public Class<EmbeddedTomEEConfiguration> getConfigurationClass() {
+        return EmbeddedTomEEConfiguration.class;
     }
 
-    public void setup(TomEEConfiguration configuration) {
-        this.configuration = configuration;
+    public void setup(EmbeddedTomEEConfiguration configuration) {
+        super.setup(configuration);
         setSystemProperties();
         container = new Container();
         container.setup(convertConfiguration(configuration));
@@ -71,7 +70,7 @@ public class EmbeddedTomEEContainer exte
      * Not exactly as elegant as I'd like. Maybe we could have the EmbeddedServer configuration in openejb-core so all the adapters can use it.
      * Depending on tomee-embedded is fine in this adapter, but less desirable in the others, as we'd get loads of stuff in the classpath we don't need.
      */
-    private Configuration convertConfiguration(TomEEConfiguration tomeeConfiguration) {
+    private Configuration convertConfiguration(EmbeddedTomEEConfiguration tomeeConfiguration) {
     	Configuration configuration = new Configuration();
     	configuration.setDir(tomeeConfiguration.getDir());
     	configuration.setHttpPort(getPortAndShare(TOMEE_ARQUILLIAN_HTTP_PORT, tomeeConfiguration.getHttpPort()));
@@ -139,7 +138,7 @@ public class EmbeddedTomEEContainer exte
     public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
     	try {
 
-            final File tempDir = FileUtils.createTempDir();
+            final File tempDir = Files.createTempDir();
             final String name = archive.getName();
             final File file = new File(tempDir, name);
             ARCHIVES.put(archive, file);
@@ -169,8 +168,8 @@ public class EmbeddedTomEEContainer exte
         File file = ARCHIVES.remove(archive);
         File folder = new File(file.getParentFile(), file.getName().substring(0, file.getName().length() - 5));
         if (folder.exists()) {
-            FileUtils.delete(folder);
+            Files.delete(folder);
         }
-        FileUtils.delete(file);
+        Files.delete(file);
     }
 }

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEConfiguration.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEConfiguration.java?rev=1243396&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEConfiguration.java (added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEConfiguration.java Mon Feb 13 02:23:54 2012
@@ -0,0 +1,81 @@
+/*
+ * 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.arquillian.remote;
+
+import org.apache.openejb.arquillian.common.Prefixes;
+import org.apache.openejb.arquillian.common.TomEEConfiguration;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Prefixes({"tomee", "tomee.remote"})
+public class RemoteTomEEConfiguration extends TomEEConfiguration {
+
+    private String groupId = "org.apache.openejb";
+    private String artifactId = "apache-tomee";
+    private String version = "1.0.0-beta-3-SNAPSHOT";
+    private String classifier = "webprofile";
+    private String type = "zip";
+
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public String getClassifier() {
+        return classifier;
+    }
+
+    public void setClassifier(String classifier) {
+        this.classifier = classifier;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getArtifactName() {
+
+        final String format = classifier == null ? "%s:%s:%s:%s" : "%s:%s:%s:%s:%s";
+
+        return String.format(format, getGroupId(), getArtifactId(), getVersion(), getType(), getClassifier());
+
+    }
+}

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java?rev=1243396&r1=1243395&r2=1243396&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java Mon Feb 13 02:23:54 2012
@@ -16,112 +16,76 @@
  */
 package org.apache.tomee.arquillian.remote;
 
-import org.apache.openejb.arquillian.common.FileUtils;
-import org.apache.openejb.arquillian.common.MavenCache;
+import org.apache.openejb.arquillian.common.Files;
+import org.apache.openejb.arquillian.common.Setup;
 import org.apache.openejb.arquillian.common.TomEEContainer;
 import org.apache.openejb.config.RemoteServer;
-import org.apache.openejb.loader.ProvisioningUtil;
-import org.apache.tomee.installer.Installer;
-import org.apache.tomee.installer.Paths;
 import org.jboss.arquillian.container.spi.client.container.LifecycleException;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.net.Socket;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.logging.Logger;
 
 /*
  * TODO: delete old embedded adapter, move the tests and set those up
  */
-public class RemoteTomEEContainer extends TomEEContainer {
-    private static File DOWNLOADED = null;
+public class RemoteTomEEContainer extends TomEEContainer<RemoteTomEEConfiguration> {
+
+    private static final Logger logger = Logger.getLogger(RemoteTomEEContainer.class.getName());
 
     private RemoteServer container;
-    private boolean needsStart = false;
+    private boolean shutdown = false;
 
     public void start() throws LifecycleException {
         if (System.getProperty("tomee.http.port") != null) {
             configuration.setHttpPort(Integer.parseInt(System.getProperty("tomee.http.port")));
         }
+
         if (System.getProperty("tomee.shutdown.port") != null) {
             configuration.setStopPort(Integer.parseInt(System.getProperty("tomee.shutdown.port")));
         }
 
         // see if TomEE is already running by checking the http port
-        try {
-            connect(configuration.getHttpPort());
-        } catch (Exception e) {
-            needsStart = true;
-        }
+        if (Setup.isRunning(configuration.getHttpPort())) {
+
+            logger.info(String.format("TomEE found running on port %s", configuration.getHttpPort()));
 
-        if (!needsStart) {
             return;
         }
 
+        shutdown = true;
+
         try {
+
             final File workingDirectory = new File(configuration.getDir());
-            workingDirectory.mkdirs();
+
             if (workingDirectory.exists()) {
-                FileUtils.deleteOnExit(workingDirectory);
-            }
 
-            File openejbHome;
-            if (DOWNLOADED != null && DOWNLOADED.getAbsolutePath().startsWith(workingDirectory.getAbsolutePath())) {
-                openejbHome = findOpenEJBHome(workingDirectory);
-            } else if (configuration.getTomcatVersion() == null || configuration.getTomcatVersion().length() == 0) {
-                downloadTomEE(workingDirectory);
-                openejbHome = findOpenEJBHome(workingDirectory);
+                Files.assertDir(workingDirectory);
+
             } else {
-                downloadTomcat(workingDirectory, configuration.getTomcatVersion());
-                openejbHome = findOpenEJBHome(workingDirectory);
-                File webappsOpenEJB = new File(openejbHome, "webapps/openejb");
-                webappsOpenEJB.mkdirs();
-                downloadOpenEJBWebapp(webappsOpenEJB);
-
-                System.setProperty("catalina.home", openejbHome.getAbsolutePath());
-                System.setProperty("catalina.base", openejbHome.getAbsolutePath());
-                System.setProperty("openejb.deploymentId.format", "{appId}/{ejbJarId}/{ejbName}");
-                Paths paths = new Paths(new File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
-                Installer installer = new Installer(paths, true);
-                installer.installAll();
-            }
-            DOWNLOADED = workingDirectory;
 
-            if (openejbHome == null || (!openejbHome.exists())) {
-                throw new LifecycleException("Error finding OPENEJB_HOME");
+                Files.mkdir(workingDirectory);
+                Files.deleteOnExit(workingDirectory);
             }
 
-            FileUtils.deleteOnExit(openejbHome);
-            Map<String, String> replacements = new HashMap<String, String>();
-            replacements.put("8080", String.valueOf(configuration.getHttpPort()));
-            replacements.put("8005", String.valueOf(configuration.getStopPort()));
-            replace(replacements, new File(openejbHome, "conf/server.xml"));
-
-            final URL logging = Thread.currentThread().getContextClassLoader().getResource("default.remote.logging.properties");
-            if (logging != null) {
-                write(logging, new File(openejbHome, "conf/logging.properties"));
+            Files.readable(workingDirectory);
+            Files.writable(workingDirectory);
+
+            File openejbHome = Setup.findHome(workingDirectory);
+
+            if (openejbHome == null) {
+                openejbHome = Setup.downloadAndUnpack(workingDirectory, configuration.getArtifactName());
             }
 
-            System.setProperty("tomee.http.port", String.valueOf(configuration.getHttpPort()));
-            System.setProperty("tomee.shutdown.port", String.valueOf(configuration.getStopPort()));
-            System.setProperty("java.naming.provider.url", "http://localhost:" +  configuration.getHttpPort() + "/tomee/ejb");
-            System.setProperty("connect.tries", "90");
-            System.setProperty("server.http.port", String.valueOf(configuration.getHttpPort()));
-            System.setProperty("server.shutdown.port", String.valueOf(configuration.getStopPort()));
-            System.setProperty("java.opts", "-Xmx512m -Xms256m -XX:PermSize=64m -XX:MaxPermSize=256m -XX:ReservedCodeCacheSize=64m -Dtomee.http.port=" + configuration.getHttpPort());
-            System.setProperty("openejb.home", openejbHome.getAbsolutePath());
+            Files.assertDir(openejbHome);
+            Files.readable(openejbHome);
+            Files.writable(openejbHome);
+
+            Setup.updateServerXml(openejbHome, configuration);
+
+            Setup.exportProperties(openejbHome, configuration);
 
             if (false) {
                 Map<Object, Object> map = new TreeMap(System.getProperties());
@@ -137,176 +101,14 @@ public class RemoteTomEEContainer extend
         }
     }
 
-    private static void write(URL resource, File file) throws IOException {
-        if (file.exists()) {
-            FileUtils.delete(file);
-        }
-        InputStream is = resource.openStream();
-        OutputStream out = new FileOutputStream(file);
-        byte buf[] = new byte[1024];
-        int len;
-        while ((len = is.read(buf)) > 0) {
-            out.write(buf, 0, len);
-        }
-        out.close();
-        is.close();
-    }
-
-    private File findOpenEJBHome(File directory) {
-        File conf = new File(directory, "conf");
-        File webapps = new File(directory, "webapps");
-
-        if (conf.exists() && conf.isDirectory() && webapps.exists() && webapps.isDirectory()) {
-            return directory;
-        }
-
-        for (File file : directory.listFiles()) {
-            if (".".equals(file.getName()) || "..".equals(file.getName())) continue;
-
-            File found = findOpenEJBHome(file);
-            if (found != null) {
-                return found;
-            }
-        }
-
-        return null;
-    }
-
-    protected void downloadTomEE(File catalinaDirectory) throws LifecycleException {
-        String artifactName;
-        if (configuration.isPlusContainer()) {
-            artifactName = "org.apache.openejb:apache-tomee:" + configuration.getOpenejbVersion() + ":zip:plus";
-        } else {
-            artifactName = "org.apache.openejb:apache-tomee:" + configuration.getOpenejbVersion() + ":zip:webprofile";
-        }
-
-        File zipFile = downloadFile(artifactName, null);
-        ZipExtractor.unzip(zipFile, catalinaDirectory);
-    }
-
-    protected File downloadFile(String artifactName, String altUrl) {
-        final String cache = System.getProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER);
-        System.setProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER, "target");
-        try {
-            final File artifact = new MavenCache().getArtifact(artifactName, altUrl);
-            if (artifact == null) throw new NullPointerException(String.format("No such artifact: %s", artifactName));
-            return artifact;
-        } finally {
-            if (cache == null) {
-                System.getProperties().remove(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER);
-            } else {
-                System.setProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER, cache);
-            }
-        }
-    }
-
-    protected void downloadOpenEJBWebapp(File targetDirectory) throws LifecycleException {
-        String artifactName;
-        if (configuration.isPlusContainer()) {
-            artifactName = "org.apache.openejb:tomee-plus-webapp:" + configuration.getOpenejbVersion() + ":war";
-        } else {
-            artifactName = "org.apache.openejb:tomee-webapp:" + configuration.getOpenejbVersion() + ":war";
-        }
-
-        File zipFile = downloadFile(artifactName, null);
-        ZipExtractor.unzip(zipFile, targetDirectory);
-    }
-
-    protected void downloadTomcat(File catalinaDirectory, String tomcatVersion) throws LifecycleException {
-        String source = null;
-
-        if (tomcatVersion.startsWith("7.")) {
-            source = "http://archive.apache.org/dist/tomcat/tomcat-7/v" + tomcatVersion + "/bin/apache-tomcat-" + tomcatVersion + ".zip";
-        }
-
-        if (tomcatVersion.startsWith("6.")) {
-            source = "http://archive.apache.org/dist/tomcat/tomcat-6/v" + tomcatVersion + "/bin/apache-tomcat-" + tomcatVersion + ".zip";
-        }
-
-        if (tomcatVersion.startsWith("5.5")) {
-            source = "http://archive.apache.org/dist/tomcat/tomcat-5/v" + tomcatVersion + "/bin/apache-tomcat-" + tomcatVersion + ".zip";
-        }
-
-        if (source == null) {
-            throw new LifecycleException("Unable to find URL for Tomcat " + tomcatVersion);
-        }
-
-        File zipFile = downloadFile("org.apache.openejb:tomcat:" + tomcatVersion + ":zip", source);
-        ZipExtractor.unzip(zipFile, catalinaDirectory);
-    }
-
     public void stop() throws LifecycleException {
         // only stop the container if we started it
-        if (needsStart) {
+        if (shutdown) {
             container.stop();
         }
     }
 
-    public void connect(int port) throws Exception {
-        Socket socket = new Socket("localhost", port);
-        OutputStream out = socket.getOutputStream();
-        out.close();
-    }
-
-    private void replace(Map<String, String> replacements, File file) throws IOException {
-        BufferedReader reader = null;
-        PrintWriter writer = null;
-
-        try {
-            File tmpFile = copyToTempFile(file);
-            reader = new BufferedReader(new FileReader(tmpFile));
-            writer = new PrintWriter(new FileWriter(file));
-            String line;
-
-            while ((line = reader.readLine()) != null) {
-                Iterator<String> iterator = replacements.keySet().iterator();
-                while (iterator.hasNext()) {
-                    String pattern = iterator.next();
-                    String replacement = replacements.get(pattern);
-
-                    line = line.replaceAll(pattern, replacement);
-                }
-
-                writer.println(line);
-            }
-        } catch (IOException e) {
-            throw e;
-        } finally {
-            if (reader != null) {
-                reader.close();
-            }
-
-            if (writer != null) {
-                writer.close();
-            }
-        }
-    }
-
-    private File copyToTempFile(File file) throws IOException {
-        InputStream is = null;
-        OutputStream os = null;
-
-        File tmpFile;
-        try {
-            tmpFile = File.createTempFile("oejb", ".fil");
-            tmpFile.deleteOnExit();
-
-            is = new FileInputStream(file);
-            os = new FileOutputStream(tmpFile);
-
-            Installer.copy(is, os);
-        } catch (IOException e) {
-            throw e;
-        } finally {
-            if (is != null) {
-                is.close();
-            }
-
-            if (os != null) {
-                os.close();
-            }
-        }
-
-        return tmpFile;
+    public Class<RemoteTomEEConfiguration> getConfigurationClass() {
+        return RemoteTomEEConfiguration.class;
     }
 }

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEObserver.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEObserver.java?rev=1243396&r1=1243395&r2=1243396&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEObserver.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEObserver.java Mon Feb 13 02:23:54 2012
@@ -30,8 +30,12 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
 public class RemoteTomEEObserver {
-    @Inject @SuiteScoped private InstanceProducer<BeanManager> beanManager;
-    @Inject @SuiteScoped private InstanceProducer<Context> context;
+    @Inject
+    @SuiteScoped
+    private InstanceProducer<BeanManager> beanManager;
+    @Inject
+    @SuiteScoped
+    private InstanceProducer<Context> context;
 
     public void beforeSuite(@Observes BeforeSuite event) {
         beanManager.set(ThreadSingletonServiceImpl.get().getBeanManagerImpl());

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEERemoteExtension.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEERemoteExtension.java?rev=1243396&r1=1243395&r2=1243396&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEERemoteExtension.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEERemoteExtension.java Mon Feb 13 02:23:54 2012
@@ -20,7 +20,9 @@ package org.apache.tomee.arquillian.remo
 import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
 
 public class RemoteTomEERemoteExtension implements RemoteLoadableExtension {
-    @Override public void register(ExtensionBuilder builder) {
-       builder.observer(RemoteTomEEObserver.class);
+
+    @Override
+    public void register(ExtensionBuilder builder) {
+        builder.observer(RemoteTomEEObserver.class);
     }
 }

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/resources/arquillian.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/resources/arquillian.xml?rev=1243396&r1=1243395&r2=1243396&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/resources/arquillian.xml (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/test/resources/arquillian.xml Mon Feb 13 02:23:54 2012
@@ -22,11 +22,9 @@
 	
        <container qualifier="tomee" default="true">
            <configuration>
-           	   <property name="dir">/tmp/arquillian-apache-tomee</property>
                <property name="httpPort">10080</property>
                <property name="stopPort">10005</property>
-               <property name="tomcatVersion"></property>
-               <property name="openejbVersion">1.0.0-beta-3-SNAPSHOT</property>
+               <property name="version">1.0.0-beta-3-SNAPSHOT</property>
            </configuration>
        </container>
 </arquillian>

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappConfiguration.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappConfiguration.java?rev=1243396&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappConfiguration.java (added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappConfiguration.java Mon Feb 13 02:23:54 2012
@@ -0,0 +1,80 @@
+/*
+ * 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.arquillian.webapp;
+
+import org.apache.openejb.arquillian.common.Prefixes;
+import org.apache.openejb.arquillian.common.TomEEConfiguration;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Prefixes({"tomee", "tomee.webapp"})
+public class TomEEWebappConfiguration extends TomEEConfiguration {
+
+    private String tomcatVersion = null;
+    private String groupId = "org.apache.openejb";
+    private String artifactId = "tomee-webapp";
+    private String version = "1.0.0-beta-3-SNAPSHOT";
+    private String type = "war";
+
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId() {
+        return artifactId;
+    }
+
+    public void setArtifactId(String artifactId) {
+        this.artifactId = artifactId;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getArtifactName() {
+
+        return String.format("%s:%s:%s:%s", getGroupId(), getArtifactId(), getVersion(), getType());
+
+    }
+
+    public String getTomcatVersion() {
+        return tomcatVersion;
+    }
+
+    public void setTomcatVersion(String tomcatVersion) {
+        this.tomcatVersion = tomcatVersion;
+    }
+
+}

Copied: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java (from r1243295, openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/RemoteTomEEContainer.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java?p2=openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java&p1=openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/RemoteTomEEContainer.java&r1=1243295&r2=1243396&rev=1243396&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/RemoteTomEEContainer.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java Mon Feb 13 02:23:54 2012
@@ -16,40 +16,35 @@
  */
 package org.apache.tomee.arquillian.webapp;
 
-import org.apache.openejb.arquillian.common.FileUtils;
-import org.apache.openejb.arquillian.common.MavenCache;
+import org.apache.openejb.arquillian.common.Files;
+import org.apache.openejb.arquillian.common.IO;
+import org.apache.openejb.arquillian.common.Setup;
 import org.apache.openejb.arquillian.common.TomEEContainer;
+import org.apache.openejb.arquillian.common.Zips;
 import org.apache.openejb.config.RemoteServer;
-import org.apache.openejb.loader.ProvisioningUtil;
 import org.apache.tomee.installer.Installer;
 import org.apache.tomee.installer.Paths;
 import org.jboss.arquillian.container.spi.client.container.LifecycleException;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.PrintWriter;
 import java.net.Socket;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.logging.Logger;
 
 /*
  * TODO: delete old embedded adapter, move the tests and set those up
  */
-public class RemoteTomEEContainer extends TomEEContainer {
-    private static File DOWNLOADED = null;
+public class TomEEWebappContainer extends TomEEContainer<TomEEWebappConfiguration> {
+
+    private static final Logger logger = Logger.getLogger(TomEEWebappContainer.class.getName());
 
     private RemoteServer container;
-    private boolean needsStart = false;
+    private boolean shutdown = false;
 
     public void start() throws LifecycleException {
         if (System.getProperty("tomee.http.port") != null) {
@@ -60,69 +55,69 @@ public class RemoteTomEEContainer extend
         }
 
         // see if TomEE is already running by checking the http port
-        try {
-            connect(configuration.getHttpPort());
-        } catch (Exception e) {
-            needsStart = true;
-        }
+        if (Setup.isRunning(configuration.getHttpPort())) {
+
+            logger.info(String.format("Tomcat found running on port %s", configuration.getHttpPort()));
 
-        if (!needsStart) {
             return;
         }
 
+        shutdown = true;
+
+        final String s = File.separator;
         try {
             final File workingDirectory = new File(configuration.getDir());
-            workingDirectory.mkdirs();
+
             if (workingDirectory.exists()) {
-                FileUtils.deleteOnExit(workingDirectory);
-            }
 
-            File openejbHome;
-            if (DOWNLOADED != null && DOWNLOADED.getAbsolutePath().startsWith(workingDirectory.getAbsolutePath())) {
-                openejbHome = findOpenEJBHome(workingDirectory);
-            } else if (configuration.getTomcatVersion() == null || configuration.getTomcatVersion().length() == 0) {
-                downloadTomEE(workingDirectory);
-                openejbHome = findOpenEJBHome(workingDirectory);
+                Files.assertDir(workingDirectory);
+
             } else {
+
+                Files.mkdir(workingDirectory);
+                Files.deleteOnExit(workingDirectory);
+            }
+
+            Files.readable(workingDirectory);
+            Files.writable(workingDirectory);
+
+            File openejbHome = Setup.findHome(workingDirectory);
+
+            if (openejbHome == null) {
+
                 downloadTomcat(workingDirectory, configuration.getTomcatVersion());
-                openejbHome = findOpenEJBHome(workingDirectory);
-                File webappsOpenEJB = new File(openejbHome, "webapps/openejb");
-                webappsOpenEJB.mkdirs();
-                downloadOpenEJBWebapp(webappsOpenEJB);
+
+                openejbHome = Setup.findHome(workingDirectory);
+
+                Files.deleteOnExit(openejbHome);
+
+                final File webapp = new File(openejbHome, "webapps" + s + "tomee");
+
+                Files.mkdir(webapp);
+                downloadOpenEJBWebapp(webapp);
 
                 System.setProperty("catalina.home", openejbHome.getAbsolutePath());
                 System.setProperty("catalina.base", openejbHome.getAbsolutePath());
+
                 System.setProperty("openejb.deploymentId.format", "{appId}/{ejbJarId}/{ejbName}");
-                Paths paths = new Paths(new File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
+
+                Paths paths = new Paths(webapp);
                 Installer installer = new Installer(paths, true);
                 installer.installAll();
             }
-            DOWNLOADED = workingDirectory;
 
-            if (openejbHome == null || (!openejbHome.exists())) {
-                throw new LifecycleException("Error finding OPENEJB_HOME");
-            }
+            Files.assertDir(openejbHome);
+            Files.readable(openejbHome);
+            Files.writable(openejbHome);
 
-            FileUtils.deleteOnExit(openejbHome);
-            Map<String, String> replacements = new HashMap<String, String>();
-            replacements.put("8080", String.valueOf(configuration.getHttpPort()));
-            replacements.put("8005", String.valueOf(configuration.getStopPort()));
-            replace(replacements, new File(openejbHome, "conf/server.xml"));
+            Setup.updateServerXml(openejbHome, configuration);
+            Setup.exportProperties(openejbHome, configuration);
 
             final URL logging = Thread.currentThread().getContextClassLoader().getResource("default.remote.logging.properties");
             if (logging != null) {
-                write(logging, new File(openejbHome, "conf/logging.properties"));
+                write(logging, new File(openejbHome, "conf" + s + "logging.properties"));
             }
 
-            System.setProperty("tomee.http.port", String.valueOf(configuration.getHttpPort()));
-            System.setProperty("tomee.shutdown.port", String.valueOf(configuration.getStopPort()));
-            System.setProperty("java.naming.provider.url", "http://localhost:" +  configuration.getHttpPort() + "/tomee/ejb");
-            System.setProperty("connect.tries", "90");
-            System.setProperty("server.http.port", String.valueOf(configuration.getHttpPort()));
-            System.setProperty("server.shutdown.port", String.valueOf(configuration.getStopPort()));
-            System.setProperty("java.opts", "-Xmx512m -Xms256m -XX:PermSize=64m -XX:MaxPermSize=256m -XX:ReservedCodeCacheSize=64m -Dtomee.http.port=" + configuration.getHttpPort());
-            System.setProperty("openejb.home", openejbHome.getAbsolutePath());
-
             if (false) {
                 Map<Object, Object> map = new TreeMap(System.getProperties());
                 for (Map.Entry<Object, Object> entry : map.entrySet()) {
@@ -139,77 +134,21 @@ public class RemoteTomEEContainer extend
 
     private static void write(URL resource, File file) throws IOException {
         if (file.exists()) {
-            FileUtils.delete(file);
+            Files.delete(file);
         }
         InputStream is = resource.openStream();
-        OutputStream out = new FileOutputStream(file);
-        byte buf[] = new byte[1024];
-        int len;
-        while ((len = is.read(buf)) > 0) {
-            out.write(buf, 0, len);
-        }
-        out.close();
-        is.close();
-    }
-
-    private File findOpenEJBHome(File directory) {
-        File conf = new File(directory, "conf");
-        File webapps = new File(directory, "webapps");
-
-        if (conf.exists() && conf.isDirectory() && webapps.exists() && webapps.isDirectory()) {
-            return directory;
-        }
-
-        for (File file : directory.listFiles()) {
-            if (".".equals(file.getName()) || "..".equals(file.getName())) continue;
-
-            File found = findOpenEJBHome(file);
-            if (found != null) {
-                return found;
-            }
-        }
 
-        return null;
-    }
-
-    protected void downloadTomEE(File catalinaDirectory) throws LifecycleException {
-        String artifactName;
-        if (configuration.isPlusContainer()) {
-            artifactName = "org.apache.openejb:apache-tomee:" + configuration.getOpenejbVersion() + ":zip:plus";
-        } else {
-            artifactName = "org.apache.openejb:apache-tomee:" + configuration.getOpenejbVersion() + ":zip:webprofile";
-        }
-
-        File zipFile = downloadFile(artifactName, null);
-        ZipExtractor.unzip(zipFile, catalinaDirectory);
-    }
-
-    protected File downloadFile(String artifactName, String altUrl) {
-        final String cache = System.getProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER);
-        System.setProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER, "target");
         try {
-            final File artifact = new MavenCache().getArtifact(artifactName, altUrl);
-            if (artifact == null) throw new NullPointerException(String.format("No such artifact: %s", artifactName));
-            return artifact;
+            IO.copy(is, file);
         } finally {
-            if (cache == null) {
-                System.getProperties().remove(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER);
-            } else {
-                System.setProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER, cache);
-            }
+            is.close();
         }
     }
 
     protected void downloadOpenEJBWebapp(File targetDirectory) throws LifecycleException {
-        String artifactName;
-        if (configuration.isPlusContainer()) {
-            artifactName = "org.apache.openejb:tomee-plus-webapp:" + configuration.getOpenejbVersion() + ":war";
-        } else {
-            artifactName = "org.apache.openejb:tomee-webapp:" + configuration.getOpenejbVersion() + ":war";
-        }
-
-        File zipFile = downloadFile(artifactName, null);
-        ZipExtractor.unzip(zipFile, targetDirectory);
+        String artifactName = configuration.getArtifactName();
+        File zipFile = Setup.downloadFile(artifactName, null);
+        Zips.unzip(zipFile, targetDirectory);
     }
 
     protected void downloadTomcat(File catalinaDirectory, String tomcatVersion) throws LifecycleException {
@@ -231,13 +170,13 @@ public class RemoteTomEEContainer extend
             throw new LifecycleException("Unable to find URL for Tomcat " + tomcatVersion);
         }
 
-        File zipFile = downloadFile("org.apache.openejb:tomcat:" + tomcatVersion + ":zip", source);
-        ZipExtractor.unzip(zipFile, catalinaDirectory);
+        File zipFile = Setup.downloadFile("org.apache.openejb:tomcat:" + tomcatVersion + ":zip", source);
+        Zips.unzip(zipFile, catalinaDirectory);
     }
 
     public void stop() throws LifecycleException {
         // only stop the container if we started it
-        if (needsStart) {
+        if (shutdown) {
             container.stop();
         }
     }
@@ -248,65 +187,7 @@ public class RemoteTomEEContainer extend
         out.close();
     }
 
-    private void replace(Map<String, String> replacements, File file) throws IOException {
-        BufferedReader reader = null;
-        PrintWriter writer = null;
-
-        try {
-            File tmpFile = copyToTempFile(file);
-            reader = new BufferedReader(new FileReader(tmpFile));
-            writer = new PrintWriter(new FileWriter(file));
-            String line;
-
-            while ((line = reader.readLine()) != null) {
-                Iterator<String> iterator = replacements.keySet().iterator();
-                while (iterator.hasNext()) {
-                    String pattern = iterator.next();
-                    String replacement = replacements.get(pattern);
-
-                    line = line.replaceAll(pattern, replacement);
-                }
-
-                writer.println(line);
-            }
-        } catch (IOException e) {
-            throw e;
-        } finally {
-            if (reader != null) {
-                reader.close();
-            }
-
-            if (writer != null) {
-                writer.close();
-            }
-        }
-    }
-
-    private File copyToTempFile(File file) throws IOException {
-        InputStream is = null;
-        OutputStream os = null;
-
-        File tmpFile;
-        try {
-            tmpFile = File.createTempFile("oejb", ".fil");
-            tmpFile.deleteOnExit();
-
-            is = new FileInputStream(file);
-            os = new FileOutputStream(tmpFile);
-
-            Installer.copy(is, os);
-        } catch (IOException e) {
-            throw e;
-        } finally {
-            if (is != null) {
-                is.close();
-            }
-
-            if (os != null) {
-                os.close();
-            }
-        }
-
-        return tmpFile;
+    public Class<TomEEWebappConfiguration> getConfigurationClass() {
+        return TomEEWebappConfiguration.class;
     }
 }

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappEJBEnricherArchiveAppender.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappEJBEnricherArchiveAppender.java?rev=1243396&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappEJBEnricherArchiveAppender.java (added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappEJBEnricherArchiveAppender.java Mon Feb 13 02:23:54 2012
@@ -0,0 +1,31 @@
+/**
+ * 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.arquillian.webapp;
+
+import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
+import org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+
+public class TomEEWebappEJBEnricherArchiveAppender implements AuxiliaryArchiveAppender {
+    @Override
+    public Archive<?> createAuxiliaryArchive() {
+        return ShrinkWrap.create(JavaArchive.class, "arquillian-tomee-testenricher-ejb.jar").addClasses(TomEEWebappObserver.class, TomEEWebappRemoteExtension.class).addAsServiceProvider(RemoteLoadableExtension.class, TomEEWebappRemoteExtension.class);
+    }
+}
\ No newline at end of file

Added: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappExtension.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappExtension.java?rev=1243396&view=auto
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappExtension.java (added)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappExtension.java Mon Feb 13 02:23:54 2012
@@ -0,0 +1,29 @@
+/**
+ * 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.arquillian.webapp;
+
+import org.jboss.arquillian.container.spi.client.container.DeployableContainer;
+import org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
+import org.jboss.arquillian.core.spi.LoadableExtension;
+
+public class TomEEWebappExtension implements LoadableExtension {
+    @Override
+    public void register(ExtensionBuilder builder) {
+        builder.service(DeployableContainer.class, TomEEWebappContainer.class).service(AuxiliaryArchiveAppender.class, TomEEWebappEJBEnricherArchiveAppender.class);
+    }
+}