diff --git a/be/BUILD b/be/BUILD new file mode 100644 index 000000000..3a83c48b2 --- /dev/null +++ b/be/BUILD @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright 2023 The Enola 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", +])] diff --git a/be/src/main/java/dev/enola/be/Be.java b/be/src/main/java/dev/enola/be/Be.java new file mode 100644 index 000000000..6bb876f89 --- /dev/null +++ b/be/src/main/java/dev/enola/be/Be.java @@ -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()); + } +} diff --git a/be/src/test/java/dev/enola/be/BeTest.java b/be/src/test/java/dev/enola/be/BeTest.java new file mode 100644 index 000000000..83369b051 --- /dev/null +++ b/be/src/test/java/dev/enola/be/BeTest.java @@ -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"); + } +} diff --git a/common/exec/BUILD b/common/exec/BUILD new file mode 100644 index 000000000..3d0b9346f --- /dev/null +++ b/common/exec/BUILD @@ -0,0 +1,68 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright 2023 The Enola 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", +])] diff --git a/common/exec/src/main/java/dev/enola/common/exec/Exec.java b/common/exec/src/main/java/dev/enola/common/exec/Exec.java new file mode 100644 index 000000000..006e26a23 --- /dev/null +++ b/common/exec/src/main/java/dev/enola/common/exec/Exec.java @@ -0,0 +1,5 @@ +package dev.enola.common.exec; + +public class Exec { + +} diff --git a/common/exec/src/main/proto/exec.proto b/common/exec/src/main/proto/exec.proto new file mode 100644 index 000000000..2bf2d4d72 --- /dev/null +++ b/common/exec/src/main/proto/exec.proto @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: Apache-2.0 +// +// Copyright 2023 The Enola 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; +} diff --git a/common/exec/src/test/java/dev/enola/common/exec/ExecTest.java b/common/exec/src/test/java/dev/enola/common/exec/ExecTest.java new file mode 100644 index 000000000..cb24dde86 --- /dev/null +++ b/common/exec/src/test/java/dev/enola/common/exec/ExecTest.java @@ -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() { + + } +}