diff --git a/library_generation/generate_library.sh b/library_generation/generate_library.sh index d4038fa9e6..88c2052b56 100755 --- a/library_generation/generate_library.sh +++ b/library_generation/generate_library.sh @@ -224,11 +224,7 @@ if [[ "${proto_only}" == "false" ]]; then mv_src_files "gapic" "test" "${temp_destination_path}" if [ "${include_samples}" == "true" ]; then # move java_gapic_srcjar/samples/snippets to samples/snippets - if [[ "${proto_path}" == "grafeas/v1" ]]; then - mv_src_files "samples" "main" "${temp_destination_path}" "io" - else - mv_src_files "samples" "main" "${temp_destination_path}" - fi + mv_src_files "samples" "main" "${temp_destination_path}" fi fi ##################### Section 3 ##################### diff --git a/library_generation/test/resources/test_mv_src/destination/java_gapic_srcjar/samples/snippets/generated/src/main/java/com/example_com_sample.txt b/library_generation/test/resources/test_mv_src/gapic/destination/java_gapic_srcjar/src/main/java/example_main.txt similarity index 100% rename from library_generation/test/resources/test_mv_src/destination/java_gapic_srcjar/samples/snippets/generated/src/main/java/com/example_com_sample.txt rename to library_generation/test/resources/test_mv_src/gapic/destination/java_gapic_srcjar/src/main/java/example_main.txt diff --git a/library_generation/test/resources/test_mv_src/destination/java_gapic_srcjar/samples/snippets/generated/src/main/java/io/example_io_sample.txt b/library_generation/test/resources/test_mv_src/gapic/destination/java_gapic_srcjar/src/test/java/example_test.txt similarity index 100% rename from library_generation/test/resources/test_mv_src/destination/java_gapic_srcjar/samples/snippets/generated/src/main/java/io/example_io_sample.txt rename to library_generation/test/resources/test_mv_src/gapic/destination/java_gapic_srcjar/src/test/java/example_test.txt diff --git a/library_generation/test/resources/test_mv_src/proto/destination/java_gapic_srcjar/proto/src/main/java/example_proto_main.txt b/library_generation/test/resources/test_mv_src/proto/destination/java_gapic_srcjar/proto/src/main/java/example_proto_main.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/library_generation/test/resources/test_mv_src/samples/destination_com/java_gapic_srcjar/samples/snippets/generated/src/main/java/com/example_com_sample.txt b/library_generation/test/resources/test_mv_src/samples/destination_com/java_gapic_srcjar/samples/snippets/generated/src/main/java/com/example_com_sample.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/library_generation/test/resources/test_mv_src/samples/destination_io/java_gapic_srcjar/samples/snippets/generated/src/main/java/io/example_io_sample.txt b/library_generation/test/resources/test_mv_src/samples/destination_io/java_gapic_srcjar/samples/snippets/generated/src/main/java/io/example_io_sample.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/library_generation/test/utilities_unit_tests.py b/library_generation/test/utilities_unit_tests.py index 64339329f3..b2f8124c90 100644 --- a/library_generation/test/utilities_unit_tests.py +++ b/library_generation/test/utilities_unit_tests.py @@ -113,28 +113,67 @@ def test_sh_util_nonexistent_function_fails(self): with self.assertRaises(RuntimeError): result = util.sh_util("nonexistent_function") + def test_mv_src_files_gapic_main_succeeds(self): + previous_dir = os.getcwd() + os.chdir(f"{resources_dir}/test_mv_src/gapic") + os.environ["folder_name"] = "example" + util.sh_util("mv_src_files gapic main destination") + self.assertTrue( + os.path.isfile( + "destination/gapic-example/src/main/java/example_main.txt" + ) + ) + shutil.rmtree("destination/gapic-example") + os.chdir(previous_dir) + + def test_mv_src_files_gapic_test_succeeds(self): + previous_dir = os.getcwd() + os.chdir(f"{resources_dir}/test_mv_src/gapic") + os.environ["folder_name"] = "example" + util.sh_util("mv_src_files gapic test destination") + self.assertTrue( + os.path.isfile( + "destination/gapic-example/src/test/java/example_test.txt" + ) + ) + shutil.rmtree("destination/gapic-example") + os.chdir(previous_dir) + + def test_mv_src_files_proto_main_succeeds(self): + previous_dir = os.getcwd() + os.chdir(f"{resources_dir}/test_mv_src/proto") + os.environ["folder_name"] = "example" + util.sh_util("mv_src_files proto main destination") + self.assertTrue( + os.path.isfile( + "destination/proto-example/src/main/java/example_proto_main.txt" + ) + ) + shutil.rmtree("destination/proto-example") + os.chdir(previous_dir) + def test_mv_src_files_sample_suffix_io_succeeds(self): previous_dir = os.getcwd() - os.chdir(f"{resources_dir}/test_mv_src") - util.sh_util("mv_src_files samples main destination io") + os.chdir(f"{resources_dir}/test_mv_src/samples") + util.sh_util("mv_src_files samples main destination_io") self.assertTrue( os.path.isfile( - "destination/samples/snippets/generated/io/example_io_sample.txt" + "destination_io/samples/snippets/generated/io/example_io_sample.txt" ) ) - shutil.rmtree("destination/samples") + shutil.rmtree("destination_io/samples") os.chdir(previous_dir) def test_mv_src_files_sample_suffix_com_succeeds(self): previous_dir = os.getcwd() - os.chdir(f"{resources_dir}/test_mv_src") - util.sh_util("mv_src_files samples main destination") + os.chdir(f"{resources_dir}/test_mv_src/samples") + util.sh_util("mv_src_files samples main destination_com") self.assertTrue( os.path.isfile( - "destination/samples/snippets/generated/com/example_com_sample.txt" + "destination_com/samples/snippets/generated/com/example_com_sample.txt" ) ) - shutil.rmtree("destination/samples") + shutil.rmtree("destination_com/samples") os.chdir(previous_dir) def test_eprint_valid_input_succeeds(self): diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index 879c3e76f2..eda0dd5ea5 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -31,13 +31,11 @@ mv_src_files() { local category=$1 # one of gapic, proto, samples local type=$2 # one of main, test local destination_path=$3 - local samples_suffix=$4 # one of com, io (grafeas) - if [ -z "${samples_suffix}" ]; then - samples_suffix="com" - fi if [ "${category}" == "samples" ]; then - src_suffix="samples/snippets/generated/src/main/java/${samples_suffix}" + src_suffix="samples/snippets/generated/src/main/java" folder_suffix="samples/snippets/generated" + mkdir -p "${destination_path}/${folder_suffix}" + cp -r "${destination_path}/java_gapic_srcjar/${src_suffix}"/* "${destination_path}/${folder_suffix}" elif [ "${category}" == "proto" ]; then src_suffix="${category}/src/${type}/java" folder_suffix="${category}-${folder_name}/src/${type}" @@ -45,11 +43,14 @@ mv_src_files() { src_suffix="src/${type}" folder_suffix="${category}-${folder_name}/src" fi + + if [ "${category}" == "samples" ]; then + exit + fi + mkdir -p "${destination_path}/${folder_suffix}" cp -r "${destination_path}/java_gapic_srcjar/${src_suffix}" "${destination_path}/${folder_suffix}" - if [ "${category}" != "samples" ]; then - rm -r -f "${destination_path}/${folder_suffix}/java/META-INF" - fi + rm -r -f "${destination_path}/${folder_suffix}/java/META-INF" } # unzip jar file