<commit_before>/*
 * Copyright 2006-2008 Web Cohesion
 *
 * 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.webcohesion.enunciate;

import com.webcohesion.enunciate.module.EnunciateModule;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.filters.ExpandProperties;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

/**
 * Ant task for enunciate.
 *
 * @author <NAME>
 */
public class EnunciateTask extends MatchingTask {

  private boolean verbose = false;
  private boolean debug = false;
  private boolean compileDebugInfo = true;
  private String encoding;
  private File configFile;
  private File basedir;
  private Path classpath;
  private File buildDir;
  private String javacSourceVersion = null;
  private String javacTargetVersion = null;
  private final ArrayList<Export> exports = new ArrayList<Export>();
  private final ArrayList<JavacArgument> javacArguments = new ArrayList<JavacArgument>();

  /**
   * Executes the enunciate task.
   */
  @Override
  public void execute() throws BuildException {
    if (basedir == null) {
      throw new BuildException("A base directory must be specified.");
    }

    DirectoryScanner scanner = getDirectoryScanner(basedir);
    scanner.scan();
    String[] files = scanner.getIncludedFiles();
    for (int i = 0; i < files.length; i++) {
      File file = new File(basedir, files[i]);
      files[i] = file.getAbsolutePath();
    }

    try {
      Enunciate enunciate = new Enunciate();

      //set up the logger.
      enunciate.setLogger(new AntEnunciateLogger());

      //set the build dir.
      enunciate.setBuildDir(this.buildDir);

      //load the config.
      if (this.configFile != null && this.configFile.exists()) {
        getProject().log("[ENUNCIATE] Using enunciate configuration at " + this.configFile.getAbsolutePath());
        ExpandProperties reader = new ExpandProperties(new FileReader(this.configFile));
        reader.setProject(getProject());
        enunciate.loadConfiguration(reader);
        enunciate.getConfiguration().setBase(this.configFile);
      }

      if (classpath != null) {
        String[] filenames = this.classpath.list();
        List<File> cp = new ArrayList<File>(filenames.length);
        for (String filename : filenames) {
          File file = new File(filename);
          if (file.exists()) {<commit_msg>Fix for ant task not adding source files as reported at #100<commit_after>/*
 * Copyright 2006-2008 Web Cohesion
 *
 * 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.webcohesion.enunciate;

import com.webcohesion.enunciate.module.EnunciateModule;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.filters.ExpandProperties;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;

/**
 * Ant task for enunciate.
 *
 * @author <NAME>
 */
public class EnunciateTask extends MatchingTask {

  private boolean verbose = false;
  private boolean debug = false;
  private boolean compileDebugInfo = true;
  private String encoding;
  private File configFile;
  private File basedir;
  private Path classpath;
  private File buildDir;
  private String javacSourceVersion = null;
  private String javacTargetVersion = null;
  private final ArrayList<Export> exports = new ArrayList<Export>();
  private final ArrayList<JavacArgument> javacArguments = new ArrayList<JavacArgument>();

  /**
   * Executes the enunciate task.
   */
  @Override
  public void execute() throws BuildException {
    if (basedir == null) {
      throw new BuildException("A base directory must be specified.");
    }

    try {
      Enunciate enunciate = new Enunciate();

      //set up the logger.
      enunciate.setLogger(new AntEnunciateLogger());

      //set the build dir.
      enunciate.setBuildDir(this.buildDir);

      //add the source files.
      DirectoryScanner scanner = getDirectoryScanner(basedir);
      scanner.scan();
      Set<File> sourceFiles = new TreeSet<File>();
      for (String file : scanner.getIncludedFiles()) {
        sourceFiles.add(new File(basedir, file));
      }
      enunciate.setSourceFiles(sourceFiles);

      //load the config.
      if (this.configFile != null && this.configFile.exists()) {
        getProject().log("[ENUNCIATE] Using enunciate configuration at " + this.configFile.getAbsolutePath());
        ExpandProperties reader = new ExpandProperties(new FileReader(this.configFile));
        reader.setProject(getProject());
        enunciate.loadConfiguration(reader);
        enunciate.getConfiguration().setBase(this.configFile);
      }

      if (classpath != null) {
        String[] filenames = this.classpath.list();
        List<File> cp = new ArrayList<File>(filenames.length);
        for (String filename : filenames) {
          File file = new File(filename);
          if (file.exists()) {
{'fraction_non_alphanumeric': 0.10225702441271303, 'fraction_numerical': 0.004299094119453401, 'mean_word_length': 3.623136976579134, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2368920', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1812, 'n_words': 550}