tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-1440 singleDeploymentByArchiveName in tomee arquillian adapters
Date Mon, 10 Nov 2014 10:50:41 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x a78192a84 -> bf365a947


TOMEE-1440 singleDeploymentByArchiveName in tomee arquillian adapters


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/bf365a94
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/bf365a94
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/bf365a94

Branch: refs/heads/tomee-1.7.x
Commit: bf365a9477a8261b324f97be83098840f6f127ae
Parents: a78192a
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Mon Nov 10 11:50:08 2014 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Mon Nov 10 11:50:08 2014 +0100

----------------------------------------------------------------------
 .../arquillian/common/TestClassDiscoverer.java  |  4 +-
 .../arquillian/common/TomEEConfiguration.java   | 16 ++++
 .../arquillian/common/TomEEContainer.java       | 87 +++++++++++++++-----
 .../embedded/EmbeddedTomEEContainer.java        | 17 ++--
 4 files changed, 94 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/bf365a94/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TestClassDiscoverer.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TestClassDiscoverer.java
b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TestClassDiscoverer.java
index 7b876f9..a9e06d0 100644
--- a/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TestClassDiscoverer.java
+++ b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TestClassDiscoverer.java
@@ -174,7 +174,7 @@ public class TestClassDiscoverer implements AdditionalBeanDiscoverer {
                 try {
                     is = new FileInputStream(info);
                 } catch (final FileNotFoundException e) {
-                    e.printStackTrace();
+                    // no-op
                 }
             }
         }
