Skip to content
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import java.util.jar.JarFile
import scala.collection.mutable
import scala.collection.JavaConversions._
import scala.reflect.runtime.universe.runtimeMirror
import scala.reflect.runtime.{universe => unv}
import scala.reflect._

/**
* A tool for generating classes to be excluded during binary checking with MIMA. It is expected
Expand Down Expand Up @@ -69,9 +71,25 @@ object GenerateMIMAIgnore {
}
}
}


def classesAnnotationCheck(className: String) = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use some formatting and naming cleanup - the indentation is weird. Also, it might be better to inline isAnnotationExistClassLevel rather than having its own function.

What about this?

def isDeveloperApi(className: String) = {
  try {
    val clazz = mirror.classSymbol(Class.forName(className, false, classLoader))
    clazz.annotations.exists(_.tpe =:= unv.typeOf[org.apache.spark.annotation.DeveloperApi])
  } catch {
    case _: Throwable => {
      println("Error determining Annotations: " + className)
      false
     }
   }
 }

try {
val annotList=mirror
.classSymbol(Class.forName(className, false, classLoader))
.annotations

isAnnotationExistClassLevel(annotList)
} catch {
case _: Throwable => {
println("Error determining Annotations: " + className)
false
}
}
}

for (className <- classes) {
val directlyPrivateSpark = isPackagePrivate(className)
val annotationCheck = classesAnnotationCheck(className)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to call this something like val developerApi to make it grammatically consistent with the other variables. I.e.

if (directlyPrivateSpark || indirectlyPrivateSpark || developerApi) privateClasses += className


/* Inner classes defined within a private[spark] class or object are effectively
invisible, so we account for them as package private. */
Expand All @@ -83,7 +101,8 @@ object GenerateMIMAIgnore {
false
}
}
if (directlyPrivateSpark || indirectlyPrivateSpark) privateClasses += className

if (directlyPrivateSpark || indirectlyPrivateSpark || annotationCheck) privateClasses += className
}
privateClasses.flatMap(c => Seq(c, c.replace("$", "#"))).toSet
}
Expand All @@ -93,7 +112,10 @@ object GenerateMIMAIgnore {
writeAll(classesPrivateWithin("org.apache.spark").mkString("\n"))
println("Created : .mima-excludes in current directory.")
}


private def isAnnotationExistClassLevel(annotList: List[unv.Annotation]): Boolean = {
annotList.exists(_.tpe =:= unv.typeOf[org.apache.spark.annotation.DeveloperApi])
}

private def shouldExclude(name: String) = {
// Heuristic to remove JVM classes that do not correspond to user-facing classes in Scala
Expand Down