Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (exec): WIP #405

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions be/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2023 The Enola <https://enola.dev> Authors
#
# 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.

load("@rules_java//java:defs.bzl", "java_binary", "java_test")

java_binary(
name = "be",
srcs = glob(["src/main/java/**/*.java"]),
main_class = "dev.enola.be.Be",
deps = [
"//common/exec",
"//common/exec:exec_proto_java_library",
],
)

[java_test(
name = name[:-len(".java")],
size = "small",
srcs = glob(["src/test/java/**/*.java"]),
resources = glob(["src/test/resources/**/*"]),
deps = [
":be",
"//common/common",
"//common/exec",
"//common/exec:exec_proto_java_library",
"@maven//:com_google_guava_guava",
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",
"@maven//:org_slf4j_slf4j_jdk14",
],
) for name in glob([
"src/test/java/**/*Test.java",
])]
11 changes: 11 additions & 0 deletions be/src/main/java/dev/enola/be/Be.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.enola.be;

import dev.enola.common.exec.ExecRequest;

public class Be {
public static void main(String[] args) {
ExecRequest.newBuilder();
System.out.println("Hi!");
// System.exit(cli(args).execute());
}
}
17 changes: 17 additions & 0 deletions be/src/test/java/dev/enola/be/BeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.enola.be;

import static com.google.common.truth.Truth.assertThat;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.junit.Test;

public class BeTest {
@Test
public void testBe() throws IOException {
Be.main(new String[] { "--", "echo", "hello, ", "world", ">hi.txt" });
assertThat(Files.readString(Path.of("hi.txt"))).isEqualTo("hello, world");
}
}
68 changes: 68 additions & 0 deletions common/exec/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2023 The Enola <https://enola.dev> Authors
#
# 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.

load("@rules_java//java:defs.bzl", "java_library", "java_proto_library", "java_test")
load("@rules_proto//proto:defs.bzl", "proto_library")

proto_library(
name = "exec_proto",
srcs = ["src/main/proto/exec.proto"],
deps = [
"@com_google_protobuf//:any_proto",
],
)

java_proto_library(
name = "exec_proto_java_library",
visibility = [
"//be:__pkg__",
],
deps = [
"exec_proto",
],
)

java_library(
name = "exec",
srcs = glob(["src/main/java/**/*.java"]),
visibility = [
"//be:__pkg__",
],
deps = [
":exec_proto_java_library",
"//common/common",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
],
)

[java_test(
name = name[:-len(".java")],
size = "small",
srcs = glob(["src/test/java/**/*.java"]),
resources = glob(["src/test/resources/**/*"]),
deps = [
"//common/common",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",
],
) for name in glob([
"src/test/java/**/*Test.java",
])]
5 changes: 5 additions & 0 deletions common/exec/src/main/java/dev/enola/common/exec/Exec.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.enola.common.exec;

public class Exec {

}
48 changes: 48 additions & 0 deletions common/exec/src/main/proto/exec.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright 2023 The Enola <https://enola.dev> Authors
//
// 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.

syntax = "proto3";

package dev.enola.exec;

option java_string_check_utf8 = true;
option java_package = "dev.enola.common.exec";
option java_multiple_files = true;

message ExecRequestResponse {
ExecRequest request = 1;
ExecResponse response = 2;
}

message ExecRequest {
// Shell under which to run. Defaults to "/usr/bin/env bash -c" if unset. Set to empty to run "directly" (without an intermediate Shell).
string shell = 1;
string cmd = 2;
repeated string args = 3;
string cwd = 4;
repeated EnvironmentVariable environment_variable = 5;
}

message ExecResponse {
int32 exit_code = 1;
string stdout = 2;
string stderr = 3;
}

message EnvironmentVariable {
string name = 1;
string value = 2;
}
13 changes: 13 additions & 0 deletions common/exec/src/test/java/dev/enola/common/exec/ExecTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.enola.common.exec;

import org.junit.Test;

public class ExecTest {

// TODO Remove this again? The test coverage for common.exec is really in be/src/test/java/dev/enola/be/BeTest.java!

@Test
public void testExec() {

}
}
Loading