File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -128,3 +128,21 @@ for candidate_name in "${SDKMAN_CANDIDATES[@]}"; do
128128done
129129unset candidate_name candidate_dir
130130export PATH
131+
132+ if [[ " $sdkman_auto_env " == " true" ]]; then
133+ if [[ " $zsh_shell " == " true" ]]; then
134+ function sdkman_auto_env() {
135+ [[ -f " .sdkmanrc" ]] && sdk env
136+ }
137+
138+ chpwd_functions+=(sdkman_auto_env)
139+ else
140+ function sdkman_auto_env() {
141+ [[ " $SDKMAN_OLD_PWD " != " $PWD " ]] && [[ -f " .sdkmanrc" ]] && sdk env
142+
143+ export SDKMAN_OLD_PWD=" $PWD "
144+ }
145+
146+ [[ -z " $PROMPT_COMMAND " ]] && PROMPT_COMMAND=" sdkman_auto_env" || PROMPT_COMMAND=" ${PROMPT_COMMAND% \; } ;sdkman_auto_env"
147+ fi
148+ fi
Original file line number Diff line number Diff line change 11package sdkman.specs
22
33import sdkman.support.SdkmanEnvSpecification
4+ import spock.lang.Unroll
45
56import java.nio.file.Paths
67
@@ -91,6 +92,41 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
9192 ]
9293 }
9394
95+ def " should execute 'sdk env' when entering a directory with an .sdkmanrc" () {
96+ given :
97+ new FileTreeBuilder (candidatesDirectory). with {
98+ " groovy" {
99+ " 2.4.1" {}
100+ }
101+ }
102+
103+ bash = sdkmanBashEnvBuilder
104+ .withVersionCache(" x.y.z" )
105+ .withOfflineMode(true )
106+ .withConfiguration(" sdkman_auto_env" , sdkmanAutoEnv)
107+ .build()
108+
109+ new FileTreeBuilder (bash. workDir). with {
110+ " project" {
111+ " .sdkmanrc" (" groovy=2.4.1\n " )
112+ }
113+ }
114+
115+ bash. start()
116+ bash. execute(" source $bootstrapScript " )
117+
118+ when :
119+ bash. execute(" cd project" )
120+
121+ then :
122+ verifyOutput(bash. output)
123+
124+ where :
125+ sdkmanAutoEnv | verifyOutput
126+ ' true' | { it. contains(" Using groovy version 2.4.1 in this shell" ) }
127+ ' false' | { ! it. contains(" Using groovy version 2.4.1 in this shell" ) }
128+ }
129+
94130 def " should issue an error if .sdkmanrc contains a malformed candidate version" () {
95131 given :
96132 bash = sdkmanBashEnvBuilder
You can’t perform that action at this time.
0 commit comments