Skip to content

Commit af2965f

Browse files
feat: download method
1 parent a9982d6 commit af2965f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/main/groovy/com/chillycheesy/modulo/tasks/RunModuloServer.groovy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import org.gradle.api.Project
55

66
class RunModuloServer implements ModuloTask {
77

8+
private final def LINK = 'https://s01.oss.sonatype.org/content/repositories/releases/com/chillycheesy/modulo-server/'
9+
810
private ModuleExtension moduleExtension
911

1012
RunModuloServer(ModuleExtension moduleExtension) {
@@ -17,7 +19,25 @@ class RunModuloServer implements ModuloTask {
1719
group = 'modulo'
1820
description = 'Run the Modulo server.'
1921
doLast {
22+
final File file = new File("modulo/modulo-server-${moduleExtension.version}.jar")
23+
if (!file.exists()) downloadFile(file)
24+
////////////////////////////////////////////////////////////////////////////////////////////////
25+
}
26+
}
27+
}
2028

29+
private def downloadFile(File file) {
30+
def url = "$LINK:${moduleExtension.version}/${file.getName()}"
31+
new URL(url).openConnection().with { connection ->
32+
connection.instanceFollowRedirects = false
33+
url = connection.getHeaderField("Location")
34+
if(!url) {
35+
file.withOutputStream { outputStream ->
36+
connection.inputStream.with { inputStream ->
37+
outputStream << inputStream
38+
inputStream.close()
39+
}
40+
}
2141
}
2242
}
2343
}

0 commit comments

Comments
 (0)