Improve task logging
authorCarsten Ziegeler <cziegeler@apache.org>
Tue, 21 Mar 2017 13:05:11 +0000 (13:05 +0000)
committerCarsten Ziegeler <cziegeler@apache.org>
Tue, 21 Mar 2017 13:05:11 +0000 (13:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1787961 13f79535-47bb-0310-9956-ffa450edef68

src/main/java/org/apache/sling/installer/factory/model/impl/InstallModelTask.java
src/main/java/org/apache/sling/installer/factory/model/impl/ModelTaskFactory.java
src/main/java/org/apache/sling/installer/factory/model/impl/ModelTransformer.java
src/main/java/org/apache/sling/installer/factory/model/impl/UninstallModelTask.java

index 063aefa..5c7d3a5 100644 (file)
@@ -93,11 +93,12 @@ public class InstallModelTask extends AbstractModelTask {
     public void execute(final InstallationContext ctx) {
         try {
             final TaskResource resource = this.getResource();
+            ctx.log("Installing {}", resource.getEntityId());
             final String modelTxt = (String) resource.getAttribute(ModelTransformer.ATTR_MODEL);
             final Integer featureIndex = (Integer) resource.getAttribute(ModelTransformer.ATTR_FEATURE_INDEX);
             final String name = (String) resource.getAttribute(ModelTransformer.ATTR_FEATURE_NAME);
             if ( modelTxt == null || featureIndex == null || name == null ) {
-                ctx.log("Unable to install model resource {} : no model found", this.getResource());
+                ctx.log("Unable to install model resource {} : no model found", resource);
                 this.getResourceGroup().setFinishState(ResourceState.IGNORED);
             } else {
                 final String path = (String) resource.getAttribute(ModelTransformer.ATTR_BASE_PATH);
@@ -107,7 +108,7 @@ public class InstallModelTask extends AbstractModelTask {
                 try {
                     final Result result = this.transform(name, modelTxt, featureIndex, resource, baseDir);
                     if ( result == null ) {
-                        ctx.log("Unable to install model resource {} : unable to create resources", this.getResource());
+                        ctx.log("Unable to install model resource {} : unable to create resources", resource);
                         this.getResourceGroup().setFinishState(ResourceState.IGNORED);
                     } else {
                         // repo init first
@@ -117,7 +118,7 @@ public class InstallModelTask extends AbstractModelTask {
                                 ops = this.repoInitParser.parse(r);
                             } catch (final IOException | RepoInitParsingException e) {
                                 logger.error("Unable to parse repoinit block.", e);
-                                ctx.log("Unable to install model resource {} : unable parse repoinit block.", this.getResource());
+                                ctx.log("Unable to install model resource {} : unable parse repoinit block.", resource);
                                 this.getResourceGroup().setFinishState(ResourceState.IGNORED);
                                 return;
                             }
@@ -130,7 +131,7 @@ public class InstallModelTask extends AbstractModelTask {
                                 session.save();
                             } catch ( final RepositoryException re) {
                                 logger.error("Unable to process repoinit block.", re);
-                                ctx.log("Unable to install model resource {} : unable to process repoinit block.", this.getResource());
+                                ctx.log("Unable to install model resource {} : unable to process repoinit block.", resource);
                                 this.getResourceGroup().setFinishState(ResourceState.IGNORED);
                                 return;
 
@@ -145,7 +146,7 @@ public class InstallModelTask extends AbstractModelTask {
                             if ( installer != null ) {
                                 installer.registerResources("model-" + name, result.resources.toArray(new InstallableResource[result.resources.size()]));
                             } else {
-                                ctx.log("Unable to install model resource {} : unable to get OSGi installer", this.getResource());
+                                ctx.log("Unable to install model resource {} : unable to get OSGi installer", resource);
                                 this.getResourceGroup().setFinishState(ResourceState.IGNORED);
                                 return;
                             }
@@ -158,6 +159,9 @@ public class InstallModelTask extends AbstractModelTask {
                         this.deleteDirectory(baseDir);
                     }
                 }
+                if ( success ) {
+                    ctx.log("Installed {}", resource.getEntityId());
+                }
             }
         } finally {
             this.cleanup();
index dfff035..4cfa59c 100644 (file)
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.installer.factory.model.impl;
 
-
 import org.apache.sling.installer.api.tasks.InstallTask;
 import org.apache.sling.installer.api.tasks.InstallTaskFactory;
 import org.apache.sling.installer.api.tasks.ResourceState;
@@ -36,7 +35,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * This task factory process model resources detected by
+ * This task factory processes model resources detected by
  * the {@link ModelTransformer}.
  */
 @Component(service = InstallTaskFactory.class)
@@ -71,11 +70,8 @@ public class ModelTaskFactory implements InstallTaskFactory {
             return null;
         }
         if (rsrc.getState() == ResourceState.UNINSTALL ) {
-            logger.info("Uninstalling {}", rsrc.getEntityId());
-
             return new UninstallModelTask(group, bundleContext);
         }
-        logger.info("Installing {}", rsrc.getEntityId());
         return new InstallModelTask(group,
                 this.settings.getRunModes(),
                 this.repository,
index e9bd83b..8b9196c 100644 (file)
@@ -17,7 +17,6 @@ package org.apache.sling.installer.factory.model.impl;/*
  * under the License.
  */
 
-
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -49,7 +48,7 @@ import org.slf4j.LoggerFactory;
 
 /**
  * This transformer detects a file with the ending ".model" containing
- * a provisioning model.
+ * a provisioning model or a model archive ending in ".mar"
  */
 @Component(service = ResourceTransformer.class)
 public class ModelTransformer implements ResourceTransformer {
index ecce2bf..5d46769 100644 (file)
@@ -23,6 +23,7 @@ import java.io.File;
 import org.apache.sling.installer.api.OsgiInstaller;
 import org.apache.sling.installer.api.tasks.InstallationContext;
 import org.apache.sling.installer.api.tasks.ResourceState;
+import org.apache.sling.installer.api.tasks.TaskResource;
 import org.apache.sling.installer.api.tasks.TaskResourceGroup;
 import org.osgi.framework.BundleContext;
 
@@ -43,13 +44,16 @@ public class UninstallModelTask extends AbstractModelTask {
             if ( installer == null ) {
                 ctx.log("Unable to get OSGi Installer service!");
             } else {
-                installer.registerResources("model-" + getResource().getAttribute(ModelTransformer.ATTR_FEATURE_NAME), null);
-                final String path = (String)this.getResource().getAttribute(ModelTransformer.ATTR_BASE_PATH);
+                final TaskResource resource = this.getResource();
+                ctx.log("Uninstalling {}", resource.getEntityId());
+                installer.registerResources("model-" + resource.getAttribute(ModelTransformer.ATTR_FEATURE_NAME), null);
+                final String path = (String)resource.getAttribute(ModelTransformer.ATTR_BASE_PATH);
                 if ( path != null ) {
                     final File dir = new File(path);
                     deleteDirectory(dir);
                 }
                 this.getResourceGroup().setFinishState(ResourceState.UNINSTALLED);
+                ctx.log("Uninstalled {}", resource.getEntityId());
             }
         } finally {
             this.cleanup();