Skip to content

Commit fef4370

Browse files
author
Marcelo Vanzin
committed
Unfork Optional.java.
Just package the class from the guava dependency instead. Note the dependency-fu needed in core/pom.xml and assembly/pom.xml to not expose the guava dependency in the user's compilation classpath.
1 parent d3ea8e1 commit fef4370

File tree

5 files changed

+77
-282
lines changed

5 files changed

+77
-282
lines changed

assembly/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@
101101
</includes>
102102
</artifactSet>
103103
<filters>
104-
<filter>
105-
<artifact>com.google.guava:guava</artifact>
106-
<excludes>
107-
<exclude>com/google/common/base/Optional*</exclude>
108-
</excludes>
109-
</filter>
110104
<filter>
111105
<artifact>*:*</artifact>
112106
<excludes>

core/pom.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,15 @@
6868
<groupId>org.eclipse.jetty</groupId>
6969
<artifactId>jetty-server</artifactId>
7070
</dependency>
71+
<!--
72+
Promote Guava to "compile" so that maven-shade-plugin picks it up (for packaging the Optional
73+
class exposed in the Java API). The plugin will then remove this dependency from the published
74+
pom, so that Guava does not pollute the client's compilation classpath.
75+
-->
7176
<dependency>
7277
<groupId>com.google.guava</groupId>
7378
<artifactId>guava</artifactId>
79+
<scope>compile</scope>
7480
</dependency>
7581
<dependency>
7682
<groupId>org.apache.commons</groupId>
@@ -322,6 +328,34 @@
322328
</arguments>
323329
</configuration>
324330
</plugin>
331+
<plugin>
332+
<groupId>org.apache.maven.plugins</groupId>
333+
<artifactId>maven-shade-plugin</artifactId>
334+
<executions>
335+
<execution>
336+
<phase>package</phase>
337+
<goals>
338+
<goal>shade</goal>
339+
</goals>
340+
<configuration>
341+
<shadedArtifactAttached>false</shadedArtifactAttached>
342+
<artifactSet>
343+
<includes>
344+
<include>com.google.guava:guava</include>
345+
</includes>
346+
</artifactSet>
347+
<filters>
348+
<filter>
349+
<artifact>com.google.guava:guava</artifact>
350+
<includes>
351+
<include>com/google/common/base/Optional*</include>
352+
</includes>
353+
</filter>
354+
</filters>
355+
</configuration>
356+
</execution>
357+
</executions>
358+
</plugin>
325359
</plugins>
326360

327361
<resources>

core/src/main/java/com/google/common/base/Optional.java

Lines changed: 0 additions & 243 deletions
This file was deleted.

project/Relocator.scala

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,9 @@ class RelocatorRemapper(relocators: List[Relocator]) extends Remapper {
8888
* should be relocated are moved to a new location, and all classes are passed through the
8989
* remapper so that references to relocated classes are fixed.
9090
*
91-
* Note about `preferLocal`: this is a hack to make sure that we always ship the Spark-compiled
92-
* version of Guava's `Optional` class. Unlike maven, sbt-assembly doesn't seem to allow filtering
93-
* of specific entries in dependencies. It also does not provide information about where does
94-
* a particular file come from. The only hint is that the temp path for the file ends with a "_dir"
95-
* when it comes from a directory, and with a hash when it comes from a jar file. So for classes
96-
* that match a regex in the `preferLocal` list, we choose the first class file in a local
97-
* directory.
98-
*
9991
* @param relocators List of relocators to apply to classes being shaded.
100-
* @param preferLocal List of regexes that match classes for which a local version is preferred.
10192
*/
102-
class ShadeStrategy(relocators: List[Relocator], preferLocal: List[Regex]) extends MergeStrategy {
93+
class ShadeStrategy(relocators: List[Relocator]) extends MergeStrategy {
10394

10495
private val remapper = new RelocatorRemapper(relocators)
10596

@@ -111,7 +102,7 @@ class ShadeStrategy(relocators: List[Relocator], preferLocal: List[Regex]) exten
111102
(files.head, path)
112103
} else {
113104
val className = path.substring(0, path.length() - ".class".length())
114-
(remap(chooseFile(path, files), tempDir), remapper.rename(className) + ".class")
105+
(remap(files.head, tempDir), remapper.rename(className) + ".class")
115106
}
116107
Right(Seq(file -> newPath))
117108
}
@@ -139,18 +130,4 @@ class ShadeStrategy(relocators: List[Relocator], preferLocal: List[Regex]) exten
139130
}
140131
}
141132

142-
private def chooseFile(path: String, files: Seq[File]): File = {
143-
if (!preferLocal.filter { r => r.pattern.matcher(path).matches() }.isEmpty) {
144-
def isLocal(f: File) = {
145-
val abs = f.getAbsolutePath()
146-
val dir = abs.substring(0, abs.length() - path.length())
147-
dir.endsWith("_dir")
148-
}
149-
150-
files.filter(isLocal).orElse(files)(0)
151-
} else {
152-
files.head
153-
}
154-
}
155-
156133
}

0 commit comments

Comments
 (0)