Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -92,6 +92,9 @@ private[deploy] object RPackageUtils extends Logging {
* Exposed for testing.
*/
private[deploy] def checkManifestForR(jar: JarFile): Boolean = {
if (jar.getManifest == null) {
return false
}
val manifest = jar.getManifest.getMainAttributes
manifest.getValue(hasRPackage) != null && manifest.getValue(hasRPackage).trim == "true"
}
Expand Down
14 changes: 10 additions & 4 deletions core/src/test/scala/org/apache/spark/deploy/IvyTestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,22 @@ private[deploy] object IvyTestUtils {
withManifest: Option[Manifest] = None): File = {
val jarFile = new File(dir, artifactName(artifact, useIvyLayout))
val jarFileStream = new FileOutputStream(jarFile)
val manifest = withManifest.getOrElse {
val mani = new Manifest()
val manifest: Manifest = withManifest.getOrElse {
if (withR) {
val mani = new Manifest()
val attr = mani.getMainAttributes
attr.put(Name.MANIFEST_VERSION, "1.0")
attr.put(new Name("Spark-HasRPackage"), "true")
mani
} else {
null
}
mani
}
val jarStream = new JarOutputStream(jarFileStream, manifest)
val jarStream = if (manifest != null) {
new JarOutputStream(jarFileStream, manifest)
} else {
new JarOutputStream(jarFileStream)
}

for (file <- files) {
val jarEntry = new JarEntry(file._1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ class RPackageUtilsSuite
}
}

test("jars without manifest return false") {
IvyTestUtils.withRepository(main, None, None) { repo =>
val jar = IvyTestUtils.packJar(new File(new URI(repo)), dep1, Nil,
useIvyLayout = false, withR = false, None)
val jarFile = new JarFile(jar)
assert(jarFile.getManifest == null, "jar file should have null manifest")
assert(!RPackageUtils.checkManifestForR(jarFile), "null manifest should return false")
}
}

test("SparkR zipping works properly") {
val tempDir = Files.createTempDir()
Utils.tryWithSafeFinally {
Expand Down