<commit_before>package org.apache.maven.reporting;

/*
 * Copyright 2005 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 org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.doxia.module.xhtml.XhtmlSink;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringInputStream;
import org.codehaus.plexus.util.StringUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * The basis for a Maven report.
 *
 * @author <a href="<EMAIL>"><NAME></a>
 * @version $Id: MavenReport.java 163376 2005-02-23 00:06:06Z brett $
 */
public abstract class AbstractMavenReport
    extends AbstractMojo
    implements MavenReport
{
    /** @todo share, use default excludes from plexus utils. */
    protected static final String[] DEFAULT_EXCLUDES = {// Miscellaneous typical temporary files
        "**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",

        // CVS
        "**/CVS", "**/CVS/**", "**/.cvsignore",

        // SCCS
        "**/SCCS", "**/SCCS/**",

        // Visual SourceSafe
        "**/vssver.scc",

        // Subversion
        "**/.svn", "**/.svn/**",

        // Mac
        "**/.DS_Store"};

    private MavenReportConfiguration config;

    private Sink sink;

    public MavenReportConfiguration getConfiguration()
    {
        return config;
    }

    public void setConfiguration( MavenReportConfiguration config )
    {
        this.config = config;
    }

    protected abstract SiteRenderer getSiteRenderer();

    protected abstract String getOutputDirectory();

    protected abstract MavenProject getProject();

    /**
     * @see org.apache.maven.plugin.Mojo#execute()
     */
    public void execute()
        throws MojoExecutionException
    {
        config = new MavenReportConfiguration();

        config.setProject( getProject() );

        config.setReportOutputDirectory( new File( getOutputDirectory() ) );

        try
        {
            String outputDirectory = getOutputDirectory();

            XhtmlSink sink = getSiteRenderer().createSink( new File( outputDirectory ), outputDirectory,
                                                      getOutputName() + ".html",
                                                      getSiteDescriptor(), "maven" );

            generate( sink, Locale.ENGLISH );
        }
        catch ( Exception e )
        {
            throw new MojoExecutionException( "An error is occurred in " + getName() + " report generation." );
        }
    }

    /**
     * @see org.apache.maven.reporting.MavenReport#generate(org.codehaus.doxia.sink.Sink, java.util.Locale)
     */
    public void generate( Sink sink, Locale locale )
        throws MavenReportException
    {
        if ( config == null )
        {
            throw new MavenReportException( "You must specify a report configuration." );
        }

        if ( sink == null )
        {
            throw new MavenReportException( "You must specify a sink configuration." );
        }
        else
        {
            this.sink = sink;
        }<commit_msg>Fix report generation in a mojo context.<commit_after>package org.apache.maven.reporting;

/*
 * Copyright 2005 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 org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.doxia.module.xhtml.XhtmlSink;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringInputStream;
import org.codehaus.plexus.util.StringUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * The basis for a Maven report.
 *
 * @author <a href="<EMAIL>"><NAME></a>
 * @version $Id: MavenReport.java 163376 2005-02-23 00:06:06Z brett $
 */
public abstract class AbstractMavenReport
    extends AbstractMojo
    implements MavenReport
{
    /** @todo share, use default excludes from plexus utils. */
    protected static final String[] DEFAULT_EXCLUDES = {// Miscellaneous typical temporary files
        "**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",

        // CVS
        "**/CVS", "**/CVS/**", "**/.cvsignore",

        // SCCS
        "**/SCCS", "**/SCCS/**",

        // Visual SourceSafe
        "**/vssver.scc",

        // Subversion
        "**/.svn", "**/.svn/**",

        // Mac
        "**/.DS_Store"};

    private MavenReportConfiguration config;

    private Sink sink;

    public MavenReportConfiguration getConfiguration()
    {
        return config;
    }

    public void setConfiguration( MavenReportConfiguration config )
    {
        this.config = config;
    }

    protected abstract SiteRenderer getSiteRenderer();

    protected abstract String getOutputDirectory();

    protected abstract MavenProject getProject();

    /**
     * @see org.apache.maven.plugin.Mojo#execute()
     */
    public void execute()
        throws MojoExecutionException
    {
        config = new MavenReportConfiguration();

        config.setProject( getProject() );

        config.setReportOutputDirectory( new File( getOutputDirectory() ) );

        try
        {
            String outputDirectory = getOutputDirectory();

            XhtmlSink sink = getSiteRenderer().createSink( new File( outputDirectory ), getOutputName() + ".html",
                                                      outputDirectory,
                                                      getSiteDescriptor(), "maven" );

            generate( sink, Locale.ENGLISH );

            getSiteRenderer().copyResources( outputDirectory, "maven" );
        }
        catch ( Exception e )
        {
            throw new MojoExecutionException( "An error is occurred in " + getName() + " report generation." );
        }
    }

    /**
     * @see org.apache.maven.reporting.MavenReport#generate(org.codehaus.doxia.sink.Sink, java.util.Locale)
     */
    public void generate( Sink sink, Locale locale )
        throws MavenReportException
    {
        if ( config == null )
        {
            throw new MavenReportException( "You must specify a report configuration." );
        }

        if ( sink == null )
        {
            throw new MavenReportException( "You must specify a sink configuration." );
        }
        else
        {
            this.sink = sink;
        }
{'fraction_non_alphanumeric': 0.11503634740466777, 'fraction_numerical': 0.007141946180334141, 'mean_word_length': 2.4274475524475525, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6445564', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2126, 'n_words': 587}