<commit_before>/*
 * Copyright 2013 <NAME> (gs<EMAIL> 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.play2;

import java.io.IOException;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.DirectoryScanner;

import com.typesafe.zinc.Compiler;
import com.typesafe.zinc.Inputs;
import com.typesafe.zinc.Setup;

import sbt.inc.Analysis;

/**
 * Abstract base class for Play! Mojos.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public abstract class AbstractPlay2ScalaCompileMojo
    extends AbstractDependencyProcessingPlay2Mojo
{
    public static final String SCALA_GROUPID = "org.scala-lang";

    public static final String SCALA_LIBRARY_ARTIFACTID = "scala-library";

    public static final String SCALA_COMPILER_ARTIFACTID = "scala-compiler";

    public static final String SCALA_REFLECT_ARTIFACTID = "scala-reflect";

    public static final String SBT_GROUP_ID = "com.typesafe.sbt";

    public static final String COMPILER_INTEGRATION_ARTIFACT_ID = "incremental-compiler";

    public static final String COMPILER_INTERFACE_ARTIFACT_ID = "compiler-interface";

    public static final String COMPILER_INTERFACE_CLASSIFIER = "sources";

    public static final String XSBTI_ARTIFACT_ID = "sbt-interface";

    public static final String COMPILE_ORDER = "mixed";

    /**
     * Contains the full list of projects in the reactor.
     * 
     */
    @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
    protected List<MavenProject> reactorProjects;

    /**
     * List of artifacts this plugin depends on.
     * 
     */
    @Parameter( property = "plugin.artifacts", required = true, readonly = true )
    private List<Artifact> pluginArtifacts;

    @Override
    protected void internalExecute()
        throws MojoExecutionException, MojoFailureException, IOException
    {
        List<String> compileSourceRoots = getCompileSourceRoots();

        if ( compileSourceRoots.isEmpty() )// ?
        {
            getLog().info( "No sources to compile" );

            return;
        }

        List<File> sourceRootDirs = new ArrayList<File>( compileSourceRoots.size() );
        for ( String compileSourceRoot : compileSourceRoots )
        {
            sourceRootDirs.add( new File( compileSourceRoot ) );
        }

        List<File> sources = getSourceFiles( sourceRootDirs );
        if ( sources.isEmpty() )
        {
            getLog().info( "No sources to compile" );

            return;
        }

        try
        {
            Artifact scalaLibraryArtifact =
                getDependencyArtifact( /*pluginArtifacts*/project.getArtifacts(), SCALA_GROUPID, SCALA_LIBRARY_ARTIFACTID, "jar" );
            if ( scalaLibraryArtifact == null )
            {
                throw new MojoExecutionException( String.format( "Required %s:%s:jar dependency not found", SCALA_GROUPID,
                                                                 SCALA_LIBRARY_ARTIFACTID ) );
            }
            
            Artifact scalaCompilerArtifact =
                getDependencyArtifact( /* pluginArtifacts */project.getArtifacts(), SCALA_GROUPID,
                                       SCALA_COMPILER_ARTIFACTID, "jar" );
            if ( scalaCompilerArtifact == null )
            {
                throw new MojoExecutionException( String.format( "Required %s:%s:jar dependency not found",
                                                                 SCALA_GROUPID, SCALA_COMPILER_ARTIFACTID ) );
            }

            Artifact scalaReflectArtifact =
                getDependencyArtifact( /* pluginArtifacts */project.getArtifacts(), SCALA_GROUPID,
                                       SCALA_REFLECT_ARTIFACTID, "jar" );
            if ( scalaReflectArtifact == null )
            {
                throw new MojoExecutionException( String.format( "Required %s:%s:jar dependency not found",
                                                                 SCALA_GROUPID, SCALA_REFLECT_ARTIFACTID ) );
            }

            List<File> scalaExtra = new ArrayList<File>();
            scalaExtra.add( scalaReflectArtifact.getFile() );

            Artifact xsbtiArtifact = getDependencyArtifact( pluginArtifacts, SBT_GROUP_ID, XSBTI_ARTIFACT_ID, "jar" );
            Artifact compilerInterfaceSrc =
                getDependencyArtifact( pluginArtifacts, SBT_GROUP_ID, COMPILER_INTERFACE_ARTIFACT_ID, "jar",
                                       COMPILER_INTERFACE_CLASSIFIER );

            SbtLogger sbtLogger = new SbtLogger( getLog() );
            Setup setup =
                Setup.create( scalaCompilerArtifact.getFile(), scalaLibraryArtifact.getFile(), scalaExtra,
                              xsbtiArtifact.getFile(), compilerInterfaceSrc.getFile(), null );
            if ( getLog().isDebugEnabled() )
            {
                Setup.debug( setup, sbtLogger );
            }
            Compiler compiler = Compiler.create( setup, sbtLogger );

            List<String> classpathElements = getClasspathElements();
            classpathElements.remove( getOutputDirectory().getAbsolutePath() );
            List<String> scalacOptions = Collections.emptyList();
            List<String> javacOptions = Collections.emptyList();<commit_msg>Pass proper options to "scalac" and "javac" compilers. In Play! defaults are:<commit_after>/*
 * Copyright 2013 <NAME> (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.play2;

import java.io.IOException;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.DirectoryScanner;

import com.typesafe.zinc.Compiler;
import com.typesafe.zinc.Inputs;
import com.typesafe.zinc.Setup;

import sbt.inc.Analysis;

/**
 * Abstract base class for Play! Mojos.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public abstract class AbstractPlay2ScalaCompileMojo
    extends AbstractDependencyProcessingPlay2Mojo
{
    public static final String SCALA_GROUPID = "org.scala-lang";

    public static final String SCALA_LIBRARY_ARTIFACTID = "scala-library";

    public static final String SCALA_COMPILER_ARTIFACTID = "scala-compiler";

    public static final String SCALA_REFLECT_ARTIFACTID = "scala-reflect";

    public static final String SBT_GROUP_ID = "com.typesafe.sbt";

    public static final String COMPILER_INTEGRATION_ARTIFACT_ID = "incremental-compiler";

    public static final String COMPILER_INTERFACE_ARTIFACT_ID = "compiler-interface";

    public static final String COMPILER_INTERFACE_CLASSIFIER = "sources";

    public static final String XSBTI_ARTIFACT_ID = "sbt-interface";

    public static final String COMPILE_ORDER = "mixed";

    /**
     * The -encoding argument for Scala and Java compilers.
     * 
     */
    @Parameter( property = "project.build.sourceEncoding" )
    protected String sourceEncoding;

    /**
     * Contains the full list of projects in the reactor.
     * 
     */
    @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
    protected List<MavenProject> reactorProjects;

    /**
     * List of artifacts this plugin depends on.
     * 
     */
    @Parameter( property = "plugin.artifacts", required = true, readonly = true )
    private List<Artifact> pluginArtifacts;

    @Override
    protected void internalExecute()
        throws MojoExecutionException, MojoFailureException, IOException
    {
        List<String> compileSourceRoots = getCompileSourceRoots();

        if ( compileSourceRoots.isEmpty() )// ?
        {
            getLog().info( "No sources to compile" );

            return;
        }

        List<File> sourceRootDirs = new ArrayList<File>( compileSourceRoots.size() );
        for ( String compileSourceRoot : compileSourceRoots )
        {
            sourceRootDirs.add( new File( compileSourceRoot ) );
        }

        List<File> sources = getSourceFiles( sourceRootDirs );
        if ( sources.isEmpty() )
        {
            getLog().info( "No sources to compile" );

            return;
        }

        try
        {
            Artifact scalaLibraryArtifact =
                getDependencyArtifact( /*pluginArtifacts*/project.getArtifacts(), SCALA_GROUPID, SCALA_LIBRARY_ARTIFACTID, "jar" );
            if ( scalaLibraryArtifact == null )
            {
                throw new MojoExecutionException( String.format( "Required %s:%s:jar dependency not found", SCALA_GROUPID,
                                                                 SCALA_LIBRARY_ARTIFACTID ) );
            }
            
            Artifact scalaCompilerArtifact =
                getDependencyArtifact( /* pluginArtifacts */project.getArtifacts(), SCALA_GROUPID,
                                       SCALA_COMPILER_ARTIFACTID, "jar" );
            if ( scalaCompilerArtifact == null )
            {
                throw new MojoExecutionException( String.format( "Required %s:%s:jar dependency not found",
                                                                 SCALA_GROUPID, SCALA_COMPILER_ARTIFACTID ) );
            }

            Artifact scalaReflectArtifact =
                getDependencyArtifact( /* pluginArtifacts */project.getArtifacts(), SCALA_GROUPID,
                                       SCALA_REFLECT_ARTIFACTID, "jar" );
            if ( scalaReflectArtifact == null )
            {
                throw new MojoExecutionException( String.format( "Required %s:%s:jar dependency not found",
                                                                 SCALA_GROUPID, SCALA_REFLECT_ARTIFACTID ) );
            }

            List<File> scalaExtra = new ArrayList<File>();
            scalaExtra.add( scalaReflectArtifact.getFile() );

            Artifact xsbtiArtifact = getDependencyArtifact( pluginArtifacts, SBT_GROUP_ID, XSBTI_ARTIFACT_ID, "jar" );
            Artifact compilerInterfaceSrc =
                getDependencyArtifact( pluginArtifacts, SBT_GROUP_ID, COMPILER_INTERFACE_ARTIFACT_ID, "jar",
                                       COMPILER_INTERFACE_CLASSIFIER );

            SbtLogger sbtLogger = new SbtLogger( getLog() );
            Setup setup =
                Setup.create( scalaCompilerArtifact.getFile(), scalaLibraryArtifact.getFile(), scalaExtra,
                              xsbtiArtifact.getFile(), compilerInterfaceSrc.getFile(), null );
            if ( getLog().isDebugEnabled() )
            {
                Setup.debug( setup, sbtLogger );
            }
            Compiler compiler = Compiler.create( setup, sbtLogger );

            List<String> classpathElements = getClasspathElements();
            classpathElements.remove( getOutputDirectory().getAbsolutePath() );

            List<String> scalacOptions = new ArrayList<String>(4);
            scalacOptions.add( "-deprecation" );
            scalacOptions.add( "-unchecked" );
            scalacOptions.add( "-encoding" );
            scalacOptions.add( sourceEncoding );

            List<String> javacOptions = new ArrayList<String>(3);
            javacOptions.add( "-encoding" );
            javacOptions.add( sourceEncoding );
            javacOptions.add( "-g" );

{'fraction_non_alphanumeric': 0.08835372463992566, 'fraction_numerical': 0.0018584481957565433, 'mean_word_length': 2.4166666666666665, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3638203', 'n_tokens_mistral': 3582, 'n_tokens_neox': 3413, 'n_words': 838}