All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.code.sbt.compiler.plugin.SBTTestCompileMojo Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/*
 * Copyright 2013-2014 Grzegorz Slowikowski (gslowikowski at gmail dot com)
 *
 * 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.google.code.sbt.compiler.plugin;

import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;

/**
 * Compile Scala and Java test sources
 * 
 * @author Grzegorz Slowikowski
 * @since 1.0.0
 */
@Mojo( name = "testCompile", defaultPhase = LifecyclePhase.TEST_COMPILE, requiresDependencyResolution = ResolutionScope.TEST )
public class SBTTestCompileMojo
    extends AbstractSBTCompileMojo
{
    /**
     * Test source inclusion filters for the compiler.
     * 
     * @since 1.0.0
     */
    @Parameter
    protected Set testIncludes = new HashSet();

    /**
     * Test source exclusion filters for the compiler.
     * 
     * @since 1.0.0
     */
    @Parameter
    protected Set testExcludes = new HashSet();

    /**
     * Set this to {@code true} to bypass compilation of test sources.
     * 
     * @since 1.0.0
     */
    @Parameter( property = "maven.test.skip" )
    protected boolean skipTest;

    /**
     * The source directories containing Scala and Java test sources to be compiled.
     */
    @Parameter( defaultValue = "${project.testCompileSourceRoots}", readonly = true, required = true )
    private List compileSourceRoots;

    /**
     * Project test classpath.
     */
    @Parameter( defaultValue = "${project.testClasspathElements}", required = true, readonly = true )
    private List classpathElements;

    /**
     * The directory where compiled test classes go.
     */
    @Parameter( defaultValue = "${project.build.testOutputDirectory}", required = true, readonly = true )
    private File outputDirectory;

    @Override
    protected void internalExecute()
        throws MojoExecutionException, MojoFailureException
    {
        if ( skipTest )
        {
            getLog().info( "Not compiling test sources" );
            return;
        }
        super.internalExecute();
    }

    @Override
    protected List getCompileSourceRoots()
    {
        return compileSourceRoots;
    }

    @Override
    protected Set getSourceIncludes()
    {
        return testIncludes;
    }
    
    @Override
    protected Set getSourceExcludes()
    {
        return testExcludes;
    }

    @Override
    protected List getClasspathElements()
    {
        return classpathElements;
    }

    @Override
    protected File getOutputDirectory()
    {
        return outputDirectory;
    }

    @Override
    protected File getAnalysisCacheFile()
    {
        return defaultTestAnalysisCacheFile( project );
    }

    @Override
    protected Map getAnalysisCacheMap()
    {
        HashMap map = new HashMap();
        for ( MavenProject reactorProject : reactorProjects )
        {
            File analysisCacheFile = defaultAnalysisCacheFile( reactorProject );
            if ( analysisCacheFile.isFile() )
            {
                File reactorProjectArtifactFile = reactorProject.getArtifact().getFile();
                if ( reactorProjectArtifactFile != null )
                {
                    map.put( reactorProjectArtifactFile.getAbsoluteFile(), analysisCacheFile.getAbsoluteFile() );
                }
            }
            
            if ( reactorProject != project )
            {
                File testAnalysisCacheFile = defaultTestAnalysisCacheFile( reactorProject );
                if ( testAnalysisCacheFile.isFile() )
                {
                    List reactorProjectattachedArtifacts = reactorProject.getAttachedArtifacts();
                    for ( Artifact artifact: reactorProjectattachedArtifacts )
                    {
                        if ( "tests".equals( artifact.getClassifier() ) )
                        {
                            map.put( artifact.getFile().getAbsoluteFile(), testAnalysisCacheFile.getAbsoluteFile() );
                            break;
                        }
                    }
                }
            }
        }
        return map;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy