Skip to content

Commit 202d2ac

Browse files
authored
overhaul (#68)
* overhaul * review fixes
1 parent 4c6e6b3 commit 202d2ac

31 files changed

Lines changed: 1360 additions & 1676 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ testproject/
2222
ptrtestproject/
2323
temp/
2424
invalidbuild/
25+
/gen_test_ci
26+
/gen_test_jass

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ dependencies {
4444
implementation 'com.fasterxml.jackson.core:jackson-databind'
4545
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
4646
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
47-
implementation 'com.github.frotty:SwingDarkFlatTable:1d9ae26e69'
4847
implementation 'com.github.Frotty:SimpleRegistry:f96dda96bd'
4948
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.17'
5049
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.32'
@@ -53,6 +52,7 @@ dependencies {
5352

5453
test {
5554
useTestNG()
55+
jvmArgs '-Djava.awt.headless=true'
5656
}
5757

5858
jacocoTestReport {

src/main/kotlin/config/DAOs.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import kotlin.collections.ArrayList
66

77
const val CONFIG_FILE_NAME = "wurst.build"
88

9+
enum class ScriptMode { LUA, JASS }
10+
enum class Wc3Patch { REFORGED, PRE_129 }
11+
912
/**
1013
* The root DAO that contains the child DAOs.
1114
* Represents a complete wurst.build file.
@@ -14,7 +17,9 @@ const val CONFIG_FILE_NAME = "wurst.build"
1417
data class WurstProjectConfigData(
1518
var projectName: String = "unnamed",
1619
val dependencies: ArrayList<String> = ArrayList(),
17-
val buildMapData: WurstProjectBuildMapData = WurstProjectBuildMapData()
20+
val buildMapData: WurstProjectBuildMapData = WurstProjectBuildMapData(),
21+
val scriptMode: ScriptMode? = null,
22+
val wc3Patch: Wc3Patch? = null
1823
) {
1924
constructor() : this("unnamed")
2025
}

src/main/kotlin/config/WurstProjectConfig.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ import file.*
1212
import global.InstallationManager
1313
import global.Log
1414
import logging.KotlinLogging
15-
import ui.UiManager
1615
import java.io.IOException
1716
import java.nio.file.Files
1817
import java.nio.file.Path
1918
import java.nio.file.Paths
2019
import java.nio.file.StandardOpenOption
21-
import javax.swing.JOptionPane
2220
/**
2321
* Created by Frotty on 10.07.2017.
2422
*/
@@ -32,11 +30,9 @@ object WurstProjectConfig {
3230
fun handleCreate(projectRoot: Path, gameRoot: Path?, projectConfig: WurstProjectConfigData) {
3331
try {
3432
createProject(projectRoot, gameRoot, projectConfig)
35-
UiManager.refreshComponents()
3633
} catch (e: Exception) {
3734
Log.print("\n===ERROR PROJECT CREATE===\n" + e.message + "\nPlease report here: github.com/wurstscript/WurstScript/issues\n")
3835
}
39-
4036
}
4137

4238
@Throws(IOException::class)
@@ -82,17 +78,15 @@ object WurstProjectConfig {
8278
if (extractSuccess) {
8379
Log.print("done\n")
8480
cleanupDownload(projectRoot)
81+
normalizeGeneratedTemplate(projectRoot)
8582
} else {
8683
Log.print("error\n")
87-
JOptionPane.showMessageDialog(null,
88-
"Error: Cannot extract patch files.\nWurst might still be in use.\nClose any Wurst, VSCode or Eclipse instances before updating.",
89-
"Error Massage", JOptionPane.ERROR_MESSAGE)
84+
log.error("❌ Cannot extract template files. Close any Wurst, VSCode or Eclipse instances and try again.")
9085
}
9186

9287
setupEnvironment(projectRoot, gameRoot, projectConfig)
9388

9489
log.info("✔ Project generated.")
95-
UiManager.refreshComponents()
9690
}
9791

9892
private fun cleanupDownload(projectRoot: Path) {
@@ -107,6 +101,18 @@ object WurstProjectConfig {
107101
}
108102
}
109103

104+
private fun normalizeGeneratedTemplate(projectRoot: Path) {
105+
val runArgs = projectRoot.resolve("wurst_run.args")
106+
if (Files.exists(runArgs)) {
107+
val normalizedArgs = Files.readString(runArgs)
108+
.lineSequence()
109+
.filterNot { it.trim().equals("lua", ignoreCase = true) || it.trim().equals("-lua", ignoreCase = true) }
110+
.joinToString(System.lineSeparator())
111+
.trimEnd() + System.lineSeparator()
112+
Files.writeString(runArgs, normalizedArgs)
113+
}
114+
}
115+
110116
private fun setupEnvironment(projectRoot: Path, gameRoot: Path?, projectConfig: WurstProjectConfigData) {
111117
Log.print("done\n")
112118

@@ -198,12 +204,10 @@ object WurstProjectConfig {
198204
DependencyManager.updateDependencies(projectRoot, config)
199205

200206
Log.print("Project successfully updated!\nReload vscode to apply the changed dependencies.\n")
201-
UiManager.refreshComponents()
202207
} catch (e: Exception) {
203208
e.printStackTrace()
204209
Log.print("\n===ERROR PROJECT UPDATE===\n" + e.message + "\nPlease report here: github.com/wurstscript/WurstScript/issues\n")
205210
}
206-
207211
}
208212

209213
private const val VSCODE_MIN_CONFIG =

src/main/kotlin/file/CLICommand.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package file
22

3+
import config.ScriptMode
4+
import config.Wc3Patch
5+
36
enum class CLICommand {
47
HELP,
58
INSTALL,
@@ -32,6 +35,42 @@ enum class GlobalOptions(val optionName: String = "", val argCount: Int = 0) {
3235
override fun runOption(setupMain: SetupMain, args: List<String>) {
3336
setupMain.measure = true
3437
}
38+
},
39+
WITH_AGENTS("--with-agents") {
40+
override fun runOption(setupMain: SetupMain, args: List<String>) {
41+
setupMain.addAgents = true
42+
}
43+
},
44+
NO_AGENTS("--no-agents") {
45+
override fun runOption(setupMain: SetupMain, args: List<String>) {
46+
setupMain.addAgents = false
47+
}
48+
},
49+
WITH_CI("--with-ci") {
50+
override fun runOption(setupMain: SetupMain, args: List<String>) {
51+
setupMain.addGithubWorkflow = true
52+
}
53+
},
54+
NO_CI("--no-ci") {
55+
override fun runOption(setupMain: SetupMain, args: List<String>) {
56+
setupMain.addGithubWorkflow = false
57+
}
58+
},
59+
SCRIPT_MODE("--script-mode", 1) {
60+
override fun runOption(setupMain: SetupMain, args: List<String>) {
61+
setupMain.scriptMode = when (args[0].lowercase()) {
62+
"jass" -> ScriptMode.JASS
63+
else -> ScriptMode.LUA
64+
}
65+
}
66+
},
67+
WC3_PATCH("--wc3-patch", 1) {
68+
override fun runOption(setupMain: SetupMain, args: List<String>) {
69+
setupMain.wc3Patch = when (args[0].lowercase()) {
70+
"pre1.29" -> Wc3Patch.PRE_129
71+
else -> Wc3Patch.REFORGED
72+
}
73+
}
3574
};
3675

3776
abstract fun runOption(setupMain: SetupMain, args: List<String>)

src/main/kotlin/file/Download.kt

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package file
22

33
import global.Log
4-
5-
64
import logging.KotlinLogging
7-
import ui.MainWindow
8-
import workers.DownloadWithProgressWorker
95
import java.io.BufferedInputStream
106
import java.io.BufferedOutputStream
117
import java.io.FileOutputStream
@@ -14,64 +10,56 @@ import java.net.HttpURLConnection
1410
import java.net.URL
1511
import java.nio.file.Files
1612
import java.nio.file.Path
13+
1714
object Download {
1815
private val log = KotlinLogging.logger {}
1916

2017
private const val compilerReleaseBaseUrl = "https://github.com/wurstscript/WurstScript/releases/download/nightly/"
2118
private const val bareboneUrl = "github.com/wurstscript/wurst-project-template/archive/master.zip"
2219

23-
@Throws(IOException::class)
24-
private fun downloadFile(filePath: String, callback: (Path) -> Unit) {
25-
if (SetupApp.setup.isGUILaunch) {
26-
DownloadWithProgressWorker(filePath, MainWindow.ui.progressBar, callback).execute()
27-
} else {
28-
downloadDirect(filePath, callback)
29-
}
30-
}
31-
32-
fun getHttpURLConnection(filePath: String): HttpURLConnection {
33-
val url = URL(filePath)
34-
val httpConnection = url.openConnection() as HttpURLConnection
35-
httpConnection.connectTimeout = 14000
36-
httpConnection.readTimeout = 20000
37-
httpConnection.addRequestProperty("User-Agent", "Chrome")
38-
return httpConnection
39-
}
40-
4120
@Throws(IOException::class)
4221
fun downloadSetup(callback: (Path) -> Unit) {
4322
throw UnsupportedOperationException("Standalone grill updates are not currently published via GitHub releases.")
4423
}
4524

4625
@Throws(IOException::class)
4726
fun downloadCompiler(callback: (Path) -> Unit) {
48-
downloadFile(compilerReleaseBaseUrl + getCompilerArchiveName(), callback)
27+
downloadDirect(compilerReleaseBaseUrl + getCompilerArchiveName(), callback)
4928
}
5029

5130
@Throws(IOException::class)
5231
fun downloadBareboneProject(callback: (Path) -> Unit) {
5332
try {
54-
downloadFile("https://$bareboneUrl", callback)
33+
downloadDirect("https://$bareboneUrl", callback)
5534
} catch (e: Exception) {
56-
log.warn( "downloadBareboneProject Exception caught", e)
35+
log.warn("downloadBareboneProject Exception caught", e)
5736
Log.println("Https error, falling back to unsafe http.")
58-
downloadFile("http://$bareboneUrl", callback)
37+
downloadDirect("http://$bareboneUrl", callback)
5938
}
6039
}
6140

41+
fun getHttpURLConnection(filePath: String): HttpURLConnection {
42+
val url = URL(filePath)
43+
val httpConnection = url.openConnection() as HttpURLConnection
44+
httpConnection.connectTimeout = 14000
45+
httpConnection.readTimeout = 20000
46+
httpConnection.addRequestProperty("User-Agent", "Chrome")
47+
return httpConnection
48+
}
49+
6250
private fun downloadDirect(filePath: String, callback: (Path) -> Unit) {
63-
val httpConnection = getHttpURLConnection(filePath)
64-
val completeFileSize = httpConnection.contentLength
65-
val size = completeFileSize / 1024 / 1024
66-
log.info("\t\uD83D\uDCE5 (" + (if (size == 0) "<1" else size) + "MB)")
67-
val input = java.io.BufferedInputStream(httpConnection.inputStream)
68-
val downloadedFile = createDownloadTempFile(filePath)
51+
val httpConnection = getHttpURLConnection(filePath)
52+
val completeFileSize = httpConnection.contentLength
53+
val size = completeFileSize / 1024 / 1024
54+
log.info("\t📥 (" + (if (size == 0) "<1" else size) + "MB)")
55+
val input = BufferedInputStream(httpConnection.inputStream)
56+
val downloadedFile = createDownloadTempFile(filePath)
6957

70-
readStream(downloadedFile, input)
58+
readStream(downloadedFile, input)
7159

72-
input.close()
73-
callback.invoke(downloadedFile)
74-
}
60+
input.close()
61+
callback.invoke(downloadedFile)
62+
}
7563

7664
private fun readStream(destination: Path, input: BufferedInputStream) {
7765
FileOutputStream(destination.toFile()).use { fos ->

0 commit comments

Comments
 (0)