homebrew-core/Formula/mockserver.rb

49 lines
1.4 KiB
Ruby

class Mockserver < Formula
desc "Mock HTTP server and proxy"
homepage "https://www.mock-server.com/"
url "https://search.maven.org/remotecontent?filepath=org/mock-server/mockserver-netty/5.11.2/mockserver-netty-5.11.2-brew-tar.tar"
sha256 "1758bb80c3e5cd250b55757a53105db7b03ff1b05d2dfca501ce5795feff8756"
license "Apache-2.0"
livecheck do
url "https://search.maven.org/remotecontent?filepath=org/mock-server/mockserver-netty/maven-metadata.xml"
regex(%r{<version>v?(\d+(?:\.\d+)+)</version>}i)
end
bottle do
sha256 cellar: :any_skip_relocation, all: "3ee84c853d1d2ecce352978200c6133696e9f7b8500186864cd130cdfa34d9d9"
end
depends_on "openjdk"
def install
inreplace "bin/run_mockserver.sh", "/usr/local", HOMEBREW_PREFIX
libexec.install Dir["*"]
(bin/"mockserver").write_env_script libexec/"bin/run_mockserver.sh", JAVA_HOME: Formula["openjdk"].opt_prefix
lib.install_symlink "#{libexec}/lib" => "mockserver"
mockserver_log = var/"log/mockserver"
mockserver_log.mkpath
libexec.install_symlink mockserver_log => "log"
end
test do
port = free_port
mockserver = fork do
exec "#{bin}/mockserver", "-serverPort", port.to_s
end
loop do
Utils.popen_read("curl", "-s", "http://localhost:#{port}/status", "-X", "PUT")
break if $CHILD_STATUS.exitstatus.zero?
end
system "curl", "-s", "http://localhost:#{port}/stop", "-X", "PUT"
Process.wait(mockserver)
end
end