Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
76 lines (60 loc) · 2.39 KB

File metadata and controls

76 lines (60 loc) · 2.39 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- mode: python; coding: utf-8 -*-
#
# Copyright (C) 2021 CONTACT Software GmbH
# https://www.contact-software.com/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Implementation of the java plugin for csspin"""
import os
import shutil
from csspin import config, die, echo, interpolate1, mv, setenv, warn
from path import Path
defaults = config(install_dir="{spin.data}/java")
def set_environment(cfg):
"""Set the environment variables needed for java"""
java_bin_dir = cfg.java.java_home / "bin"
setenv(
JAVA_HOME=cfg.java.java_home,
PATH=os.pathsep.join((java_bin_dir, "{PATH}")),
)
def configure(cfg):
"""Configure the java plugin"""
if cfg.java.use:
warn(f"java.version will be ignored, since java.use is set to '{cfg.java.use}'")
if java_path := shutil.which(interpolate1(cfg.java.use)):
# assuming java to be $JAVA_HOME/bin/java
cfg.java.java_home = Path(java_path).realpath().dirname().dirname()
else:
die(f"Could not find java executable '{cfg.java.use}'")
elif cfg.java.version:
cfg.java.java_home = Path(interpolate1(cfg.java.install_dir)) / str(
cfg.java.version
)
else:
die(
"'csspin_java.java' does not set a default version for java. "
"Set either 'java.version' or 'java.use'."
)
def provision(cfg):
"""Install java if it does not exist"""
if cfg.java.version and not (cfg.java.use or cfg.java.java_home.exists()):
from tempfile import TemporaryDirectory
import jdk
with TemporaryDirectory() as tmp_dir:
echo(f"Downloading JDK from {jdk.get_download_url(cfg.java.version)}")
jdk_path = jdk.install(cfg.java.version, path=Path(tmp_dir))
mv(jdk_path, cfg.java.java_home)
set_environment(cfg)
def init(cfg):
"""Initialize the environment"""
set_environment(cfg)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.