@@ -753,7 +753,9 @@ private[spark] object SparkSubmitUtils {
753
753
* @param artifactId the artifactId of the coordinate
754
754
* @param version the version of the coordinate
755
755
*/
756
- private [deploy] case class MavenCoordinate (groupId : String , artifactId : String , version : String )
756
+ private [deploy] case class MavenCoordinate (groupId : String , artifactId : String , version : String ) {
757
+ override def toString : String = s " $groupId: $artifactId: $version"
758
+ }
757
759
758
760
/**
759
761
* Extracts maven coordinates from a comma-delimited string. Coordinates should be provided
@@ -776,6 +778,10 @@ private[spark] object SparkSubmitUtils {
776
778
}
777
779
}
778
780
781
+ /** Path of the local Maven cache. */
782
+ private [spark] def m2Path : File = new File (System .getProperty(" user.home" ),
783
+ " .m2" + File .separator + " repository" + File .separator)
784
+
779
785
/**
780
786
* Extracts maven coordinates from a comma-delimited string
781
787
* @param remoteRepos Comma-delimited string of remote repositories
@@ -789,8 +795,7 @@ private[spark] object SparkSubmitUtils {
789
795
790
796
val localM2 = new IBiblioResolver
791
797
localM2.setM2compatible(true )
792
- val m2Path = " .m2" + File .separator + " repository" + File .separator
793
- localM2.setRoot(new File (System .getProperty(" user.home" ), m2Path).toURI.toString)
798
+ localM2.setRoot(m2Path.toURI.toString)
794
799
localM2.setUsepoms(true )
795
800
localM2.setName(" local-m2-cache" )
796
801
cr.add(localM2)
@@ -915,69 +920,72 @@ private[spark] object SparkSubmitUtils {
915
920
" "
916
921
} else {
917
922
val sysOut = System .out
918
- // To prevent ivy from logging to system out
919
- System .setOut(printStream)
920
- val artifacts = extractMavenCoordinates(coordinates)
921
- // Default configuration name for ivy
922
- val ivyConfName = " default"
923
- // set ivy settings for location of cache
924
- val ivySettings : IvySettings = new IvySettings
925
- // Directories for caching downloads through ivy and storing the jars when maven coordinates
926
- // are supplied to spark-submit
927
- val alternateIvyCache = ivyPath.getOrElse(" " )
928
- val packagesDirectory : File =
929
- if (alternateIvyCache.trim.isEmpty) {
930
- new File (ivySettings.getDefaultIvyUserDir, " jars" )
923
+ try {
924
+ // To prevent ivy from logging to system out
925
+ System .setOut(printStream)
926
+ val artifacts = extractMavenCoordinates(coordinates)
927
+ // Default configuration name for ivy
928
+ val ivyConfName = " default"
929
+ // set ivy settings for location of cache
930
+ val ivySettings : IvySettings = new IvySettings
931
+ // Directories for caching downloads through ivy and storing the jars when maven coordinates
932
+ // are supplied to spark-submit
933
+ val alternateIvyCache = ivyPath.getOrElse(" " )
934
+ val packagesDirectory : File =
935
+ if (alternateIvyCache.trim.isEmpty) {
936
+ new File (ivySettings.getDefaultIvyUserDir, " jars" )
937
+ } else {
938
+ ivySettings.setDefaultIvyUserDir(new File (alternateIvyCache))
939
+ ivySettings.setDefaultCache(new File (alternateIvyCache, " cache" ))
940
+ new File (alternateIvyCache, " jars" )
941
+ }
942
+ printStream.println(
943
+ s " Ivy Default Cache set to: ${ivySettings.getDefaultCache.getAbsolutePath}" )
944
+ printStream.println(s " The jars for the packages stored in: $packagesDirectory" )
945
+ // create a pattern matcher
946
+ ivySettings.addMatcher(new GlobPatternMatcher )
947
+ // create the dependency resolvers
948
+ val repoResolver = createRepoResolvers(remoteRepos, ivySettings)
949
+ ivySettings.addResolver(repoResolver)
950
+ ivySettings.setDefaultResolver(repoResolver.getName)
951
+
952
+ val ivy = Ivy .newInstance(ivySettings)
953
+ // Set resolve options to download transitive dependencies as well
954
+ val resolveOptions = new ResolveOptions
955
+ resolveOptions.setTransitive(true )
956
+ val retrieveOptions = new RetrieveOptions
957
+ // Turn downloading and logging off for testing
958
+ if (isTest) {
959
+ resolveOptions.setDownload(false )
960
+ resolveOptions.setLog(LogOptions .LOG_QUIET )
961
+ retrieveOptions.setLog(LogOptions .LOG_QUIET )
931
962
} else {
932
- ivySettings.setDefaultIvyUserDir(new File (alternateIvyCache))
933
- ivySettings.setDefaultCache(new File (alternateIvyCache, " cache" ))
934
- new File (alternateIvyCache, " jars" )
963
+ resolveOptions.setDownload(true )
935
964
}
936
- printStream.println(
937
- s " Ivy Default Cache set to: ${ivySettings.getDefaultCache.getAbsolutePath}" )
938
- printStream.println(s " The jars for the packages stored in: $packagesDirectory" )
939
- // create a pattern matcher
940
- ivySettings.addMatcher(new GlobPatternMatcher )
941
- // create the dependency resolvers
942
- val repoResolver = createRepoResolvers(remoteRepos, ivySettings)
943
- ivySettings.addResolver(repoResolver)
944
- ivySettings.setDefaultResolver(repoResolver.getName)
945
-
946
- val ivy = Ivy .newInstance(ivySettings)
947
- // Set resolve options to download transitive dependencies as well
948
- val resolveOptions = new ResolveOptions
949
- resolveOptions.setTransitive(true )
950
- val retrieveOptions = new RetrieveOptions
951
- // Turn downloading and logging off for testing
952
- if (isTest) {
953
- resolveOptions.setDownload(false )
954
- resolveOptions.setLog(LogOptions .LOG_QUIET )
955
- retrieveOptions.setLog(LogOptions .LOG_QUIET )
956
- } else {
957
- resolveOptions.setDownload(true )
958
- }
959
965
960
- // A Module descriptor must be specified. Entries are dummy strings
961
- val md = getModuleDescriptor
962
- md.setDefaultConf(ivyConfName)
966
+ // A Module descriptor must be specified. Entries are dummy strings
967
+ val md = getModuleDescriptor
968
+ md.setDefaultConf(ivyConfName)
963
969
964
- // Add exclusion rules for Spark and Scala Library
965
- addExclusionRules(ivySettings, ivyConfName, md)
966
- // add all supplied maven artifacts as dependencies
967
- addDependenciesToIvy(md, artifacts, ivyConfName)
970
+ // Add exclusion rules for Spark and Scala Library
971
+ addExclusionRules(ivySettings, ivyConfName, md)
972
+ // add all supplied maven artifacts as dependencies
973
+ addDependenciesToIvy(md, artifacts, ivyConfName)
968
974
969
- // resolve dependencies
970
- val rr : ResolveReport = ivy.resolve(md, resolveOptions)
971
- if (rr.hasError) {
972
- throw new RuntimeException (rr.getAllProblemMessages.toString)
975
+ // resolve dependencies
976
+ val rr : ResolveReport = ivy.resolve(md, resolveOptions)
977
+ if (rr.hasError) {
978
+ throw new RuntimeException (rr.getAllProblemMessages.toString)
979
+ }
980
+ // retrieve all resolved dependencies
981
+ ivy.retrieve(rr.getModuleDescriptor.getModuleRevisionId,
982
+ packagesDirectory.getAbsolutePath + File .separator +
983
+ " [organization]_[artifact]-[revision].[ext]" ,
984
+ retrieveOptions.setConfs(Array (ivyConfName)))
985
+ resolveDependencyPaths(rr.getArtifacts.toArray, packagesDirectory)
986
+ } finally {
987
+ System .setOut(sysOut)
973
988
}
974
- // retrieve all resolved dependencies
975
- ivy.retrieve(rr.getModuleDescriptor.getModuleRevisionId,
976
- packagesDirectory.getAbsolutePath + File .separator +
977
- " [organization]_[artifact]-[revision].[ext]" ,
978
- retrieveOptions.setConfs(Array (ivyConfName)))
979
- System .setOut(sysOut)
980
- resolveDependencyPaths(rr.getArtifacts.toArray, packagesDirectory)
981
989
}
982
990
}
983
991
}
0 commit comments