Skip to content

Commit 647c547

Browse files
committed
Reveiw feedback.
1 parent c39f3b5 commit 647c547

File tree

3 files changed

+43
-46
lines changed

3 files changed

+43
-46
lines changed

bin/spark-class

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ fi
129129

130130
# Compute classpath using external script
131131
CLASSPATH=`$FWDIR/bin/compute-classpath.sh`
132-
CLASSPATH="$CLASSPATH:$SPARK_TOOLS_JAR"
133-
if [ "$1" == "org.apache.spark.tools.JavaAPICompletenessChecker" ]; then
132+
if [[ "$1" =~ org.apache.spark.tools.* ]]; then
134133
CLASSPATH="$CLASSPATH:$SPARK_TOOLS_JAR"
135134
fi
136135

project/MimaBuild.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ object MimaBuild {
88
import com.typesafe.tools.mima.core._
99
import com.typesafe.tools.mima.core.ProblemFilters._
1010

11-
// Excludes relevant to all Spark versions
12-
val defaultExcludes = Seq(excludePackage("org.apache.spark.repl"))
11+
// Excludes placed here will be used for all Spark versions
12+
val defaultExcludes = Seq()
1313

1414
// Read package-private excludes from file
1515
val excludeFilePath = (base.getAbsolutePath + "/.mima-excludes")
@@ -51,7 +51,7 @@ object MimaBuild {
5151
case _ => Seq()
5252
}
5353

54-
packagePrivateExcludes ++ versionExcludes
54+
defaultExcludes ++ packagePrivateExcludes ++ versionExcludes
5555
}
5656

5757
def mimaSettings(sparkHome: File) = mimaDefaultSettings ++ Seq(

tools/src/main/scala/org/apache/spark/tools/GenerateMIMAIgnore.scala

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,24 @@ object GenerateMIMAIgnore {
4646
val privateClasses = mutable.HashSet[String]()
4747

4848
def isPackagePrivate(className: String) = {
49-
try {
50-
/* Couldn't figure out if it's possible to determine a-priori whether a given symbol
51-
is a module or class. */
52-
53-
val privateAsClass = mirror
54-
.staticClass(className)
55-
.privateWithin
56-
.fullName
57-
.startsWith(packageName)
58-
59-
val privateAsModule = mirror
60-
.staticModule(className)
61-
.privateWithin
62-
.fullName
63-
.startsWith(packageName)
64-
65-
privateAsClass || privateAsModule
66-
} catch {
49+
try {
50+
/* Couldn't figure out if it's possible to determine a-priori whether a given symbol
51+
is a module or class. */
52+
53+
val privateAsClass = mirror
54+
.staticClass(className)
55+
.privateWithin
56+
.fullName
57+
.startsWith(packageName)
58+
59+
val privateAsModule = mirror
60+
.staticModule(className)
61+
.privateWithin
62+
.fullName
63+
.startsWith(packageName)
64+
65+
privateAsClass || privateAsModule
66+
} catch {
6767
case _: Throwable => {
6868
println("Error determining visibility: " + className)
6969
false
@@ -95,26 +95,11 @@ object GenerateMIMAIgnore {
9595
println("Created : .mima-excludes in current directory.")
9696
}
9797

98-
/**
99-
* Get all classes in a package from a jar file.
100-
*/
101-
private def getAllClasses(jarPath: String, packageName: String) = {
102-
val jar = new JarFile(new File(jarPath))
103-
val enums = jar.entries().map(_.getName).filter(_.startsWith(packageName))
104-
val classes = mutable.HashSet[Class[_]]()
105-
for (entry <- enums) {
106-
if (!entry.endsWith("/") && !entry.endsWith("MANIFEST.MF") && !entry.endsWith("properties")) {
107-
classes += Class.forName(entry.trim.replaceAll(".class", "").replace('/', '.'))
108-
}
109-
}
110-
classes
111-
}
11298

11399
private def shouldExclude(name: String) = {
114100
// Heuristic to remove JVM classes that do not correspond to user-facing classes in Scala
115-
Try(mirror.staticClass(name)).isFailure ||
116101
name.contains("anon") ||
117-
name.endsWith("class") ||
102+
name.endsWith("$class") ||
118103
name.contains("$sp")
119104
}
120105

@@ -123,35 +108,48 @@ object GenerateMIMAIgnore {
123108
* and subpackages both from directories and jars present on the classpath.
124109
*/
125110
private def getClasses(packageName: String,
126-
classLoader: ClassLoader = Thread.currentThread().getContextClassLoader): Seq[String] = {
111+
classLoader: ClassLoader = Thread.currentThread().getContextClassLoader): Set[String] = {
127112
val path = packageName.replace('.', '/')
128113
val resources = classLoader.getResources(path)
129114

130115
val jars = resources.filter(x => x.getProtocol == "jar")
131116
.map(_.getFile.split(":")(1).split("!")(0))
132-
val classesFromJars = jars.map(getAllClasses(_, path)).flatten
117+
val classesFromJars = jars.map(getClassesFromJar(_, path)).flatten
133118

134119
val dirs = resources.filter(x => x.getProtocol == "file")
135120
.map(x => new File(x.getFile.split(":").last))
136-
val classFromDirs = dirs.map(findClasses(_, packageName)).flatten
121+
val classFromDirs = dirs.map(getClassesFromDir(_, packageName)).flatten
137122

138-
(classFromDirs ++ classesFromJars).map(_.getName).filter(!shouldExclude(_)).toSeq
123+
(classFromDirs ++ classesFromJars).map(_.getName).filterNot(shouldExclude).toSet
139124
}
140125

141-
private def findClasses(directory: File, packageName: String): Seq[Class[_]] = {
126+
private def getClassesFromDir(directory: File, packageName: String): Seq[Class[_]] = {
142127
val classes = mutable.ArrayBuffer[Class[_]]()
143128
if (!directory.exists()) {
144129
return classes
145130
}
146131
val files = directory.listFiles()
147132
for (file <- files) {
148133
if (file.isDirectory) {
149-
classes ++= findClasses(file, packageName + "." + file.getName)
134+
classes ++= getClassesFromDir(file, packageName + "." + file.getName)
150135
} else if (file.getName.endsWith(".class")) {
151-
val className = file.getName.substring(0, file.getName.length() - 6)
136+
val className = file.getName.stripSuffix(".class")
152137
classes += Class.forName(packageName + '.' + className)
153138
}
154139
}
155140
classes
156141
}
142+
143+
/**
144+
* Get all classes in a package from a jar file.
145+
*/
146+
private def getClassesFromJar(jarPath: String, packageName: String) = {
147+
val jar = new JarFile(new File(jarPath))
148+
val enums = jar.entries().map(_.getName).filter(_.startsWith(packageName))
149+
val classes = mutable.HashSet[Class[_]]()
150+
for (entry <- enums if entry.endsWith(".class")) {
151+
classes += Class.forName(entry.trim.replaceAll(".class", "").replace('/', '.'))
152+
}
153+
classes
154+
}
157155
}

0 commit comments

Comments
 (0)