class Wireshare < Formula
  desc "Peer-to-peer sharing for Gnutella, BitTorrent, magnet, and eD2k"
  homepage "@release_homepage_url@"
  url "@source_tarball_url@"
  sha256 "@source_tarball_sha256@"
  license "GPL-3.0-or-later"
  version "@release_version@"

  depends_on "gradle" => :build
  depends_on "openjdk@21"

  def install
    env_java = Formula["openjdk@21"].opt_prefix
    ENV["JAVA_HOME"] = env_java

    system "./gradlew", "--no-daemon", "wireShareJar"

    bin.install "packaging/common/launchers/WireShare" => "WireShare"
    share.install "WireShare.jar" => "wireshare/@wire_share_jar_name@"
    prefix.install "packaging/common/app/@release_app_id@.desktop" => "share/applications/@release_app_id@.desktop"
    prefix.install "packaging/common/app/@release_app_id@.metainfo.xml" => "share/metainfo/@release_app_id@.metainfo.xml"
    prefix.install "packaging/common/icons" => "share/icons"
  end

  test do
    assert_match "@release_app_name@", shell_output("#{bin}/WireShare --help", 1)
  end
end
