<commit_before>package org.apache.maven.plugin.it;

/*
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * 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.
 */

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.dag.CycleDetectedException;

/**
 * @goal fork
 *
 * @execute phase="package"
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ForkMojo
    extends AbstractMojo
{
    /**
     * @parameter expression="${component.org.apache.maven.lifecycle.LifecycleExecutor}"
     */
    private LifecycleExecutor lifecycleExecutor;

    /**
     * @parameter expression="${session}"
     */
    private MavenSession session;

    /**
     * @parameter expression="${settings}"
     */
    private Settings settings;

    /**
     * @parameter expression="${project}"
     */
    private MavenProject project;

    /**
     * @parameter expression="${project.basedir}/src/it/"
     */
    private File integrationTestsDirectory;


    public void execute()
        throws MojoExecutionException
    {
        try
        {
            buildProjects();
        }
        catch ( CycleDetectedException e )
        {
            throw new MojoExecutionException( "Error building projects", e );
        }
        catch ( LifecycleExecutionException e )
        {
            throw new MojoExecutionException( "Error building projects", e );
        }
    }

    private void buildProjects()
        throws CycleDetectedException, LifecycleExecutionException, MojoExecutionException
    {
        List projects = collectProjects();

        ReactorManager rm = new ReactorManager( projects );

        rm.setFailureBehavior( ReactorManager.FAIL_AT_END );

        List goals = Collections.singletonList( "package" );

        MavenSession forkedSession = new MavenSession(
            session.getContainer(), session.getSettings(),
            session.getLocalRepository(),
            session.getEventDispatcher(),
            rm, goals, integrationTestsDirectory.toString()
        );

        MavenExecutionResponse response = lifecycleExecutor.execute( forkedSession,
            rm, forkedSession.getEventDispatcher()
        );

        if ( response.isExecutionFailure() )
        {
            throw new MojoExecutionException(
                "Integration test failed" );<commit_msg>Add the project itself to the 'reactorprojects' of the forked build, so dependencies can at least resolve the target/artifact.jar. Blacklist the project to skip building it again.<commit_after>package org.apache.maven.plugin.it;

/*
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * 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.
 */

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.dag.CycleDetectedException;

/**
 * @goal fork
 *
 * @execute phase="package"
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ForkMojo
    extends AbstractMojo
{
    /**
     * @parameter expression="${component.org.apache.maven.lifecycle.LifecycleExecutor}"
     */
    private LifecycleExecutor lifecycleExecutor;

    /**
     * @parameter expression="${session}"
     */
    private MavenSession session;

    /**
     * @parameter expression="${settings}"
     */
    private Settings settings;

    /**
     * @parameter expression="${project}"
     */
    private MavenProject project;

    /**
     * @parameter expression="${project.basedir}/src/it/"
     */
    private File integrationTestsDirectory;


    public void execute()
        throws MojoExecutionException
    {
        try
        {
            buildProjects();
        }
        catch ( CycleDetectedException e )
        {
            throw new MojoExecutionException( "Error building projects", e );
        }
        catch ( LifecycleExecutionException e )
        {
            throw new MojoExecutionException( "Error building projects", e );
        }
    }

    private void buildProjects()
        throws CycleDetectedException, LifecycleExecutionException, MojoExecutionException
    {
        List projects = collectProjects();

        projects.add( project );

        ReactorManager rm = new ReactorManager( projects );

        rm.setFailureBehavior( ReactorManager.FAIL_AT_END );

        rm.blackList( project );

        List goals = Collections.singletonList( "package" );

        MavenSession forkedSession = new MavenSession(
            session.getContainer(), session.getSettings(),
            session.getLocalRepository(),
            session.getEventDispatcher(),
            rm, goals, integrationTestsDirectory.toString()
        );

        MavenExecutionResponse response = lifecycleExecutor.execute( forkedSession,
            rm, forkedSession.getEventDispatcher()
        );

        if ( response.isExecutionFailure() )
        {
            throw new MojoExecutionException(
                "Integration test failed" );
{'fraction_non_alphanumeric': 0.09464856230031948, 'fraction_numerical': 0.003194888178913738, 'mean_word_length': 3.1808569838619922, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1796110', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1891, 'n_words': 498}