Author: rmannibucau Date: Tue Apr 2 09:23:54 2013 New Revision: 1463460 URL: http://svn.apache.org/r1463460 Log: TOMEE-880 remote deployment of app through tomee mvn plugin
Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/DeployMojo.java Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java?rev=1463460&r1=1463459&r2=1463460&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java Tue Apr 2 09:23:54 2013 @@ -31,7 +31,9 @@ import org.apache.openejb.config.WebModu import org.apache.openejb.config.sys.AdditionalDeployments; import org.apache.openejb.config.sys.Deployments; import org.apache.openejb.config.sys.JaxbOpenejb; +import org.apache.openejb.loader.Files; import org.apache.openejb.loader.IO; +import org.apache.openejb.loader.ProvisioningUtil; import org.apache.openejb.loader.SystemInstance; import org.apache.openejb.util.LogCategory; import org.apache.openejb.util.Logger; @@ -62,9 +64,13 @@ import static org.apache.openejb.loader. @TransactionManagement(BEAN) @Alternative public class DeployerEjb implements Deployer { + private static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB, DeployerEjb.class); public static final String OPENEJB_DEPLOYER_FORCED_APP_ID_PROP = "openejb.deployer.forced.appId"; - public static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB, DeployerEjb.class); + + public static final String OPENEJB_USE_BINARIES = "openejb.deployer.binaries.use"; + public static final String OPENEJB_PATH_BINARIES = "openejb.deployer.binaries.path"; + public static final String OPENEJB_VALUE_BINARIES = "openejb.deployer.binaries.value"; public static final ThreadLocal<Boolean> AUTO_DEPLOY = new ThreadLocal<Boolean>(); @@ -145,7 +151,13 @@ public class DeployerEjb implements Depl AppModule appModule = null; - final File file = new File(realLocation(rawLocation)); + final File file; + if ("true".equalsIgnoreCase(properties.getProperty(OPENEJB_USE_BINARIES, "false"))) { + file = copyBinaries(properties); + } else { + file = new File(realLocation(rawLocation)); + } + final boolean autoDeploy = Boolean.parseBoolean(properties.getProperty("openejb.app.autodeploy", "false")); if (WebAppDeployer.Helper.isWebApp(file) && !oldWarDeployer) { @@ -247,6 +259,26 @@ public class DeployerEjb implements Depl } } + private static File copyBinaries(final Properties props) throws OpenEJBException { + final File dump = ProvisioningUtil.cacheFile(props.getProperty(OPENEJB_PATH_BINARIES, "dump.war")); + if (dump.exists()) { + Files.delete(dump); + final String name = dump.getName(); + if (name.endsWith("ar") && name.length() > 4) { + final File exploded = new File(dump.getParentFile(), name.substring(0, name.length() - 4)); + if (exploded.exists()) { + Files.delete(exploded); + } + } + } + try { + IO.copy(byte[].class.cast(props.get(OPENEJB_VALUE_BINARIES)), dump); + } catch (final IOException e) { + throw new OpenEJBException(e); + } + return dump; + } + private synchronized void saveDeployment(final File file, final boolean add) { final Deployments deps = new Deployments(); if (file.isDirectory()) { Modified: tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java?rev=1463460&r1=1463459&r2=1463460&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java (original) +++ tomee/tomee/trunk/container/openejb-loader/src/main/java/org/apache/openejb/loader/ProvisioningUtil.java Tue Apr 2 09:23:54 2013 @@ -51,7 +51,7 @@ public class ProvisioningUtil { } public static String cache() { - return System.getProperty(OPENEJB_DEPLOYER_CACHE_FOLDER, new File(System.getProperty("openejb.base", "."), "temp").getAbsolutePath()); + return System.getProperty(OPENEJB_DEPLOYER_CACHE_FOLDER, TEMP_DIR); } public static File cacheFile(final String path) { Modified: tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/DeployMojo.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/DeployMojo.java?rev=1463460&r1=1463459&r2=1463460&view=diff ============================================================================== --- tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/DeployMojo.java (original) +++ tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/DeployMojo.java Tue Apr 2 09:23:54 2013 @@ -23,7 +23,12 @@ import org.apache.maven.plugins.annotati import org.apache.maven.plugins.annotations.Parameter; import org.apache.openejb.OpenEJBException; import org.apache.openejb.assembler.Deployer; +import org.apache.openejb.assembler.DeployerEjb; +import org.apache.openejb.loader.IO; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -36,19 +41,50 @@ public class DeployMojo extends Abstract @Parameter protected Map<String, String> systemVariables = new HashMap<String, String>(); + @Parameter(property = "tomee-plugin.binary", defaultValue = "false") + private boolean useBinaries; + @Override public void execute() throws MojoExecutionException, MojoFailureException { final Deployer deployer = (Deployer) lookup("openejb/DeployerBusinessRemote"); - try { - if (systemVariables.isEmpty()) { - deployer.deploy(path); - } else { + if ((!"localhost".equals(tomeeHost) && !tomeeHost.startsWith("127.")) || useBinaries) { + + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final byte[] archive; + FileInputStream fis = null; + try { + fis = new FileInputStream(path); + IO.copy(fis, baos); + archive = baos.toByteArray(); + } catch (Exception e) { + throw new TomEEException(e.getMessage(), e); + } finally { + IO.close(fis); + IO.close(baos); + } + + try { final Properties prop = new Properties(); prop.putAll(systemVariables); + prop.put(DeployerEjb.OPENEJB_USE_BINARIES, "true"); + prop.put(DeployerEjb.OPENEJB_PATH_BINARIES, new File(path).getName()); + prop.put(DeployerEjb.OPENEJB_VALUE_BINARIES, archive); deployer.deploy(path, prop); + } catch (OpenEJBException e) { + throw new TomEEException(e.getMessage(), e); + } + } else { + try { + if (systemVariables.isEmpty()) { + deployer.deploy(path); + } else { + final Properties prop = new Properties(); + prop.putAll(systemVariables); + deployer.deploy(path, prop); + } + } catch (OpenEJBException e) { + throw new TomEEException(e.getMessage(), e); } - } catch (OpenEJBException e) { - throw new TomEEException(e.getMessage(), e); } } }