<commit_before>package hudson.plugins.tasks.parser;

import hudson.plugins.tasks.model.WorkspaceFile;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang.StringUtils;

/**
 * Classifies a Java workspace file that is part of a maven module.
 *
 * @author <NAME>
 */
public class MavenJavaClassifier implements FileClassifier {
    /** {@inheritDoc} */
    public void classify(final WorkspaceFile file, final InputStream stream) throws IOException {
        try {
            LineIterator iterator = IOUtils.lineIterator(stream, "UTF-8");
            while (iterator.hasNext()) {
                String line = iterator.nextLine();
                if (line.matches("^package .*;$")) {
                    file.setPackageName(StringUtils.substringBetween(line, " ", ";").trim());
                    break;
                }
            }
        }
        finally {
            IOUtils.closeQuietly(stream);
        }
        String module = StringUtils.substringBefore(file.getName(), "/src/");
        if (module.contains("/")) {
            module = StringUtils.substringAfterLast(module, "/");
        }
        if (StringUtils.isNotBlank(module)) {
            file.setModuleName(module);
        }<commit_msg>Added new constructors to support maven builds.<commit_after>package hudson.plugins.tasks.parser;

import hudson.plugins.tasks.model.WorkspaceFile;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang.StringUtils;

/**
 * Classifies a Java workspace file that is part of a maven module.
 *
 * @author <NAME>
 */
public class MavenJavaClassifier implements FileClassifier {
    /** Predefined module name. */
    private final String moduleName;

    /**
     * Creates a new instance of <code>MavenJavaClassifier</code>.
     */
    public MavenJavaClassifier() {
        moduleName = null;
    }

    /**
     * Creates a new instance of <code>MavenJavaClassifier</code>.
     *
     * @param moduleName predefined maven module name
     */
    public MavenJavaClassifier(final String moduleName) {
        this.moduleName = moduleName;
    }

    /** {@inheritDoc} */
    public void classify(final WorkspaceFile file, final InputStream stream) throws IOException {
        try {
            LineIterator iterator = IOUtils.lineIterator(stream, "UTF-8");
            while (iterator.hasNext()) {
                String line = iterator.nextLine();
                if (line.matches("^package .*;$")) {
                    file.setPackageName(StringUtils.substringBetween(line, " ", ";").trim());
                    break;
                }
            }
        }
        finally {
            IOUtils.closeQuietly(stream);
        }
        if (moduleName == null) {
            guessModuleName(file);
        }
        else {
            file.setModuleName(moduleName);
        }
    }

    /**
     * Guesses a maven module name based on the source folder.
     *
     * @param file the file to guess the module for
     */
    private void guessModuleName(final WorkspaceFile file) {
        String module = StringUtils.substringBefore(file.getName(), "/src/");
        if (module.contains("/")) {
            module = StringUtils.substringAfterLast(module, "/");
        }
        if (StringUtils.isNotBlank(module)) {
            file.setModuleName(module);
        }
{'fraction_non_alphanumeric': 0.1138557637705849, 'fraction_numerical': 0.0005678591709256105, 'mean_word_length': 2.2650602409638556, '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': '1792702', 'n_tokens_mistral': 956, 'n_tokens_neox': 947, 'n_words': 215}