@@ -712,7 +712,9 @@ private[spark] object SparkSubmitUtils {
712
712
* @param artifactId the artifactId of the coordinate
713
713
* @param version the version of the coordinate
714
714
*/
715
- private [deploy] case class MavenCoordinate (groupId : String , artifactId : String , version : String )
715
+ private [deploy] case class MavenCoordinate (groupId : String , artifactId : String , version : String ) {
716
+ override def toString : String = s " $groupId: $artifactId: $version"
717
+ }
716
718
717
719
/**
718
720
* Extracts maven coordinates from a comma-delimited string. Coordinates should be provided
@@ -735,6 +737,10 @@ private[spark] object SparkSubmitUtils {
735
737
}
736
738
}
737
739
740
+ /** Path of the local Maven cache. */
741
+ private [spark] def m2Path : File = new File (System .getProperty(" user.home" ),
742
+ " .m2" + File .separator + " repository" + File .separator)
743
+
738
744
/**
739
745
* Extracts maven coordinates from a comma-delimited string
740
746
* @param remoteRepos Comma-delimited string of remote repositories
@@ -748,8 +754,7 @@ private[spark] object SparkSubmitUtils {
748
754
749
755
val localM2 = new IBiblioResolver
750
756
localM2.setM2compatible(true )
751
- val m2Path = " .m2" + File .separator + " repository" + File .separator
752
- localM2.setRoot(new File (System .getProperty(" user.home" ), m2Path).toURI.toString)
757
+ localM2.setRoot(m2Path.toURI.toString)
753
758
localM2.setUsepoms(true )
754
759
localM2.setName(" local-m2-cache" )
755
760
cr.add(localM2)
@@ -874,69 +879,72 @@ private[spark] object SparkSubmitUtils {
874
879
" "
875
880
} else {
876
881
val sysOut = System .out
877
- // To prevent ivy from logging to system out
878
- System .setOut(printStream)
879
- val artifacts = extractMavenCoordinates(coordinates)
880
- // Default configuration name for ivy
881
- val ivyConfName = " default"
882
- // set ivy settings for location of cache
883
- val ivySettings : IvySettings = new IvySettings
884
- // Directories for caching downloads through ivy and storing the jars when maven coordinates
885
- // are supplied to spark-submit
886
- val alternateIvyCache = ivyPath.getOrElse(" " )
887
- val packagesDirectory : File =
888
- if (alternateIvyCache.trim.isEmpty) {
889
- new File (ivySettings.getDefaultIvyUserDir, " jars" )
882
+ try {
883
+ // To prevent ivy from logging to system out
884
+ System .setOut(printStream)
885
+ val artifacts = extractMavenCoordinates(coordinates)
886
+ // Default configuration name for ivy
887
+ val ivyConfName = " default"
888
+ // set ivy settings for location of cache
889
+ val ivySettings : IvySettings = new IvySettings
890
+ // Directories for caching downloads through ivy and storing the jars when maven coordinates
891
+ // are supplied to spark-submit
892
+ val alternateIvyCache = ivyPath.getOrElse(" " )
893
+ val packagesDirectory : File =
894
+ if (alternateIvyCache.trim.isEmpty) {
895
+ new File (ivySettings.getDefaultIvyUserDir, " jars" )
896
+ } else {
897
+ ivySettings.setDefaultIvyUserDir(new File (alternateIvyCache))
898
+ ivySettings.setDefaultCache(new File (alternateIvyCache, " cache" ))
899
+ new File (alternateIvyCache, " jars" )
900
+ }
901
+ printStream.println(
902
+ s " Ivy Default Cache set to: ${ivySettings.getDefaultCache.getAbsolutePath}" )
903
+ printStream.println(s " The jars for the packages stored in: $packagesDirectory" )
904
+ // create a pattern matcher
905
+ ivySettings.addMatcher(new GlobPatternMatcher )
906
+ // create the dependency resolvers
907
+ val repoResolver = createRepoResolvers(remoteRepos, ivySettings)
908
+ ivySettings.addResolver(repoResolver)
909
+ ivySettings.setDefaultResolver(repoResolver.getName)
910
+
911
+ val ivy = Ivy .newInstance(ivySettings)
912
+ // Set resolve options to download transitive dependencies as well
913
+ val resolveOptions = new ResolveOptions
914
+ resolveOptions.setTransitive(true )
915
+ val retrieveOptions = new RetrieveOptions
916
+ // Turn downloading and logging off for testing
917
+ if (isTest) {
918
+ resolveOptions.setDownload(false )
919
+ resolveOptions.setLog(LogOptions .LOG_QUIET )
920
+ retrieveOptions.setLog(LogOptions .LOG_QUIET )
890
921
} else {
891
- ivySettings.setDefaultIvyUserDir(new File (alternateIvyCache))
892
- ivySettings.setDefaultCache(new File (alternateIvyCache, " cache" ))
893
- new File (alternateIvyCache, " jars" )
922
+ resolveOptions.setDownload(true )
894
923
}
895
- printStream.println(
896
- s " Ivy Default Cache set to: ${ivySettings.getDefaultCache.getAbsolutePath}" )
897
- printStream.println(s " The jars for the packages stored in: $packagesDirectory" )
898
- // create a pattern matcher
899
- ivySettings.addMatcher(new GlobPatternMatcher )
900
- // create the dependency resolvers
901
- val repoResolver = createRepoResolvers(remoteRepos, ivySettings)
902
- ivySettings.addResolver(repoResolver)
903
- ivySettings.setDefaultResolver(repoResolver.getName)
904
-
905
- val ivy = Ivy .newInstance(ivySettings)
906
- // Set resolve options to download transitive dependencies as well
907
- val resolveOptions = new ResolveOptions
908
- resolveOptions.setTransitive(true )
909
- val retrieveOptions = new RetrieveOptions
910
- // Turn downloading and logging off for testing
911
- if (isTest) {
912
- resolveOptions.setDownload(false )
913
- resolveOptions.setLog(LogOptions .LOG_QUIET )
914
- retrieveOptions.setLog(LogOptions .LOG_QUIET )
915
- } else {
916
- resolveOptions.setDownload(true )
917
- }
918
924
919
- // A Module descriptor must be specified. Entries are dummy strings
920
- val md = getModuleDescriptor
921
- md.setDefaultConf(ivyConfName)
925
+ // A Module descriptor must be specified. Entries are dummy strings
926
+ val md = getModuleDescriptor
927
+ md.setDefaultConf(ivyConfName)
922
928
923
- // Add exclusion rules for Spark and Scala Library
924
- addExclusionRules(ivySettings, ivyConfName, md)
925
- // add all supplied maven artifacts as dependencies
926
- addDependenciesToIvy(md, artifacts, ivyConfName)
929
+ // Add exclusion rules for Spark and Scala Library
930
+ addExclusionRules(ivySettings, ivyConfName, md)
931
+ // add all supplied maven artifacts as dependencies
932
+ addDependenciesToIvy(md, artifacts, ivyConfName)
927
933
928
- // resolve dependencies
929
- val rr : ResolveReport = ivy.resolve(md, resolveOptions)
930
- if (rr.hasError) {
931
- throw new RuntimeException (rr.getAllProblemMessages.toString)
934
+ // resolve dependencies
935
+ val rr : ResolveReport = ivy.resolve(md, resolveOptions)
936
+ if (rr.hasError) {
937
+ throw new RuntimeException (rr.getAllProblemMessages.toString)
938
+ }
939
+ // retrieve all resolved dependencies
940
+ ivy.retrieve(rr.getModuleDescriptor.getModuleRevisionId,
941
+ packagesDirectory.getAbsolutePath + File .separator +
942
+ " [organization]_[artifact]-[revision].[ext]" ,
943
+ retrieveOptions.setConfs(Array (ivyConfName)))
944
+ resolveDependencyPaths(rr.getArtifacts.toArray, packagesDirectory)
945
+ } finally {
946
+ System .setOut(sysOut)
932
947
}
933
- // retrieve all resolved dependencies
934
- ivy.retrieve(rr.getModuleDescriptor.getModuleRevisionId,
935
- packagesDirectory.getAbsolutePath + File .separator +
936
- " [organization]_[artifact]-[revision].[ext]" ,
937
- retrieveOptions.setConfs(Array (ivyConfName)))
938
- System .setOut(sysOut)
939
- resolveDependencyPaths(rr.getArtifacts.toArray, packagesDirectory)
940
948
}
941
949
}
942
950
}
0 commit comments