sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1738224 - in /sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl: compiler/ engine/compiled/ engine/extension/use/
Date Fri, 08 Apr 2016 09:38:23 GMT
Author: radu
Date: Fri Apr  8 09:38:23 2016
New Revision: 1738224

URL: http://svn.apache.org/viewvc?rev=1738224&view=rev
Log:
trivial: enhanced debug logging

Modified:
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyJavaCompilerService.java
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/UnitChangeMonitor.java
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/compiled/SourceIdentifier.java
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyJavaCompilerService.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyJavaCompilerService.java?rev=1738224&r1=1738223&r2=1738224&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyJavaCompilerService.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/SightlyJavaCompilerService.java
Fri Apr  8 09:38:23 2016
@@ -98,24 +98,31 @@ public class SightlyJavaCompilerService
      * @throws CompilerException in case of any runtime exception
      */
     public Object getInstance(RenderContext renderContext, String className) {
+        LOG.debug("Attempting to load class {}.", className);
         if (className.contains(".")) {
             if (unitChangeMonitor.getLastModifiedDateForJavaUseObject(className) > 0)
{
                 // it looks like the POJO comes from the repo and it was changed since it
was last loaded
+                LOG.debug("Class {} identifies a POJO from the repository that was changed
since the last time it was instantiated.",
+                        className);
                 Object result = compileRepositoryJavaClass(renderContext.getScriptResourceResolver(),
className);
                 unitChangeMonitor.clearJavaUseObject(className);
                 return result;
             }
             try {
                 // the object either comes from a bundle or from the repo but it was not
registered by the UnitChangeMonitor
+                LOG.debug("Attempting to load class {} from the classloader cache.", className);
                 return loadObject(className);
             } catch (CompilerException cex) {
                 // the object definitely doesn't come from a bundle so we should attempt
to compile it from the repo
+                LOG.debug("Class {} identifies a POJO from the repository and it needs to
be compiled.", className);
                 return compileRepositoryJavaClass(renderContext.getScriptResourceResolver(),
className);
             }
         } else {
             Resource pojoResource = UseProviderUtils.locateScriptResource(renderContext,
className + ".java");
             if (pojoResource != null) {
-                return getInstance(renderContext, Utils.getJavaNameFromPath(pojoResource.getPath()));
+                String fqcn = Utils.getJavaNameFromPath(pojoResource.getPath());
+                LOG.debug("Class {} has FQCN {}.", className, fqcn);
+                return getInstance(renderContext, fqcn);
             }
         }
         throw new SightlyException("Cannot find class " + className + ".");
@@ -135,6 +142,7 @@ public class SightlyJavaCompilerService
                 readLock.unlock();
                 writeLock.lock();
                 try {
+                    LOG.debug("Need to recompile {}.", sourceIdentifier.toString());
                     return internalCompileSource(sourceCode, sourceIdentifier.getFullyQualifiedName());
                 } finally {
                     // downgrade write lock since we've probably compiled the source code
by now
@@ -142,6 +150,7 @@ public class SightlyJavaCompilerService
                     writeLock.unlock();
                 }
             } else {
+                LOG.debug("No need to recompile {}, loading it from the classloader cache.",
sourceIdentifier.toString());
                 return classLoaderWriter.getClassLoader().loadClass(sourceIdentifier.getFullyQualifiedName()).newInstance();
             }
         } catch (Exception e) {
@@ -187,9 +196,8 @@ public class SightlyJavaCompilerService
         if (errors != null && errors.size() > 0) {
             throw new CompilerException(CompilerException.CompilerExceptionCause.COMPILER_ERRORS,
createErrorMsg(errors));
         }
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("script compiled: {}", compilationResult.didCompile());
-            LOG.debug("compilation took {}ms", end - start);
+        if (compilationResult.didCompile()) {
+            LOG.debug("Class {} was compiled in {}ms.", fqcn, end - start);
         }
         /**
          * the class loader might have become dirty, so let the {@link ClassLoaderWriter}
decide which class loader to return

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/UnitChangeMonitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/UnitChangeMonitor.java?rev=1738224&r1=1738223&r2=1738224&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/UnitChangeMonitor.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/UnitChangeMonitor.java
Fri Apr  8 09:38:23 2016
@@ -154,8 +154,10 @@ public class UnitChangeMonitor {
     private void processEvent(Event event) {
         String path = (String) event.getProperty(SlingConstants.PROPERTY_PATH);
         String topic = event.getTopic();
+        LOG.debug("Received event {} for path {}.", topic, path);
         if (SlingConstants.TOPIC_RESOURCE_ADDED.equals(topic) || SlingConstants.TOPIC_RESOURCE_CHANGED.equals(topic))
{
             if (path.endsWith(".java")) {
+                LOG.debug("Java Use Object {} was {}.", path, topic);
                 slyJavaUseMap.put(Utils.getJavaNameFromPath(path), System.currentTimeMillis());
             } else if (path.endsWith(SightlyScriptEngineFactory.EXTENSION)) {
                 ResourceResolver resolver = null;
@@ -175,12 +177,15 @@ public class UnitChangeMonitor {
                 if (StringUtils.isEmpty(encoding)) {
                     encoding = sightlyEngineConfiguration.getEncoding();
                 }
+                LOG.debug("Sightly script {} was {}.", path, topic);
                 slyScriptsMap.put(path, new SightlyScriptMetaInfo(encoding, System.currentTimeMillis()));
             }
         } else if (SlingConstants.TOPIC_RESOURCE_REMOVED.equals(topic)) {
             if (path.endsWith(".java")) {
+                LOG.debug("Removed Java Use Object {} from UnitChangeMonitor cache.", path);
                 slyJavaUseMap.remove(Utils.getJavaNameFromPath(path));
             } else if (path.endsWith(SightlyScriptEngineFactory.EXTENSION)) {
+                LOG.debug("Removed script {} from UnitChangeMonitor cache.", path);
                 slyScriptsMap.remove(path);
             }
         }

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/compiled/SourceIdentifier.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/compiled/SourceIdentifier.java?rev=1738224&r1=1738223&r2=1738224&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/compiled/SourceIdentifier.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/compiled/SourceIdentifier.java
Fri Apr  8 09:38:23 2016
@@ -126,4 +126,8 @@ public class SourceIdentifier {
         return scriptName.substring(lastDotIndex);
     }
 
+    @Override
+    public String toString() {
+        return "SourceIdentifier { resourcePath=" + resource.getPath() + ", fqcn=" + fullyQualifiedName
+ " }";
+    }
 }

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java?rev=1738224&r1=1738223&r2=1738224&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java
(original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java
Fri Apr  8 09:38:23 2016
@@ -88,9 +88,11 @@ public class JavaUseProvider implements
 
         Object result;
         try {
+            LOG.debug("Attempting to load class {} from the classloader cache.", identifier);
             Class<?> cls = classLoaderWriter.getClassLoader().loadClass(identifier);
             if (unitChangeMonitor.getLastModifiedDateForJavaUseObject(identifier) > 0)
{
                 // the object is a POJO that was changed in the repository but not recompiled;
+                LOG.debug("Class {} was available in the classloader cache but it needs to
be recompiled.");
                 result = sightlyJavaCompilerService.getInstance(renderContext, identifier);
                 if (result instanceof Use) {
                     ((Use) result).init(BindingsUtils.merge(globalBindings, arguments));
@@ -124,6 +126,7 @@ public class JavaUseProvider implements
             /**
              * this object is either not exported from a bundle, or it's a POJO from the
repository that wasn't loaded before
              */
+            LOG.debug("Class {} was not found in the classloader cache.", identifier);
             result = sightlyJavaCompilerService.getInstance(renderContext, identifier);
             if (result instanceof Use) {
                 ((Use) result).init(BindingsUtils.merge(globalBindings, arguments));



Mime
View raw message