1+ import java .io .File
12import java .net .{HttpURLConnection , URL }
23
34import sbt .internal .util .ManagedLogger
@@ -31,8 +32,8 @@ class Dependency(dependencyString: String, logger: ManagedLogger) {
3132 // Test if the url exists
3233 val connection = new URL (url).openConnection.asInstanceOf [HttpURLConnection ]
3334 connection.setRequestMethod(" HEAD" )
34- connection.setConnectTimeout(5000 )
35- connection.setReadTimeout(5000 )
35+ connection.setConnectTimeout(100 )
36+ connection.setReadTimeout(100 )
3637 val status = connection.getResponseCode
3738 connection.disconnect()
3839 available = status == 200
@@ -44,22 +45,56 @@ class Dependency(dependencyString: String, logger: ManagedLogger) {
4445}
4546
4647object BootstrapUtility {
48+ val dependencyListFileName = " dependencyList.txt"
49+ val dependencyXMLFileName = " bootstrap/src/main/resources/dependencies.xml"
4750
48- def bootstrapDependencyGenTask (logger : ManagedLogger ): Unit = {
51+ def bootstrapGenTask (logger : ManagedLogger , scalaLibraryVersion : String ): Unit = {
4952 println(" Welcome to the bootstrap generation utility. It's time to build!" )
50- println(" Please enter the console output of the task 'dependencyList' without the intro part (so only the dependencies)." )
51- println(" Should look like '[info] ... [info] ...'" )
52- println(" > " )
5353
54- // We just assume that the building guy knows what he's doing, lol
55- val input = scala.io.Source .fromInputStream(System .in).bufferedReader().readLine()
54+ // Dependency management
55+ val dependencyList = retrieveDependencies(logger, scalaLibraryVersion)
56+ saveDependencyXML(dependencyList, logger)
5657
57- // Splits the lines at the info tag of the console output
58- val lines = input.replaceFirst(" \\ [info\\ ] " , " " ).split(" \\ [info\\ ] " )
59- val dependencies = for (line <- lines) yield new Dependency (line, logger)
58+ // Copy built jar files
59+ copyJars(logger)
60+ }
61+
62+ private def saveDependencyXML (dependencyList : List [Dependency ], logger : ManagedLogger ): Unit = {
63+
64+ }
6065
61- // Modify dependencies: Remove ChatOverflow, add scala library
66+ private def copyJars ( logger : ManagedLogger ) : Unit = {
6267 }
6368
69+ private def retrieveDependencies (logger : ManagedLogger , scalaLibraryVersion : String ): List [Dependency ] = {
70+
71+ val dependencyFile = new File (dependencyListFileName)
72+
73+ if (! dependencyFile.exists()) {
74+ logger error " No dependency file found. Please copy the output of the task 'dependencyList' into a file named 'dependencyList.txt' in the root folder."
75+ List [Dependency ]()
76+ } else {
77+
78+ // Load file, remove the info tag and create dependency objects
79+ val input = scala.io.Source .fromFile(dependencyFile).getLines().toList
80+ val lines = input.map(line => line.replaceFirst(" \\ [info\\ ] " , " " ))
81+ val dependencies = for (line <- lines) yield new Dependency (line, logger)
82+
83+ // Modify dependencies: Remove ChatOverflow, add scala library
84+ val depsWithoutChatOverflow = dependencies.filter(d =>
85+ d.nameWithoutScalaVersion != " chatoverflow" && d.nameWithoutScalaVersion != " chatoverflow-api" )
86+ val modifiedDependencies = depsWithoutChatOverflow ++
87+ List (new Dependency (s " org.scala-lang:scala-library: $scalaLibraryVersion" , logger))
88+
89+ // Info output
90+ logger info s " Found ${modifiedDependencies.length} dependencies. "
91+ if (modifiedDependencies.exists(d => ! d.available)) {
92+ logger warn " Found the following dependencies, that could not be retrieved online:"
93+ logger warn modifiedDependencies.filter(d => ! d.available).map(_.toString).mkString(" \n " )
94+ }
95+
96+ modifiedDependencies
97+ }
98+ }
6499
65100}
0 commit comments