<commit_before>/**
 * Copyright 2022 <NAME>
 * <p>
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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.github.dkorotych.gradle.maven;

import org.apache.commons.lang3.StringUtils;
import org.gradle.api.GradleException;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

import static com.github.dkorotych.gradle.maven.MavenDescriptor.isMavenExecutionFile;
import static com.github.dkorotych.gradle.maven.MavenDescriptor.isMavenExecutionWrapperFile;

/**
 * A provider that allows you to find a Maven installation directory.
 *
 * @author <NAME> (dkorotych at gmail dot com).
 */
public class MavenHomeProvider {
    private Path mavenHome;

    /**
     * Try to find Maven installed in the system.
     * If {@code MAVEN_HOME}, {@code M2_HOME} or {@code maven.home} variables are set in the system and Maven
     * executable files are found in them, then this directory is considered
     *
     * @return true, if Maven founded by environment settings, false - otherwise
     */
    public boolean findMavenHome() {
        return mavenHome != null
                || tryToSetMavenHome("maven.home", true)
                || tryToSetMavenHome("MAVEN_HOME", false)
                || tryToSetMavenHome("M2_HOME", false);
    }

    /**
     * Returns the Maven directory for the process.
     *
     * @return The Maven directory
     */
    public Path getMavenHome() {
        return mavenHome;
    }

    /**
     * Sets the Maven directory for the process.
     * The supplied argument is evaluated as per {@link org.gradle.api.Project#file(Object)}.
     *
     * @param dir The Maven directory
     */
    @SuppressWarnings("PMD.CognitiveComplexity")
    public void setMavenHome(final File dir) {
        mavenHome = Optional.ofNullable(dir)
                .filter(File::exists)
                .map(file -> {
                    try {
                        return file.getCanonicalFile();
                    } catch (IOException e) {
                        throw new GradleException("Can't create canonical file name", e);
                    }
                })
                .map(file -> {
                    File returnValue = null;
                    if (file.isDirectory()) {<commit_msg>Try to run validation on the matrix of Maven and matrix of Gradle versions<commit_after>/**
 * Copyright 2022 <NAME>
 * <p>
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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.github.dkorotych.gradle.maven;

import org.apache.commons.lang3.StringUtils;
import org.gradle.api.GradleException;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

import static com.github.dkorotych.gradle.maven.MavenDescriptor.isMavenExecutionFile;
import static com.github.dkorotych.gradle.maven.MavenDescriptor.isMavenExecutionWrapperFile;

/**
 * A provider that allows you to find a Maven installation directory.
 *
 * @author <NAME> (dkorotych at gmail dot com).
 */
public class MavenHomeProvider {
    private Path mavenHome;

    /**
     * Try to find Maven installed in the system.
     * If {@code MAVEN_HOME}, {@code M2_HOME} or {@code maven.home} variables are set in the system and Maven
     * executable files are found in them, then this directory is considered
     *
     * @return true, if Maven founded by environment settings, false - otherwise
     */
    public boolean findMavenHome() {
        return mavenHome != null
                || tryToSetMavenHome("maven.home", true)
                || tryToSetMavenHome("MAVEN_HOME", false)
                || tryToSetMavenHome("M2_HOME", false);
    }

    /**
     * Returns the Maven directory for the process.
     *
     * @return The Maven directory
     */
    public Path getMavenHome() {
        return mavenHome;
    }

    /**
     * Sets the Maven directory for the process.
     * The supplied argument is evaluated as per {@link org.gradle.api.Project#file(Object)}.
     *
     * @param dir The Maven directory
     */
    @SuppressWarnings("PMD.CognitiveComplexity")
    public void setMavenHome(final File dir) {
        mavenHome = Optional.ofNullable(dir)
                .filter(File::exists)
                .map(file -> {
                    try {
                        System.err.println("canonical file = " + file.getCanonicalFile());
                        return file.getCanonicalFile();
                    } catch (IOException e) {
                        throw new GradleException("Can't create canonical file name", e);
                    }
                })
                .map(file -> {
                        System.err.println("absolute file = " + file.getAbsoluteFile());
                        return file.getAbsoluteFile();
                })
                .map(file -> {
                    File returnValue = null;
                    if (file.isDirectory()) {
{'fraction_non_alphanumeric': 0.09442824748947198, 'fraction_numerical': 0.0035633300939423387, 'mean_word_length': 2.41726618705036, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 18, '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': '2893961', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1644, 'n_words': 544}