create versioning system

This commit is contained in:
Bryson Steck 2023-05-27 00:22:51 -06:00
parent 443a153024
commit 88802ece04
4 changed files with 40 additions and 6 deletions

View file

@ -32,8 +32,6 @@ plugins {
apply plugin: 'io.github.fvarrui.javapackager.plugin' apply plugin: 'io.github.fvarrui.javapackager.plugin'
version = "1.0"
repositories { repositories {
// Use Maven Central for resolving dependencies. // Use Maven Central for resolving dependencies.
mavenCentral() mavenCentral()
@ -112,6 +110,28 @@ task pack(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: bu
} }
} }
task createProperties(dependsOn: processResources) {
doLast {
def stdout = new ByteArrayOutputStream()
if (project.hasProperty("release")) {
project.version = 1.0
} else {
exec {
commandLine "git", "log", "-n", "1", "--pretty=format:\"%h\""
standardOutput = stdout
}
project.version = "git(" + stdout.toString().trim().replaceAll("\"", "") + ")"
}
new File("$buildDir/resources/main/xyz/brysonsteck/ServerCraft/info.properties").withWriter { w ->
Properties p = new Properties()
p['version'] = project.version.toString()
p.store w, null
}
}
}
build.doLast { build.doLast {
if (OperatingSystem.current().isLinux()) { if (OperatingSystem.current().isLinux()) {
exec { exec {
@ -125,6 +145,10 @@ build.doLast {
} }
} }
classes {
dependsOn createProperties
}
javafx { javafx {
version = "20" version = "20"
modules = ['javafx.controls', 'javafx.fxml', 'javafx.graphics'] modules = ['javafx.controls', 'javafx.fxml', 'javafx.graphics']

View file

@ -4,12 +4,18 @@ import javafx.fxml.FXML
import javafx.application.Platform import javafx.application.Platform
import javafx.scene.Node import javafx.scene.Node
import javafx.scene.control.Hyperlink import javafx.scene.control.Hyperlink
import javafx.scene.control.Label
import javafx.stage.Stage import javafx.stage.Stage
import javafx.event.ActionEvent import javafx.event.ActionEvent
import java.awt.Desktop import java.awt.Desktop
import java.net.URI import java.net.URI
import java.util.Properties
import xyz.brysonsteck.ServerCraft.App
class InfoController { class InfoController {
@FXML
lateinit private var version: Label
private val emails = mapOf( private val emails = mapOf(
"bryson" to "me@brysonsteck.xyz" "bryson" to "me@brysonsteck.xyz"
) )
@ -19,6 +25,13 @@ class InfoController {
private val source = "https://codeberg.org/brysonsteck/ServerCraft" private val source = "https://codeberg.org/brysonsteck/ServerCraft"
private val license = "https://www.gnu.org/licenses/gpl-3.0.html" private val license = "https://www.gnu.org/licenses/gpl-3.0.html"
@FXML
public fun initialize() {
val props = Properties()
props.load(App().javaClass.getResourceAsStream("info.properties"))
version.text += props.getProperty("version")
}
@FXML @FXML
private fun openHyperlink(e: ActionEvent) { private fun openHyperlink(e: ActionEvent) {
val link = e.source as Hyperlink val link = e.source as Hyperlink
@ -52,7 +65,6 @@ class InfoController {
} }
} }
split[0].equals("license") -> { split[0].equals("license") -> {
println("license")
if (!os.contains("linux")) { if (!os.contains("linux")) {
desktop.browse(URI(license)) desktop.browse(URI(license))
} else { } else {

View file

@ -54,14 +54,12 @@ class Download: Runnable {
// Make sure response code is in the 200 range. // Make sure response code is in the 200 range.
if (connection.responseCode / 100 != 2) { if (connection.responseCode / 100 != 2) {
println(connection.responseCode)
status = Status.ERROR status = Status.ERROR
} }
// Check for valid content length. // Check for valid content length.
contentLength = connection.getContentLength(); contentLength = connection.getContentLength();
if (contentLength < 1) { if (contentLength < 1) {
println(connection.getContentLength())
status = Status.ERROR status = Status.ERROR
} }

View file

@ -27,7 +27,7 @@
<Font name="System Bold" size="28.0" /> <Font name="System Bold" size="28.0" />
</font> </font>
</Label> </Label>
<Label layoutX="146.0" layoutY="82.0" text="Version 1.0" /> <Label fx:id="version" layoutX="146.0" layoutY="82.0" text="Version " />
<ButtonBar layoutY="318.0" prefHeight="40.0" prefWidth="398.0"> <ButtonBar layoutY="318.0" prefHeight="40.0" prefWidth="398.0">
<buttons> <buttons>
<Button mnemonicParsing="false" onAction="#closeInfo" text="Close" /> <Button mnemonicParsing="false" onAction="#closeInfo" text="Close" />