Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 7c41683

Browse files
committed
Added dependency testing.
1 parent c59b51b commit 7c41683

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

project/BootstrapUtility.scala

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.net.{HttpURLConnection, URL}
2+
13
import sbt.internal.util.ManagedLogger
24

35
class Dependency(dependencyString: String, logger: ManagedLogger) {
@@ -7,9 +9,12 @@ class Dependency(dependencyString: String, logger: ManagedLogger) {
79
var available = false
810
create()
911

12+
override def toString: String = {
13+
s"$nameWithoutScalaVersion ($version) - $available - $url"
14+
}
15+
1016
private def create(): Unit = {
1117
val DependencyRegex = "([^:]+):([^:_]+)(_[^:]+)?:([^:]+)".r
12-
// TODO: HTTPS?
1318
val mavenCentralFormat = "http://central.maven.org/maven2/%s/%s/%s/%s.jar"
1419

1520
dependencyString match {
@@ -23,8 +28,14 @@ class Dependency(dependencyString: String, logger: ManagedLogger) {
2328
url = mavenCentralFormat.format(depAuthor.replaceAll("\\.", "/"), s"$combinedName",
2429
depVersion, s"$combinedName-$depVersion")
2530

26-
logger info url
27-
// TODO: Test availability of URL without full download (?), save into available
31+
// Test if the url exists
32+
val connection = new URL(url).openConnection.asInstanceOf[HttpURLConnection]
33+
connection.setRequestMethod("HEAD")
34+
connection.setConnectTimeout(5000)
35+
connection.setReadTimeout(5000)
36+
val status = connection.getResponseCode
37+
connection.disconnect()
38+
available = status == 200
2839
case _ =>
2940
logger warn s"Invalid dependency format: '$dependencyString'."
3041
}
@@ -47,15 +58,8 @@ object BootstrapUtility {
4758
val lines = input.replaceFirst("\\[info\\] ", "").split(" \\[info\\] ")
4859
val dependencies = for (line <- lines) yield new Dependency(line, logger)
4960

50-
//val testString = "[info] log4j:log4j:1.2.17"
51-
//logger info testString
52-
//logger info removeInfo(testString)
53-
//new Dependency(removeInfo(testString), logger)
61+
// Modify dependencies: Remove ChatOverflow, add scala library
5462
}
5563

56-
private def removeInfo(dependencyString: String): String = {
57-
val InfoRegex = "^\\[info\\] ".r
58-
InfoRegex.replaceFirstIn(dependencyString, "")
59-
}
6064

6165
}

0 commit comments

Comments
 (0)