Skip to content

Commit

Permalink
use new devcontainer.java library
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Hoß committed Dec 7, 2022
1 parent aea2c1b commit 2883161
Show file tree
Hide file tree
Showing 31 changed files with 209 additions and 483 deletions.
20 changes: 12 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>wtf.metio.maven.parents</groupId>
<artifactId>maven-parents-java-stable</artifactId>
<version>2022.10.28</version>
<version>2022.11.25</version>
</parent>

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
Expand Down Expand Up @@ -94,6 +94,11 @@
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
<dependency>
<groupId>wtf.metio.devcontainer</groupId>
<artifactId>devcontainer.java</artifactId>
<version>2022.12.7</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -155,7 +160,7 @@
<path>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>4.6.3</version>
<version>4.7.0</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
Expand Down Expand Up @@ -195,7 +200,6 @@
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<version>0.9.18</version>
<executions>
<execution>
<id>build-native</id>
Expand Down Expand Up @@ -290,17 +294,17 @@
<mainClass>picocli.codegen.docgen.manpage.ManPageGenerator</mainClass>
<arguments>
<argument>--outdir=${project.build.directory}/generated-picocli-docs</argument>
<argument>wtf.metio.ilo.shell.Shell</argument>
<argument>wtf.metio.ilo.compose.Compose</argument>
<argument>wtf.metio.ilo.devcontainer.Devcontainer</argument>
<argument>wtf.metio.ilo.devfile.Devfile</argument>
<argument>wtf.metio.ilo.shell.ShellCommand</argument>
<argument>wtf.metio.ilo.compose.ComposeCommand</argument>
<argument>wtf.metio.ilo.devcontainer.DevcontainerCommand</argument>
<argument>wtf.metio.ilo.devfile.DevfileCommand</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>4.6.3</version>
<version>4.7.0</version>
<type>jar</type>
</dependency>
</dependencies>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
requires info.picocli;
requires com.fasterxml.jackson.databind;
requires com.fasterxml.jackson.dataformat.yaml;
requires wtf.metio.devcontainer;

opens wtf.metio.ilo to info.picocli;
opens wtf.metio.ilo.compose to info.picocli;
opens wtf.metio.ilo.devcontainer to info.picocli, com.fasterxml.jackson.databind;
opens wtf.metio.ilo.devcontainer to info.picocli;
opens wtf.metio.ilo.devfile to info.picocli, com.fasterxml.jackson.databind;
opens wtf.metio.ilo.shell to info.picocli;
opens wtf.metio.ilo.version to info.picocli;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/wtf/metio/ilo/Ilo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import picocli.AutoComplete;
import picocli.CommandLine;
import wtf.metio.ilo.cli.RunCommands;
import wtf.metio.ilo.compose.Compose;
import wtf.metio.ilo.devcontainer.Devcontainer;
import wtf.metio.ilo.devfile.Devfile;
import wtf.metio.ilo.compose.ComposeCommand;
import wtf.metio.ilo.devcontainer.DevcontainerCommand;
import wtf.metio.ilo.devfile.DevfileCommand;
import wtf.metio.ilo.errors.ExitCodes;
import wtf.metio.ilo.errors.PrintingExceptionHandler;
import wtf.metio.ilo.shell.Shell;
import wtf.metio.ilo.shell.ShellCommand;
import wtf.metio.ilo.version.VersionProvider;

