/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of 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.jboss.as.arquillian.service;

import java.util.List;

import org.jboss.as.deployment.processor.AnnotationIndexProcessor;
import org.jboss.as.deployment.unit.DeploymentUnitContext;
import org.jboss.as.deployment.unit.DeploymentUnitProcessingException;
import org.jboss.as.deployment.unit.DeploymentUnitProcessor;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.junit.runner.RunWith;

/**
 * [TODO]
 *
 * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
 */
public class ArquillianRunWithAnnotationProcessor implements DeploymentUnitProcessor {

    @Override
    public void processDeployment(DeploymentUnitContext context) throws DeploymentUnitProcessingException {

        final Index index = context.getAttachment(AnnotationIndexProcessor.ATTACHMENT_KEY);
        if (index == null) {
            return; // Skip if there is no annotation index
        }

        final DotName runWithName = DotName.createSimple(RunWith.class.getName());
        final List<AnnotationTarget> targets = index.getAnnotationTargets(runWithName);
        if (targets == null)
            return; // Skip if there are no @RunWith annotations

        ArquillianConfig arqConfig = new ArquillianConfig(context);
        context.putAttachment(ArquillianConfig.KEY, arqConfig);

        for (AnnotationTarget target : targets) {
            if (target instanceof ClassInfo == false) {
                continue;
            }
            final ClassInfo classInfo = (ClassInfo) target;
            final String testClassName = classInfo.name().toString();
            arqConfig.addTestClass(testClassName);
        }
    }

}

@@ -1527,14 +1527,198 @@
 %0A * 
-%5BTODO%5D
+Uses the annotation index to check whether there is a class annotated with @RunWith.%0A * In which case an %7B@link ArquillianConfig%7D object that names the test class is attached to the context.
 %0A *%0A
@@ -1774,16 +1774,52 @@
 han%3C/a%3E%0A
+ * @author Thomas.Diesler@jboss.com%0A
  */%0Apubl
@@ -2143,18 +2143,16 @@
 == null)
- %7B
 %0A       
@@ -2203,26 +2203,16 @@
 on index
-%0A        %7D
 %0A%0A      
@@ -2395,32 +2395,53 @@
 (targets == null
+ %7C%7C targets.isEmpty()
 )%0A            re
@@ -2722,25 +2722,16 @@
 Info
- == false
 ) %7B%0A    
     
@@ -2730,44 +2730,8 @@
     
-            continue;%0A            %7D%0A
     
@@ -2786,16 +2786,20 @@
 target;%0A
+    
         
@@ -2872,16 +2872,20 @@
         
+  
+  
 arqConfi
@@ -2911,24 +2911,38 @@
 ClassName);%0A
+            %7D%0A
         %7D%0A  
@@ -2945,11 +2945,10 @@
 %7D%0A    %7D%0A
-%0A
 %7D%0A

Fix @RunWith annotation processing, which resulted in all deployments beeing registered with Arquillian service and deployed bundles not being started automatically