<commit_before>package org.cleartk.plugin;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.uima.UIMAFramework;
import org.apache.uima.tools.jcasgen.IError;
import org.apache.uima.tools.jcasgen.Jg;
import org.apache.uima.util.Level;
import org.apache.uima.util.Logger;

/**
 * Applies JCasGen to create Java files from XML type system descriptions.
 * 
 * @goal generate
 * @phase generate-sources
 */
public class JCasGenMojo extends AbstractMojo {

  /**
   * The path to the XML type system description.
   * 
   * @parameter
   * @required
   * @readonly
   */
  private String typeSystem;

  /**
   * The directory where the generated sources will be written.
   * 
   * @parameter default-value="${project.build.directory}/generated-sources/jcasgen"
   * @required
   * @readonly
   */
  private File outputDirectory;

  /**
   * The Maven Project.
   * 
   * @parameter property="project"
   * @required
   * @readonly
   */
  private MavenProject project;

  public void execute() throws MojoExecutionException, MojoFailureException {
    String typeSystemPath = this.typeSystem;
    boolean isFile = false;
    try {
      URL url = new URL(this.typeSystem);
      url.toURI();
    } catch (MalformedURLException e) {
      isFile = true;
    } catch (URISyntaxException e) {
      isFile = true;
    }
    if (isFile) {
      typeSystemPath = new File(this.project.getBasedir(), this.typeSystem).getAbsolutePath();
    }
    JCasGenErrors error = new JCasGenErrors();
    Jg jCasGen = new Jg();
    jCasGen.error = error;
    String[] args = new String[] {
        "-jcasgeninput",
        typeSystemPath,
        "-jcasgenoutput",
        this.outputDirectory.getAbsolutePath() };
    try {
      jCasGen.main1(args);
    } catch (JCasGenException e) {
      throw new MojoExecutionException("JCasGen could not generate sources", e.getCause());
    }
    this.project.addCompileSourceRoot(this.outputDirectory.getPath());<commit_msg>Fixes JCasGen Maven plugin handling of classpath which was causing type system import by name to fail<commit_after>package org.cleartk.plugin;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.uima.UIMAFramework;
import org.apache.uima.tools.jcasgen.IError;
import org.apache.uima.tools.jcasgen.Jg;
import org.apache.uima.util.Level;
import org.apache.uima.util.Logger;

/**
 * Applies JCasGen to create Java files from XML type system descriptions.
 * 
 * Note that by default this runs at the process-resources phase because it requires the XML
 * descriptor files to already be at the appropriate places on the classpath, and the
 * generate-resources phase runs before resources are copied.
 * 
 * @goal generate
 * @phase process-resources
 */
public class JCasGenMojo extends AbstractMojo {

  /**
   * The path to the XML type system description.
   * 
   * @parameter
   * @required
   * @readonly
   */
  private String typeSystem;

  /**
   * The directory where the generated sources will be written.
   * 
   * @parameter default-value="${project.build.directory}/generated-sources/jcasgen"
   * @required
   * @readonly
   */
  private File outputDirectory;

  /**
   * The Maven Project.
   * 
   * @parameter property="project"
   * @required
   * @readonly
   */
  private MavenProject project;

  public void execute() throws MojoExecutionException, MojoFailureException {
    String typeSystemPath = this.typeSystem;
    boolean isFile = false;
    try {
      URL url = new URL(this.typeSystem);
      url.toURI();
    } catch (MalformedURLException e) {
      isFile = true;
    } catch (URISyntaxException e) {
      isFile = true;
    }
    if (isFile) {
      typeSystemPath = new File(this.project.getBasedir(), this.typeSystem).getAbsolutePath();
    }
    JCasGenErrors error = new JCasGenErrors();
    Jg jCasGen = new Jg();
    jCasGen.error = error;
    String[] args = new String[] {
        "-jcasgeninput",
        typeSystemPath,
        "-jcasgenoutput",
        this.outputDirectory.getAbsolutePath(),
        "=jcasgenclasspath",
        this.project.getBuild().getOutputDirectory() };
    try {
      jCasGen.main1(args);
    } catch (JCasGenException e) {
      throw new MojoExecutionException("JCasGen could not generate sources", e.getCause());
    }
    this.project.addCompileSourceRoot(this.outputDirectory.getPath());
{'fraction_non_alphanumeric': 0.1053494568559131, 'fraction_numerical': 0.0004099200655872105, 'mean_word_length': 3.3963963963963963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4045825', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1457, 'n_words': 361}