import java.nio.file.Paths;
Expand All @@ -38,10 +38,10 @@
optionListHeading = "%nOptions:%n",
commandListHeading = "%nCommands:%n",
subcommands = {
Shell.class,
Compose.class,
Devcontainer.class,
Devfile.class,
ShellCommand.class,
ComposeCommand.class,
DevcontainerCommand.class,
DevfileCommand.class,
AutoComplete.GenerateCompletion.class
},
showDefaultValues = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@
descriptionHeading = "%n",
optionListHeading = "%n"
)
public final class Compose implements Callable<Integer> {
public final class ComposeCommand implements Callable<Integer> {

@CommandLine.Mixin
public ComposeOptions options;

private final CliExecutor<? super ComposeRuntime, ComposeCLI, ComposeOptions> executor;

// default constructor for picocli
public Compose() {
public ComposeCommand() {
this(new ComposeExecutor());
}

// constructor for testing
Compose(final CliExecutor<? super ComposeRuntime, ComposeCLI, ComposeOptions> executor) {
ComposeCommand(final CliExecutor<? super ComposeRuntime, ComposeCLI, ComposeOptions> executor) {
this.executor = executor;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/wtf/metio/ilo/compose/ComposeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public final class ComposeOptions implements Options {
public ComposeRuntime runtime;

@CommandLine.Option(
names = {"--no-interactive"},
names = {"--interactive"},
description = "Allocate a pseudo TTY or not.",
defaultValue = "true",
fallbackValue = "true",
negatable = true
)
public boolean interactive;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/wtf/metio/ilo/compose/DockerCompose2.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package wtf.metio.ilo.compose;

/**
* Support for 'docker compose' aka 'Compose V2'
* Support for 'docker compose' aka 'ComposeCommand V2'
*
* @see <a href="https://docs.docker.com/compose/cli-command/">official documentation</a>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
package wtf.metio.ilo.devcontainer;

import picocli.CommandLine;
import wtf.metio.ilo.compose.Compose;
import wtf.metio.ilo.shell.Shell;
import wtf.metio.devcontainer.Devcontainer;
import wtf.metio.ilo.compose.ComposeCommand;
import wtf.metio.ilo.errors.DevcontainerJsonMissingException;
import wtf.metio.ilo.shell.ShellCommand;
import wtf.metio.ilo.utils.Streams;
import wtf.metio.ilo.utils.Strings;
import wtf.metio.ilo.version.VersionProvider;

import java.io.IOException;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.concurrent.Callable;

import static wtf.metio.ilo.devcontainer.DevcontainerJsonParser.findJson;
import static wtf.metio.ilo.devcontainer.DevcontainerJsonParser.parseJson;
import static wtf.metio.ilo.devcontainer.DevcontainerOptionsMapper.composeOptions;
import static wtf.metio.ilo.devcontainer.DevcontainerOptionsMapper.shellOptions;

Expand All @@ -32,23 +35,24 @@
descriptionHeading = "%n",
optionListHeading = "%n"
)
public final class Devcontainer implements Callable<Integer> {
public final class DevcontainerCommand implements Callable<Integer> {

@CommandLine.Mixin
public DevcontainerOptions options;

@Override
public Integer call() {
public Integer call() throws IOException {
final var currentDir = Paths.get(System.getProperty("user.dir"));
final var json = findJson(currentDir, options.locations);
final var devcontainer = parseJson(json);
final var json = Streams.findFirst(currentDir, options.locations)
.orElseThrow(DevcontainerJsonMissingException::new);
final var devcontainer = Devcontainer.parse(json);

if (null != devcontainer.dockerComposeFile && !devcontainer.dockerComposeFile.isEmpty()) {
final var command = new Compose();
if (Objects.nonNull(devcontainer.dockerComposeFile()) && !devcontainer.dockerComposeFile().isEmpty()) {
final var command = new ComposeCommand();
command.options = composeOptions(options, devcontainer, json);
return command.call();
} else if (Strings.isNotBlank(devcontainer.image)) {
final var command = new Shell();
} else if (Strings.isNotBlank(devcontainer.image())) {
final var command = new ShellCommand();
command.options = shellOptions(options, devcontainer);
return command.call();
}
Expand Down
50 changes: 0 additions & 50 deletions src/main/java/wtf/metio/ilo/devcontainer/DevcontainerJson.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class DevcontainerOptions implements Options {
names = {"--mount-project-dir"},
description = "Mount the project directory into the running container.",
defaultValue = "true",
fallbackValue = "true",
negatable = true
)
public boolean mountProjectDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

package wtf.metio.ilo.devcontainer;

import wtf.metio.devcontainer.Build;
import wtf.metio.ilo.compose.ComposeOptions;
import wtf.metio.ilo.shell.ShellOptions;
import wtf.metio.devcontainer.Devcontainer;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -18,39 +20,37 @@

final class DevcontainerOptionsMapper {

static ShellOptions shellOptions(final DevcontainerOptions options, final DevcontainerJson devcontainer) {
static ShellOptions shellOptions(final DevcontainerOptions options, final Devcontainer devcontainer) {
final var opts = new ShellOptions();
opts.debug = options.debug;
opts.pull = options.pull;
opts.removeImage = options.removeImage;
opts.runtime = options.shellRuntime;
opts.mountProjectDir = options.mountProjectDir;
opts.image = devcontainer.image;
opts.context = Optional.ofNullable(devcontainer.build)
.map(build -> build.context)
.or(() -> Optional.ofNullable(devcontainer.context))
opts.image = devcontainer.image();
opts.context = Optional.ofNullable(devcontainer.build())
.map(Build::context)
.orElse(".");
opts.containerfile = Optional.ofNullable(devcontainer.build)
.map(build -> build.dockerFile)
.or(() -> Optional.ofNullable(devcontainer.dockerFile))
opts.containerfile = Optional.ofNullable(devcontainer.build())
.map(Build::dockerfile)
.orElse("");
opts.ports = Stream.ofNullable(devcontainer.forwardPorts)
opts.ports = Stream.ofNullable(devcontainer.forwardPorts())
.flatMap(Collection::stream)
.map(port -> port + ":" + port)
.toList();
return opts;
}

static ComposeOptions composeOptions(final DevcontainerOptions options, final DevcontainerJson devcontainer, final Path devcontainerJson) {
static ComposeOptions composeOptions(final DevcontainerOptions options, final Devcontainer devcontainer, final Path devcontainerJson) {
final var opts = new ComposeOptions();
opts.file = Stream.ofNullable(devcontainer.dockerComposeFile)
opts.file = Stream.ofNullable(devcontainer.dockerComposeFile())
.flatMap(Collection::stream)
.map(Paths::get)
.map(devcontainerJson::relativize)
.map(Path::toAbsolutePath)
.map(Path::toString)
.toList();
opts.service = devcontainer.service;
opts.service = devcontainer.service();
opts.debug = options.debug;
opts.pull = options.pull;
opts.runtime = options.composeRuntime;
Expand Down
Loading

0 comments on commit 2883161

Please sign in to comment.