Check resources for redeployment and reloading. @param app The web application to check @param skipFileModificationResolutionCheck When checking files for modification should the check that requires that any file modific
(DeployedApplication app, boolean skipFileModificationResolutionCheck)
| 1314 | * as the resolution of the file time stamp be skipped |
| 1315 | */ |
| 1316 | protected void checkResources(DeployedApplication app, boolean skipFileModificationResolutionCheck) { |
| 1317 | String[] resources = app.redeployResources.keySet().toArray(new String[0]); |
| 1318 | // Offset the current time by the resolution of File.lastModified() |
| 1319 | long currentTimeWithResolutionOffset = System.currentTimeMillis() - FILE_MODIFICATION_RESOLUTION_MS; |
| 1320 | for (int i = 0; i < resources.length; i++) { |
| 1321 | File resource = new File(resources[i]); |
| 1322 | if (log.isTraceEnabled()) { |
| 1323 | log.trace("Checking context[" + app.name + "] redeploy resource " + resource); |
| 1324 | } |
| 1325 | long lastModified = app.redeployResources.get(resources[i]).longValue(); |
| 1326 | if (resource.exists() || lastModified == 0) { |
| 1327 | // File.lastModified() has a resolution of 1s (1000ms). The last |
| 1328 | // modified time has to be more than 1000ms ago to ensure that |
| 1329 | // modifications that take place in the same second are not |
| 1330 | // missed. See Bug 57765. |
| 1331 | if (resource.lastModified() != lastModified && |
| 1332 | (!host.getAutoDeploy() || resource.lastModified() < currentTimeWithResolutionOffset || |
| 1333 | skipFileModificationResolutionCheck)) { |
| 1334 | if (resource.isDirectory()) { |
| 1335 | // No action required for modified directory |
| 1336 | app.redeployResources.put(resources[i], Long.valueOf(resource.lastModified())); |
| 1337 | } else if (app.hasDescriptor && resource.getName().toLowerCase(Locale.ENGLISH).endsWith(".war")) { |
| 1338 | // Modified WAR triggers a reload if there is an XML |
| 1339 | // file present |
| 1340 | // The only resource that should be deleted is the |
| 1341 | // expanded WAR (if any) |
| 1342 | Context context = (Context) host.findChild(app.name); |
| 1343 | String docBase = context.getDocBase(); |
| 1344 | if (!docBase.toLowerCase(Locale.ENGLISH).endsWith(".war")) { |
| 1345 | // This is an expanded directory |
| 1346 | File docBaseFile = new File(docBase); |
| 1347 | if (!docBaseFile.isAbsolute()) { |
| 1348 | docBaseFile = new File(host.getAppBaseFile(), docBase); |
| 1349 | } |
| 1350 | reload(app, docBaseFile, resource.getAbsolutePath()); |
| 1351 | } else { |
| 1352 | reload(app, null, null); |
| 1353 | } |
| 1354 | // Update times |
| 1355 | app.redeployResources.put(resources[i], Long.valueOf(resource.lastModified())); |
| 1356 | app.timestamp = System.currentTimeMillis(); |
| 1357 | boolean unpackWAR = unpackWARs; |
| 1358 | if (unpackWAR && context instanceof StandardContext) { |
| 1359 | unpackWAR = ((StandardContext) context).getUnpackWAR(); |
| 1360 | } |
| 1361 | if (unpackWAR) { |
| 1362 | addWatchedResources(app, context.getDocBase(), context); |
| 1363 | } else { |
| 1364 | addWatchedResources(app, null, context); |
| 1365 | } |
| 1366 | return; |
| 1367 | } else { |
| 1368 | // Everything else triggers a redeploy |
| 1369 | // (just need to undeploy here, deploy will follow) |
| 1370 | undeploy(app); |
| 1371 | deleteRedeployResources(app, resources, i, false); |
| 1372 | return; |
| 1373 | } |
no test coverage detected