Skip to content

Commit 9148233

Browse files
Hector Geraldinomarc0der
authored andcommitted
Add relocation hooks
1 parent ba6f26f commit 9148233

File tree

6 files changed

+120
-0
lines changed

6 files changed

+120
-0
lines changed

app/controllers/HooksController.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ class HooksController @Inject() (cc: ControllerComponents)
8080
case (Pre, _, _, _, _) =>
8181
Ok(views.txt.default_pre(candidate, version, platform))
8282

83+
//RELOCATE
84+
case (Relocate, Java, _, MacX64 | MacARM64, _) =>
85+
Ok(views.txt.java_relocate_osx_tarball(candidate, version, platform))
86+
case (Relocate, JMC, _, MacX64 | MacARM64, _) =>
87+
Ok(views.txt.jmc_relocate_unix_tarball(candidate, version, vendor, jmcBinaryExec(vendor, MacX64)))
88+
case (Relocate, JMC, _, LinuxX32 | LinuxX64 | LinuxARM64 | LinuxARM32HF | LinuxARM32SF, _) =>
89+
Ok(views.txt.jmc_relocate_unix_tarball(candidate, version, vendor, jmcBinaryExec(vendor, platform)))
90+
case (Relocate, JMC, _, Windows64, _) =>
91+
Ok(views.txt.jmc_relocate_win_zip(candidate, version, vendor, jmcBinaryExec(vendor, Windows64)))
92+
8393
case (_, _, _, _, _) => NotFound
8494
}
8595
}

app/domain/domain.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ object Hooks {
7171
def from(phase: String) = phase match {
7272
case Post.phase => Post
7373
case Pre.phase => Pre
74+
case Relocate.phase => Relocate
7475
}
7576
}
7677
case object Post extends Hooks {
@@ -79,3 +80,6 @@ case object Post extends Hooks {
7980
case object Pre extends Hooks {
8081
override val phase = "pre"
8182
}
83+
case object Relocate extends Hooks {
84+
override val phase = "relocate"
85+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@import domain._
2+
@(candidate: Candidate, version: String, platform: Platform)#!/bin/bash
3+
#Relocation Hook: osx-java
4+
function __sdkman_relocate_installation_hook {
5+
__sdkman_echo_debug "A @{platform.name} relocation hook was found for @{candidate.name} @{version}-openjdk."
6+
7+
local present_dir="$(pwd)"
8+
local candidate_dir="${SDKMAN_CANDIDATE_DIR}/@{candidate.name}/@{version}"
9+
local work_jdk_dir="${SDKMAN_DIR}/tmp/@{candidate.name}-@{version}"
10+
11+
echo ""
12+
__sdkman_echo_green "Relocating @{candidate.name} @version..."
13+
14+
#Move ./Contents/Home to temp location
15+
cd "$candidate_dir"/*/Contents
16+
mv -f Home "$work_jdk_dir"
17+
18+
#Replace candidate
19+
cd "$present_dir"
20+
rm -rf "$candidate_dir"
21+
mv -f "$work_jdk_dir" "$candidate_dir"
22+
23+
echo ""
24+
__sdkman_echo_green "Done relocating..."
25+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@import domain._
2+
@(candidate: Candidate, version: String, vendor: String, executableBinary: String)#!/bin/bash
3+
#Relocation Hook: unix-jmc-tarball
4+
function __sdkman_relocate_installation_hook {
5+
__sdkman_echo_debug "A unix relocate hook was found for JMC @vendor @version."
6+
7+
local present_dir="$(pwd)"
8+
local executable_binary="@{executableBinary}"
9+
local candidate_dir="${SDKMAN_CANDIDATE_DIR}/@{candidate.name}/@{version}"
10+
11+
echo ""
12+
__sdkman_echo_green "Relocating JMC @vendor @version..."
13+
14+
@if(vendor == "zulu") {
15+
# deal with zulu folder structure
16+
cd "$candidate_dir"/*
17+
} else {
18+
# deal with jmc flat structure
19+
cd "$candidate_dir"
20+
}
21+
22+
mkdir bin
23+
cd bin
24+
ln -s ../"${executable_binary}" jmc
25+
cd "$present_dir"
26+
27+
echo ""
28+
__sdkman_echo_green "Done relocating..."
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@import domain._
2+
@(candidate: Candidate, version: String, vendor: String, executableBinary: String)#!/bin/bash
3+
#Relocation Hook: win-jmc-zip
4+
function __sdkman_relocate_installation_hook {
5+
__sdkman_echo_debug "A Windows relocate hook was found for JMC @vendor @version."
6+
7+
local present_dir="$(pwd)"
8+
local executable_binary="@{executableBinary}"
9+
local candidate_dir="${SDKMAN_CANDIDATE_DIR}/@{candidate.name}/@{version}"
10+
11+
echo ""
12+
__sdkman_echo_green "Relocating JMC @vendor @version..."
13+
14+
@if(vendor == "zulu") {
15+
# deal with zulu folder structure
16+
cd "$candidate_dir"/*
17+
} else {
18+
# deal with jmc flat structure
19+
cd "$candidate_dir"
20+
}
21+
22+
mkdir bin
23+
cd bin
24+
ln -s ../"${executable_binary}" jmc
25+
cd "$present_dir"
26+
27+
echo ""
28+
__sdkman_echo_green "Done relocating..."
29+
}

features/relocate_hooks.feature

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Feature: Relocate Hooks
2+
3+
Scenario: A Relocate Hook request for java OSX served
4+
When a hook is requested at /hooks/relocate/java/8.0.161-zulu/darwinx64
5+
Then a 200 status code is received
6+
And the response script contains "Relocation Hook: osx-java"
7+
8+
Scenario: A Relocate Hook request for java Linux is not served
9+
When a hook is requested at /hooks/relocate/java/9.0.4-open/linuxx64
10+
Then a 404 status code is received
11+
12+
Scenario Outline:
13+
When a hook is requested at <uri>
14+
Then a 200 status code is received
15+
And the response script contains "<contains>"
16+
Examples:
17+
| uri | contains |
18+
| /hooks/relocate/jmc/8.0.0.17-zulu/linuxx64 | Relocation Hook: unix-jmc-tarball |
19+
| /hooks/relocate/jmc/8.0.0-adpt/linuxx64 | Relocation Hook: unix-jmc-tarball |
20+
| /hooks/relocate/jmc/8.0.0.17-zulu/darwinx64 | Relocation Hook: unix-jmc-tarball |
21+
| /hooks/relocate/jmc/8.0.0-adpt/darwinx64 | Relocation Hook: unix-jmc-tarball |
22+
| /hooks/relocate/jmc/8.0.0-adpt/cygwin | Relocation Hook: win-jmc-zip |
23+
| /hooks/relocate/jmc/8.0.0-adpt/msys_nt-10.0 | Relocation Hook: win-jmc-zip |

0 commit comments

Comments
 (0)