class Cassandra < Formula desc "Eventually consistent, distributed key-value store" homepage "https://cassandra.apache.org" url "https://archive.apache.org/dist/cassandra/3.11.4/apache-cassandra-3.11.4-bin.tar.gz" sha256 "5d598e23c3ffc4db0301ec2b313061e3208fae0f9763d4b47888237dd9069987" bottle do cellar :any_skip_relocation rebuild 1 sha256 "e9f5422b20f44c82dc3399f34da97e314cb0047c9b99c7325b1c1a91ad3063f5" => :catalina sha256 "75d3a49ace9a7596bbd41106955464d5db48239a2fc6e481d92c0fa18a0e37e6" => :mojave sha256 "69d5dc8380290293b5a5dd138dfde2b2dc33577b8e08d057154e2703cb1a841d" => :high_sierra end depends_on "cython" => :build depends_on "python" # Only >=Yosemite has new enough setuptools for successful compile of the below deps. resource "setuptools" do url "https://files.pythonhosted.org/packages/c2/f7/c7b501b783e5a74cf1768bc174ee4fb0a8a6ee5af6afa92274ff964703e0/setuptools-40.8.0.zip" sha256 "6e4eec90337e849ade7103723b9a99631c1f0d19990d6e8412dc42f5ae8b304d" end resource "futures" do url "https://files.pythonhosted.org/packages/1f/9e/7b2ff7e965fc654592269f2906ade1c7d705f1bf25b7d469fa153f7d19eb/futures-3.2.0.tar.gz" sha256 "9ec02aa7d674acb8618afb127e27fde7fc68994c0437ad759fa094a574adb265" end resource "six" do url "https://files.pythonhosted.org/packages/dd/bf/4138e7bfb757de47d1f4b6994648ec67a51efe58fa907c1e11e350cddfca/six-1.12.0.tar.gz" sha256 "d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" end resource "thrift" do url "https://files.pythonhosted.org/packages/c6/b4/510617906f8e0c5660e7d96fbc5585113f83ad547a3989b80297ac72a74c/thrift-0.11.0.tar.gz" sha256 "7d59ac4fdcb2c58037ebd4a9da5f9a49e3e034bf75b3f26d9fe48ba3d8806e6b" end resource "cql" do url "https://files.pythonhosted.org/packages/0b/15/523f6008d32f05dd3c6a2e7c2f21505f0a785b6dc8949cad325306858afc/cql-1.4.0.tar.gz" sha256 "7857c16d8aab7b736ab677d1016ef8513dedb64097214ad3a50a6c550cb7d6e0" end resource "cassandra-driver" do url "https://files.pythonhosted.org/packages/31/07/2423f77878559593ef17175ef2e0372dc91994368b15c6a47fca40b416ea/cassandra-driver-3.16.0.tar.gz" sha256 "42bcb167a90da6604081872ef609a327a63273842da81120fc462de031155abe" end def install (var/"lib/cassandra").mkpath (var/"log/cassandra").mkpath xy = Language::Python.major_minor_version "python3" pypath = libexec/"vendor/lib/python#{xy}/site-packages" ENV.prepend_create_path "PYTHONPATH", pypath resources.each do |r| r.stage do system "python3", *Language::Python.setup_install_args(libexec/"vendor") end end inreplace "conf/cassandra.yaml", "/var/lib/cassandra", "#{var}/lib/cassandra" inreplace "conf/cassandra-env.sh", "/lib/", "/" inreplace "bin/cassandra", "-Dcassandra.logdir\=$CASSANDRA_HOME/logs", "-Dcassandra.logdir\=#{var}/log/cassandra" inreplace "bin/cassandra.in.sh" do |s| s.gsub! "CASSANDRA_HOME=\"`dirname \"$0\"`/..\"", "CASSANDRA_HOME=\"#{libexec}\"" # Store configs in etc, outside of keg s.gsub! "CASSANDRA_CONF=\"$CASSANDRA_HOME/conf\"", "CASSANDRA_CONF=\"#{etc}/cassandra\"" # Jars installed to prefix, no longer in a lib folder s.gsub! "\"$CASSANDRA_HOME\"/lib/*.jar", "\"$CASSANDRA_HOME\"/*.jar" # The jammm Java agent is not in a lib/ subdir either: s.gsub! "JAVA_AGENT=\"$JAVA_AGENT -javaagent:$CASSANDRA_HOME/lib/jamm-", "JAVA_AGENT=\"$JAVA_AGENT -javaagent:$CASSANDRA_HOME/jamm-" # Storage path s.gsub! "cassandra_storagedir\=\"$CASSANDRA_HOME/data\"", "cassandra_storagedir\=\"#{var}/lib/cassandra\"" end rm Dir["bin/*.bat", "bin/*.ps1"] # This breaks on `brew uninstall cassandra && brew install cassandra` # https://github.com/Homebrew/homebrew/pull/38309 (etc/"cassandra").install Dir["conf/*"] libexec.install Dir["*.txt", "{bin,interface,javadoc,pylib,lib/licenses}"] libexec.install Dir["lib/*.jar"] pkgshare.install [libexec/"bin/cassandra.in.sh", libexec/"bin/stop-server"] inreplace Dir["#{libexec}/bin/cassandra*", "#{libexec}/bin/debug-cql", "#{libexec}/bin/nodetool", "#{libexec}/bin/sstable*"], %r{`dirname "?\$0"?`/cassandra.in.sh}, "#{pkgshare}/cassandra.in.sh" # Make sure tools are installed rm Dir[buildpath/"tools/bin/*.bat"] # Delete before install to avoid copying useless files (libexec/"tools").install Dir[buildpath/"tools/lib/*.jar"] # Tools use different cassandra.in.sh and should be changed differently mv buildpath/"tools/bin/cassandra.in.sh", buildpath/"tools/bin/cassandra-tools.in.sh" inreplace buildpath/"tools/bin/cassandra-tools.in.sh" do |s| # Tools have slightly different path to CASSANDRA_HOME s.gsub! "CASSANDRA_HOME=\"`dirname $0`/../..\"", "CASSANDRA_HOME=\"#{libexec}\"" # Store configs in etc, outside of keg s.gsub! "CASSANDRA_CONF=\"$CASSANDRA_HOME/conf\"", "CASSANDRA_CONF=\"#{etc}/cassandra\"" # Core Jars installed to prefix, no longer in a lib folder s.gsub! "\"$CASSANDRA_HOME\"/lib/*.jar", "\"$CASSANDRA_HOME\"/*.jar" # Tools Jars are under tools folder s.gsub! "\"$CASSANDRA_HOME\"/tools/lib/*.jar", "\"$CASSANDRA_HOME\"/tools/*.jar" # Storage path s.gsub! "cassandra_storagedir\=\"$CASSANDRA_HOME/data\"", "cassandra_storagedir\=\"#{var}/lib/cassandra\"" end pkgshare.install [buildpath/"tools/bin/cassandra-tools.in.sh"] # Update tools script files inreplace Dir[buildpath/"tools/bin/*"], "`dirname \"$0\"`/cassandra.in.sh", "#{pkgshare}/cassandra-tools.in.sh" # Make sure tools are available bin.install Dir[buildpath/"tools/bin/*"] bin.write_exec_script Dir["#{libexec}/bin/*"] rm %W[#{bin}/cqlsh #{bin}/cqlsh.py] # Remove existing exec scripts (bin/"cqlsh").write_env_script libexec/"bin/cqlsh", :PYTHONPATH => pypath (bin/"cqlsh.py").write_env_script libexec/"bin/cqlsh.py", :PYTHONPATH => pypath end plist_options :manual => "cassandra -f" def plist; <<~EOS KeepAlive Label #{plist_name} ProgramArguments #{opt_bin}/cassandra -f RunAtLoad WorkingDirectory #{var}/lib/cassandra EOS end test do assert_match version.to_s, shell_output("#{bin}/cassandra -v") output = shell_output("#{bin}/cqlsh localhost 2>&1", 1) assert_match "Connection error", output end end