<commit_before>package io.jenkins.plugins.analysis.core.steps;

import java.util.Collection;
import java.util.Collections;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.StaplerProxy;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import io.jenkins.plugins.analysis.core.quality.HealthDescriptor;
import io.jenkins.plugins.analysis.core.quality.HealthReportBuilder;
import jenkins.tasks.SimpleBuildStep.LastBuildAction;

import hudson.model.Action;
import hudson.model.HealthReport;
import hudson.model.HealthReportingAction;
import hudson.model.Run;
import hudson.plugins.analysis.Messages;
import hudson.plugins.analysis.util.ToolTipProvider;

/**
 * Controls the live cycle of the results in a job. This action persists the results
 * of a build and displays them on the build page. The actual visualization of
 * the results is defined in the matching <code>summary.jelly</code> file.
 * <p>
 * Moreover, this class renders the results trend.
 * </p>
 *
 * @author <NAME>
 */
//CHECKSTYLE:COUPLING-OFF
@ExportedBean
public class PipelineResultAction implements StaplerProxy, HealthReportingAction, ToolTipProvider, LastBuildAction, Action {
    private final Run<?, ?> run;
    private AnalysisResult result;
    private String id;
    private HealthDescriptor healthDescriptor;

    /**
     * Creates a new instance of <code>AbstractResultAction</code>.
     *  @param run
     *            the associated build of this action
     * @param result
     * @param healthDescriptor
     */
    public PipelineResultAction(final Run<?, ?> run, final AnalysisResult result, final String id,
                                final HealthDescriptor healthDescriptor) {
        this.run = run;
        this.result = result;
        this.id = id;
        this.healthDescriptor = healthDescriptor;
    }

    public Run<?, ?> getRun() {
        return run;
    }

    public String getId() {
        return id;
    }

    @Override @Exported
    public String getDisplayName() {
        return getIssueParser().getLinkName();
    }

    @Override
    public String getUrlName() {
        return getIssueParser().getResultUrl();
    }

    @Override @Exported
    public final HealthReport getBuildHealth() {
        return new HealthReportBuilder(healthDescriptor).computeHealth(getResult());
    }

    @Override
    public Collection<? extends Action> getProjectActions() {
        return Collections.singleton(new ProjectAction(run.getParent(), id));
    }

    @Override
    public final Object getTarget() {
        return getResult();
    }

    @Exported
    public AnalysisResult getResult() {
        return result;
    }

    @Override
    public String getIconFileName() {
        if (getResult().getNumberOfAnnotations() > 0) {
            return getSmallImage();
        }
        return null;
    }

    /**
     * Returns whether a large image is defined.
     *
     * @return <code>true</code> if a large image is defined, <code>false</code>
     *         otherwise. If no large image is defined, then the attribute
     *         {@code icon} must to be provided in jelly tag {@code summary}.
     * @since 1.41
     */
    public boolean hasLargeImage() {
        return StringUtils.isNotBlank(getLargeImageName());
    }

    /**
     * Returns the URL of the 48x48 image used in the build summary.
     *
     * @return the URL of the image
     * @since 1.41
     */
    public String getLargeImageName() {
        return getIssueParser().getLargeIconUrl();
    }

    /**
     * Returns the URL of the 24x24 image used in the build link.
     *
     * @return the URL of the image
     * @since 1.41
     */
    public String getSmallImageName() {
        return getSmallImage();
    }

    /**
     * Returns the URL of the 24x24 image used in the build link.
     *
     * @return the URL of the image
     */
    protected String getSmallImage() {
        return getIssueParser().getSmallIconUrl();
    }

    // FIXME: should be handled by IssuesParser
    @Override
    public String getTooltip(final int numberOfItems) {
        if (numberOfItems == 1) {
            return getSingleItemTooltip();
        }
        else {
            return getMultipleItemsTooltip(numberOfItems);
        }
    }

    /**
     * Returns the tooltip for several items.
     *
     * @param numberOfItems
     *            the number of items to display the tooltip for
     * @return the tooltip for several items
     */
    protected String getMultipleItemsTooltip(final int numberOfItems) {
        return Messages.ResultAction_MultipleWarnings(numberOfItems);
    }

    /**
     * Returns the tooltip for exactly one item.
     *
     * @return the tooltip for exactly one item
     */
    protected String getSingleItemTooltip() {
        return Messages.ResultAction_OneWarning();
    }

    @Exported
    public boolean isSuccessful() {
        return getResult().isSuccessful();
    }

