in src/main/java/org/apache/sling/scripting/sightly/impl/engine/compiled/SlingHTLMasterCompiler.java [368:392]
private Object getUseObjectAndRecompileIfNeeded(Resource pojoResource)
throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException,
InvocationTargetException {
SourceIdentifier sourceIdentifier = new SourceIdentifier(sightlyEngineConfiguration, pojoResource.getPath());
long sourceLastModifiedDateFromCache =
resourceBackedPojoChangeMonitor.getLastModifiedDateForJavaUseObject(pojoResource.getPath());
long classLastModifiedDate = classLoaderWriter.getLastModified("/" + sourceIdentifier.getFullyQualifiedClassName()
.replaceAll("\\.", "/") + ".class");
if (sourceLastModifiedDateFromCache == 0) {
// first access; let's check the real last modified date of the source
long sourceLastModifiedDate = pojoResource.getResourceMetadata().getModificationTime();
resourceBackedPojoChangeMonitor.recordLastModifiedTimestamp(pojoResource.getPath(), sourceLastModifiedDate);
if (classLastModifiedDate < 0 || sourceLastModifiedDate > classLastModifiedDate) {
return compileSource(sourceIdentifier, IOUtils.toString(pojoResource.adaptTo(InputStream.class), StandardCharsets.UTF_8));
} else {
return classLoaderWriter.getClassLoader().loadClass(sourceIdentifier.getFullyQualifiedClassName()).getDeclaredConstructor().newInstance();
}
} else {
if (sourceLastModifiedDateFromCache > classLastModifiedDate) {
return compileSource(sourceIdentifier, IOUtils.toString(pojoResource.adaptTo(InputStream.class), StandardCharsets.UTF_8));
} else {
return classLoaderWriter.getClassLoader().loadClass(sourceIdentifier.getFullyQualifiedClassName()).getDeclaredConstructor().newInstance();
}
}
}