Skip to content

Commit

Permalink
Merge pull request scalacenter#747 from scalacenter/topic/fix-java-ho…
Browse files Browse the repository at this point in the history
…mebrew

Don't fail bloop if Java 11 installed in Mac OS
  • Loading branch information
jvican authored Dec 4, 2018
2 parents 006b467 + 977e1c9 commit 601b4f6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 33 deletions.
93 changes: 64 additions & 29 deletions bin/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from __future__ import print_function

import sys
import argparse
import os
from os.path import expanduser, isdir, isfile, join, dirname, abspath
from subprocess import CalledProcessError, check_call
import platform
import sys
import re
from shutil import copyfileobj, copyfile
Expand Down Expand Up @@ -98,7 +100,8 @@
SYSTEMD_SERVICE_URL = "https://raw.githubusercontent.com/scalacenter/bloop/%s/etc/systemd/bloop.service" % ETC_VERSION
XDG_APPLICATION_URL = "https://raw.githubusercontent.com/scalacenter/bloop/%s/etc/xdg/bloop.desktop" % ETC_VERSION
XDG_ICON_URL = "https://raw.githubusercontent.com/scalacenter/bloop/%s/etc/xdg/bloop.png" % ETC_VERSION
BLOOP_COURSIER_TARGET = join(BLOOP_INSTALLATION_TARGET, "blp-coursier")
BLOOP_COURSIER_BINARY_NAME = "blp-coursier"
BLOOP_COURSIER_TARGET = join(BLOOP_INSTALLATION_TARGET, BLOOP_COURSIER_BINARY_NAME)
BLOOP_SERVER_TARGET = join(BLOOP_INSTALLATION_TARGET, "blp-server")
BLOOP_CLIENT_TARGET = join(BLOOP_INSTALLATION_TARGET, "bloop")
ZSH_COMPLETION_TARGET = join(ZSH_COMPLETION_DIR, "_bloop")
Expand All @@ -112,6 +115,20 @@

BUFFER_SIZE = 4096

MACOS_LAUNCH_SCRIPT_CONTENTS = """
#!/usr/bin/env sh
BASE_BIN_DIR=$(dirname "$0")
COURSIER_BIN="$BASE_BIN_DIR/%s"
/usr/libexec/java_home -v 1.8 -F -R --exec java \
-Divy.home=%s -jar "$COURSIER_BIN" launch %s \
-r bintray:scalameta/maven \
-r bintray:scalacenter/releases \
-r https://oss.sonatype.org/content/repositories/staging \
--main bloop.Server
""" % (BLOOP_COURSIER_BINARY_NAME, args.ivy_home, BLOOP_ARTIFACT)


def download(url, target):
try:
socket = urlopen(url)
Expand Down Expand Up @@ -144,39 +161,57 @@ def download_and_install_template(url, target, permissions=0o644):
os.remove(template_target)
os.chmod(target, permissions)

def make_executable(path):
mode = os.stat(path).st_mode
mode |= (mode & 0o444) >> 2 # copy R bits to X
os.chmod(path, mode)

def coursier_bootstrap(target, main):
http = []
https = []

if "http_proxy" in os.environ:
http_proxy = urlparse(os.environ['http_proxy'])
http = [
"-Dhttp.proxyHost="+http_proxy.hostname,
"-Dhttp.proxyPort="+str(http_proxy.port)
]

if "https_proxy" in os.environ:
https_proxy = urlparse(os.environ['https_proxy'])
https = [
"-Dhttps.proxyHost="+https_proxy.hostname,
"-Dhttps.proxyPort="+str(https_proxy.port)
]

try:
from os.path import expanduser
ivy_home = expanduser("~") + "/.ivy2/"
https = []
http = []
if "http_proxy" in os.environ:
http_proxy = urlparse(os.environ['http_proxy'])
http = [
"-Dhttp.proxyHost="+http_proxy.hostname,
"-Dhttp.proxyPort="+str(http_proxy.port)
]

if "https_proxy" in os.environ:
https_proxy = urlparse(os.environ['https_proxy'])
https = [
"-Dhttps.proxyHost="+https_proxy.hostname,
"-Dhttps.proxyPort="+str(https_proxy.port)
]

if is_local:
check_call(["java"] + http + https + ["-Divy.home=" + args.ivy_home, "-jar", BLOOP_COURSIER_TARGET, "bootstrap", BLOOP_ARTIFACT,
# Use own script if Mac OS system to avoid launchd problems with java environment variables
if platform.system() == "Darwin":
# Resolve first so that `coursier launch` in script doesn't
check_call(["java"] + http + https + ["-Divy.home=" + args.ivy_home, "-jar", BLOOP_COURSIER_TARGET, "fetch", BLOOP_ARTIFACT,
"-r", "bintray:scalameta/maven",
"-r", "bintray:scalacenter/releases",
"-o", target, "-f", "--standalone", "--main", main
"-r", "bintray:scalacenter/releases"
])

# Write the script in blp-server path so that it works
with open(target, 'w') as output_file:
output_file.write(MACOS_LAUNCH_SCRIPT_CONTENTS)

make_executable(target)
else:
check_call(["java"] + http + https + ["-jar", BLOOP_COURSIER_TARGET, "bootstrap", BLOOP_ARTIFACT,
"-r", "bintray:scalameta/maven",
"-r", "bintray:scalacenter/releases",
"-r", "https://oss.sonatype.org/content/repositories/staging",
"-o", target, "-f", "--standalone", "--main", main
])
if is_local:
check_call(["java"] + http + https + ["-Divy.home=" + args.ivy_home, "-jar", BLOOP_COURSIER_TARGET, "bootstrap", BLOOP_ARTIFACT,
"-r", "bintray:scalameta/maven",
"-r", "bintray:scalacenter/releases",
"-o", target, "-f", "--standalone", "--main", main
])
else:
check_call(["java"] + http + https + ["-jar", BLOOP_COURSIER_TARGET, "bootstrap", BLOOP_ARTIFACT,
"-r", "bintray:scalameta/maven",
"-r", "bintray:scalacenter/releases",
"-r", "https://oss.sonatype.org/content/repositories/staging",
"-o", target, "-f", "--standalone", "--main", main
])
except CalledProcessError as e:
print("Coursier couldn't create %s. Please report an issue." % target)
print("Command: %s" % e.cmd)
Expand Down
6 changes: 2 additions & 4 deletions project/ReleaseUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ object ReleaseUtils {
| bash_completion.install "bin/bash/bloop"
| fish_completion.install "bin/fish/bloop.fish"
|
| File.delete("bin/blp-coursier")
|
| # We need to create these files manually here, because otherwise launchd
| # will create them with owner set to `root` (see the plist file below).
| FileUtils.mkdir_p("log/bloop/")
Expand All @@ -125,9 +123,9 @@ object ReleaseUtils {
| <key>KeepAlive</key>
| <true/>
| <key>StandardOutPath</key>
| <string>#{var}/log/bloop/bloop.out.log</string>
| <string>#{prefix}/log/bloop/bloop.out.log</string>
| <key>StandardErrorPath</key>
| <string>#{var}/log/bloop/bloop.err.log</string>
| <string>#{prefix}/log/bloop/bloop.err.log</string>
|</dict>
|</plist>
| EOS
Expand Down

0 comments on commit 601b4f6

Please sign in to comment.