/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with this
 * work for additional information regarding copyright ownership. The ASF
 * licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.apache.sling.launchpad.installer.impl;

import java.io.InputStream;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

import org.apache.sling.installer.api.InstallableResource;
import org.apache.sling.installer.api.OsgiInstaller;
import org.apache.sling.launchpad.api.LaunchpadContentProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LaunchpadConfigInstaller {

    /**
     * Resources supplied under this path by
     * LaunchpadContentProvider are considered for installation
     * as configurations
     */
    private static final String ROOT_CONFIG_PATH = "resources/config";

    /**
     * Resources supplied under this path by
     * LaunchpadContentProvider are considered for installation
     * as files
     */
    private static final String ROOT_INSTALL_PATH = "resources/install";

    public static void install(final OsgiInstaller installer,
            final LaunchpadContentProvider resourceProvider) {
        final Logger logger = LoggerFactory.getLogger(LaunchpadConfigInstaller.class);
        logger.info("Activating launchpad config installer, configuration path={}, install path={}",
                ROOT_CONFIG_PATH, ROOT_INSTALL_PATH);

        final Collection<InstallableResource> installables = new HashSet<InstallableResource>();

        // configurations
        final Iterator<String> configPaths = resourceProvider.getChildren(ROOT_CONFIG_PATH);
        while (configPaths.hasNext()) {
            final String path = configPaths.next();
            logger.info("Config launchpad file will be installed: {}", path);
            final InputStream stream = resourceProvider.getResourceAsStream(path);
            installables.add(new InstallableResource(path, stream, null, null, InstallableResource.TYPE_PROPERTIES, null));
        }

        // files
        final Iterator<String> filePaths = resourceProvider.getChildren(ROOT_INSTALL_PATH);
        while (filePaths.hasNext()) {
            final String path = filePaths.next();
            logger.info("Launchpad file will be installed: {}", path);
            final InputStream stream = resourceProvider.getResourceAsStream(path);
            installables.add(new InstallableResource(path, stream, null, null, InstallableResource.TYPE_FILE, null));
        }

        final InstallableResource [] toInstall = installables.toArray(new InstallableResource []{});
        installer.registerResources("launchpad", (toInstall));
        logger.info("{} resources registered with OsgiInstaller", toInstall.length);
    }
}
@@ -2241,32 +2241,73 @@
 T_CONFIG_PATH);%0A
+        if ( configPaths != null ) %7B%0A    
         while (c
@@ -2334,32 +2334,36 @@
 ) %7B%0A            
+   
+ 
 final String pat
@@ -2378,32 +2378,36 @@
 igPaths.next();%0A
+    
             logg
@@ -2460,32 +2460,36 @@
 ed: %7B%7D%22, path);%0A
+    
             fina
@@ -2559,32 +2559,36 @@
 h);%0A            
+    
 installables.add
@@ -2675,32 +2675,46 @@
 ERTIES, null));%0A
+            %7D%0A
         %7D%0A%0A     
@@ -2809,32 +2809,71 @@
 _INSTALL_PATH);%0A
+        if ( filePaths != null ) %7B%0A    
         while (f
@@ -2886,32 +2886,36 @@
 hs.hasNext()) %7B%0A
+    
             fina
@@ -2952,32 +2952,36 @@
 ();%0A            
+    
 logger.info(%22Lau
@@ -3015,32 +3015,36 @@
 ed: %7B%7D%22, path);%0A
+    
             fina
@@ -3114,32 +3114,36 @@
 h);%0A            
+ 
+   
 installables.add
@@ -3224,32 +3224,46 @@
 E_FILE, null));%0A
+            %7D%0A
         %7D%0A%0A     

Add extra null checks