<commit_before>
import scalac._;
import scala.tools.util.Reporter;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.Javac;
import org.apache.tools.ant.taskdefs.LogStreamHandler;
import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path;
import java.io.IOException;

package scala.tools.scala4ant {

  /** Scala compiler adaptor. adapted from (see below for additions to Scala license)
  *  jaco.framework.ant.AntCompilerAdaptor (c) <NAME>, and
  *  org.apache.tools.ant.taskdefs.DefaultCompilerAdapter
  *                          (c) the Apache Software Foundation
  *
  * @author  <NAME>
  * @version 1.6
  * $Id$
  */

  class AntAdaptor extends DefaultCompilerAdapter {

    final val FSEP = java.io.File.separator;
    final val PSEP = java.io.File.pathSeparator;

    final val PRODUCT = System.getProperty("scala.product", "scalac");
    final val VERSION = System.getProperty("scala.version", "unknown version");

    def runCompiler( args:Array[String] ) = {
      var ex:Throwable = _;
      //Console.println("runCompiler");
      var result = true;
      try {
        scala.tools.scalac.Main.main1( false, args );
      } catch {
        case e:Throwable =>
          ex = e;
      }
      if( null != ex ) {
        ex.printStackTrace();
	    throw new BuildException("internal error of scalac:"+ex.getClass());
      }

      if( scala.tools.scalac.Main.reporter.errors() > 0 )
        throw new BuildException("there were compile errors");

	  true
    }

    def compilerName() = "scalac";

    override def setJavac( attributes:Javac ) = {
      super.setJavac( attributes );
    }

    def execute() = {
      attributes.log("Using " + compilerName() + " as scala compiler",
                     Project.MSG_VERBOSE);
      runCompiler( setupScalacCommand().getArguments() );
    }

    def inferScalaPath( paths:Array[String] ) = {

      //Console.println("inferScalaPath");
      var x:List[String] = Nil;
      for (val p <- paths) {
        val z = p.lastIndexOf("lib"+FSEP+"scala.jar");
        if( z > -1 ) {                            // distribution
          val p1 = new StringBuffer( p.substring( 0, z ) );
          x = p1.append("src").toString() :: p :: x ;
          x = p::x;
        } else {
          val z2 = p.lastIndexOf("scala"+FSEP+"classes");
          if( z2 > -1 ) {                         // developer version
            val p1 = new StringBuffer(
              p.substring( 0, z2 + 6  /* length of "scala"+SEP */ )
            );
            x = p :: p1.append("sources").toString() :: x ;
          }
        }
      }
      //Console.println("DONE inferScalaPath");
      x
    };

    def setupScalacCommand() = {
      //Console.println("setupScalaCommand");
      val cmd = new Commandline();
      val cp = new Path( this.project );

      //- encoding?
      val stask = this.attributes.asInstanceOf[ScalacTask];
      if(null != stask.getEncoding()) {
        cmd.createArgument().setValue( "-encoding" );
        cmd.createArgument().setValue( stask.getEncoding() );
      }

      if( destDir != null ) {
        cmd.createArgument().setValue( "-d" );
        cmd.createArgument().setFile( destDir );
        cp.setLocation( destDir );
      }

      /* cp.addExisting( Path.systemClasspath );*/
      /* cp.addJavaRuntime(); */

      if( compileClasspath != null ) {
        cp.addExisting( compileClasspath );
      }

      cmd.createArgument().setValue("-classpath");
      cmd.createArgument().setPath( cp );

      var bcp = inferScalaPath(Path.systemClasspath.list());
      val bcps = (bcp./: (PSEP) { (x:String,y:String) => x+PSEP+y });

      /* scala.tools.util.ClassPath replaces "::" / ";;" at the beginning
         with something meaningful<commit_msg>Added 'debug' option to scalac task.<commit_after>
import scalac._;
import scala.tools.util.Reporter;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.Javac;
import org.apache.tools.ant.taskdefs.LogStreamHandler;
import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path;
import java.io.IOException;

package scala.tools.scala4ant {

  /** Scala compiler adaptor. adapted from (see below for additions to Scala license)
  *  jaco.framework.ant.AntCompilerAdaptor (c) <NAME>, and
  *  org.apache.tools.ant.taskdefs.DefaultCompilerAdapter
  *                          (c) the Apache Software Foundation
  *
  * @author  <NAME>
  * @version 1.6
  * $Id$
  */

  class AntAdaptor extends DefaultCompilerAdapter {

    final val FSEP = java.io.File.separator;
    final val PSEP = java.io.File.pathSeparator;

    final val PRODUCT = System.getProperty("scala.product", "scalac");
    final val VERSION = System.getProperty("scala.version", "unknown version");

    def runCompiler( args:Array[String] ) = {
      var ex:Throwable = _;
      //Console.println("runCompiler");
      var result = true;
      try {
        scala.tools.scalac.Main.main1( false, args );
      } catch {
        case e:Throwable =>
          ex = e;
      }
      if( null != ex ) {
        ex.printStackTrace();
	    throw new BuildException("internal error of scalac:"+ex.getClass());
      }

      if( scala.tools.scalac.Main.reporter.errors() > 0 )
        throw new BuildException("there were compile errors");

	  true
    }

    def compilerName() = "scalac";

    override def setJavac( attributes:Javac ) = {
      super.setJavac( attributes );
    }

    def execute() = {
      attributes.log("Using " + compilerName() + " as scala compiler",
                     Project.MSG_VERBOSE);
      runCompiler( setupScalacCommand().getArguments() );
    }

    def inferScalaPath( paths:Array[String] ) = {

      //Console.println("inferScalaPath");
      var x:List[String] = Nil;
      for (val p <- paths) {
        val z = p.lastIndexOf("lib"+FSEP+"scala.jar");
        if( z > -1 ) {                            // distribution
          val p1 = new StringBuffer( p.substring( 0, z ) );
          x = p1.append("src").toString() :: p :: x ;
          x = p::x;
        } else {
          val z2 = p.lastIndexOf("scala"+FSEP+"classes");
          if( z2 > -1 ) {                         // developer version
            val p1 = new StringBuffer(
              p.substring( 0, z2 + 6  /* length of "scala"+SEP */ )
            );
            x = p :: p1.append("sources").toString() :: x ;
          }
        }
      }
      //Console.println("DONE inferScalaPath");
      x
    };

    def setupScalacCommand() = {
      //Console.println("setupScalaCommand");
      val cmd = new Commandline();
      val cp = new Path( this.project );

      //- encoding?
      val stask = this.attributes.asInstanceOf[ScalacTask];
      if(null != stask.getEncoding()) {
        cmd.createArgument().setValue( "-encoding" );
        cmd.createArgument().setValue( stask.getEncoding() );
      }

      if( destDir != null ) {
        cmd.createArgument().setValue( "-d" );
        cmd.createArgument().setFile( destDir );
        cp.setLocation( destDir );
      }

      if ( debug )
        cmd.createArgument().setValue( "-g" );

      /* cp.addExisting( Path.systemClasspath );*/
      /* cp.addJavaRuntime(); */

      if( compileClasspath != null ) {
        cp.addExisting( compileClasspath );
      }

      cmd.createArgument().setValue("-classpath");
      cmd.createArgument().setPath( cp );

      var bcp = inferScalaPath(Path.systemClasspath.list());
      val bcps = (bcp./: (PSEP) { (x:String,y:String) => x+PSEP+y });

      /* scala.tools.util.ClassPath replaces "::" / ";;" at the beginning
         with something meaningful
{'fraction_non_alphanumeric': 0.1407973921765296, 'fraction_numerical': 0.004262788365095286, 'mean_word_length': 2.296280991735537, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '245472', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2430, 'n_words': 506}