<commit_before>package org.scm4j.releaser;

import static org.scm4j.releaser.Utils.reportDuration;

import java.util.LinkedHashMap;
import java.util.List;

import org.scm4j.commons.Version;
import org.scm4j.commons.progress.IProgress;
import org.scm4j.commons.progress.ProgressConsole;
import org.scm4j.releaser.branch.DevelopBranch;
import org.scm4j.releaser.branch.ReleaseBranch;
import org.scm4j.releaser.branch.ReleaseBranchFactory;
import org.scm4j.releaser.conf.Component;
import org.scm4j.releaser.conf.DelayedTagsFile;
import org.scm4j.releaser.exceptions.ENoReleaseBranchForPatch;
import org.scm4j.releaser.exceptions.ENoReleases;
import org.scm4j.releaser.exceptions.EReleaserException;
import org.scm4j.vcs.api.IVCS;
import org.scm4j.vcs.api.VCSCommit;
import org.scm4j.vcs.api.VCSTag;
import org.scm4j.vcs.api.WalkDirection;

public class ExtendedStatusBuilder {

	private static final int PARALLEL_CALCULATION_AWAIT_TIME = 500;
	private static final int COMMITS_RANGE_LIMIT = 10;
	
	public ExtendedStatus getAndCacheMinorStatus(Component comp) {
		CachedStatuses cache = new CachedStatuses();
		return getAndCacheMinorStatus(comp, cache);
	}

	public ExtendedStatus getAndCacheMinorStatus(Component comp, CachedStatuses cache) {
		return getAndCacheStatus(comp, cache, new ProgressConsole(), false);
	}
	
	public ExtendedStatus getAndCachePatchStatus(Component comp, CachedStatuses cache) {
		return getAndCacheStatus(comp, cache, new ProgressConsole(), true);
	}

	public ExtendedStatus getAndCacheStatus(Component comp, CachedStatuses cache, IProgress progress, boolean patch) {
		
		ExtendedStatus existing = cache.putIfAbsent(comp.getUrl(), ExtendedStatus.DUMMY);
		

	
		
		while (ExtendedStatus.DUMMY == existing) {
			try {
				Thread.sleep(PARALLEL_CALCULATION_AWAIT_TIME);
				existing = cache.get(comp.getUrl());
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
		}

		if (null != existing) {
			return existing;
		}

		ExtendedStatus res = patch ? 
			getPatchStatus(comp, cache, progress) :
			getMinorStatus(comp, cache, progress);
		
		cache.replace(comp.getUrl(), res);
		return res;
	}
	
	private ExtendedStatus getMinorStatus(Component comp, CachedStatuses cache, IProgress progress) {
		ReleaseBranch rb = reportDuration(() -> ReleaseBranchFactory.getCRB(comp), "CRB created", comp, progress);<commit_msg>fixed different components with the same urls processing: 	was: the one comp is used instead of all different components with the same url 	now: different comps with the same urls, subComps, nextVersions and statuses<commit_after>package org.scm4j.releaser;

import static org.scm4j.releaser.Utils.reportDuration;

import java.util.LinkedHashMap;
import java.util.List;

import org.scm4j.commons.Version;
import org.scm4j.commons.progress.IProgress;
import org.scm4j.commons.progress.ProgressConsole;
import org.scm4j.releaser.branch.DevelopBranch;
import org.scm4j.releaser.branch.ReleaseBranch;
import org.scm4j.releaser.branch.ReleaseBranchFactory;
import org.scm4j.releaser.conf.Component;
import org.scm4j.releaser.conf.DelayedTagsFile;
import org.scm4j.releaser.exceptions.ENoReleaseBranchForPatch;
import org.scm4j.releaser.exceptions.ENoReleases;
import org.scm4j.releaser.exceptions.EReleaserException;
import org.scm4j.vcs.api.IVCS;
import org.scm4j.vcs.api.VCSCommit;
import org.scm4j.vcs.api.VCSTag;
import org.scm4j.vcs.api.WalkDirection;

public class ExtendedStatusBuilder {

	private static final int PARALLEL_CALCULATION_AWAIT_TIME = 500;
	private static final int COMMITS_RANGE_LIMIT = 10;
	
	public ExtendedStatus getAndCacheMinorStatus(Component comp) {
		CachedStatuses cache = new CachedStatuses();
		return getAndCacheMinorStatus(comp, cache);
	}

	public ExtendedStatus getAndCacheMinorStatus(Component comp, CachedStatuses cache) {
		return getAndCacheStatus(comp, cache, new ProgressConsole(), false);
	}
	
	public ExtendedStatus getAndCachePatchStatus(Component comp, CachedStatuses cache) {
		return getAndCacheStatus(comp, cache, new ProgressConsole(), true);
	}

	public ExtendedStatus getAndCacheStatus(Component comp, CachedStatuses cache, IProgress progress, boolean patch) {
		
		ExtendedStatus existing = cache.putIfAbsent(comp.getUrl(), ExtendedStatus.DUMMY);
		
		while (ExtendedStatus.DUMMY == existing) {
			try {
				Thread.sleep(PARALLEL_CALCULATION_AWAIT_TIME);
				existing = cache.get(comp.getUrl());
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
		}

		if (null != existing) {
			return new ExtendedStatus(existing.getNextVersion(), existing.getStatus(), existing.getSubComponents(), comp);
		}

		ExtendedStatus res = patch ? 
			getPatchStatus(comp, cache, progress) :
			getMinorStatus(comp, cache, progress);
		
		cache.replace(comp.getUrl(), res);
		return res;
	}
	
	private ExtendedStatus getMinorStatus(Component comp, CachedStatuses cache, IProgress progress) {
		ReleaseBranch rb = reportDuration(() -> ReleaseBranchFactory.getCRB(comp), "CRB created", comp, progress);
{'fraction_non_alphanumeric': 0.09460266879107747, 'fraction_numerical': 0.00876319458275244, 'mean_word_length': 5.687083888149134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5010099', 'n_tokens_mistral': 1753, 'n_tokens_neox': 1605, 'n_words': 336}