/*
 * 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.deltaspike.jsf.impl.resource;

import javax.faces.application.Resource;
import javax.faces.application.ResourceHandler;
import javax.faces.application.ResourceHandlerWrapper;
import org.apache.deltaspike.core.api.projectstage.ProjectStage;
import org.apache.deltaspike.core.util.ClassUtils;
import org.apache.deltaspike.core.util.ProjectStageProducer;

/**
 * {@link ResourceHandlerWrapper} to deliver uncompressed resources in {@link ProjectStage#Development}.
 */
public class DeltaSpikeResourceHandler extends ResourceHandlerWrapper
{
    private static final String LIBRARY = "deltaspike";
    private static final String LIBRARY_UNCOMPRESSED = "deltaspike-uncompressed";
    
    private final ResourceHandler wrapped;
    private final String version;

    public DeltaSpikeResourceHandler(ResourceHandler resourceHandler)
    {
        super();

        wrapped = resourceHandler;
        version = ClassUtils.getJarVersion(this.getClass());
    }

    @Override
    public Resource createResource(String resourceName, String libraryName)
    {
        Resource resource = wrapped.createResource(resourceName, libraryName);

        if (resource != null && libraryName != null && LIBRARY.equals(libraryName))
        {
            if (ProjectStageProducer.getInstance().getProjectStage() == ProjectStage.Development)
            {
                resource = wrapped.createResource(resourceName, LIBRARY_UNCOMPRESSED);
            }
            
            resource = new DeltaSpikeResource(resource, version);
        }

        return resource;
    }

    @Override
    public ResourceHandler getWrapped()
    {
        return wrapped;
    }
}

@@ -1054,16 +1054,143 @@
 tStage;%0A
+import org.apache.deltaspike.core.spi.activation.Deactivatable;%0Aimport org.apache.deltaspike.core.util.ClassDeactivationUtils;%0A
 import o
@@ -1228,24 +1228,24 @@
 ClassUtils;%0A
-
 import org.a
@@ -1476,16 +1476,41 @@
 rWrapper
+ implements Deactivatable
 %0A%7B%0A    p
@@ -1723,16 +1723,53 @@
 version;
+%0A    private final boolean activated;
 %0A%0A    pu
@@ -1952,16 +1952,89 @@
 ass());%0A
+        activated = ClassDeactivationUtils.isActivated(this.getClass());%0A
     %7D%0A%0A 
@@ -2204,24 +2204,24 @@
 raryName);%0A%0A
-
         if (
@@ -2220,16 +2220,29 @@
     if (
+activated && 
 resource

DELTASPIKE-621 DeltaSpikeResourceHandler should implement Deactivatable