Skip to content
Snippets Groups Projects
Unverified Commit c0a02442 authored by Misty De Meo's avatar Misty De Meo
Browse files

Revert "language/java: use shortened brew paths"

This reverts commits 318175cf,
e7ab7603 and
3b35af63 (PR #11537).
parent 1cb0f0fb
No related branches found
No related tags found
No related merge requests found
......@@ -365,7 +365,7 @@ class Pathname
target = Pathname.new(target) # allow pathnames or strings
join(target.basename).write <<~SH
#!/bin/bash
exec "#{Utils.shortened_brew_path(target)}" "$@"
exec "#{target}" "$@"
SH
end
end
......@@ -381,7 +381,7 @@ class Pathname
dirname.mkpath
write <<~SH
#!/bin/bash
#{env_export}exec "#{Utils.shortened_brew_path(target)}" #{args} "$@"
#{env_export}exec "#{target}" #{args} "$@"
SH
end
......@@ -410,7 +410,7 @@ class Pathname
mkpath
(self/script_name).write <<~EOS
#!/bin/bash
export JAVA_HOME="#{Language::Java.overridable_short_java_home_env(java_version)[:JAVA_HOME]}"
export JAVA_HOME="#{Language::Java.overridable_java_home_env(java_version)[:JAVA_HOME]}"
exec "${JAVA_HOME}/bin/java" #{java_opts} -jar "#{target_jar}" "$@"
EOS
end
......
......@@ -36,26 +36,13 @@ module Language
end
private_class_method :java_home_shell
def self.short_java_home_shell(version = nil)
Utils.shortened_brew_path(java_home(version))
end
private_class_method :short_java_home_shell
def self.java_home_env(version = nil)
{ JAVA_HOME: java_home_shell(version) }
end
def self.short_java_home_env(version = nil)
{ JAVA_HOME: short_java_home_shell(version) }
end
def self.overridable_java_home_env(version = nil)
{ JAVA_HOME: "${JAVA_HOME:-#{java_home_shell(version)}}" }
end
def self.overridable_short_java_home_env(version = nil)
{ JAVA_HOME: "${JAVA_HOME:-#{short_java_home_shell(version)}}" }
end
end
end
......
......@@ -19,14 +19,6 @@ describe Language::Java do
end
end
let(:expected_short_home) do
if OS.mac?
"$(brew --prefix)/opt/openjdk/libexec/openjdk.jdk/Contents/Home"
else
"$(brew --prefix)/opt/openjdk/libexec"
end
end
before do
allow(Formula).to receive(:[]).and_return(f)
allow(f).to receive(:any_version_installed?).and_return(true)
......@@ -57,18 +49,6 @@ describe Language::Java do
end
end
describe "::short_java_home_env" do
it "returns short java_home path if version specified" do
short_java_home_env = described_class.short_java_home_env("1.8+")
expect(short_java_home_env[:JAVA_HOME]).to eql(expected_short_home)
end
it "returns short java_home path if version is not specified" do
short_java_home_env = described_class.short_java_home_env
expect(short_java_home_env[:JAVA_HOME]).to eql(expected_short_home)
end
end
describe "::overridable_java_home_env" do
it "returns java_home path if version specified" do
overridable_java_home_env = described_class.overridable_java_home_env("1.8+")
......@@ -80,16 +60,4 @@ describe Language::Java do
expect(overridable_java_home_env[:JAVA_HOME]).to eql("${JAVA_HOME:-#{expected_home}}")
end
end
describe "::overridable_short_java_home_env" do
it "returns short java_home path if version specified" do
overridable_short_java_home_env = described_class.overridable_short_java_home_env("1.8+")
expect(overridable_short_java_home_env[:JAVA_HOME]).to eql("${JAVA_HOME:-#{expected_short_home}}")
end
it "returns short java_home path if version is not specified" do
overridable_short_java_home_env = described_class.overridable_short_java_home_env
expect(overridable_short_java_home_env[:JAVA_HOME]).to eql("${JAVA_HOME:-#{expected_short_home}}")
end
end
end
# typed: false
# frozen_string_literal: true
require "utils/path"
describe Utils do
describe "::path_is_parent_of?" do
it "returns true when child path is a descendant of the parent" do
expect(described_class.path_is_parent_of?("/foo", "/foo/bar/baz")).to eq(true)
end
it "returns false when child path is not a descendant of the parent" do
expect(described_class.path_is_parent_of?("/foo/bar/baz/qux", "/foo/bar")).to eq(false)
end
end
describe "::shortened_brew_path" do
it "returns shortened path when the path can be expressed with the output of a brew command" do
expect(described_class.shortened_brew_path("#{HOMEBREW_PREFIX}/foo/bar")).to eq("$(brew --prefix)/foo/bar")
end
it "returns shortened path with $(brew --prefix <formula>) when path is in a linked keg", :integration_test do
install_test_formula "testball"
f = Formula["testball"]
expect(described_class.shortened_brew_path("#{f.opt_prefix}/main.c")).to eq("$(brew --prefix testball)/main.c")
end
it "returns the original path when the path cannot be shortened" do
expect(described_class.shortened_brew_path("/foo/bar/baz")).to eq("/foo/bar/baz")
end
end
end
......@@ -13,7 +13,6 @@ require "utils/git_repository"
require "utils/github"
require "utils/inreplace"
require "utils/link"
require "utils/path"
require "utils/popen"
require "utils/repology"
require "utils/svn"
......
# typed: strict
# frozen_string_literal: true
# Helper functions for working with paths
module Utils
extend T::Sig
# Checks if a a child path is a descendant of a given parent path
sig { params(parent_path: T.any(String, Pathname), child_path: T.any(String, Pathname)).returns(T::Boolean) }
def self.path_is_parent_of?(parent_path, child_path)
parent_component_array = Pathname(parent_path).each_filename.to_a
child_component_array = Pathname(child_path).each_filename.to_a
child_component_array.first(parent_component_array.length) == parent_component_array
end
# Gets a condensed short brew path for a given path, or the original path if it cannot be condensed
sig { params(long_path: T.any(String, Pathname)).returns(String) }
def self.shortened_brew_path(long_path)
short_path = long_path.to_s
long_path = Pathname(long_path)
if long_path.exist?
begin
k = Keg.for(long_path)
opt_record = k.opt_record
formula_name = k.to_formula.name
rescue FormulaUnavailableError, NotAKegError
nil
else
short_path = short_path.sub(/\A#{Regexp.escape(opt_record.to_s)}/, "$(brew --prefix #{formula_name})")
end
end
try_paths = {
HOMEBREW_CACHE => "--cache",
HOMEBREW_CELLAR => "--cellar",
HOMEBREW_REPOSITORY => "--repository",
HOMEBREW_PREFIX => "--prefix",
}
try_paths.each do |try_path, flag|
if path_is_parent_of?(try_path, long_path)
short_path = short_path.sub(/\A#{Regexp.escape(try_path.to_s)}/, "$(brew #{flag})")
break
end
end
short_path
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment