summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPolina Genova2013-05-17 04:09:56 (EDT)
committer Violeta Georgieva2013-05-17 04:16:43 (EDT)
commit0b08503bb3bc3c9bd54c335f32aaa0278eb3a3b0 (patch)
treec7ec289474a542fa0766a3cc11dd7c1fbe4d3dbe
parentd5e501339185dfe360a24c210d35ebc22a382587 (diff)
downloadorg.eclipse.virgo.nano-0b08503bb3bc3c9bd54c335f32aaa0278eb3a3b0.zip
org.eclipse.virgo.nano-0b08503bb3bc3c9bd54c335f32aaa0278eb3a3b0.tar.gz
org.eclipse.virgo.nano-0b08503bb3bc3c9bd54c335f32aaa0278eb3a3b0.tar.bz2
bug 408123: Preserve original war name in deploy status files.
-rw-r--r--org.eclipse.virgo.nano.deployer/src/main/java/org/eclipse/virgo/nano/deployer/util/StatusFileModificator.java31
-rw-r--r--org.eclipse.virgo.nano.deployer/src/test/java/org/eclipse/virgo/nano/deployer/util/StatusFileModificatorTest.java43
-rw-r--r--org.eclipse.virgo.nano.deployer/src/test/resources/test/test#strangesymbols.deploy.ok2
-rw-r--r--org.eclipse.virgo.nano.deployer/src/test/resources/test/test#strangesymbols.undeploy.ok2
-rw-r--r--org.eclipse.virgo.nano.deployer/src/test/resources/test/teststrangesymbols.undeploy.ok2
5 files changed, 78 insertions, 2 deletions
diff --git a/org.eclipse.virgo.nano.deployer/src/main/java/org/eclipse/virgo/nano/deployer/util/StatusFileModificator.java b/org.eclipse.virgo.nano.deployer/src/main/java/org/eclipse/virgo/nano/deployer/util/StatusFileModificator.java
index a637dd7..917ee3d 100644
--- a/org.eclipse.virgo.nano.deployer/src/main/java/org/eclipse/virgo/nano/deployer/util/StatusFileModificator.java
+++ b/org.eclipse.virgo.nano.deployer/src/main/java/org/eclipse/virgo/nano/deployer/util/StatusFileModificator.java
@@ -63,6 +63,10 @@ public class StatusFileModificator {
private static final String[] STATUS_FILENAMES_SUFFEXES = { DOT + OP_DEPLOY + DOT + SUCCESS_MARK, DOT + OP_DEPLOY + DOT + ERROR_MARK,
DOT + OP_UNDEPLOY + DOT + SUCCESS_MARK, DOT + OP_UNDEPLOY + DOT + ERROR_MARK };
+ //pattern that matches the deploy status files - ".deploy.(ok|error)"
+ private static final String STATUS_FILENAMES_DEPLOY_PATTERN = DOT + OP_DEPLOY + DOT + '(' + SUCCESS_MARK + '|' + ERROR_MARK + ')';
+
+
/**
* Deletes the current status file (if any) for the given deployable archive
*/
@@ -78,6 +82,33 @@ public class StatusFileModificator {
}
}
}
+
+ /**
+ * Deletes the first occurrence of a status file from deploy operation that matches the given war name pattern (if
+ * any). There should be one match only.
+ *
+ * @return the war name prefix of the deleted status file or empty string, if there's no match found
+ */
+ public static String deleteStatusFileByNamePattern(String warNamePattern, File pickupDir) {
+ final File stateDir = new File(pickupDir, STATE_DIR_NAME);
+ if (stateDir.exists()) {
+ String[] statusFileNames = stateDir.list();
+ for (String stateFileName : statusFileNames) {
+ if (stateFileName.matches(warNamePattern + STATUS_FILENAMES_DEPLOY_PATTERN)) {
+ deleteFile(new File(stateDir, stateFileName));
+ return stateFileName.substring(0, stateFileName.lastIndexOf(OP_DEPLOY) - 1);
+ }
+ }
+ } else {
+ if (logger.isInfoEnabled()) {
+ logger.info("State directory [" + stateDir.getAbsolutePath() + "] does not exist. Therefore, there is no status file to delete.");
+ }
+ }
+ if (logger.isWarnEnabled()) {
+ logger.warn("Cannot delete any status file, as no status file matches the given warNamePattern [" + warNamePattern + "].");
+ }
+ return EMPTY_STRING;
+ }
/**
* Create status file about the given deplayable archive.
diff --git a/org.eclipse.virgo.nano.deployer/src/test/java/org/eclipse/virgo/nano/deployer/util/StatusFileModificatorTest.java b/org.eclipse.virgo.nano.deployer/src/test/java/org/eclipse/virgo/nano/deployer/util/StatusFileModificatorTest.java
index 6297c25..960d809 100644
--- a/org.eclipse.virgo.nano.deployer/src/test/java/org/eclipse/virgo/nano/deployer/util/StatusFileModificatorTest.java
+++ b/org.eclipse.virgo.nano.deployer/src/test/java/org/eclipse/virgo/nano/deployer/util/StatusFileModificatorTest.java
@@ -30,6 +30,9 @@ public class StatusFileModificatorTest {
"src/test/resources/test/testapp1.deploy.error", "src/test/resources/test/testapp1.undeploy.error",
"src/test/resources/test/testapp2.deploy.ok" };
+ private static final String[] strangeStatusFiles = { "src/test/resources/test/test#strangesymbols.undeploy.ok",
+ "src/test/resources/test/test#strangesymbols.deploy.ok", "src/test/resources/test/teststrangesymbols.undeploy.ok"};
+
@Before
public void setUp() {
PICKUP_DIR.createDirectory();
@@ -53,6 +56,34 @@ public class StatusFileModificatorTest {
StatusFileModificator.deleteStatusFile("testapp2", pickupFolder);
assertTrue(stateFolder.list().length == 0);
}
+
+ @Test
+ public void deleteStatusFileByPatternTest() throws Exception {
+ STATE_DIR.createDirectory();
+ copyDummyStatusFiles();
+ File stateFolder = STATE_DIR.toFile();
+ File pickupFolder = PICKUP_DIR.toFile();
+ assertTrue(stateFolder.list().length == 5);
+ String deleted = StatusFileModificator.deleteStatusFileByNamePattern("testapp2", pickupFolder);
+ assertTrue(stateFolder.list().length == 4);
+ assertTrue("Only 'testapp2' file should be deleted : ", deleted.equals("testapp2"));
+ StatusFileModificator.deleteStatusFile("testapp1", pickupFolder);
+ assertTrue(stateFolder.list().length == 0);
+ }
+
+ @Test
+ public void deleteStatusFileByPatternStrangeSymbolsTest() throws Exception {
+ STATE_DIR.createDirectory();
+ copyStrangeStatusFiles();
+ File stateFolder = STATE_DIR.toFile();
+ File pickupFolder = PICKUP_DIR.toFile();
+ assertTrue(stateFolder.list().length == 3);
+ String deleted = StatusFileModificator.deleteStatusFileByNamePattern("test[^a-zA-Z0-9_-]strangesymbols", pickupFolder);
+ assertTrue(stateFolder.list().length == 2);
+ assertTrue("Only 'test#strangesymbols' file should be deleted: ", deleted.equals("test#strangesymbols"));
+ assertTrue("Both undeploy status files should not be deleted: ",
+ stateFolder.list()[0].contains(".undeploy.") && stateFolder.list()[1].contains(".undeploy."));
+ }
@Test
public void createStatusFileOkTest() throws Exception {
@@ -91,8 +122,16 @@ public class StatusFileModificatorTest {
}
private void copyDummyStatusFiles() {
- for (String dummyStatusFile : dummyStatusFiles) {
- PathReference sourceFile = new PathReference(dummyStatusFile);
+ copyStatusFiles(dummyStatusFiles);
+ }
+
+ private void copyStrangeStatusFiles() {
+ copyStatusFiles(strangeStatusFiles);
+ }
+
+ private void copyStatusFiles(String[] files) {
+ for (String statusFile : files) {
+ PathReference sourceFile = new PathReference(statusFile);
assertTrue(sourceFile.exists());
PathReference copy = sourceFile.copy(STATE_DIR);
assertTrue(copy.exists());
diff --git a/org.eclipse.virgo.nano.deployer/src/test/resources/test/test#strangesymbols.deploy.ok b/org.eclipse.virgo.nano.deployer/src/test/resources/test/test#strangesymbols.deploy.ok
new file mode 100644
index 0000000..6674615
--- /dev/null
+++ b/org.eclipse.virgo.nano.deployer/src/test/resources/test/test#strangesymbols.deploy.ok
@@ -0,0 +1,2 @@
+bundle-id=197
+last-modified=1345737442754
diff --git a/org.eclipse.virgo.nano.deployer/src/test/resources/test/test#strangesymbols.undeploy.ok b/org.eclipse.virgo.nano.deployer/src/test/resources/test/test#strangesymbols.undeploy.ok
new file mode 100644
index 0000000..6674615
--- /dev/null
+++ b/org.eclipse.virgo.nano.deployer/src/test/resources/test/test#strangesymbols.undeploy.ok
@@ -0,0 +1,2 @@
+bundle-id=197
+last-modified=1345737442754
diff --git a/org.eclipse.virgo.nano.deployer/src/test/resources/test/teststrangesymbols.undeploy.ok b/org.eclipse.virgo.nano.deployer/src/test/resources/test/teststrangesymbols.undeploy.ok
new file mode 100644
index 0000000..6674615
--- /dev/null
+++ b/org.eclipse.virgo.nano.deployer/src/test/resources/test/teststrangesymbols.undeploy.ok
@@ -0,0 +1,2 @@
+bundle-id=197
+last-modified=1345737442754