Skip to content

Commit

Permalink
check java version for azure (#957)
Browse files Browse the repository at this point in the history
* check java version for azure

* Azure java version identification

* use winup:matches

---------

Co-authored-by: kaiqianyang <kaiqianyang@microsoftcom>
Co-authored-by: PhilipCattanach <pcattana@redhat.com>
  • Loading branch information
3 people committed Jun 7, 2023
1 parent ab7882a commit be700f2
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 0 deletions.
67 changes: 67 additions & 0 deletions rules/rules-reviewed/azure/azure-java-version.windup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0"?>
<ruleset id="azure-java-version"
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>
Check non-LTS Java versions
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-xml,3.0.0.Final" />
</dependencies>
<sourceTechnology id="springboot"/>
<sourceTechnology id="eap" versionRange="[7,8)" />
<targetTechnology id="azure-spring-apps"/>
<targetTechnology id="azure-appservice"/>
<targetTechnology id="azure-aks"/>
<targetTechnology id="azure-container-apps"/>
<tag>version</tag>
</metadata>
<rules>
<rule id="azure-java-version-01000">
<when>
<xmlfile matches="//m:java.version[windup:matches(text(), '{v}')]" in="pom.xml" as="result">
<namespace prefix="m" uri="http://maven.apache.org/POM/4.0.0"/>
</xmlfile>
</when>
<perform>
<iteration over="result">
<hint title="Non-LTS version Java" category-id="potential" effort="3">
<message>
<![CDATA[
The application is using non-LTS version Java.
JDK on LTS version is recommended, i.e. JAVA_8, JAVA_11 or JAVA_17.
]]>
</message>
</hint>
</iteration>
</perform>
<where param="v">
<matches pattern="(9|10|12|13|14|15|16|19|20).*"/>
</where>
</rule>
<rule id="azure-java-version-02000">
<when>
<xmlfile matches="//m:java.version[windup:matches(text(), '{v}')]" in="pom.xml" as="result">
<namespace prefix="m" uri="http://maven.apache.org/POM/4.0.0"/>
</xmlfile>
</when>
<perform>
<iteration over="result">
<hint title="Java version found to be lower than JAVA_8" category-id="potential" effort="3">
<message>
<![CDATA[
The application is using Java version lower than JAVA_8.
JDK on LTS version is recommended, i.e. JAVA_8, JAVA_11 or JAVA_17.
]]>
</message>
</hint>
</iteration>
</perform>
<where param="v">
<matches pattern="1\.[0-7]"/>
</where>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<ruletest id="azure-java-version-test" 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">
<testDataPath>data/azure-java-version</testDataPath>
<rulePath>../azure-java-version.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="azure-java-version-test-01000">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="The application is using non-LTS version Java." />
</iterable-filter>
</not>
</when>
<perform>
<fail message="non-LTS JAVA version hint was not found!" />
</perform>
</rule>
<rule id="azure-java-version-test-02000">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="The application is using Java version lower than JAVA_8." />
</iterable-filter>
</not>
</when>
<perform>
<fail message="JAVA version lower than java_8 hint was not found!" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>19</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.12</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

0 comments on commit be700f2

Please sign in to comment.