-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add spring-boot-to-azure-system-config rule (#968)
Co-authored-by: kaiqianyang <kaiqianyang@microsoftcom>
- Loading branch information
1 parent
9c87a1d
commit 646b9fc
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
rules/rules-reviewed/azure/springboot/spring-boot-to-azure-system-config.windup.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0"?> | ||
<ruleset id="spring-boot-to-azure-system-config" | ||
xmlns="http://windup.jboss.org/schema/jboss-ruleset" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd"> | ||
<metadata> | ||
<description> | ||
Find usages of System.getenv, System.getProperty, System.setProperty, System.setProperties | ||
</description> | ||
<dependencies> | ||
<addon id="org.jboss.windup.rules,windup-rules-xml,3.0.0.Final"/> | ||
</dependencies> | ||
<sourceTechnology id="springboot"/> | ||
<targetTechnology id="azure-spring-apps"/> | ||
<targetTechnology id="azure-appservice"/> | ||
<targetTechnology id="azure-aks"/> | ||
<targetTechnology id="azure-container-apps"/> | ||
<tag>config</tag> | ||
</metadata> | ||
<rules> | ||
<rule id="spring-boot-to-azure-system-config-01000"> | ||
<when> | ||
<or> | ||
<javaclass references="java.lang.System.getenv({*})"> | ||
<location>METHOD_CALL</location> | ||
</javaclass> | ||
<javaclass references="java.lang.System.getProperty({*})"> | ||
<location>METHOD_CALL</location> | ||
</javaclass> | ||
<javaclass references="java.lang.System.setProperty({*})"> | ||
<location>METHOD_CALL</location> | ||
</javaclass> | ||
<javaclass references="java.lang.System.setProperties({*})"> | ||
<location>METHOD_CALL</location> | ||
</javaclass> | ||
</or> | ||
</when> | ||
<perform> | ||
<hint title="The application uses environment variables/system properties" category-id="optional" effort="1"> | ||
<message> | ||
<![CDATA[ | ||
Review the usage of environment variables and system properties and externalize them. | ||
You can inject any per-service configuration settings into each service as environment variables. | ||
Any system properties that the code depends on will need to be defined in JVM options. | ||
]]> | ||
</message> | ||
|
||
<link title="Configure per-service secrets and externalized settings" href="https://learn.microsoft.com/azure/developer/java/migration/migrate-spring-boot-to-azure-spring-apps#configure-per-service-secrets-and-externalized-settings"/> | ||
</hint> | ||
</perform> | ||
</rule> | ||
</rules> | ||
</ruleset> |
29 changes: 29 additions & 0 deletions
29
...ure/springboot/tests/data/spring-boot-to-azure-system-config/SystemGetEnvGetProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Contains code that should match for the following tests: | ||
// | ||
// eap-to-azure-appservice-environment-variables-001 | ||
|
||
public class SystemGetEnvGetProperty { | ||
|
||
public static void main(String[] args) { | ||
int PORT = -1; | ||
|
||
// Attempt to read a port number from the environment | ||
try { | ||
PORT = Integer.parseInt(System.getenv("PORT")); | ||
} catch (Exception ex) { | ||
} | ||
|
||
// Attempt to read the port number from a System property | ||
try { | ||
PORT = Integer.parseInt(System.getProperty("PORT")); | ||
} catch (Exception ex) { | ||
} | ||
|
||
if (PORT < 0) { | ||
PORT = 8080; | ||
} | ||
|
||
System.out.println(String.format("Found port: %d", PORT)); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
.../rules-reviewed/azure/springboot/tests/spring-boot-to-azure-system-config.windup.test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0"?> | ||
<ruletest xmlns="http://windup.jboss.org/schema/jboss-ruleset" | ||
id="spring-boot-to-azure-system-config-test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd"> | ||
<testDataPath>data/spring-boot-to-azure-system-config</testDataPath> | ||
<!-- By default sourceMode is True, so it will only consider .java files, not .jar binaries --> | ||
<sourceMode>true</sourceMode> | ||
<rulePath>../spring-boot-to-azure-system-config.windup.xml</rulePath> | ||
<ruleset> | ||
<rules> | ||
<rule id="spring-boot-to-azure-system-config-001-test"> | ||
<when> | ||
<not> | ||
<iterable-filter size="2"> | ||
<hint-exists message="Review the usage of environment variables and system properties and externalize them*"/> | ||
</iterable-filter> | ||
</not> | ||
</when> | ||
<perform> | ||
<fail message="[spring-boot-to-azure-system-config-001-test] hint was not found!" /> | ||
</perform> | ||
</rule> | ||
</rules> | ||
</ruleset> | ||
</ruletest> |