4 Commits

Author SHA1 Message Date
4f82639658 v0.16.0 2023-05-17 00:43:15 -07:00
5429dcddd5 Strip kubeliv from contributors. 2023-04-20 00:54:06 -07:00
1a968a6489 Cleanup smart downloader utility. 2023-03-18 14:55:19 -07:00
aa2750bdc0 Start work on v0.16.0-SNAPSHOT 2023-03-16 17:44:48 -07:00
8 changed files with 23 additions and 19 deletions

View File

@ -5,4 +5,3 @@ Concrete is a Gradle plugin for Bukkit projects. Originally spawned out of the G
## Contributors
- [@azenla](https://github.com/azenla)
- [@kubeliv](https://github.com/kubeliv)

View File

@ -9,7 +9,7 @@ plugins {
}
group = "gay.pizza.foundation"
version = "0.15.0"
version = "0.16.0"
repositories {
mavenCentral()
@ -17,9 +17,9 @@ repositories {
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10")
implementation("org.jetbrains.kotlin:kotlin-serialization:1.8.10")
implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.2")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21")
implementation("org.jetbrains.kotlin:kotlin-serialization:1.8.21")
implementation("com.github.johnrengelman:shadow:8.1.1")
implementation("com.google.code.gson:gson:2.10.1")
// Implementation of crypto used in smart downloader.
@ -128,7 +128,7 @@ publishing {
}
tasks.withType<Wrapper> {
gradleVersion = "8.0"
gradleVersion = "8.1.1"
}
java {

View File

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,7 +1,6 @@
package gay.pizza.foundation.concrete
import org.gradle.api.Project
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.get
import org.gradle.language.jvm.tasks.ProcessResources

View File

@ -1,9 +1,13 @@
package gay.pizza.foundation.concrete
import java.net.URI
import java.nio.file.Files
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse.BodyHandlers
import java.nio.file.Path
import java.security.MessageDigest
import kotlin.io.path.exists
import kotlin.io.path.inputStream
class SmartDownloader(
private val localFilePath: Path,
@ -20,23 +24,25 @@ class SmartDownloader(
}
private fun downloadRemoteFile() {
val url = remoteDownloadUrl.toURL()
val remoteFileStream = url.openStream()
val localFileStream = Files.newOutputStream(localFilePath)
remoteFileStream.transferTo(localFileStream)
val httpClient = HttpClient.newHttpClient()
val request = HttpRequest.newBuilder()
.GET()
.uri(remoteDownloadUrl)
.build()
httpClient.send(request, BodyHandlers.ofFile(localFilePath))
val hashResult = checkLocalFileHash()
if (hashResult != HashResult.ValidHash) {
throw RuntimeException("Download of $remoteDownloadUrl did not result in valid hash.")
throw RuntimeException("Download of $remoteDownloadUrl did not result in a valid hash.")
}
}
private fun checkLocalFileHash(): HashResult {
if (!Files.exists(localFilePath)) {
if (!localFilePath.exists()) {
return HashResult.DoesNotExist
}
val digest = MessageDigest.getInstance("SHA-256")
val localFileStream = Files.newInputStream(localFilePath)
val localFileStream = localFilePath.inputStream()
val buffer = ByteArray(16 * 1024)
while (true) {