generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdb9568
commit 56929d7
Showing
28 changed files
with
468 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2024 Oracle and/or its affiliates | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
id 'gdk-module' | ||
id 'io.micronaut.application' | ||
id 'com.github.johnrengelman.shadow' | ||
} | ||
|
||
dependencies { | ||
annotationProcessor mnLibs.picocli.codegen | ||
|
||
compileOnly mnLibs.graal | ||
|
||
implementation projects.gdkCliCore | ||
|
||
runtimeOnly libs.bouncycastle.bcpkix | ||
runtimeOnly libs.bouncycastle.bcprov | ||
runtimeOnly libs.jansi | ||
runtimeOnly libs.jline | ||
runtimeOnly libs.slf4j.nop | ||
} | ||
|
||
configurations.configureEach { | ||
exclude module: 'logback-classic' | ||
} | ||
|
||
micronaut { | ||
version libs.micronaut.starter.api.get().version | ||
processing { | ||
incremental true | ||
annotations 'cloud.graal.gdk.*' | ||
} | ||
} | ||
|
||
tasks.named('shadowJar') { | ||
mergeServiceFiles() | ||
} | ||
|
||
tasks.named('shadowDistZip') { | ||
enabled = false | ||
} | ||
tasks.named('shadowDistTar') { | ||
enabled = false | ||
} | ||
|
||
tasks.register('copyShadowJar', Sync) { | ||
from shadowJar.outputs | ||
into "${project.rootProject.buildDir}/libs" | ||
rename { String fileName -> 'cli.jar' } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2024 Oracle and/or its affiliates | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
id 'gdk-module' | ||
id 'com.diffplug.spotless' | ||
} | ||
|
||
spotless { | ||
java { | ||
licenseHeaderFile rootProject.file('config/spotless.license.java') | ||
target 'src/main/java/**' | ||
targetExclude '**/*.rocker.raw', '**/GdkBaseCommand.java', '**/GdkStarter.java', '**/AbstractStarter.java' | ||
} | ||
format 'javaMisc', { | ||
target 'src/main/**/package-info.java', 'src/main/**/module-info.java' | ||
licenseHeaderFile rootProject.file('config/spotless.license.java'), '\\/\\*\\*' | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2024 Oracle and/or its affiliates | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
id 'groovy' | ||
id 'com.adarshr.test-logger' | ||
id 'io.micronaut.library' | ||
} | ||
|
||
micronaut { | ||
testRuntime 'spock2' | ||
} | ||
|
||
test { | ||
maxHeapSize = '16G' | ||
} | ||
|
||
testlogger { | ||
theme 'standard-parallel' | ||
showFullStackTraces true | ||
showStandardStreams true | ||
showPassedStandardStreams false | ||
showSkippedStandardStreams false | ||
showFailedStandardStreams true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= gdk-cli-core | ||
|
||
This submodule is a reusable library contains most of the code for the CLI except for the main class and the build configuration to enable running the CLI. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2024 Oracle and/or its affiliates | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
id 'gdk-module-public' | ||
id 'io.micronaut.library' | ||
} | ||
|
||
dependencies { | ||
annotationProcessor mnLibs.picocli.codegen | ||
|
||
// not in libs.versions.toml to keep Micronaut version in one place | ||
api(libs.micronaut.starter.cli) { | ||
exclude group: 'io.micronaut', module: 'micronaut-buffer-netty' | ||
exclude group: 'io.micronaut', module: 'micronaut-http-client' | ||
exclude group: 'io.micronaut', module: 'micronaut-http-client-core' | ||
exclude group: 'io.micronaut', module: 'micronaut-http-netty' | ||
exclude group: 'io.micronaut', module: 'micronaut-websocket' | ||
exclude group: 'io.micronaut.testresources', module: 'micronaut-test-resources-build-tools' | ||
exclude group: 'io.netty', module: 'netty-buffer' | ||
exclude group: 'io.netty', module: 'netty-codec' | ||
exclude group: 'io.netty', module: 'netty-codec-http' | ||
exclude group: 'io.netty', module: 'netty-codec-http2' | ||
exclude group: 'io.netty', module: 'netty-codec-socks' | ||
exclude group: 'io.netty', module: 'netty-common' | ||
exclude group: 'io.netty', module: 'netty-handler' | ||
exclude group: 'io.netty', module: 'netty-handler-proxy' | ||
exclude group: 'io.netty', module: 'netty-resolver' | ||
exclude group: 'io.netty', module: 'netty-transport' | ||
exclude group: 'io.swagger.core.v3', module: 'swagger-annotations' | ||
exclude group: 'org.eclipse.jgit', module: 'org.eclipse.jgit' | ||
exclude group: 'org.jline', module: 'jline' | ||
} | ||
api mnLibs.micronaut.picocli | ||
api mnLibs.picocli | ||
api mnLibs.micronaut.jackson.databind | ||
api mnLibs.micronaut.validation | ||
api projects.gdkCore | ||
} | ||
|
||
micronaut { | ||
version libs.micronaut.starter.api.get().version | ||
processing { | ||
incremental true | ||
annotations 'cloud.graal.gdk.*' | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
gdk/gdk-cli-core/src/main/java/cloud/graal/gdk/AbstractStarter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright 2017-2022 original authors | ||
* Copyright 2024 Oracle and/or its affiliates | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cloud.graal.gdk; | ||
|
||
import cloud.graal.gdk.command.GdkBaseCommand; | ||
import io.micronaut.context.ApplicationContext; | ||
import io.micronaut.context.BeanContext; | ||
import io.micronaut.inject.BeanDefinition; | ||
import io.micronaut.starter.cli.CodeGenConfig; | ||
import io.micronaut.starter.cli.InteractiveShell; | ||
import io.micronaut.starter.cli.MicronautFactory; | ||
import io.micronaut.starter.cli.command.CodeGenCommand; | ||
import io.micronaut.starter.io.ConsoleOutput; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.ParameterException; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
/** | ||
* Base class for CLI main classes. Starts an interactive shell if passed no | ||
* arguments, otherwise instantiates the requested command class. | ||
* <p> | ||
* Based on io.micronaut.starter.cli.MicronautStarter. | ||
*/ | ||
public abstract class AbstractStarter extends GdkBaseCommand { | ||
|
||
protected static final BiFunction<Throwable, CommandLine, Integer> EXCEPTION_HANDLER = (e, commandLine) -> { | ||
GdkBaseCommand command = commandLine.getCommand(); | ||
command.err(e.getMessage()); | ||
if (command.showStacktrace()) { | ||
e.printStackTrace(commandLine.getErr()); | ||
} | ||
return 1; | ||
}; | ||
|
||
protected boolean interactiveShell = false; | ||
|
||
protected CommandLine createCommandLine() { | ||
boolean noOpConsole = interactiveShell; | ||
try (BeanContext beanContext = ApplicationContext.builder().deduceEnvironment(false).start()) { | ||
return createCommandLine(beanContext, noOpConsole); | ||
} | ||
} | ||
|
||
protected int execute(String[] args) { | ||
boolean noOpConsole = args.length > 0 && args[0].startsWith("update-cli-config"); | ||
try (BeanContext beanContext = ApplicationContext.builder().deduceEnvironment(false).start()) { | ||
return createCommandLine(beanContext, noOpConsole).execute(args); | ||
} | ||
} | ||
|
||
protected CommandLine createCommandLine(BeanContext beanContext, boolean noOpConsole) { | ||
CommandLine commandLine = new CommandLine(this, new MicronautFactory(beanContext)); | ||
commandLine.setExecutionExceptionHandler((ex, commandLine1, parseResult) -> EXCEPTION_HANDLER.apply(ex, commandLine1)); | ||
commandLine.setUsageHelpWidth(100); | ||
|
||
addCodegenCommands(beanContext, noOpConsole, commandLine); | ||
|
||
return commandLine; | ||
} | ||
|
||
protected void addCodegenCommands(BeanContext beanContext, boolean noOpConsole, CommandLine commandLine) { | ||
CodeGenConfig codeGenConfig = CodeGenConfig.load(beanContext, noOpConsole ? ConsoleOutput.NOOP : this); | ||
if (codeGenConfig != null) { | ||
beanContext.getBeanDefinitions(CodeGenCommand.class).stream() | ||
.map(BeanDefinition::getBeanType) | ||
.map(bt -> beanContext.createBean(bt, codeGenConfig)) | ||
.filter(CodeGenCommand::applies) | ||
.forEach(commandLine::addSubcommand); | ||
} | ||
} | ||
|
||
/** | ||
* @return the name of the cli, for use in the interactive shell. | ||
*/ | ||
protected String getCliName() { | ||
return "gdk"; | ||
} | ||
|
||
protected void startShell() { | ||
CommandLine commandLine = createCommandLine(); | ||
interactiveShell = true; | ||
new InteractiveShell(commandLine, this::execute, EXCEPTION_HANDLER, "@|blue " + getCliName() + ">|@ ").start(); | ||
} | ||
|
||
@Override | ||
public Integer call() { | ||
throw new ParameterException(spec.commandLine(), "No command specified"); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
gdk/gdk-cli-core/src/main/java/cloud/graal/gdk/command/AbstractExternalCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2024 Oracle and/or its affiliates | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cloud.graal.gdk.command; | ||
|
||
/** | ||
* Convenience base class for external commands. | ||
*/ | ||
public abstract class AbstractExternalCommand extends GdkBaseCommand implements ExternalCommand { | ||
} |
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
gdk/gdk-cli-core/src/main/java/cloud/graal/gdk/command/ExternalCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2024 Oracle and/or its affiliates | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cloud.graal.gdk.command; | ||
|
||
/** | ||
* Marker interface for addon commands, e.g. extensions created by users. | ||
*/ | ||
public interface ExternalCommand { | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.