/*
 * Copyright 2015-2016 Canoo Engineering AG.
 *
 * Licensed 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 com.canoo.dolphin.server.controller;

import com.canoo.dolphin.server.DolphinController;
import org.reflections.Reflections;
import org.reflections.util.ConfigurationBuilder;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by hendrikebbers on 16.09.15.
 */
public class ControllerRepository {

    private static Map<String, Class> controllersClasses;

    private static boolean initialized = false;

    private ControllerRepository() {
    }

    public static synchronized void init() {
        if (initialized) {
            throw new RuntimeException(ControllerRepository.class.getName() + " already initialized");
        }
        controllersClasses = new HashMap<>();

        ConfigurationBuilder configuration = ConfigurationBuilder.build(ControllerRepository.class.getClassLoader());

        //Special case for JBOSS Application server to get all classes
        try {
            Enumeration<URL> res = ControllerRepository.class.getClassLoader().getResources("");
            while(res.hasMoreElements()) {
                URL resURL = res.nextElement();
                if(!configuration.getUrls().contains(resURL)) {
                    configuration.getUrls().add(resURL);
                }
            }
        } catch (IOException e) {
            throw new RuntimeException("Error in Dolphin Platform controller class scan", e);
        }


        //Remove native libs (will be added on Mac in a Spring Boot app)
        Set<URL> urls = configuration.getUrls();
        List<URL> toRemove = new ArrayList<>();
        for(URL url : urls) {
            if(url.toString().endsWith(".jnilib")) {
                toRemove.add(url);
            }
        }
        for(URL url : toRemove) {
            configuration.getUrls().remove(url);
        }

        Reflections reflections = new Reflections(configuration);
        Set<Class<?>> foundControllerClasses = reflections.getTypesAnnotatedWith(DolphinController.class);
        for (Class<?> controllerClass : foundControllerClasses) {
            String name = controllerClass.getName();
            if (controllerClass.getAnnotation(DolphinController.class).value() != null && !controllerClass.getAnnotation(DolphinController.class).value().trim().isEmpty()) {
                name = controllerClass.getAnnotation(DolphinController.class).value();
            }
            controllersClasses.put(name, controllerClass);
        }
        initialized = true;
    }

    public static synchronized Class getControllerClassForName(String name) {
        if(!initialized) {
            throw new IllegalStateException(ControllerRepository.class.getName() + " has not been initialized!");
        }
        return controllersClasses.get(name);
    }
}

@@ -1776,16 +1776,17 @@
    while
+ 
 (res.has
@@ -1823,178 +1823,55 @@
     
-URL resURL = res.nextElement();%0A                if(!configuration.getUrls().contains(resURL)) %7B%0A                    configuration.getUrls().add(resURL);%0A                %7D
+configuration.getUrls().add(res.nextElement());
 %0A   
@@ -2194,32 +2194,33 @@
 %3E();%0A        for
+ 
 (URL url : urls)
@@ -2236,16 +2236,17 @@
       if
+ 
 (url.toS
@@ -2327,32 +2327,32 @@
     %7D%0A        %7D%0A
-
         for(URL 
@@ -2346,16 +2346,17 @@
      for
+ 
 (URL url
@@ -3189,16 +3189,17 @@
       if
+ 
 (!initia

Change based on review