VirtualFile originalRoot = createDeploymentRoot("/synch/war", "simple.war");
VFSDeploymentUnit deploymentUnit = assertDeploy(originalRoot);
try
{
VirtualFile tempRoot = deploymentUnit.getRoot();
StructureModificationChecker checker = createStructureModificationChecker();
assertFalse(checker.hasStructureBeenModified(originalRoot));
// add new file
URI rootURI = VFSUtils.getRealURL(originalRoot).toURI();
File rootFile = new File(rootURI);
File newFile = newFile(rootFile, "newfile.txt");
try
{
assertNull(tempRoot.getChild("newfile.txt"));
assertFalse(checker.hasStructureBeenModified(originalRoot));
assertNotNull(tempRoot.getChild("newfile.txt"));
// try deleting this one now
assertTrue(newFile.delete());
assertFalse(checker.hasStructureBeenModified(originalRoot));
assertNull(tempRoot.getChild("newfile.txt"));
}
finally
{
if (newFile.exists())
assertTrue(newFile.delete());
}
// update some file
File updateFile = new File(rootFile, "test.jsp");
assertTrue(updateFile.exists());
assertTrue(updateFile.setLastModified(System.currentTimeMillis() + 1500l));
@SuppressWarnings("deprecation")
VirtualFile testJsp = tempRoot.findChild("test.jsp");
long tempTimestamp = testJsp.getLastModified();
// Platform dependent precision for last modified, let's wait a minimum of 1 sec
Thread.sleep(1500l);
assertFalse(checker.hasStructureBeenModified(originalRoot));
long lastModified = testJsp.getLastModified();
long diff = lastModified - tempTimestamp;
assertTrue("Last modified diff is not bigger then 0, diff: " + diff, diff > 0);
// update something outside recurse filter
VirtualFile someProps = originalRoot.getChild("WEB-INF/classes/some.properties");
assertNotNull(someProps);
updateFile = new File(VFSUtils.getRealURL(someProps).toURI());
assertTrue(updateFile.exists());
assertTrue(updateFile.setLastModified(System.currentTimeMillis() + 1500l));
@SuppressWarnings("deprecation")
VirtualFile tempProps = tempRoot.findChild("WEB-INF/classes/some.properties");
tempTimestamp = tempProps.getLastModified();
// Platform dependent precision for last modified, let's wait a minimum of 1 sec
Thread.sleep(1500l);
assertFalse(checker.hasStructureBeenModified(originalRoot));
assertEquals(tempTimestamp, tempProps.getLastModified());
// add new file into WEB-INF
VirtualFile webInfo = originalRoot.getChild("WEB-INF");
File webInfFile = new File(VFSUtils.getCompatibleURI(webInfo));
File newWebInfFile = newFile(webInfFile, "newfile.txt");
try
{
assertNull(tempRoot.getChild("WEB-INF/newfile.txt"));
assertFalse(checker.hasStructureBeenModified(originalRoot));
assertNotNull(tempRoot.getChild("WEB-INF/newfile.txt"));
assertFalse(checker.hasStructureBeenModified(originalRoot));
// try deleting this one now
assertTrue(newWebInfFile.delete());
assertFalse(checker.hasStructureBeenModified(originalRoot));
assertNull(tempRoot.getChild("WEB-INF/newfile.txt"));
}
finally
{
if (newWebInfFile.exists())
assertTrue(newWebInfFile.delete());
}
// check we don't update for nothing
@SuppressWarnings("deprecation")
VirtualFile xhtml = tempRoot.findChild("test.xhtml");
long xhtmlTimestamp = xhtml.getLastModified();
// Platform dependent precision for last modified, let's wait a minimum of 1 sec
Thread.sleep(1500l);
assertFalse(checker.hasStructureBeenModified(originalRoot));
assertEquals(xhtmlTimestamp, xhtml.getLastModified());
}
finally
{
undeploy(deploymentUnit);