Skip to content

Commit

Permalink
Merge branch 'master' into prt
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Sep 27, 2019
2 parents a981fc5 + a59794b commit 3ae170b
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions synthtool/languages/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,46 @@
import glob
import os
import requests
import synthtool as s
from synthtool import cache
from synthtool import log
from synthtool import shell
from pathlib import Path

JAR_DOWNLOAD_URL = "https://github.com/google/google-java-format/releases/download/google-java-format-{version}/google-java-format-{version}-all-deps.jar"
DEFAULT_FORMAT_VERSION = "1.7"
GOOD_LICENSE = """
/*
* Copyright 2019 Google LLC
*
* 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.
*/
"""
PROTOBUF_HEADER = "// Generated by the protocol buffer compiler. DO NOT EDIT!"
BAD_LICENSE = """/\\*
\\* Copyright 2018 Google LLC
\\*
\\* 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
\\*
\\* http://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.
\\*/
"""


def format_code(
Expand Down Expand Up @@ -52,3 +85,20 @@ def _download_formatter(version: str, dest: Path) -> None:
response.raise_for_status()
with open(dest, "wb") as fh:
fh.write(response.content)


def fix_proto_headers(proto_root: Path) -> None:
s.replace(
[proto_root / "src/**/*.java"],
PROTOBUF_HEADER,
f"{GOOD_LICENSE}{PROTOBUF_HEADER}",
)
s.replace([proto_root / "src/**/*Name.java"], BAD_LICENSE, GOOD_LICENSE)


def fix_grpc_headers(grpc_root: Path, package_name: str) -> None:
s.replace(
[grpc_root / "src/**/*.java"],
f"package {package_name};",
f"{GOOD_LICENSE}package {package_name};",
)

0 comments on commit 3ae170b

Please # to comment.