if ((!resource.isDirectory()) &&
resource.lastModified() > lastModified) {
// Undeploy application
if (log.isInfoEnabled())
log.info(sm.getString("hostConfig.undeploy", app.name));
ContainerBase context =
(ContainerBase) host.findChild(app.name);
try {
host.removeChild(context);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log.warn(sm.getString
("hostConfig.context.remove", app.name), t);
}
// Delete other redeploy resources
for (int j = i + 1; j < resources.length; j++) {
try {
File current = new File(resources[j]);
current = current.getCanonicalFile();
if ((current.getAbsolutePath().startsWith(
appBase().getAbsolutePath() +
File.separator))
|| (current.getAbsolutePath().startsWith(
configBase().getAbsolutePath()))) {
if (log.isDebugEnabled())
log.debug("Delete " + current);
ExpandWar.delete(current);
}
} catch (IOException e) {
log.warn(sm.getString
("hostConfig.canonicalizing", app.name), e);
}
}
deployed.remove(app.name);
return;
}
} else {
// There is a chance the the resource was only missing
// temporarily eg renamed during a text editor save
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
// Ignore
}
// Recheck the resource to see if it was really deleted
if (resource.exists()) {
continue;
}
long lastModified =
app.redeployResources.get(resources[i]).longValue();
if (lastModified == 0L) {
continue;
}
// Undeploy application
if (log.isInfoEnabled())
log.info(sm.getString("hostConfig.undeploy", app.name));
ContainerBase context =
(ContainerBase) host.findChild(app.name);
try {
host.removeChild(context);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log.warn(sm.getString
("hostConfig.context.remove", app.name), t);
}
// Delete all redeploy resources
for (int j = i + 1; j < resources.length; j++) {
try {
File current = new File(resources[j]);
current = current.getCanonicalFile();
if ((current.getAbsolutePath().startsWith(
appBase().getAbsolutePath() + File.separator))
|| (current.getAbsolutePath().startsWith(
configBase().getAbsolutePath()))) {
if (log.isDebugEnabled())
log.debug("Delete " + current);
ExpandWar.delete(current);
}
} catch (IOException e) {
log.warn(sm.getString
("hostConfig.canonicalizing", app.name), e);
}
}
// Delete reload resources as well (to remove any remaining .xml
// descriptor)
String[] resources2 =
app.reloadResources.keySet().toArray(new String[0]);
for (int j = 0; j < resources2.length; j++) {
try {
File current = new File(resources2[j]);
current = current.getCanonicalFile();
if ((current.getAbsolutePath().startsWith(
appBase().getAbsolutePath() + File.separator))
|| ((current.getAbsolutePath().startsWith(
configBase().getAbsolutePath())
&& (current.getAbsolutePath().endsWith(".xml"))))) {
if (log.isDebugEnabled())
log.debug("Delete " + current);
ExpandWar.delete(current);
}
} catch (IOException e) {
log.warn(sm.getString
("hostConfig.canonicalizing", app.name), e);
}
}
deployed.remove(app.name);
return;
}
}
resources = app.reloadResources.keySet().toArray(new String[0]);
for (int i = 0; i < resources.length; i++) {
File resource = new File(resources[i]);
if (log.isDebugEnabled())
log.debug("Checking context[" + app.name +
"] reload resource " + resource);
long lastModified =
app.reloadResources.get(resources[i]).longValue();
if ((!resource.exists() && lastModified != 0L)
|| (resource.lastModified() != lastModified)) {
// Reload application
if(log.isInfoEnabled())
log.info(sm.getString("hostConfig.reload", app.name));
Container context = host.findChild(app.name);
try {
// Might not have started if start failed last time
if (context.getState().isAvailable()) {
context.stop();
}
} catch (Exception e) {
log.warn(sm.getString
("hostConfig.context.restart", app.name), e);
}
// If the context was not started (for example an error
// in web.xml) we'll still get to try to start
try {
context.start();
} catch (Exception e) {
log.warn(sm.getString
("hostConfig.context.restart", app.name), e);
}
// Update times