Skip to content

Commit 5d78351

Browse files
chore: Update Gradle wrapper to version 8.14.1
I've upgraded the Gradle wrapper to use Gradle version 8.14.1. This updates the `distributionUrl` in `gradle/wrapper/gradle-wrapper.properties` and ensures associated wrapper scripts are consistent. Using a more recent Gradle version helps with performance, compatibility with modern JDKs and Kotlin, and access to new Gradle features.
1 parent 35a39db commit 5d78351

File tree

8 files changed

+286
-136
lines changed

8 files changed

+286
-136
lines changed

build.gradle.kts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22
import com.github.jengelman.gradle.plugins.shadow.transformers.ComponentsXmlResourceTransformer
3-
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
3+
import java.util.Locale // Added for toLowerCase
44
import java.time.ZoneOffset
55
import java.time.ZonedDateTime
6+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget // Moved import to top
67

7-
val kotlinVersion: String = "2.1.21-embedded"
8+
val kotlinVersion: String = "2.2.0-RC2"
89

910
plugins {
10-
kotlin("jvm") version "2.1.21-embedded"
11+
kotlin("jvm") version "2.2.0-RC2"
1112
application
1213
id("com.adarshr.test-logger") version "3.2.0"
1314
id("com.github.gmazzo.buildconfig") version "3.1.0"
@@ -72,16 +73,16 @@ idea {
7273

7374
java {
7475
toolchain {
75-
languageVersion.set(JavaLanguageVersion.of(11))
76+
languageVersion.set(JavaLanguageVersion.of(21))
7677
}
7778

7879
withJavadocJar()
7980
withSourcesJar()
8081
}
8182

82-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
83-
kotlinOptions {
84-
jvmTarget = "11"
83+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach { // Changed .all to .configureEach as per modern practice
84+
compilerOptions {
85+
jvmTarget.set(JvmTarget.JVM_21)
8586
}
8687
}
8788

@@ -187,7 +188,7 @@ application {
187188
}
188189

189190
fun adjustVersion(archiveVersion: String): String {
190-
var newVersion = archiveVersion.toLowerCaseAsciiOnly()
191+
var newVersion = archiveVersion.lowercase(Locale.ROOT) // Changed to lowercase(Locale.ROOT)
191192

192193
val temporaryVersion = newVersion.substringBeforeLast(".")
193194

@@ -304,11 +305,12 @@ dependencies {
304305

305306
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
306307
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
307-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
308+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0") // Updated for Kotlin 2.0.0
308309

309310
implementation("org.jetbrains.kotlin:kotlin-scripting-common:$kotlinVersion")
310311
implementation("org.jetbrains.kotlin:kotlin-scripting-jvm:$kotlinVersion")
311312
implementation("org.jetbrains.kotlin:kotlin-scripting-dependencies-maven-all:$kotlinVersion")
313+
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:2.2.0-RC2") // Added as requested
312314

313315
implementation("org.apache.commons:commons-lang3:3.12.0")
314316
implementation("commons-io:commons-io:2.11.0")

examples/find_large_files.kts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env kscript
2+
@file:DependsOn("com.github.ajalt:clikt:3.2.0") // For command line parsing
3+
4+
import com.github.ajalt.clikt.core.CliktCommand
5+
import com.github.ajalt.clikt.parameters.options.*
6+
import com.github.ajalt.clikt.parameters.types.long
7+
import com.github.ajalt.clikt.parameters.types.path
8+
import java.io.File
9+
import java.nio.file.Files
10+
import java.nio.file.Path
11+
import java.util.zip.ZipEntry
12+
import java.util.zip.ZipOutputStream
13+
14+
class FindLargeFiles : CliktCommand(help = "Finds files larger than a specified size and optionally zips them.") {
15+
val directory: Path by option("-d", "--directory", help = "Directory to search (default: current directory)")
16+
.path(mustExist = true, canBeFile = false, mustBeReadable = true)
17+
.default(Path.of("."))
18+
19+
val minSize: Long by option("-s", "--size", help = "Minimum file size in MB")
20+
.long()
21+
.default(100L)
22+
23+
val archivePath: Path? by option("-a", "--archive", help = "Optional ZIP file path to archive found files")
24+
.path(canBeDir = false) // Removed mustBeWritable as it causes issues if file doesn't exist for parent dir check
25+
26+
val quiet: Boolean by option("-q", "--quiet", help = "Suppress listing of found files").flag(default = false)
27+
28+
val force: Boolean by option("-f", "--force", help="Force overwrite of existing archive").flag(default = false)
29+
30+
31+
override fun run() {
32+
val minSizeBytes = minSize * 1024 * 1024
33+
if (!quiet) {
34+
echo("Searching for files larger than $minSize MB ($minSizeBytes bytes) in directory: $directory")
35+
}
36+
37+
val largeFiles = mutableListOf<File>()
38+
39+
directory.toFile().walkTopDown().forEach { file ->
40+
if (file.isFile && file.length() >= minSizeBytes) {
41+
largeFiles.add(file)
42+
if (!quiet) {
43+
echo("Found: ${file.absolutePath} (${file.length() / (1024 * 1024)} MB)")
44+
}
45+
}
46+
}
47+
48+
if (largeFiles.isEmpty()) {
49+
if (!quiet) {
50+
echo("No files found larger than $minSize MB.")
51+
}
52+
return
53+
}
54+
55+
if (!quiet) {
56+
echo("\nFound ${largeFiles.size} file(s) larger than $minSize MB.")
57+
}
58+
59+
archivePath?.let { zipPath ->
60+
if (Files.exists(zipPath) && !force) {
61+
// Simplified prompt for non-interactive, or use a different Clikt mechanism for actual prompting if needed
62+
val shouldOverwrite = System.getenv("KSCRIPT_OVERWRITE_ARCHIVE") == "true" // Example: control via env var
63+
if (!shouldOverwrite) {
64+
echo("Archive '$zipPath' exists. Overwrite not forced and not confirmed. Archiving cancelled.", err = true)
65+
return
66+
}
67+
}
68+
69+
if (!quiet) {
70+
echo("Archiving ${largeFiles.size} file(s) to $zipPath ...")
71+
}
72+
try {
73+
ZipOutputStream(Files.newOutputStream(zipPath)).use { zos ->
74+
largeFiles.forEach { file ->
75+
// Ensure relative paths for zip entries if directory is not current
76+
val entryPath = if (directory.toFile().absolutePath == Path.of(".").toFile().absolutePath) {
77+
file.toPath() // Use relative path if searching "."
78+
} else {
79+
directory.relativize(file.toPath())
80+
}
81+
val zipEntry = ZipEntry(entryPath.toString())
82+
zos.putNextEntry(zipEntry)
83+
Files.copy(file.toPath(), zos)
84+
zos.closeEntry()
85+
if (!quiet) {
86+
echo(" Added: ${file.name}")
87+
}
88+
}
89+
}
90+
if (!quiet) {
91+
echo("Archiving complete: $zipPath")
92+
}
93+
} catch (e: Exception) {
94+
echo("Error during archiving: ${e.message}", err = true)
95+
// e.printStackTrace() // for more detailed debug if necessary
96+
}
97+
}
98+
}
99+
}
100+
101+
fun main(args: Array<String>) = FindLargeFiles().main(args)

examples/test_kotlin2_feature.kts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env kscript
2+
3+
// This script uses a 'value class', a feature refined in modern Kotlin.
4+
@JvmInline
5+
value class UserId(val id: String) {
6+
fun greet(): String = "Hello, User '${id}' from a value class!"
7+
}
8+
9+
fun main() {
10+
val userId = UserId("KTS_User_123")
11+
val greeting = userId.greet()
12+
println(greeting)
13+
println("Kotlin 2.x feature (value class) test successful!")
14+
}
15+
16+
main()

gradle/wrapper/gradle-wrapper.jar

34 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

gradlew

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144144
case $MAX_FD in #(
145145
max*)
146146
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
147-
# shellcheck disable=SC3045
147+
# shellcheck disable=SC3045
148148
MAX_FD=$( ulimit -H -n ) ||
149149
warn "Could not query maximum file descriptor limit"
150150
esac
151151
case $MAX_FD in #(
152152
'' | soft) :;; #(
153153
*)
154154
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
155-
# shellcheck disable=SC3045
155+
# shellcheck disable=SC3045
156156
ulimit -n "$MAX_FD" ||
157157
warn "Could not set maximum file descriptor limit to $MAX_FD"
158158
esac

test/test_js_wrapper.js

100644100755
Lines changed: 85 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,101 @@ const { spawn } = require('child_process');
33
const path = require('path');
44
const fs = require('fs');
55

6-
const projectRoot = path.resolve(__dirname, '..');
7-
const jsWrapperPath = path.join(projectRoot, 'wrappers', 'kscript_js_wrapper.js');
8-
const testScriptPath = path.join(projectRoot, 'examples', 'test_wrapper.kts');
6+
function runKscriptTest(kscriptFile, expectedOutputSubstring) {
7+
return new Promise((resolve) => { // Removed reject, will resolve with true/false
8+
console.log(`Running Node.js kscript test: ${kscriptFile}...`);
99

10-
console.log(`Project root: ${projectRoot}`);
11-
console.log(`Executing: node ${jsWrapperPath} ${testScriptPath}`);
10+
const projectRoot = path.resolve(__dirname, '..');
11+
const jarPath = path.join(projectRoot, 'wrappers', 'kscript.jar');
12+
const wrapperScriptPath = path.join(projectRoot, 'wrappers', 'kscript_js_wrapper.js');
13+
const kscriptFilePath = path.join(projectRoot, 'examples', kscriptFile);
1214

13-
// Check if wrapper exists
14-
if (!fs.existsSync(jsWrapperPath)) {
15-
console.error(`JavaScript wrapper not found at ${jsWrapperPath}`);
16-
process.exit(1);
17-
}
15+
if (!fs.existsSync(jarPath)) {
16+
console.error(`ERROR: kscript.jar not found at ${jarPath}`);
17+
console.log(`Node.js wrapper test for ${kscriptFile} SKIPPED due to missing kscript.jar.`);
18+
resolve(false);
19+
return;
20+
}
1821

19-
// Check if test kts script exists
20-
if (!fs.existsSync(testScriptPath)) {
21-
console.error(`Test kts script not found at ${testScriptPath}`);
22-
process.exit(1);
23-
}
22+
if (!fs.existsSync(wrapperScriptPath)) {
23+
console.error(`ERROR: Node.js wrapper script not found at ${wrapperScriptPath}`);
24+
resolve(false);
25+
return;
26+
}
2427

25-
const kscriptProcess = spawn('node', [jsWrapperPath, testScriptPath], {
26-
stdio: ['pipe', 'pipe', 'pipe'], // Pipe stdin, stdout, stderr
27-
timeout: 30000 // 30 seconds timeout
28-
});
28+
if (!fs.existsSync(kscriptFilePath)) {
29+
console.error(`ERROR: Test kscript file not found at ${kscriptFilePath}`);
30+
resolve(false);
31+
return;
32+
}
2933

30-
let stdoutData = '';
31-
let stderrData = '';
34+
console.log(`Executing command: node ${wrapperScriptPath} ${kscriptFilePath}`);
35+
const kscriptProcess = spawn('node', [wrapperScriptPath, kscriptFilePath], {
36+
stdio: ['pipe', 'pipe', 'pipe'],
37+
timeout: 60000 // 60 seconds timeout, increased for kscript compilation
38+
});
3239

33-
kscriptProcess.stdout.on('data', (data) => {
34-
stdoutData += data.toString();
35-
});
40+
let stdoutData = '';
41+
let stderrData = '';
3642

37-
kscriptProcess.stderr.on('data', (data) => {
38-
stderrData += data.toString();
39-
});
43+
kscriptProcess.stdout.on('data', (data) => { stdoutData += data.toString(); });
44+
kscriptProcess.stderr.on('data', (data) => { stderrData += data.toString(); });
4045

41-
kscriptProcess.on('close', (code) => {
42-
stdoutData = stdoutData.trim();
43-
stderrData = stderrData.trim();
46+
// Timeout handling is implicitly done by spawn's timeout option, which emits 'error' with err.code 'ETIMEDOUT'
47+
// or kills the process and it closes with a signal code.
4448

45-
console.log(`Return Code: ${code}`);
46-
console.log(`Stdout:\n${stdoutData}`);
47-
if (stderrData) {
48-
console.log(`Stderr:\n${stderrData}`);
49-
}
49+
kscriptProcess.on('close', (code, signal) => {
50+
stdoutData = stdoutData.trim();
51+
stderrData = stderrData.trim();
5052

51-
// Similar to the Python test, kscript.jar and Java might not be available.
52-
// We're checking if the wrapper attempts the execution.
53-
54-
if (stdoutData.includes("kscript wrapper test successful!")) {
55-
console.log("JavaScript wrapper test potentially successful (if kscript.jar was runnable)!");
56-
// In a real test environment:
57-
// if (code === 0 && stdoutData.includes("kscript wrapper test successful!")) {
58-
// console.log("JavaScript wrapper test successful!");
59-
// process.exit(0);
60-
// } else {
61-
// console.error("JavaScript wrapper test failed: Output or return code mismatch.");
62-
// process.exit(1);
63-
// }
64-
process.exit(0); // For now, assume success if output is seen
65-
66-
} else if (stderrData.includes("ENOENT") && stderrData.includes("java")) {
67-
// This error (ENOENT spawn java ENOENT) means the system couldn't find 'java' command
68-
console.log("JavaScript wrapper test partially passed: 'java' command not found, as might be expected in a limited test env.");
69-
process.exit(0);
70-
} else if (stderrData.toLowerCase().includes("error executing jar") || (stderrData.includes("kscript.jar") && (stderrData.includes("not found") || stderrData.includes("no such file")))) {
71-
console.log("JavaScript wrapper test partially passed: kscript.jar not found or error during Java execution, as might be expected (no Java/JAR in test env).");
53+
if (stdoutData) console.log(`Stdout:\n${stdoutData}`);
54+
if (stderrData) console.error(`Stderr:\n${stderrData}`);
55+
56+
if (signal) { // Process was killed, e.g. by timeout
57+
console.error(`Test FAILED for ${kscriptFile} due to signal: ${signal}`);
58+
resolve(false);
59+
} else if (code === 0 && stdoutData.includes(expectedOutputSubstring)) {
60+
console.log(`Test PASSED for ${kscriptFile}!`);
61+
resolve(true);
62+
} else {
63+
console.error(`Test FAILED for ${kscriptFile}. Exit code: ${code}`);
64+
if (!stdoutData.includes(expectedOutputSubstring)) {
65+
console.error(`Expected substring '${expectedOutputSubstring}' not found in stdout.`);
66+
}
67+
resolve(false);
68+
}
69+
});
70+
71+
kscriptProcess.on('error', (err) => {
72+
// This 'error' event usually means the process could not be spawned or was killed due to timeout.
73+
if (err.code === 'ETIMEDOUT') {
74+
console.error(`Test TIMEOUT for ${kscriptFile}`);
75+
} else {
76+
console.error(`Test ERRORED for ${kscriptFile}: ${err.message}`);
77+
}
78+
// Ensure stderrData from the process is also logged if available
79+
if (stderrData.trim()) console.error(`Stderr (on error event):\n${stderrData.trim()}`);
80+
resolve(false);
81+
});
82+
});
83+
}
84+
85+
async function main() {
86+
console.log("Starting Node.js wrapper tests...");
87+
// Similar to the Python test, this version is stricter and expects kscript.jar to be present.
88+
// If java and kscript.jar are not functional, the wrapper will likely forward an error from java,
89+
// which will be caught as a test failure.
90+
91+
const test1Success = await runKscriptTest('test_wrapper.kts', 'kscript wrapper test successful!');
92+
const test2Success = await runKscriptTest('test_kotlin2_feature.kts', 'Kotlin 2.x feature (value class) test successful!');
93+
94+
if (test1Success && test2Success) {
95+
console.log("All Node.js wrapper tests PASSED!");
7296
process.exit(0);
73-
}
74-
else {
75-
console.error("JavaScript wrapper test failed: Did not see expected success message or known error conditions for missing Java/JAR.");
97+
} else {
98+
console.error("One or more Node.js wrapper tests FAILED or were SKIPPED.");
7699
process.exit(1);
77100
}
78-
});
79-
80-
kscriptProcess.on('error', (err) => {
81-
console.error(`Failed to start subprocess: ${err.message}`);
82-
process.exit(1);
83-
});
84-
85-
kscriptProcess.on('timeout', () => {
86-
console.error('JavaScript wrapper test failed: Timeout expired.');
87-
kscriptProcess.kill(); // Ensure the process is killed on timeout
88-
process.exit(1);
89-
});
101+
}
102+
103+
main();

0 commit comments

Comments
 (0)