/*
 * Copyright 2016-2016 the original author or authors.
 *
 * 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 org.joinfaces.autoconfigure.myfaces;

import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.faces.context.ExternalContext;

import org.apache.myfaces.spi.AnnotationProvider;

/**
 * Servlet context configurer of MyFaces.
 * @author Marcelo Fernandes
 */
public class JoinFacesAnnotationProvider extends AnnotationProvider {

	private static Map<Class<? extends Annotation>, Set<Class<?>>> annotatedClasses;

	private static Collection<URL> urls;

	public static void setAnnotatedClasses(Map<Class<? extends Annotation>, Set<Class<?>>> annotatedClasses) {
		JoinFacesAnnotationProvider.annotatedClasses = annotatedClasses;
	}

	public static void setUrls(Collection<URL> urls) {
		JoinFacesAnnotationProvider.urls = urls;
	}

	@Override
	public Map<Class<? extends Annotation>, Set<Class<?>>> getAnnotatedClasses(ExternalContext ctx) {
		return annotatedClasses;
	}

	@Override
	public Set<URL> getBaseUrls() {
		return new HashSet<>(urls);
	}
}

@@ -661,16 +661,44 @@
 faces;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -944,16 +944,73 @@
 rovider;
+%0Aimport org.apache.myfaces.spi.AnnotationProviderWrapper;
 %0A%0A/**%0A *
@@ -1149,16 +1149,23 @@
 Provider
+Wrapper
  %7B%0A%0A%09pri
@@ -1282,16 +1282,126 @@
  urls;%0A%0A
+%09public JoinFacesAnnotationProvider(AnnotationProvider annotationProvider) %7B%0A%09%09super(annotationProvider);%0A%09%7D%0A%0A
 %09public 
@@ -1786,108 +1786,402 @@
 %7B%0A%09%09
-return annotatedClasses;%0A%09%7D%0A%0A%09@Override%0A%09public Set%3CURL%3E getBaseUrls() %7B%0A%09%09return new HashSet%3C%3E(urls
+if (annotatedClasses != null) %7B%0A%09%09%09return annotatedClasses;%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09return super.getAnnotatedClasses(ctx);%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public Set%3CURL%3E getBaseUrls() throws IOException %7B%0A%09%09if (urls != null) %7B%0A%09%09%09return new HashSet%3C%3E(urls);%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09return super.getBaseUrls();%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public Set%3CURL%3E getBaseUrls(ExternalContext ctx) throws IOException %7B%0A%09%09return getBaseUrls(
 );%0A%09

fix MyFaces war-deployment