<commit_before>package com.github.benmanes.gradle.versions.updates.resolutionstrategy

import com.github.benmanes.gradle.versions.updates.Coordinate
import groovy.transform.TupleConstructor
import org.gradle.api.Action
import org.gradle.api.artifacts.ComponentSelection
import org.gradle.api.artifacts.ComponentSelectionRules
import org.gradle.internal.rules.RuleAction
import org.gradle.internal.rules.RuleSourceBackedRuleAction
import org.gradle.model.internal.type.ModelType

@TupleConstructor(includeFields=true)
class ComponentSelectionRulesWithCurrent {

  private final ComponentSelectionRules delegate
  private final Map<Coordinate.Key, Coordinate> currentCoordinates

  ComponentSelectionRulesWithCurrent all(
      Action<? super ComponentSelectionWithCurrent> selectionAction) {
    delegate.all(new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        selectionAction.execute(wrapComponentSelection(inner))
      }
    })
    return this
  }

  ComponentSelectionRulesWithCurrent all(Closure<?> closure) {
    delegate.all(new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        ComponentSelectionWithCurrent wrapped = wrapComponentSelection(inner)
        closure.delegate = wrapped
        closure(wrapped)
      }
    })
    return this
  }

  ComponentSelectionRulesWithCurrent all(Object ruleSource) {
    RuleAction<ComponentSelectionWithCurrent> ruleAction = RuleSourceBackedRuleAction.create(
      ModelType.of(ComponentSelectionWithCurrent), ruleSource)
    delegate.all(new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        ruleAction.execute(wrapComponentSelection(inner), [])
      }
    })
    return this
  }

  ComponentSelectionRulesWithCurrent withModule(Object id,
      Action<? super ComponentSelectionWithCurrent> selectionAction) {
    delegate.withModule(id, new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        selectionAction.execute(wrapComponentSelection(inner))
      }
    })
    return this
  }

  ComponentSelectionRulesWithCurrent withModule(Object id, Closure<?> closure) {
    delegate.withModule(id, new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        ComponentSelectionWithCurrent wrapped = wrapComponentSelection(inner)
        closure.delegate = wrapped
        closure(wrapped)
      }
    })
    return this
  }

  ComponentSelectionRulesWithCurrent withModule(Object id, Object ruleSource) {
    RuleAction<ComponentSelectionWithCurrent> ruleAction = RuleSourceBackedRuleAction.create(
      ModelType.of(ComponentSelectionWithCurrent), ruleSource)
    delegate.withModule(id, new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        ruleAction.execute(wrapComponentSelection(inner), [])
      }
    })
    return this
  }

  private ComponentSelectionWithCurrent wrapComponentSelection(ComponentSelection inner) {
    Coordinate candidateCoordinate = Coordinate.from(inner.candidate)
    Coordinate current = currentCoordinates.get(candidateCoordinate.key)
    ComponentSelectionWithCurrent wrapped = new ComponentSelectionWithCurrent(current.version,
      inner)
    return wrapped
  }
}<commit_msg>Check if original dependency exists in component selection<commit_after>package com.github.benmanes.gradle.versions.updates.resolutionstrategy

import com.github.benmanes.gradle.versions.updates.Coordinate
import groovy.transform.TupleConstructor
import org.gradle.api.Action
import org.gradle.api.artifacts.ComponentSelection
import org.gradle.api.artifacts.ComponentSelectionRules
import org.gradle.internal.rules.RuleAction
import org.gradle.internal.rules.RuleSourceBackedRuleAction
import org.gradle.model.internal.type.ModelType

@TupleConstructor(includeFields=true)
class ComponentSelectionRulesWithCurrent {

  private final ComponentSelectionRules delegate
  private final Map<Coordinate.Key, Coordinate> currentCoordinates

  ComponentSelectionRulesWithCurrent all(
      Action<? super ComponentSelectionWithCurrent> selectionAction) {
    delegate.all(new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        ComponentSelectionWithCurrent wrapped = wrapComponentSelection(inner)
        if (wrapped != null) {
          selectionAction.execute(wrapped)
        }
      }
    })
    return this
  }

  ComponentSelectionRulesWithCurrent all(Closure<?> closure) {
    delegate.all(new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        ComponentSelectionWithCurrent wrapped = wrapComponentSelection(inner)
        if (wrapped != null) {
          closure.delegate = wrapped
          closure(wrapped)
        }
      }
    })
    return this
  }

  ComponentSelectionRulesWithCurrent all(Object ruleSource) {
    RuleAction<ComponentSelectionWithCurrent> ruleAction = RuleSourceBackedRuleAction.create(
      ModelType.of(ComponentSelectionWithCurrent), ruleSource)
    delegate.all(new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        ComponentSelectionWithCurrent wrapped = wrapComponentSelection(inner)
        if (wrapped != null) {
          ruleAction.execute(wrapped, [])
        }
      }
    })
    return this
  }

  ComponentSelectionRulesWithCurrent withModule(Object id,
      Action<? super ComponentSelectionWithCurrent> selectionAction) {
    delegate.withModule(id, new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        ComponentSelectionWithCurrent wrapped = wrapComponentSelection(inner)
        if (wrapped != null) {
          selectionAction.execute(wrapped)
        }
      }
    })
    return this
  }

  ComponentSelectionRulesWithCurrent withModule(Object id, Closure<?> closure) {
    delegate.withModule(id, new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        ComponentSelectionWithCurrent wrapped = wrapComponentSelection(inner)
        if (wrapped != null) {
          closure.delegate = wrapped
          closure(wrapped)
        }
      }
    })
    return this
  }

  ComponentSelectionRulesWithCurrent withModule(Object id, Object ruleSource) {
    RuleAction<ComponentSelectionWithCurrent> ruleAction = RuleSourceBackedRuleAction.create(
      ModelType.of(ComponentSelectionWithCurrent), ruleSource)
    delegate.withModule(id, new Action<ComponentSelection>() {
      void execute(ComponentSelection inner) {
        ComponentSelectionWithCurrent wrapped = wrapComponentSelection(inner)
        if (wrapped != null) {
          ruleAction.execute(wrapped, [])
        }
      }
    })
    return this
  }

  private ComponentSelectionWithCurrent wrapComponentSelection(ComponentSelection inner) {
    Coordinate candidateCoordinate = Coordinate.from(inner.candidate)
    Coordinate current = currentCoordinates.get(candidateCoordinate.key)
    if (current == null) return null

    return new ComponentSelectionWithCurrent(current?.version, inner)
  }
}
{'fraction_non_alphanumeric': 0.0771850170261067, 'fraction_numerical': 0.0, 'mean_word_length': 4.202214022140222, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '24104', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1709, 'n_words': 333}