homebrew-core/Formula/google-java-format.rb

55 lines
1.8 KiB
Ruby

class GoogleJavaFormat < Formula
include Language::Python::Shebang
desc "Reformats Java source code to comply with Google Java Style"
homepage "https://github.com/google/google-java-format"
url "https://github.com/google/google-java-format/releases/download/v1.15.0/google-java-format-1.15.0-all-deps.jar"
sha256 "a356bb0236b29c57a3ab678f17a7b027aad603b0960c183a18f1fe322e4f38ea"
license "Apache-2.0"
bottle do
rebuild 1
sha256 cellar: :any_skip_relocation, all: "c8f46c31667409fd1540e1219812dc2ee3308d6c4774c6f1a6765a5d1a6405ae"
end
depends_on "openjdk"
depends_on "python@3.11"
resource "google-java-format-diff" do
url "https://raw.githubusercontent.com/google/google-java-format/v1.15.0/scripts/google-java-format-diff.py"
sha256 "4c46a4ed6c39c2f7cbf2bc7755eefd7eaeb0a3db740ed1386053df822f15782b"
end
def install
libexec.install "google-java-format-#{version}-all-deps.jar" => "google-java-format.jar"
bin.write_jar_script libexec/"google-java-format.jar", "google-java-format"
resource("google-java-format-diff").stage do
bin.install "google-java-format-diff.py" => "google-java-format-diff"
rewrite_shebang detected_python_shebang, bin/"google-java-format-diff"
end
end
test do
(testpath/"foo.java").write "public class Foo{\n}\n"
assert_match "public class Foo {}", shell_output("#{bin}/google-java-format foo.java")
(testpath/"bar.java").write <<~BAR
class Bar{
int x;
}
BAR
patch = <<~PATCH
--- a/bar.java
+++ b/bar.java
@@ -1,0 +2 @@ class Bar{
+ int x ;
PATCH
`echo '#{patch}' | #{bin}/google-java-format-diff -p1 -i`
assert_equal <<~BAR, File.read(testpath/"bar.java")
class Bar{
int x;
}
BAR
assert_equal version, resource("google-java-format-diff").version
end
end