@@ -187,7 +187,7 @@ public class TestClassDiscoverer implements AdditionalBeanDiscoverer {
             try {
                 return org.apache.openejb.loader.IO.slurp(is);
             } catch (final IOException e) {
-                e.printStackTrace();
+                // no-op
             } finally {
                 org.apache.openejb.loader.IO.close(is);
             }

http://git-wip-us.apache.org/repos/asf/tomee/blob/bf365a94/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java
b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java
index 10d356a..230261c 100644
--- a/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java
+++ b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java
@@ -22,8 +22,13 @@ import org.jboss.arquillian.container.spi.ConfigurationException;
 import org.jboss.arquillian.container.spi.client.container.ContainerConfiguration;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 
+import static java.util.Arrays.asList;
+
 @SuppressWarnings("UnusedDeclaration")
 public class TomEEConfiguration implements ContainerConfiguration {
 
@@ -46,6 +51,7 @@ public class TomEEConfiguration implements ContainerConfiguration {
     protected String webContextToUseWithEars;
     protected boolean keepServerXmlAsThis;
     protected boolean singleDumpByArchiveName;
+    protected Collection<String> singleDeploymentByArchiveName = Collections.emptyList();
 
     public boolean isUnpackWars() {
         return unpackWars;
@@ -220,4 +226,14 @@ public class TomEEConfiguration implements ContainerConfiguration {
     public void setSingleDumpByArchiveName(final boolean singleDumpByArchiveName) {
         this.singleDumpByArchiveName = singleDumpByArchiveName;
     }
+
+    public boolean isSingleDeploymentByArchiveName(final String name) {
+        return singleDeploymentByArchiveName.contains(name) || singleDeploymentByArchiveName.contains("*")
|| singleDeploymentByArchiveName.contains("true");
+    }
+
+    public void setSingleDeploymentByArchiveName(final String singleDeploymentByArchiveName)
{
+        this.singleDeploymentByArchiveName = singleDeploymentByArchiveName == null || singleDeploymentByArchiveName.trim().isEmpty()
?
+                Collections.<String>emptyList() : new HashSet<String>(asList(singleDeploymentByArchiveName.split("
*, *")));
+        this.singleDumpByArchiveName = true; // implied otherwise what would be the sense?
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/bf365a94/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
index c82ed1f..e891e6c 100644
--- a/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
+++ b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
@@ -251,10 +251,11 @@ public abstract class TomEEContainer<Configuration extends TomEEConfiguration>
i
     @Override
     public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException
{
         try {
-            final File file = dumpFile(archive);
+            final Dump dump = dumpFile(archive);
+            final File file = dump.getFile();
 
             final String fileName = file.getName();
-            if (fileName.endsWith(".war") || fileName.endsWith(".ear")) {
+            if (dump.isCreated() && (fileName.endsWith(".war") || fileName.endsWith(".ear")))
{
                 // extracted folder, TODO: openejb work dir is ignored here
                 Files.deleteOnExit(new File(file.getParentFile(), fileName.substring(0, fileName.length()
- 4)));
             }
@@ -262,26 +263,40 @@ public abstract class TomEEContainer<Configuration extends TomEEConfiguration>
i
             final AppInfo appInfo;
             final String archiveName = archive.getName();
             try {
-                final Properties deployerProperties = getDeployerProperties();
-                if (deployerProperties == null) {
-                    appInfo = deployer().deploy(file.getAbsolutePath());
-                } else {
-                    final Properties props = new Properties();
-                    props.putAll(deployerProperties);
+                if (dump.isCreated() || !configuration.isSingleDeploymentByArchiveName(archiveName))
{
+                    final Properties deployerProperties = getDeployerProperties();
+                    if (deployerProperties == null) {
+                        appInfo = deployer().deploy(file.getAbsolutePath());
+                    } else {
+                        final Properties props = new Properties();
+                        props.putAll(deployerProperties);
+
+                        if ("true".equalsIgnoreCase(deployerProperties.getProperty(DeployerEjb.OPENEJB_USE_BINARIES,
"false"))) {
+                            final byte[] slurpBinaries = IO.slurpBytes(file);
+                            props.put(DeployerEjb.OPENEJB_VALUE_BINARIES, slurpBinaries);
+                            props.put(DeployerEjb.OPENEJB_PATH_BINARIES, archive.getName());
+                        }
 
-                    if ("true".equalsIgnoreCase(deployerProperties.getProperty(DeployerEjb.OPENEJB_USE_BINARIES,
"false"))) {
-                        final byte[] slurpBinaries = IO.slurpBytes(file);
-                        props.put(DeployerEjb.OPENEJB_VALUE_BINARIES, slurpBinaries);
-                        props.put(DeployerEjb.OPENEJB_PATH_BINARIES, archive.getName());
+                        appInfo = deployer().deploy(file.getAbsolutePath(), props);
                     }
 
-                    appInfo = deployer().deploy(file.getAbsolutePath(), props);
+                    if (appInfo != null) {
+                        moduleIds.put(archiveName, new DeployedApp(appInfo.path, file));
+                        Files.deleteOnExit(file); // "i" folder
+                    }
+                } else {
+                    final String path = moduleIds.get(archiveName).path;
+                    AppInfo selected = null;
+                    for (final AppInfo info : deployer().getDeployedApps()) {
+                        if (path.equals(info.path)) {
+                            selected = info;
+                            break;
+                        }
+                    }
+                    appInfo = selected;
                 }
 
-                if (appInfo != null) {
-                    moduleIds.put(archiveName, new DeployedApp(appInfo.path, file));
-                    Files.deleteOnExit(file); // "i" folder
-                } else {
+                if (appInfo == null) {
                     LOGGER.severe("appInfo was not found for " + file.getPath() + ", available
are: " + apps());
                     throw new OpenEJBException("can't get appInfo");
                 }
@@ -323,7 +338,7 @@ public abstract class TomEEContainer<Configuration extends TomEEConfiguration>
i
         return null;
     }
 
-    protected File dumpFile(final Archive<?> archive) {
+    protected Dump dumpFile(final Archive<?> archive) {
         final String tmpDir = configuration.getAppWorkingDir();
         Files.deleteOnExit(new File(tmpDir));
 
@@ -353,8 +368,13 @@ public abstract class TomEEContainer<Configuration extends TomEEConfiguration>
i
         if (file.exists()) {
             size = file.length();
         }
+
+        final boolean created;
         if (!configuration.isSingleDumpByArchiveName() || !file.exists()) {
             finalArchive.as(ZipExporter.class).exportTo(file, true);
+            created = true;
+        } else {
+            created = false;
         }
         if (size > 0 && size != file.length()) {
             LOGGER.warning("\nFile overwritten but size doesn't match: (now) "
@@ -363,7 +383,7 @@ public abstract class TomEEContainer<Configuration extends TomEEConfiguration>
i
                     + "\n");
         }
 
-        return file;
+        return new Dump(file, created);
     }
 
     private Collection<String> apps() {
@@ -435,15 +455,20 @@ public abstract class TomEEContainer<Configuration extends TomEEConfiguration>
i
 
     @Override
     public void undeploy(final Archive<?> archive) throws DeploymentException {
-        final DeployedApp deployed = moduleIds.remove(archive.getName());
+        final String archiveName = archive.getName();
+        if (configuration.isSingleDeploymentByArchiveName(archiveName)) {
+            return;
+        }
+
+        final DeployedApp deployed = moduleIds.remove(archiveName);
         try {
             if (deployed == null) {
-                LOGGER.warning(archive.getName() + " was not deployed");
+                LOGGER.warning(archiveName + " was not deployed");
                 return;
             }
             deployer().undeploy(deployed.path);
         } catch (final Exception e) {
-            throw new DeploymentException("Unable to undeploy " + archive.getName(), e);
+            throw new DeploymentException("Unable to undeploy " + archiveName, e);
         } finally {
             if (deployed != null && !configuration.isSingleDumpByArchiveName()) {
                 LOGGER.info("cleaning " + deployed.file.getAbsolutePath());
@@ -482,4 +507,22 @@ public abstract class TomEEContainer<Configuration extends TomEEConfiguration>
i
             this.file = file;
         }
     }
+
+    protected final class Dump {
+        private final File file;
+        private final boolean created;
+
+        public Dump(final File file, final boolean created) {
+            this.file = file;
+            this.created = created;
+        }
+
+        public File getFile() {
+            return file;
+        }
+
+        public boolean isCreated() {
+            return created;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/bf365a94/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
b/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
index e6f4d6a..3478732 100644
--- a/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
+++ b/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
@@ -115,7 +115,6 @@ public class EmbeddedTomEEContainer extends TomEEContainer<EmbeddedTomEEConfigur
             // this property is not mandatory by default but depending the protocol it can
be relevant so adding it by default
             SystemInstance.get().setProperty("org.apache.openejb.servlet.filters", ArquillianFilterRunner.class.getName()
+ "=/ArquillianServletRunner");
         } catch (final Exception e) {
-            e.printStackTrace();
             throw new LifecycleException("Something went wrong", e);
         }
     }
@@ -142,10 +141,14 @@ public class EmbeddedTomEEContainer extends TomEEContainer<EmbeddedTomEEConfigur
             final File file = new File(tempDir, name);
             */
             final String name = archive.getName();
-            final File file = this.dumpFile(archive);
-            ARCHIVES.put(archive, file);
+            final Dump dump = this.dumpFile(archive);
+            final File file = dump.getFile();
+
+            if (dump.isCreated() || !configuration.isSingleDeploymentByArchiveName(name))
{
+                ARCHIVES.put(archive, file);
+                this.container.deploy(name, file);
+            }
 
-            this.container.deploy(name, file);
             final AppInfo info = this.container.getInfo(name);
             final String context = this.getArchiveNameWithoutExtension(archive);
 
@@ -159,7 +162,6 @@ public class EmbeddedTomEEContainer extends TomEEContainer<EmbeddedTomEEConfigur
 
             return new ProtocolMetaData().addContext(httpContext);
         } catch (final Exception e) {
-            e.printStackTrace();
             throw new DeploymentException("Unable to deploy", e);
         }
     }
@@ -168,10 +170,13 @@ public class EmbeddedTomEEContainer extends TomEEContainer<EmbeddedTomEEConfigur
     public void undeploy(final Archive<?> archive) throws DeploymentException {
         final String name = archive.getName();
         stopCdiContexts(name);
+        if (configuration.isSingleDeploymentByArchiveName(name)) {
+            return;
+        }
+
         try {
             this.container.undeploy(name);
         } catch (final Exception e) {
-            e.printStackTrace();
             throw new DeploymentException("Unable to undeploy", e);
         }
         final File file = ARCHIVES.remove(archive);


Mime
View raw message