0001 /*
0002 * Licensed to the Apache Software Foundation (ASF) under one or more
0003 * contributor license agreements. See the NOTICE file distributed with
0004 * this work for additional information regarding copyright ownership.
0005 * The ASF licenses this file to You under the Apache License, Version 2.0
0006 * (the "License"); you may not use this file except in compliance with
0007 * the License. You may obtain a copy of the License at
0008 *
0009 * http://www.apache.org/licenses/LICENSE-2.0
0010 *
0011 * Unless required by applicable law or agreed to in writing, software
0012 * distributed under the License is distributed on an "AS IS" BASIS,
0013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014 * See the License for the specific language governing permissions and
0015 * limitations under the License.
0016 */
0017
0018 import sbt._
0019 import sbt.Keys.version
0020
0021 import com.typesafe.tools.mima.core._
0022 import com.typesafe.tools.mima.core.MissingClassProblem
0023 import com.typesafe.tools.mima.core.MissingTypesProblem
0024 import com.typesafe.tools.mima.core.ProblemFilters._
0025 import com.typesafe.tools.mima.plugin.MimaKeys.{mimaBinaryIssueFilters, mimaPreviousArtifacts}
0026 import com.typesafe.tools.mima.plugin.MimaPlugin.mimaDefaultSettings
0027
0028
0029 object MimaBuild {
0030
0031 def excludeMember(fullName: String) = Seq(
0032 ProblemFilters.exclude[MissingMethodProblem](fullName),
0033 // Sometimes excluded methods have default arguments and
0034 // they are translated into public methods/fields($default$) in generated
0035 // bytecode. It is not possible to exhaustively list everything.
0036 // But this should be okay.
0037 ProblemFilters.exclude[MissingMethodProblem](fullName+"$default$2"),
0038 ProblemFilters.exclude[MissingMethodProblem](fullName+"$default$1"),
0039 ProblemFilters.exclude[MissingFieldProblem](fullName),
0040 ProblemFilters.exclude[IncompatibleResultTypeProblem](fullName),
0041 ProblemFilters.exclude[IncompatibleMethTypeProblem](fullName),
0042 ProblemFilters.exclude[IncompatibleFieldTypeProblem](fullName)
0043 )
0044
0045 // Exclude a single class
0046 def excludeClass(className: String) = Seq(
0047 ProblemFilters.exclude[Problem](className + ".*"),
0048 ProblemFilters.exclude[MissingClassProblem](className),
0049 ProblemFilters.exclude[MissingTypesProblem](className)
0050 )
0051
0052 // Exclude a Spark class, that is in the package org.apache.spark
0053 def excludeSparkClass(className: String) = {
0054 excludeClass("org.apache.spark." + className)
0055 }
0056
0057 // Exclude a Spark package, that is in the package org.apache.spark
0058 def excludeSparkPackage(packageName: String) = {
0059 ProblemFilters.exclude[Problem]("org.apache.spark." + packageName + ".*")
0060 }
0061
0062 def ignoredABIProblems(base: File, currentSparkVersion: String) = {
0063
0064 // Excludes placed here will be used for all Spark versions
0065 val defaultExcludes = Seq()
0066
0067 // Read package-private excludes from file
0068 val classExcludeFilePath = file(base.getAbsolutePath + "/.generated-mima-class-excludes")
0069 val memberExcludeFilePath = file(base.getAbsolutePath + "/.generated-mima-member-excludes")
0070
0071 val ignoredClasses: Seq[String] =
0072 if (!classExcludeFilePath.exists()) {
0073 Seq()
0074 } else {
0075 IO.read(classExcludeFilePath).split("\n")
0076 }
0077
0078 val ignoredMembers: Seq[String] =
0079 if (!memberExcludeFilePath.exists()) {
0080 Seq()
0081 } else {
0082 IO.read(memberExcludeFilePath).split("\n")
0083 }
0084
0085 defaultExcludes ++ ignoredClasses.flatMap(excludeClass) ++
0086 ignoredMembers.flatMap(excludeMember) ++ MimaExcludes.excludes(currentSparkVersion)
0087 }
0088
0089 def mimaSettings(sparkHome: File, projectRef: ProjectRef) = {
0090 val organization = "org.apache.spark"
0091 val previousSparkVersion = "2.4.0"
0092 val project = projectRef.project
0093 val fullId = "spark-" + project + "_2.12"
0094 mimaDefaultSettings ++
0095 Seq(mimaPreviousArtifacts := Set(organization % fullId % previousSparkVersion),
0096 mimaBinaryIssueFilters ++= ignoredABIProblems(sparkHome, version.value))
0097 }
0098
0099 }