<commit_before>import com.google.auto.value.AutoValue
import japicmp.model.JApiChangeStatus
import japicmp.model.JApiClass
import japicmp.model.JApiCompatibility
import japicmp.model.JApiCompatibilityChange
import japicmp.model.JApiConstructor
import japicmp.model.JApiMethod
import me.champeau.gradle.japicmp.JapicmpTask
import me.champeau.gradle.japicmp.report.Severity
import me.champeau.gradle.japicmp.report.Violation
import me.champeau.gradle.japicmp.report.stdrules.AbstractRecordingSeenMembers
import me.champeau.gradle.japicmp.report.stdrules.RecordSeenMembersSetup
import me.champeau.gradle.japicmp.report.stdrules.SourceCompatibleRule
import me.champeau.gradle.japicmp.report.stdrules.UnchangedMemberRule


plugins {
  base

  id("me.champeau.gradle.japicmp")
}

/**
 * The latest *released* version of the project. Evaluated lazily so the work is only done if necessary.
 */
val latestReleasedVersion: String by lazy {
  // hack to find the current released version of the project
  val temp: Configuration = configurations.create("tempConfig")
  // pick the api, since it's always there.
  dependencies.add(temp.name, "io.opentelemetry:opentelemetry-api:latest.release")
  val moduleVersion = configurations["tempConfig"].resolvedConfiguration.firstLevelModuleDependencies.elementAt(0).moduleVersion
  configurations.remove(temp)
  logger.debug("Discovered latest release version: " + moduleVersion)
  moduleVersion
}

class AllowDefaultMethodRule : AbstractRecordingSeenMembers() {
  override fun maybeAddViolation(member: JApiCompatibility): Violation? {
    for (change in member.compatibilityChanges) {
      if (isAbstractMethodOnAutoValue(member, change)) {
        continue
      }
      if (isLogRename(member)) {
        continue
      }
      if (!change.isSourceCompatible) {
        return Violation.error(member, "Not source compatible")
      }
      if (!change.isBinaryCompatible) {
        return Violation.notBinaryCompatible(member, Severity.error)
      }
    }
    return null
  }

  /**
   * Checks if the change is an abstract method on a class annotated with AutoValue.
   * AutoValues need to override default interface methods and declare them abstract again.
   * It causes METHOD_ABSTRACT_ADDED_TO_CLASS - source-incompatible change. It's
   * false-positive since AutoValue will generate implementation anyway.
   */
  fun isAbstractMethodOnAutoValue(member: JApiCompatibility, change: JApiCompatibilityChange): Boolean {
    return change == JApiCompatibilityChange.METHOD_ABSTRACT_ADDED_TO_CLASS &&
      member is JApiMethod &&
      member.getjApiClass().newClass.get().getAnnotation(AutoValue::class.java) != null
  }

  /**
   * Check if the change is related to log related renames.
   */
  // TODO(jack-berg): remove after 1.19.0.
  fun isLogRename(member: JApiCompatibility): Boolean {
    try {
      if (member is JApiMethod) {
        val longName = member.oldMethod.get().longName
        return longName.matches(".*OpenTelemetrySdk\\.getSdkLogEmitterProvider.*".toRegex()) ||
          longName.matches(".*OpenTelemetrySdkBuilder\\.setLogEmitterProvider.*".toRegex()) ||
          longName.matches(".*AutoConfigurationCustomizer\\.addLogExporterCustomizer.*".toRegex()) ||
          longName.matches(".*AutoConfigurationCustomizer\\.addLogEmitterProviderCustomizer.*".toRegex()) ||
          longName.matches(".*ConfigurableLogExporterProvider.*".toRegex()) ||
          longName.matches(".*SystemOutLogExporter.*".toRegex()) ||
          longName.matches(".*OtlpJsonLoggingLogExporter.*".toRegex())
      } else if (member is JApiClass) {
        val fqcn = member.fullyQualifiedName
        return fqcn.matches(".*SystemOutLogExporter".toRegex()) ||
          fqcn.matches(".*ConfigurableLogExporterProvider".toRegex()) ||
          fqcn.matches(".*OtlpJsonLoggingLogExporter".toRegex())
      } else if (member is JApiConstructor) {
        return member.oldConstructor.get().longName.matches(".*SystemOutLogExporter.*".toRegex())
      }
      return false
    } catch (e: IllegalStateException) {
      return false
    }
  }
}
<commit_msg>Remove japicmp exception for log SDK changes (#4977)<commit_after>import com.google.auto.value.AutoValue
import japicmp.model.JApiChangeStatus
import japicmp.model.JApiCompatibility
import japicmp.model.JApiCompatibilityChange
import japicmp.model.JApiMethod
import me.champeau.gradle.japicmp.JapicmpTask
import me.champeau.gradle.japicmp.report.Severity
import me.champeau.gradle.japicmp.report.Violation
import me.champeau.gradle.japicmp.report.stdrules.AbstractRecordingSeenMembers
import me.champeau.gradle.japicmp.report.stdrules.RecordSeenMembersSetup
import me.champeau.gradle.japicmp.report.stdrules.SourceCompatibleRule
import me.champeau.gradle.japicmp.report.stdrules.UnchangedMemberRule


plugins {
  base

  id("me.champeau.gradle.japicmp")
}

/**
 * The latest *released* version of the project. Evaluated lazily so the work is only done if necessary.
 */
val latestReleasedVersion: String by lazy {
  // hack to find the current released version of the project
  val temp: Configuration = configurations.create("tempConfig")
  // pick the api, since it's always there.
  dependencies.add(temp.name, "io.opentelemetry:opentelemetry-api:latest.release")
  val moduleVersion = configurations["tempConfig"].resolvedConfiguration.firstLevelModuleDependencies.elementAt(0).moduleVersion
  configurations.remove(temp)
  logger.debug("Discovered latest release version: " + moduleVersion)
  moduleVersion
}

class AllowDefaultMethodRule : AbstractRecordingSeenMembers() {
  override fun maybeAddViolation(member: JApiCompatibility): Violation? {
    for (change in member.compatibilityChanges) {
      if (isAbstractMethodOnAutoValue(member, change)) {
        continue
      }
      if (!change.isSourceCompatible) {
        return Violation.error(member, "Not source compatible")
      }
      if (!change.isBinaryCompatible) {
        return Violation.notBinaryCompatible(member, Severity.error)
      }
    }
    return null
  }

  /**
   * Checks if the change is an abstract method on a class annotated with AutoValue.
   * AutoValues need to override default interface methods and declare them abstract again.
   * It causes METHOD_ABSTRACT_ADDED_TO_CLASS - source-incompatible change. It's
   * false-positive since AutoValue will generate implementation anyway.
   */
  fun isAbstractMethodOnAutoValue(member: JApiCompatibility, change: JApiCompatibilityChange): Boolean {
    return change == JApiCompatibilityChange.METHOD_ABSTRACT_ADDED_TO_CLASS &&
      member is JApiMethod &&
      member.getjApiClass().newClass.get().getAnnotation(AutoValue::class.java) != null
  }
}

{'fraction_non_alphanumeric': 0.09756461975197968, 'fraction_numerical': 0.0014940983116689078, 'mean_word_length': 4.31691818903892, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4331106', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1977, 'n_words': 404}