    public IssueParser getIssueParser() {<commit_msg>[JENKINS-45846] Make run transient and implement RunAction2.<commit_after>package io.jenkins.plugins.analysis.core.steps;

import java.util.Collection;
import java.util.Collections;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.StaplerProxy;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import io.jenkins.plugins.analysis.core.quality.HealthDescriptor;
import io.jenkins.plugins.analysis.core.quality.HealthReportBuilder;
import jenkins.model.RunAction2;
import jenkins.tasks.SimpleBuildStep.LastBuildAction;

import hudson.model.Action;
import hudson.model.HealthReport;
import hudson.model.HealthReportingAction;
import hudson.model.Run;
import hudson.plugins.analysis.Messages;
import hudson.plugins.analysis.util.ToolTipProvider;

/**
 * Controls the live cycle of the results in a job. This action persists the results of a build and displays them on the
 * build page. The actual visualization of the results is defined in the matching {@code summary.jelly} file. <p>
 * Moreover, this class renders the results trend. </p>
 *
 * @author <NAME>
 */
//CHECKSTYLE:COUPLING-OFF
@ExportedBean
public class PipelineResultAction implements StaplerProxy, HealthReportingAction, ToolTipProvider, LastBuildAction, RunAction2 {
    private transient Run<?, ?> run;

    private final AnalysisResult result;
    private final String id;
    private final HealthDescriptor healthDescriptor;

    /**
     * Creates a new instance of <code>AbstractResultAction</code>.
     *
     * @param run
     *         the associated build of this action
     * @param id
     *         the ID of the parser
     * @param result
     *         the result of the static analysis run
     * @param healthDescriptor
     *         defines the health for the current result
     */
    public PipelineResultAction(final Run<?, ?> run, final String id, final AnalysisResult result,
            final HealthDescriptor healthDescriptor) {
        this.run = run;
        this.result = result;
        this.id = id;
        this.healthDescriptor = healthDescriptor;
    }

    public Run<?, ?> getRun() {
        return run;
    }

    @Override
    public void onAttached(final Run<?, ?> r) {
        run = r;
        result.setRun(r);
    }

    @Override
    public void onLoad(final Run<?, ?> r) {
        onAttached(r);
    }

    public String getId() {
        return id;
    }

    @Override
    @Exported
    public String getDisplayName() {
        return getIssueParser().getLinkName();
    }

    @Override
    public String getUrlName() {
        return getIssueParser().getResultUrl();
    }

    @Override
    @Exported
    public HealthReport getBuildHealth() {
        return new HealthReportBuilder(healthDescriptor).computeHealth(getResult());
    }

    @Override
    public Collection<? extends Action> getProjectActions() {
        return Collections.singleton(new ProjectAction(run.getParent(), id));
    }

    @Override
    public final Object getTarget() {
        return getResult();
    }

    @Exported
    public AnalysisResult getResult() {
        return result;
    }

    @Override
    public String getIconFileName() {
        if (getResult().getNumberOfAnnotations() > 0) {
            return getSmallImage();
        }
        return null;
    }

    /**
     * Returns whether a large image is defined.
     *
     * @return <code>true</code> if a large image is defined, <code>false</code> otherwise. If no large image is
     *         defined, then the attribute {@code icon} must to be provided in jelly tag {@code summary}.
     * @since 1.41
     */
    public boolean hasLargeImage() {
        return StringUtils.isNotBlank(getLargeImageName());
    }

    /**
     * Returns the URL of the 48x48 image used in the build summary.
     *
     * @return the URL of the image
     * @since 1.41
     */
    public String getLargeImageName() {
        return getIssueParser().getLargeIconUrl();
    }

    /**
     * Returns the URL of the 24x24 image used in the build link.
     *
     * @return the URL of the image
     * @since 1.41
     */
    public String getSmallImageName() {
        return getSmallImage();
    }

    /**
     * Returns the URL of the 24x24 image used in the build link.
     *
     * @return the URL of the image
     */
    protected String getSmallImage() {
        return getIssueParser().getSmallIconUrl();
    }

    // FIXME: should be handled by IssuesParser
    @Override
    public String getTooltip(final int numberOfItems) {
        if (numberOfItems == 1) {
            return getSingleItemTooltip();
        }
        else {
            return getMultipleItemsTooltip(numberOfItems);
        }
    }

    /**
     * Returns the tooltip for several items.
     *
     * @param numberOfItems
     *         the number of items to display the tooltip for
     *
     * @return the tooltip for several items
     */
    protected String getMultipleItemsTooltip(final int numberOfItems) {
        return Messages.ResultAction_MultipleWarnings(numberOfItems);
    }

    /**
     * Returns the tooltip for exactly one item.
     *
     * @return the tooltip for exactly one item
     */
    protected String getSingleItemTooltip() {
        return Messages.ResultAction_OneWarning();
    }

    @Exported
    public boolean isSuccessful() {
        return getResult().isSuccessful();
    }

    private IssueParser getIssueParser() {
{'fraction_non_alphanumeric': 0.08992085439115095, 'fraction_numerical': 0.005149232382950319, 'mean_word_length': 2.6016483516483517, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, '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': '6746688', 'n_tokens_mistral': 2950, 'n_tokens_neox': 2837, 'n_words': 858}