Author: rmannibucau Date: Tue Sep 30 21:45:01 2014 New Revision: 1628555 URL: http://svn.apache.org/r1628555 Log: TOMEE-1367 singleDumpByArchiveName to avoid to dump N times the same SW archive
Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java tomee/tomee/trunk/arquillian/arquillian-tomee-remote/pom.xml tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/CheckServerInfoTest.java tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/unpack/UnpackTest.java tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/resources/arquillian.xml Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java?rev=1628555&r1=1628554&r2=1628555&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java (original) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEConfiguration.java Tue Sep 30 21:45:01 2014 @@ -45,6 +45,7 @@ public class TomEEConfiguration implemen protected String properties = ""; protected String webContextToUseWithEars; protected boolean keepServerXmlAsThis; + protected boolean singleDumpByArchiveName = false; public boolean isUnpackWars() { return unpackWars; @@ -211,4 +212,12 @@ public class TomEEConfiguration implemen public void setKeepServerXmlAsThis(final boolean keepServerXmlAsThis) { this.keepServerXmlAsThis = keepServerXmlAsThis; } + + public boolean isSingleDumpByArchiveName() { + return singleDumpByArchiveName; + } + + public void setSingleDumpByArchiveName(final boolean singleDumpByArchiveName) { + this.singleDumpByArchiveName = singleDumpByArchiveName; + } } Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1628555&r1=1628554&r2=1628555&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java (original) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java Tue Sep 30 21:45:01 2014 @@ -254,11 +254,9 @@ public abstract class TomEEContainer<Con final File file = dumpFile(archive); final String fileName = file.getName(); - if (fileName.endsWith(".war")) { // ?? - final File extracted = new File(file.getParentFile(), fileName.substring(0, fileName.length() - 4)); - if (extracted.exists()) { - extracted.deleteOnExit(); - } + if (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))); } final AppInfo appInfo; @@ -330,20 +328,37 @@ public abstract class TomEEContainer<Con Files.deleteOnExit(new File(tmpDir)); File file; - int i = 0; - do { // be sure we don't override something existing - file = new File(tmpDir + File.separator + i++ + File.separator + archive.getName()); - } while (file.getParentFile().exists()); // we will delete the parent (to clean even complicated unpacking) + if (configuration.isSingleDumpByArchiveName()) { + file = new File(tmpDir + File.separator + archive.getName()); + } else { + int i = 0; + do { // be sure we don't override something existing + file = new File(tmpDir + File.separator + i++ + File.separator + archive.getName()); + } while (file.getParentFile().exists()); // we will delete the parent (to clean even complicated unpacking) + } if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { LOGGER.warning("can't create " + file.getParent()); } Files.deleteOnExit(file.getParentFile()); + final Assignable finalArchive; if (isTestable(archive, deployment.get())) { - archiveWithTestInfo(archive).as(ZipExporter.class).exportTo(file, true); + finalArchive = archiveWithTestInfo(archive); } else { - archive.as(ZipExporter.class).exportTo(file, true); + finalArchive = archive; + } + + long size = -1; + if (file.exists()) { + size = file.length(); + } + finalArchive.as(ZipExporter.class).exportTo(file, true); + if (size > 0 && size != file.length()) { + LOGGER.warning("\nFile overwritten but size doesn't match: (now) " + + file.length() + "/(before) " + size + " name="+ file.getName() + + (configuration.isSingleDumpByArchiveName() ? " maybe set singleDumpByArchiveName to false" : "") + + "\n"); } return file; @@ -428,13 +443,15 @@ public abstract class TomEEContainer<Con } catch (final Exception e) { throw new DeploymentException("Unable to undeploy " + archive.getName(), e); } finally { - LOGGER.info("cleaning " + deployed.file.getAbsolutePath()); - Files.tryTodelete(deployed.file); // "i" folder - - final File pathFile = new File(deployed.path); - if (!deployed.path.equals(deployed.file.getAbsolutePath()) && pathFile.exists()) { - LOGGER.info("cleaning " + pathFile); - Files.delete(pathFile); + if (deployed != null && !configuration.isSingleDumpByArchiveName()) { + LOGGER.info("cleaning " + deployed.file.getAbsolutePath()); + Files.tryTodelete(deployed.file); // "i" folder + + final File pathFile = new File(deployed.path); + if (!deployed.path.equals(deployed.file.getAbsolutePath()) && pathFile.exists()) { + LOGGER.info("cleaning " + pathFile); + Files.delete(pathFile); + } } } } Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-remote/pom.xml URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-remote/pom.xml?rev=1628555&r1=1628554&r2=1628555&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-remote/pom.xml (original) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-remote/pom.xml Tue Sep 30 21:45:01 2014 @@ -213,6 +213,15 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.17</version> + <configuration> + <reuseForks>true</reuseForks> + <forkCount>1</forkCount> + </configuration> + </plugin> </plugins> </build> </project> Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/CheckServerInfoTest.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/CheckServerInfoTest.java?rev=1628555&r1=1628554&r2=1628555&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/CheckServerInfoTest.java (original) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/CheckServerInfoTest.java Tue Sep 30 21:45:01 2014 @@ -32,7 +32,7 @@ import static org.junit.Assert.assertTru public class CheckServerInfoTest { @Deployment public static WebArchive war() { - return ShrinkWrap.create(WebArchive.class).addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("foo.txt")); + return ShrinkWrap.create(WebArchive.class, "info.war").addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("foo.txt")); } @Test Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/unpack/UnpackTest.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/unpack/UnpackTest.java?rev=1628555&r1=1628554&r2=1628555&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/unpack/UnpackTest.java (original) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/unpack/UnpackTest.java Tue Sep 30 21:45:01 2014 @@ -38,7 +38,7 @@ public class UnpackTest extends Assert { @Deployment public static WebArchive createDeployment() { return ShrinkWrap - .create(WebArchive.class, "unpacktest.war") + .create(WebArchive.class, "test.war") .addAsLibraries(JarLocation.jarLocation(Test.class)) .addClass(TestServlet.class) .addClass(TestEjb.class) Modified: tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/resources/arquillian.xml URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/resources/arquillian.xml?rev=1628555&r1=1628554&r2=1628555&view=diff ============================================================================== --- tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/resources/arquillian.xml (original) +++ tomee/tomee/trunk/arquillian/arquillian-tomee-remote/src/test/resources/arquillian.xml Tue Sep 30 21:45:01 2014 @@ -22,6 +22,7 @@ <container qualifier="tomee" default="true"> <configuration> +<!-- <property name="singleDumpByArchiveName">true</property> --> <property name="httpPort">-1</property> <property name="stopPort">-1</property> <property name="ajpPort">-1</property>