/*
 * 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.cloudstack.spring.module.locator.impl;

import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.apache.cloudstack.spring.module.locator.ModuleDefinitionLocator;
import org.apache.cloudstack.spring.module.model.ModuleDefinition;
import org.apache.cloudstack.spring.module.model.impl.DefaultModuleDefinition;
import org.apache.cloudstack.spring.module.util.ModuleLocationUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

public class ClasspathModuleDefinitionLocator implements ModuleDefinitionLocator {
    
    protected ResourcePatternResolver getResolver() {
        return new PathMatchingResourcePatternResolver();
    }
    
    public Collection<ModuleDefinition> locateModules(String context) throws IOException {
        ResourcePatternResolver resolver = getResolver();
        
        Map<String, ModuleDefinition> allModules = discoverModules(context, resolver);
        
        return allModules.values();
    }
    
    protected Map<String, ModuleDefinition> discoverModules(String baseDir, ResourcePatternResolver resolver) throws IOException {
        Map<String, ModuleDefinition> result = new HashMap<String, ModuleDefinition>();
        
        for ( Resource r : resolver.getResources(ModuleLocationUtils.getModulesLocation(baseDir)) ) {
            DefaultModuleDefinition def = new DefaultModuleDefinition(baseDir, r, resolver);
            def.init();
            
            if ( def.isValid() )
                result.put(def.getName(), def);
        }
        
        return result;
    }
    
}

@@ -1257,16 +1257,73 @@
 nUtils;%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -1359,16 +1359,16 @@
 source;%0A
-
 import o
@@ -1591,20 +1591,120 @@
 cator %7B%0A
+%0A
     
+private static final Logger log = LoggerFactory.getLogger(ClasspathModuleDefinitionLocator.class);%0A
 %0A    pro
@@ -1810,28 +1810,38 @@
 er();%0A    %7D%0A
+%0A
     
+@Override
 %0A    public 
@@ -1974,33 +1974,25 @@
 Resolver();%0A
-        
 %0A
+
         Map%3C
@@ -2066,25 +2066,17 @@
 olver);%0A
-        
 %0A
+
         
@@ -2109,21 +2109,17 @@
 ;%0A    %7D%0A
-    
 %0A
+
     prot
@@ -2329,25 +2329,17 @@
 ion%3E();%0A
-        
 %0A
+
         
@@ -2428,24 +2428,87 @@
 seDir)) ) %7B%0A
+            log.debug(%22Discovered module: %5B%7B%7D%5D%22, r.getURL());%0A%0A
             
@@ -2616,21 +2616,9 @@
 ();%0A
-            
 %0A
+
     
@@ -2708,17 +2708,9 @@
   %7D%0A
-        
 %0A
+
     
@@ -2734,15 +2734,11 @@
 ;%0A    %7D%0A
-    
 %0A%7D%0A

Add debug logging