11import java .io .File
2- import java .net .{HttpURLConnection , URL }
32import java .nio .file .{Files , Paths }
43
4+ import BuildUtility .withTaskInfo
55import sbt .internal .util .ManagedLogger
66
7- import scala .xml .{Node , XML }
8-
9- /**
10- * A dependency holds all information of a library like name, version and maven url.
11- *
12- * @param dependencyString the input string from the 'dependencyList' sbt command
13- * @param logger the sbt logger
14- */
15- class Dependency (dependencyString : String , logger : ManagedLogger ) {
16- var nameWithoutScalaVersion = " "
17- var version = " "
18- var url = " "
19- var available = false
20- create()
21-
22- override def toString : String = {
23- s " $nameWithoutScalaVersion ( $version) - $available - $url"
24- }
25-
26- /**
27- * Converts the dependency to its xml representation, ready to be saved.
28- *
29- * @return a xml node called 'dependency'
30- */
31- def toXML : Node = {
32- <dependency >
33- <name >
34- {nameWithoutScalaVersion}
35- </name >
36- <version >
37- {version}
38- </version >
39- <url >
40- {url}
41- </url >
42- </dependency >
43- }
44-
45- /**
46- * This constructor-alike function reads the console output of the 'dependencyList' sbt command
47- * and fills all required information into the dependency object
48- */
49- private def create (): Unit = {
50- val DependencyRegex = " ([^:]+):([^:_]+)(_[^:]+)?:([^:]+)" .r
51- val mavenCentralFormat = " http://central.maven.org/maven2/%s/%s/%s/%s.jar"
52-
53- dependencyString match {
54- case DependencyRegex (depAuthor, depName, scalaVersion, depVersion) =>
55- this .nameWithoutScalaVersion = depName
56- this .version = depVersion
57-
58- val combinedName = if (scalaVersion != null ) depName + scalaVersion else depName
59-
60- // Create URL for maven central
61- url = mavenCentralFormat.format(depAuthor.replaceAll(" \\ ." , " /" ), s " $combinedName" ,
62- depVersion, s " $combinedName- $depVersion" )
63-
64- available = testURL(0 , 3 )
65-
66- case _ =>
67- logger warn s " Invalid dependency format: ' $dependencyString'. "
68- }
69- }
70-
71- /**
72- * Tests, if the dependency url is available. Uses recursion to handle connection faults.
73- */
74- private def testURL (recursionCount : Int , recursionLimit : Int ): Boolean = {
75-
76- var status = - 1
77-
78- try {
79-
80- // Test if the url exists
81- val connection = new URL (url).openConnection.asInstanceOf [HttpURLConnection ]
82- connection.setRequestMethod(" HEAD" )
83- connection.setConnectTimeout(200 )
84- connection.setReadTimeout(200 )
85- status = connection.getResponseCode
86- connection.disconnect()
87-
88- } catch {
89- case e : Exception => logger warn s " Error while testing dependency (attempt $recursionCount of $recursionLimit) " +
90- s " availability of ${this }: ${e.getMessage}"
91- }
92-
93- if (status != 200 && recursionCount + 1 <= recursionLimit) {
94- testURL(recursionCount + 1 , recursionLimit)
95- } else {
96- status == 200
97- }
98- }
99-
100- }
7+ import scala .xml .XML
1018
1029/**
10310 * Holds the functionality to read all dependencies and feed the bootstrap launcher with this information.
@@ -115,13 +22,12 @@ object BootstrapUtility {
11522 * @param scalaLibraryVersion the current scala library version
11623 */
11724 def bootstrapGenTask (logger : ManagedLogger , scalaLibraryVersion : String ): Unit = {
118- println(" Welcome to the bootstrap generation utility. It's time to build!" )
119-
120- // Dependency management
121- val dependencyList = retrieveDependencies(logger, scalaLibraryVersion)
122- saveDependencyXML(dependencyList, logger)
25+ withTaskInfo(" BOOTSTRAP GENERATION" , logger) {
12326
124- println(" Finished bootstrap generation utility. Have a nice day!" )
27+ // Dependency management
28+ val dependencyList = retrieveDependencies(logger, scalaLibraryVersion)
29+ saveDependencyXML(dependencyList, logger)
30+ }
12531 }
12632
12733 /**
@@ -195,48 +101,52 @@ object BootstrapUtility {
195101 // Assuming, before this: clean, bs, assembly bootstrapProject, package
196102 // Assuming: Hardcoded "bin/" and "deploy/" folders
197103 // Assuming: A folder called "deployment-files" with all additional files (license, bat, etc.)
198- logger info " Started deployment process."
199104
200- // First step: Preparing bin folder
201- logger info " Preparing 'bin/' folder."
202- createOrEmptyFolder(" bin/" )
105+ withTaskInfo(" PREPARE DEPLOYMENT" , logger) {
203106
204- // Second step: Preparing deploy folder, copying bin folder, bootstrap launcher, etc.
205- logger info " Preparing 'deploy/' folder."
206- createOrEmptyFolder(" deploy/" )
207- createOrEmptyFolder(" deploy/bin/" )
107+ logger info " Started deployment process."
208108
209- // Third step: Copying chat overflow files
210- logger info " Copying chat overflow files..."
109+ // First step: Preparing bin folder
110+ logger info " Preparing 'bin/' folder."
111+ createOrEmptyFolder(" bin/" )
211112
212- val sourceJarDirectories = List (s " target/scala- $scalaLibraryVersion/ " ,
213- s " api/target/scala- $scalaLibraryVersion/ " )
113+ // Second step: Preparing deploy folder, copying bin folder, bootstrap launcher, etc.
114+ logger info " Preparing 'deploy/' folder."
115+ createOrEmptyFolder(" deploy/" )
116+ createOrEmptyFolder(" deploy/bin/" )
214117
215- val targetJarDirectories = List (" bin" , " deploy/bin" )
118+ // Third step: Copying chat overflow files
119+ logger info " Copying chat overflow files..."
216120
217- for (sourceDirectory <- sourceJarDirectories) {
218- copyJars(sourceDirectory, targetJarDirectories, logger)
219- }
121+ val sourceJarDirectories = List (s " target/scala- $scalaLibraryVersion/ " ,
122+ s " api/target/scala- $scalaLibraryVersion/ " )
220123
221- // Fourth step: Copy bootstrap launcher
222- copyJars(s " bootstrap/target/scala- $scalaLibraryVersion/ " , List (" deploy/" ), logger)
124+ val targetJarDirectories = List (" bin" , " deploy/bin" )
223125
224- // Last step: Copy additional files
225- logger info " Copying additional deployment files..."
226- val deploymentFiles = new File (" deployment-files/" )
227- if (! deploymentFiles.exists()) {
228- logger warn " Unable to find deployment files."
229- } else {
230- for (deploymentFile <- deploymentFiles.listFiles()) {
231- Files .copy(Paths .get(deploymentFile.getAbsolutePath),
232- Paths .get(s " deploy/ ${deploymentFile.getName}" ))
233- logger info s " Finished copying additional deployment file ' ${deploymentFile.getName}'. "
126+ for (sourceDirectory <- sourceJarDirectories) {
127+ copyJars(sourceDirectory, targetJarDirectories, logger)
234128 }
235- }
236129
237- // TODO: Deployment readme file html
238- // TODO: Deployment bat file
239- // TODO: Deployment unix launch file (...?)
130+ // Fourth step: Copy bootstrap launcher
131+ copyJars(s " bootstrap/target/scala- $scalaLibraryVersion/ " , List (" deploy/" ), logger)
132+
133+ // Last step: Copy additional files
134+ logger info " Copying additional deployment files..."
135+ val deploymentFiles = new File (" deployment-files/" )
136+ if (! deploymentFiles.exists()) {
137+ logger warn " Unable to find deployment files."
138+ } else {
139+ for (deploymentFile <- deploymentFiles.listFiles()) {
140+ Files .copy(Paths .get(deploymentFile.getAbsolutePath),
141+ Paths .get(s " deploy/ ${deploymentFile.getName}" ))
142+ logger info s " Finished copying additional deployment file ' ${deploymentFile.getName}'. "
143+ }
144+ }
145+
146+ // TODO: Deployment readme file html
147+ // TODO: Deployment bat file
148+ // TODO: Deployment unix launch file (...?)
149+ }
240150 }
241151
242152 /**
@@ -276,6 +186,4 @@ object BootstrapUtility {
276186 }
277187}
278188
279- // TODO: Use withTaskInfo to properly print tasks
280- // TODO: Create missing deployment files
281- // TODO: Create and commit deploy run configuration. clean, package, bs, assembly (bootstrapProject), deploy
189+ // TODO: Create missing deployment files
0 commit comments