From 9a1817e859a21b84fde9717edd2fe2e020d95f85 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 3 May 2025 22:09:32 +0800 Subject: [PATCH] feat: init commit --- .gitignore | 8 ++++- build.gradle | 34 +++++++++++++++++++ justfile | 8 +++++ src/main/java/me/hatter/demo/TestCli.java | 24 +++++++++++++ .../hatter/demo/commands/DemoSubCommand.java | 16 +++++++++ .../META-INF/native-image/reflect-config.json | 9 +++++ 6 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 build.gradle create mode 100644 justfile create mode 100644 src/main/java/me/hatter/demo/TestCli.java create mode 100644 src/main/java/me/hatter/demo/commands/DemoSubCommand.java create mode 100644 src/main/resources/META-INF/native-image/reflect-config.json diff --git a/.gitignore b/.gitignore index 5760a7a..4434647 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +native-application.iml +native-application.ipr +native-application.iws +.gradle/ +build/ # ---> Java # Compiled class file *.class @@ -31,7 +36,8 @@ replay_pid* .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..3d16ee1 --- /dev/null +++ b/build.gradle @@ -0,0 +1,34 @@ +plugins { + id 'idea' + id 'application' + id 'org.graalvm.buildtools.native' version '0.10.6' +} + +def addRepo = new File(System.getProperty("user.home"), ".build_add.repo") + +repositories { + mavenLocal() + maven() { url 'https://maven.aliyun.com/repository/central' } + mavenCentral() + jcenter() +} + +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' + annotationProcessor 'info.picocli:picocli-codegen:4.7.7' + implementation 'com.google.guava:guava:30.0-jre' + implementation("commons-lang:commons-lang:2.6") + implementation("commons-io:commons-io:2.19.0") + implementation("info.picocli:picocli:4.7.7") + implementation("com.google.code.gson:gson:2.13.1") +} + + +application { + mainClass = 'me.hatter.demo.TestCli' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/justfile b/justfile new file mode 100644 index 0000000..6f98328 --- /dev/null +++ b/justfile @@ -0,0 +1,8 @@ +_: + @just --list + +idea: + buildj :::gradle8.14 idea + +build: + JAVA_HOME=$HOME/.sdkman/candidates/java/24.0.1-graal/ buildj :::gradle8.14 nativeCompile diff --git a/src/main/java/me/hatter/demo/TestCli.java b/src/main/java/me/hatter/demo/TestCli.java new file mode 100644 index 0000000..8a3cd5f --- /dev/null +++ b/src/main/java/me/hatter/demo/TestCli.java @@ -0,0 +1,24 @@ +package me.hatter.demo; + +import me.hatter.demo.commands.DemoSubCommand; +import picocli.CommandLine; +import picocli.CommandLine.Command; + +@Command(name = "example", + mixinStandardHelpOptions = true, + version = "Picocli example 1.0", + subcommands = { + DemoSubCommand.class + }) +public class TestCli implements Runnable { + + public static void main(String[] args) { + int exitCode = new CommandLine(new TestCli()).execute(args); + System.exit(exitCode); + } + + public void run() { + System.out.println("Use --help for help"); + } +} + diff --git a/src/main/java/me/hatter/demo/commands/DemoSubCommand.java b/src/main/java/me/hatter/demo/commands/DemoSubCommand.java new file mode 100644 index 0000000..5ee6886 --- /dev/null +++ b/src/main/java/me/hatter/demo/commands/DemoSubCommand.java @@ -0,0 +1,16 @@ +package me.hatter.demo.commands; + + +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; + +@Command(name = "demo", description = "Demo subcommand") +public class DemoSubCommand implements Runnable { + @Option(names = {"-h", "--help"}, usageHelp = true, description = "Show this help message and exit.")//, hidden = true) + boolean helpRequested = false; + + @Override + public void run() { + System.out.println("Subcommand demo."); + } +} \ No newline at end of file diff --git a/src/main/resources/META-INF/native-image/reflect-config.json b/src/main/resources/META-INF/native-image/reflect-config.json new file mode 100644 index 0000000..dc01b65 --- /dev/null +++ b/src/main/resources/META-INF/native-image/reflect-config.json @@ -0,0 +1,9 @@ +[ + { + "name": "com.aliyun.security.llm.objects.ScannerArchiveMeta", + "allDeclaredConstructors": true, + "allDeclaredMethods": true, + "allDeclaredFields": true, + "unsafeAllocated": true + } +]