<commit_before>package com.atlassian.jira.plugins.dvcs.spi.bitbucket.linker;

import com.atlassian.jira.plugins.dvcs.model.Repository;
import com.atlassian.jira.plugins.dvcs.service.RepositoryService;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.BitbucketClientBuilderFactory;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.model.BitbucketConstants;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.model.BitbucketRepositoryLink;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.model.BitbucketRepositoryLinkHandler;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.request.BitbucketRequestException;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.restpoints.RepositoryLinkRemoteRestpoint;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.sal.api.ApplicationProperties;
import com.atlassian.sal.api.UrlMode;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * <p>
 * Implementation of BitbucketLinker that configures repository links on bitbucket repositories
 * </p>
 * https://confluence.atlassian.com/display/BITBUCKET/Repository+links
 */
@Component ("bitbucketLinker")
public class BitbucketLinkerImpl implements BitbucketLinker
{
    private final Logger log = LoggerFactory.getLogger(BitbucketLinkerImpl.class);
    private final String baseUrl;
    private final BitbucketClientBuilderFactory bitbucketClientBuilderFactory;
    private final ProjectManager projectManager;

    RepositoryService repositoryService;

    @Autowired
    public BitbucketLinkerImpl(BitbucketClientBuilderFactory bitbucketClientBuilderFactory,
            @ComponentImport ApplicationProperties applicationProperties, @ComponentImport ProjectManager projectManager, RepositoryService repositoryService)
    {
        this.bitbucketClientBuilderFactory = checkNotNull(bitbucketClientBuilderFactory);
        this.projectManager = checkNotNull(projectManager);
        this.repositoryService = checkNotNull(repositoryService);
        this.baseUrl = normaliseBaseUrl(applicationProperties.getBaseUrl(UrlMode.CANONICAL));
    }

    /**
     * Remove forward slash at the end of url.
     *
     * @param url a url to be processed
     * @return the url supplied with no "/" at the end of it
     */
    private String normaliseBaseUrl(String url)
    {
        if (StringUtils.isNotBlank(url) && url.endsWith("/"))
        {<commit_msg>FUSE-2502 Initial workaround for circular dependency issue. Requires a separate PR to be commited for the full fix.<commit_after>package com.atlassian.jira.plugins.dvcs.spi.bitbucket.linker;

import com.atlassian.jira.plugins.dvcs.model.Repository;
import com.atlassian.jira.plugins.dvcs.service.RepositoryService;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.BitbucketClientBuilderFactory;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.model.BitbucketConstants;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.model.BitbucketRepositoryLink;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.model.BitbucketRepositoryLinkHandler;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.request.BitbucketRequestException;
import com.atlassian.jira.plugins.dvcs.spi.bitbucket.clientlibrary.restpoints.RepositoryLinkRemoteRestpoint;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.sal.api.ApplicationProperties;
import com.atlassian.sal.api.UrlMode;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * <p>
 * Implementation of BitbucketLinker that configures repository links on bitbucket repositories
 * </p>
 * https://confluence.atlassian.com/display/BITBUCKET/Repository+links
 */
@Component ("bitbucketLinker")
public class BitbucketLinkerImpl implements BitbucketLinker
{
    private final Logger log = LoggerFactory.getLogger(BitbucketLinkerImpl.class);
    private final String baseUrl;
    private final BitbucketClientBuilderFactory bitbucketClientBuilderFactory;
    private final ProjectManager projectManager;

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    public BitbucketLinkerImpl(BitbucketClientBuilderFactory bitbucketClientBuilderFactory,
            @ComponentImport ApplicationProperties applicationProperties, @ComponentImport ProjectManager projectManager)
    {
        this.bitbucketClientBuilderFactory = checkNotNull(bitbucketClientBuilderFactory);
        this.projectManager = checkNotNull(projectManager);
        this.baseUrl = normaliseBaseUrl(applicationProperties.getBaseUrl(UrlMode.CANONICAL));
    }

    @VisibleForTesting
    public BitbucketLinkerImpl(BitbucketClientBuilderFactory bitbucketClientBuilderFactory,
            @ComponentImport ApplicationProperties applicationProperties, @ComponentImport ProjectManager projectManager,
            final RepositoryService repositoryService)
    {
        this(bitbucketClientBuilderFactory, applicationProperties, projectManager);
        this.repositoryService = repositoryService;
    }

    /**
     * Remove forward slash at the end of url.
     *
     * @param url a url to be processed
     * @return the url supplied with no "/" at the end of it
     */
    private String normaliseBaseUrl(String url)
    {
        if (StringUtils.isNotBlank(url) && url.endsWith("/"))
        {
{'fraction_non_alphanumeric': 0.08634245777518929, 'fraction_numerical': 0.0011648223645894002, 'mean_word_length': 5.307621671258035, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '7493876', 'n_tokens_mistral': 1906, 'n_tokens_neox': 1894, 'n_words': 345}