Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
61ff3c98
Commit
61ff3c98
authored
Apr 15, 2021
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish 'Don't detect CloudPlatform when property is set'
See gh-25455
parent
70f44d3a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
17 deletions
+8
-17
CloudPlatform.java
...in/java/org/springframework/boot/cloud/CloudPlatform.java
+6
-12
CloudPlatformTests.java
...va/org/springframework/boot/cloud/CloudPlatformTests.java
+2
-5
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java
View file @
61ff3c98
...
...
@@ -140,7 +140,8 @@ public enum CloudPlatform {
* @return if the platform is active.
*/
public
boolean
isActive
(
Environment
environment
)
{
return
isEnforced
(
environment
)
||
(
isAutoDetectionEnabled
(
environment
)
&&
isDetected
(
environment
));
String
platformProperty
=
environment
.
getProperty
(
PROPERTY_NAME
);
return
isEnforced
(
platformProperty
)
||
(
platformProperty
==
null
&&
isDetected
(
environment
));
}
/**
...
...
@@ -151,7 +152,10 @@ public enum CloudPlatform {
* @since 2.3.0
*/
public
boolean
isEnforced
(
Environment
environment
)
{
String
platform
=
environment
.
getProperty
(
PROPERTY_NAME
);
return
isEnforced
(
environment
.
getProperty
(
PROPERTY_NAME
));
}
private
boolean
isEnforced
(
String
platform
)
{
return
name
().
equalsIgnoreCase
(
platform
);
}
...
...
@@ -164,16 +168,6 @@ public enum CloudPlatform {
*/
public
abstract
boolean
isDetected
(
Environment
environment
);
/**
* Determines if it is enabled that the platform is detected by looking for
* platform-specific environment variables.
* @param environment the environment
* @return if the platform auto-detection is enabled.
*/
private
boolean
isAutoDetectionEnabled
(
Environment
environment
)
{
return
environment
.
getProperty
(
PROPERTY_NAME
)
==
null
;
}
/**
* Returns if the platform is behind a load balancer and uses
* {@literal X-Forwarded-For} headers.
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/CloudPlatformTests.java
View file @
61ff3c98
...
...
@@ -18,9 +18,7 @@ package org.springframework.boot.cloud;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -148,9 +146,8 @@ class CloudPlatformTests {
envVars
.
put
(
"EXAMPLE_SERVICE_PORT"
,
"8080"
);
Environment
environment
=
getEnvironmentWithEnvVariables
(
envVars
);
((
MockEnvironment
)
environment
).
setProperty
(
"spring.main.cloud-platform"
,
"none"
);
List
<
CloudPlatform
>
activeCloudPlatforms
=
Stream
.
of
(
CloudPlatform
.
values
())
.
filter
((
cloudPlatform
)
->
cloudPlatform
.
isActive
(
environment
)).
collect
(
Collectors
.
toList
());
assertThat
(
activeCloudPlatforms
).
containsExactly
(
CloudPlatform
.
NONE
);
assertThat
(
Stream
.
of
(
CloudPlatform
.
values
()).
filter
((
platform
)
->
platform
.
isActive
(
environment
)))
.
containsExactly
(
CloudPlatform
.
NONE
);
}
private
Environment
getEnvironmentWithEnvVariables
(
Map
<
String
,
Object
>
environmentVariables
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment