<commit_before>/**
 * Formic installer framework.
 * Copyright (C) 2005 - 2006  <NAME>
 *
 * This library 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 library 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 library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.formic.ant.util;

import java.io.File;

import org.apache.commons.io.FilenameUtils;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;

import org.apache.tools.ant.taskdefs.Chmod;
import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.taskdefs.Mkdir;
import org.apache.tools.ant.taskdefs.Property;
import org.apache.tools.ant.taskdefs.Replace;

/**
 * Utility methods for executing some common ant tasks.
 *
 * @author <NAME> (<EMAIL>)
 * @version $Revision$
 */
public class AntUtils
{
  private static final String FORMIC_HOME_PROPERTY = "formic.home";
  private static final String FORMIC_HOME_ENV = "env.FORMIC_HOME";
  private static String formicHome;

  /**
   * Gets the location of the formic distribution based on the current
   * settings.
   *
   * @return The formic home directory.
   */
  public static String getFormicHome (Project project)
    throws BuildException
  {
    if(formicHome == null){
      // first try ant property.
      formicHome = project.getProperty(FORMIC_HOME_PROPERTY);

      // attempt to locate environment variable.
      if(formicHome == null){
        AntUtils.property(project, "env");
        formicHome = project.getProperty(FORMIC_HOME_ENV);
      }

      if(formicHome == null){
        throw new BuildException(
            "Unable to determine location of formic distribution:  " +
            "Property 'formic.home' not set. " +
            "Environment variable 'FORMIC_HOME' not found.");
      }
    }

    return formicHome;
  }
  /**
   * Executes a chmod for the specified file.
   *
   * @param project The current project.
   * @param file The file to chmod.
   * @param permissions The new file permissions.
   */
  public static void chmod (Project project, File file, String permissions)
  {
    Chmod chmod = new Chmod();
    chmod.setProject(project);
    chmod.setFile(file);
    chmod.setPerm(permissions);
    chmod.execute();
  }

  /**
   * Copies a file from src to dest.
   *
   * @param project The current project.
   * @param taskName The task name to use (name printed to console).
   * @param src The src file.
   * @param dest The dest file.
   */
  public static void copy (
      Project project, String taskName, File src, File dest)
  {
    Copy copy = new Copy();
    copy.setTaskName(taskName);
    copy.setProject(project);
    copy.setFile(src);
    copy.setTofile(dest);
    copy.execute();
  }

  /**
   * Make a new directory.
   *
   * @param project The current project.
   * @param taskName The task name to use (name printed to console).
   * @param dir The directory to create.
   */
  public static void mkdir (Project project, String taskName, File dir)
  {
    Mkdir mkdir = new Mkdir();
    mkdir.setProject(project);
    mkdir.setTaskName(taskName);
    mkdir.setDir(dir);
    mkdir.execute();
  }

  /**
   * Sets the environment property.
   *
   * @param project The current project.
   * @param env The environment property name to use.
   */
  public static void property (Project project, String env)
  {
    Property property = new Property();
    property.setProject(project);
    property.setEnvironment(env);
    property.execute();
  }

  /**
   * Sets a new property to the value of the supplied location.
   *
   * @param project The current project.
   * @param name The property name.
   * @param value The property value.
   */
  public static void property (Project project, String name, String value)
  {
    Property property = new Property();
    property.setProject(project);
    property.setName(name);
    property.setValue(value);
    property.execute();
  }

  /**
   * Sets a new property to the value of the supplied location.
   *
   * @param project The current project.
   * @param name The property name.<commit_msg>document typo<commit_after>/**
 * Formic installer framework.
 * Copyright (C) 2005 - 2006  <NAME>
 *
 * This library 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 library 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 library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.formic.ant.util;

import java.io.File;

import org.apache.commons.io.FilenameUtils;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;

import org.apache.tools.ant.taskdefs.Chmod;
import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.taskdefs.Mkdir;
import org.apache.tools.ant.taskdefs.Property;
import org.apache.tools.ant.taskdefs.Replace;

/**
 * Utility methods for executing some common ant tasks.
 *
 * @author <NAME> (<EMAIL>)
 * @version $Revision$
 */
public class AntUtils
{
  private static final String FORMIC_HOME_PROPERTY = "formic.home";
  private static final String FORMIC_HOME_ENV = "env.FORMIC_HOME";
  private static String formicHome;

  /**
   * Gets the location of the formic distribution based on the current
   * settings.
   *
   * @return The formic home directory.
   */
  public static String getFormicHome (Project project)
    throws BuildException
  {
    if(formicHome == null){
      // first try ant property.
      formicHome = project.getProperty(FORMIC_HOME_PROPERTY);

      // attempt to locate environment variable.
      if(formicHome == null){
        AntUtils.property(project, "env");
        formicHome = project.getProperty(FORMIC_HOME_ENV);
      }

      if(formicHome == null){
        throw new BuildException(
            "Unable to determine location of formic distribution:  " +
            "Property 'formic.home' not set. " +
            "Environment variable 'FORMIC_HOME' not found.");
      }
    }

    return formicHome;
  }
  /**
   * Executes a chmod for the specified file.
   *
   * @param project The current project.
   * @param file The file to chmod.
   * @param permissions The new file permissions.
   */
  public static void chmod (Project project, File file, String permissions)
  {
    Chmod chmod = new Chmod();
    chmod.setProject(project);
    chmod.setFile(file);
    chmod.setPerm(permissions);
    chmod.execute();
  }

  /**
   * Copies a file from src to dest.
   *
   * @param project The current project.
   * @param taskName The task name to use (name printed to console).
   * @param src The src file.
   * @param dest The dest file.
   */
  public static void copy (
      Project project, String taskName, File src, File dest)
  {
    Copy copy = new Copy();
    copy.setTaskName(taskName);
    copy.setProject(project);
    copy.setFile(src);
    copy.setTofile(dest);
    copy.execute();
  }

  /**
   * Make a new directory.
   *
   * @param project The current project.
   * @param taskName The task name to use (name printed to console).
   * @param dir The directory to create.
   */
  public static void mkdir (Project project, String taskName, File dir)
  {
    Mkdir mkdir = new Mkdir();
    mkdir.setProject(project);
    mkdir.setTaskName(taskName);
    mkdir.setDir(dir);
    mkdir.execute();
  }

  /**
   * Sets the environment property.
   *
   * @param project The current project.
   * @param env The environment property name to use.
   */
  public static void property (Project project, String env)
  {
    Property property = new Property();
    property.setProject(project);
    property.setEnvironment(env);
    property.execute();
  }

  /**
   * Sets a new property to the supplied value.
   *
   * @param project The current project.
   * @param name The property name.
   * @param value The property value.
   */
  public static void property (Project project, String name, String value)
  {
    Property property = new Property();
    property.setProject(project);
    property.setName(name);
    property.setValue(value);
    property.execute();
  }

  /**
   * Sets a new property to the value of the supplied location.
   *
   * @param project The current project.
   * @param name The property name.
{'fraction_non_alphanumeric': 0.09565968473331894, 'fraction_numerical': 0.005182465990066941, 'mean_word_length': 3.0256410256410255, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '922024', 'n_tokens_mistral': 2711, 'n_tokens_neox': 2642, 'n_words': 959}