/*
 * Copyright 2008-2011 Red Hat, Inc, and individual contributors.
 * 
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.fnbox.core.processors;

import org.fnbox.core.ClojureMetaData;
import org.fnbox.core.ClojureRuntime;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.logging.Logger;
import org.jboss.modules.Module;

/**
 * Handle mounting .clj files and marking them as a DEPLOYMENT_ROOT
 * FIXME: This doesn't handle archives
 * 
 */
public class ClojureRuntimeInstaller implements DeploymentUnitProcessor {
    
    public ClojureRuntimeInstaller() {
    }

    @Override
    public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
        DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

        if (!deploymentUnit.hasAttachment( ClojureMetaData.ATTACHMENT_KEY )) {
            return;
        }
        
        Module module = deploymentUnit.getAttachment( Attachments.MODULE );
        
        deploymentUnit.putAttachment( ClojureRuntime.ATTACHMENT_KEY, new ClojureRuntime( module.getClassLoader() ) );
    }

    @Override
    public void undeploy(DeploymentUnit context) {
       
    }
        
    static final Logger log = Logger.getLogger( "org.fnbox.core.as" );
}

@@ -1340,111 +1340,89 @@
 %0A * 
-Handle mounting .clj files and marking them as a DEPLOYMENT_ROOT%0A * FIXME: This doesn't handle archives
+Attaches a ClojureRuntime to the deployment. There is one ClojureRuntime per app.
 %0A * 
@@ -2222,18 +2222,15 @@
 box.core
-.as
 %22 );%0A%7D%0A

Fix comment.