From bcd75a08e366e8739718fca09528e08bc2b94dfc Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Mon, 16 Mar 2020 15:17:22 -0700 Subject: [PATCH] feat(java_templates): add sample pom files (#430) Co-authored-by: Justin Beckwith --- .../samples/install-without-bom/pom.xml | 51 +++++++++++ .../templates/java_library/samples/pom.xml | 56 +++++++++++++ .../java_library/samples/snapshot/pom.xml | 84 +++++++++++++++++++ .../java_library/samples/snippets/pom.xml | 62 ++++++++++++++ synthtool/languages/java.py | 15 +++- 5 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 synthtool/gcp/templates/java_library/samples/install-without-bom/pom.xml create mode 100644 synthtool/gcp/templates/java_library/samples/pom.xml create mode 100644 synthtool/gcp/templates/java_library/samples/snapshot/pom.xml create mode 100644 synthtool/gcp/templates/java_library/samples/snippets/pom.xml diff --git a/synthtool/gcp/templates/java_library/samples/install-without-bom/pom.xml b/synthtool/gcp/templates/java_library/samples/install-without-bom/pom.xml new file mode 100644 index 000000000..35ddcc4cb --- /dev/null +++ b/synthtool/gcp/templates/java_library/samples/install-without-bom/pom.xml @@ -0,0 +1,51 @@ +{% set group_id = metadata['repo']['distribution_name'].split(':')|first -%} +{% set artifact_id = metadata['repo']['distribution_name'].split(':')|last -%} + + + 4.0.0 + com.google.cloud + {{metadata['repo']['name']}}-snapshot + jar + Google {{metadata['repo']['name_pretty']}} Install Without Bom + https://github.com/{{metadata['repo']['repo']}} + + + + com.google.cloud.samples + shared-configuration + 1.0.12 + + + + 1.8 + 1.8 + UTF-8 + + + + + + + {{ group_id }} + {{ artifact_id }} + {{ metadata['latest_version'] }} + + + + + junit + junit + 4.13 + test + + + com.google.truth + truth + 1.0.1 + test + + + diff --git a/synthtool/gcp/templates/java_library/samples/pom.xml b/synthtool/gcp/templates/java_library/samples/pom.xml new file mode 100644 index 000000000..b2443d2ca --- /dev/null +++ b/synthtool/gcp/templates/java_library/samples/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + com.google.cloud + google-cloud-{{metadata['repo']['name']}}-samples + 0.0.1-SNAPSHOT + pom + Google {{metadata['repo']['name_pretty']}} Samples Parent + https://github.com/{{metadata['repo']['repo']}} + + Java idiomatic client for Google Cloud Platform services. + + + + + com.google.cloud.samples + shared-configuration + 1.0.12 + + + + 1.8 + 1.8 + UTF-8 + + + + install-without-bom + snapshot + snippets + + + + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + true + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.8 + + true + + + + + diff --git a/synthtool/gcp/templates/java_library/samples/snapshot/pom.xml b/synthtool/gcp/templates/java_library/samples/snapshot/pom.xml new file mode 100644 index 000000000..cd443205a --- /dev/null +++ b/synthtool/gcp/templates/java_library/samples/snapshot/pom.xml @@ -0,0 +1,84 @@ +{% set group_id = metadata['repo']['distribution_name'].split(':')|first -%} +{% set artifact_id = metadata['repo']['distribution_name'].split(':')|last -%} + + + 4.0.0 + com.google.cloud + {{metadata['repo']['name']}}-snapshot + jar + Google {{metadata['repo']['name_pretty']}} Snapshot Samples + https://github.com/{{metadata['repo']['repo']}} + + + + com.google.cloud.samples + shared-configuration + 1.0.12 + + + + 1.8 + 1.8 + UTF-8 + + + + + + {{ group_id }} + {{ artifact_id }} + {{ metadata['latest_version'] }} + + + + junit + junit + 4.13 + test + + + com.google.truth + truth + 1.0.1 + test + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + add-snippets-source + + add-source + + + + ../snippets/src/main/java + + + + + add-snippets-tests + + add-test-source + + + + ../snippets/src/test/java + + + + + + + + \ No newline at end of file diff --git a/synthtool/gcp/templates/java_library/samples/snippets/pom.xml b/synthtool/gcp/templates/java_library/samples/snippets/pom.xml new file mode 100644 index 000000000..1c14e6ff3 --- /dev/null +++ b/synthtool/gcp/templates/java_library/samples/snippets/pom.xml @@ -0,0 +1,62 @@ +{% set group_id = metadata['repo']['distribution_name'].split(':')|first -%} +{% set artifact_id = metadata['repo']['distribution_name'].split(':')|last -%} + + + 4.0.0 + com.google.cloud + {{metadata['repo']['name']}}-snippets + jar + Google {{metadata['repo']['name_pretty']}} Snippets + https://github.com/{{metadata['repo']['repo']}} + + + + com.google.cloud.samples + shared-configuration + 1.0.12 + + + + 1.8 + 1.8 + UTF-8 + + + + + + + + com.google.cloud + libraries-bom + {{ metadata['latest_bom_version'] }} + pom + import + + + + + + + {{ group_id }} + {{ artifact_id }} + + + + + junit + junit + 4.13 + test + + + com.google.truth + truth + 1.0.1 + test + + + diff --git a/synthtool/languages/java.py b/synthtool/languages/java.py index a55aa477a..dff873987 100644 --- a/synthtool/languages/java.py +++ b/synthtool/languages/java.py @@ -321,6 +321,19 @@ def bazel_library( return library +def _merge_common_templates( + source_text: str, destination_text: str, file_path: Path +) -> str: + log.debug(f"merge: {file_path}") + # keep any existing pom.xml + if file_path.match("pom.xml"): + log.info(f"existing pom file found ({file_path}) - keeping the existing") + return destination_text + + # by default return the newly generated content + return source_text + + def common_templates(excludes: List[str] = [], **kwargs) -> None: """Generate common templates for a Java Library @@ -353,4 +366,4 @@ def common_templates(excludes: List[str] = [], **kwargs) -> None: kwargs["metadata"] = metadata templates = gcp.CommonTemplates().java_library(**kwargs) - s.copy([templates], excludes=excludes) + s.copy([templates], excludes=excludes, merge=_merge_common_templates)