From 0aa6f1b70664fa3e18abbced76c5ed32b75156c3 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Fri, 9 Jan 2015 13:22:39 +0100 Subject: [PATCH] 420944 Hot Deployment of WAR when Context XML exists doesn't trigger redeploy --- .../deploy/providers/WebAppProvider.java | 155 +++++++++++++++++- 1 file changed, 148 insertions(+), 7 deletions(-) diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java index dde95535181..20af493c5d6 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java @@ -111,12 +111,7 @@ public class WebAppProvider extends ScanningAppProvider // else is it a war file if (lowername.endsWith(".war")) { - String base=name.substring(0,name.length()-4); - // ignore if it is a war for an existing xml file? - if (exists(base+".xml")||exists(base+".XML")) - return false; - - // OK to deploy it then + //defer deployment decision to fileChanged() return true; } @@ -238,7 +233,8 @@ public class WebAppProvider extends ScanningAppProvider { _tempDirectory = directory; } - + + /* ------------------------------------------------------------ */ /** * Get the user supplied Work Directory. * @@ -360,5 +356,150 @@ public class WebAppProvider extends ScanningAppProvider } return webAppContext; } + + + /* ------------------------------------------------------------ */ + @Override + protected void fileChanged(String filename) throws Exception + { + File file = new File(filename); + if (!file.exists()) + return; + + File parent = file.getParentFile(); + + //is the file that changed a directory? + if (file.isDirectory()) + { + //is there a .xml file of the same name? + if (exists(file.getName()+".xml")||exists(file.getName()+".XML")) + return; //ignore it + + //is there .war file of the same name? + if (exists(file.getName()+".war")||exists(file.getName()+".WAR")) + return; //ignore it + + super.fileChanged(filename); + return; + } + + + String lowname = file.getName().toLowerCase(Locale.ENGLISH); + //is the file that changed a .war file? + if (lowname.endsWith(".war")) + { + String name = file.getName(); + String base=name.substring(0,name.length()-4); + String xmlname = base+".xml"; + if (exists(xmlname)) + { + //if a .xml file exists for it, then redeploy that instead + File xml = new File (parent, xmlname); + super.fileChanged(xml.getCanonicalPath()); + return; + } + + xmlname = base+".XML"; + if (exists(xmlname)) + { + //if a .XML file exists for it, then redeploy that instead + File xml = new File(parent, xmlname); + super.fileChanged(xml.getCanonicalPath()); + return; + } + + //redeploy the changed war + super.fileChanged(filename); + return; + } + + //is the file that changed a .xml file? + if (lowname.endsWith(".xml")) + super.fileChanged(filename); + } + + /* ------------------------------------------------------------ */ + @Override + protected void fileAdded(String filename) throws Exception + { + File file = new File(filename); + if (!file.exists()) + return; + + //is the file that was added a directory? + if (file.isDirectory()) + { + //is there a .xml file of the same name? + if (exists(file.getName()+".xml")||exists(file.getName()+".XML")) + return; //assume we will get added events for the xml file + + //is there .war file of the same name? + if (exists(file.getName()+".war")||exists(file.getName()+".WAR")) + return; //assume we will get added events for the war file + + super.fileAdded(filename); + return; + } + + + //is the file that was added a .war file? + String lowname = file.getName().toLowerCase(Locale.ENGLISH); + if (lowname.endsWith(".war")) + { + String name = file.getName(); + String base=name.substring(0,name.length()-4); + //is there a .xml file of the same name? + if (exists(base+".xml")||exists(base+".XML")) + return; //ignore it as we should get addition of the xml file + + super.fileAdded(filename); + return; + } + + //is the file that was added an .xml file? + if (lowname.endsWith(".xml")) + super.fileAdded(filename); + } + + + /* ------------------------------------------------------------ */ + @Override + protected void fileRemoved(String filename) throws Exception + { + File file = new File(filename); + + //is the file that was removed a directory? + if (file.isDirectory()) + { + //is there a .xml file of the same name? + if (exists(file.getName()+".xml")||exists(file.getName()+".XML")) + return; //assume we will get removed events for the xml file + + //is there .war file of the same name? + if (exists(file.getName()+".war")||exists(file.getName()+".WAR")) + return; //assume we will get removed events for the war file + + super.fileRemoved(filename); + return; + } + + //is the file that was removed a .war file? + String lowname = file.getName().toLowerCase(Locale.ENGLISH); + if (lowname.endsWith(".war")) + { + //is there a .xml file of the same name? + String name = file.getName(); + String base=name.substring(0,name.length()-4); + if (exists(base+".xml")||exists(base+".XML")) + return; //ignore it as we should get removal of the xml file + + super.fileRemoved(filename); + return; + } + + //is the file that was removed an .xml file? + if (lowname.endsWith(".xml")) + super.fileRemoved(filename); + } }