spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aarondav <...@git.apache.org>
Subject [GitHub] spark pull request: SPARK-1094 Support MiMa for reporting binary c...
Date Sun, 23 Mar 2014 06:39:16 GMT
Github user aarondav commented on a diff in the pull request:

    https://github.com/apache/spark/pull/207#discussion_r10865835
  
    --- Diff: tools/src/main/scala/org/apache/spark/tools/GenerateMIMAIgnore.scala ---
    @@ -0,0 +1,157 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.tools
    +
    +import java.io.File
    +import java.util.jar.JarFile
    +
    +import scala.collection.mutable
    +import scala.collection.JavaConversions._
    +import scala.reflect.runtime.universe.runtimeMirror
    +import scala.util.Try
    +
    +/**
    + * A tool for generating classes to be excluded during binary checking with MIMA. It
is expected
    + * that this tool is run with ./spark-class.
    + *
    + * MIMA itself only supports JVM-level visibility and doesn't account for package-private
classes.
    + * This tool looks at all currently package-private classes and generates exclusions
for them. Note
    + * that this approach is not sound. It can lead to false positives if we move or rename
a previously
    + * package-private class. It can lead to false negatives if someone explicitly makes
a class
    + * package-private that wasn't before. This exists only to help catch certain classes
of changes
    + * which might be difficult to catch during review.
    + */
    +object GenerateMIMAIgnore {
    +  private val classLoader = Thread.currentThread().getContextClassLoader
    +  private val mirror = runtimeMirror(classLoader)
    +
    +  private def classesPrivateWithin(packageName: String): Set[String] = {
    +
    +    val classes = getClasses(packageName, classLoader)
    +    val privateClasses = mutable.HashSet[String]()
    +
    +    def isPackagePrivate(className: String) = {
    +     try {
    +       /* Couldn't figure out if it's possible to determine a-priori whether a given
symbol
    +          is a module or class. */
    +
    +       val privateAsClass = mirror
    +         .staticClass(className)
    +         .privateWithin
    +         .fullName
    +         .startsWith(packageName)
    +
    +       val privateAsModule = mirror
    +         .staticModule(className)
    +         .privateWithin
    +         .fullName
    +         .startsWith(packageName)
    +
    +       privateAsClass || privateAsModule
    +     } catch {
    +        case _: Throwable => {
    +          println("Error determining visibility: " + className)
    +          false
    +        }
    +      }
    +    }
    +
    +    for (className <- classes) {
    +      val directlyPrivateSpark = isPackagePrivate(className)
    +
    +      /* Inner classes defined within a private[spark] class or object are effectively
    +         invisible, so we account for them as package private. */
    +      val indirectlyPrivateSpark = {
    +        val maybeOuter = className.toString.takeWhile(_ != '$')
    +        if (maybeOuter != className) {
    +          isPackagePrivate(maybeOuter)
    +        } else {
    +          false
    +        }
    +      }
    +      if (directlyPrivateSpark || indirectlyPrivateSpark) privateClasses += className
    +    }
    +    privateClasses.flatMap(c => Seq(c, c.replace("$", "#"))).toSet
    +  }
    +
    +  def main(args: Array[String]) {
    +    scala.tools.nsc.io.File(".mima-excludes").
    +      writeAll(classesPrivateWithin("org.apache.spark").mkString("\n"))
    +    println("Created : .mima-excludes in current directory.")
    +  }
    +
    +  /**
    +   * Get all classes in a package from a jar file.
    +   */
    +  private def getAllClasses(jarPath: String, packageName: String) = {
    --- End diff --
    
    getAllClasses, getClasses, and findClasses perhaps could be renamed to something like
getClassesFromJar, getClasses, and getClassesFromDir, respectively.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message