Skip to content

Commit

Permalink
Winduprule-1030 (#1022)
Browse files Browse the repository at this point in the history
* kitchesink quarkus migration rules

* kitchensink migration rules tests

* add rule for junit

* jax-rs activation rule
  • Loading branch information
m-brophy authored Oct 13, 2023
1 parent 672eb21 commit 7969042
Show file tree
Hide file tree
Showing 18 changed files with 369 additions and 1 deletion.
1 change: 1 addition & 0 deletions rules/rules-reviewed/eap8/eap7/hibernate-6.2.windup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</dependencies>
<targetTechnology id="hibernate" versionRange="[6.2,)" />
<targetTechnology id="eap" versionRange="[8,)" />
<targetTechnology id="quarkus" versionRange="[3,)" />
<tag>hibernate</tag>
</metadata>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</dependencies>
<targetTechnology id="eap" versionRange="[8,)" />
<targetTechnology id="hibernate" versionRange="[6.1,)" />
<targetTechnology id="quarkus" versionRange="[3,)" />
<tag>hibernate</tag>
<tag>eap8</tag>
</metadata>
Expand Down
1 change: 1 addition & 0 deletions rules/rules-reviewed/eap8/eap7/hibernate-search.windup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</dependencies>
<targetTechnology id="eap" versionRange="[8,)" />
<targetTechnology id="hibernate" versionRange="[6,)" />
<targetTechnology id="quarkus" versionRange="[3,)" />
<tag>hibernate</tag>
<tag>eap8</tag>
</metadata>
Expand Down
1 change: 1 addition & 0 deletions rules/rules-reviewed/eap8/eap7/hibernate6.windup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</dependencies>
<targetTechnology id="hibernate" versionRange="[6,)" />
<targetTechnology id="eap" versionRange="[8,)" />
<targetTechnology id="quarkus" versionRange="[3,)" />
<tag>hibernate</tag>
</metadata>

Expand Down
29 changes: 29 additions & 0 deletions rules/rules-reviewed/quarkus/java-ee/cdi-to-quarkus.windup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,34 @@
</iteration>
</perform>
</rule>
<rule id="cdi-to-quarkus-00040">
<when>
<javaclass references="javax.enterprise.inject.Produces">
<location>ANNOTATION</location>
</javaclass>
</when>
<perform>
<hint title="Producer annotation no longer required" effort="1" category-id="potential">
<message>In Quarkus, you can skip the @Produces annotation completely if the producer method is annotated with a scope annotation, a stereotype or a qualifier..
This field could be accessed using a `@Named` getter method instead.
</message>
<link title="Quarkus Simplified Producer Method Declaration" href="https://quarkus.io/guides/cdi-reference#simplified-producer-method-declaration"/>
</hint>
</perform>
</rule>
<rule id="cdi-to-quarkus-00050">
<when>
<javaclass references="javax.ejb.Stateless">
<location>ANNOTATION</location>
</javaclass>
</when>
<perform>
<hint title="Stateless annotation can be replaced with scope" effort="1" category-id="potential">
<message>Stateless EJBs can be converted to a cdi bean by replacing the `@Stateless` annotation with a scope eg `@ApplicationScoped`
</message>
<link title="Quarkus CDI reference" href="https://quarkus.io/guides/cdi-reference"/>
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<ruleset xmlns="http://windup.jboss.org/schema/jboss-ruleset" id="dependency-removal-for-quarkus"
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>
This ruleset gives hints to migrate JAX-RS applications to Quarkus extension
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-javaee,3.0.0.Final" />
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final" />
<addon id="org.jboss.windup.rules,windup-rules-xml,3.0.0.Final" />
</dependencies>
<sourceTechnology id="java-ee" />
<targetTechnology id="quarkus" />
</metadata>
<rules>
<rule id="dependency-removal-for-quarkus-00000">
<when>
<or>
<project><artifact groupId="org.jboss.spec.javax.annotation" artifactId="jboss-annotations-api_1.3_spec" /></project>
<project><artifact groupId="org.jboss.spec.javax.ejb" artifactId="jboss-ejb-api_3.2_spec" /></project>
<project><artifact groupId="org.jboss.spec.javax.xml.bind" artifactId="jboss-jaxb-api_2.3_spec" /></project>
</or>
</when>
<perform>
<hint title="Remove non-quarkus dependencies" effort="1" category-id="mandatory">
<message>
Non-quarkus dependencies are no longer required and can be removed.
</message>
<link title="Quarkus - Guide" href="https://quarkus.io/guides" />
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0"?>
<!DOCTYPE ruleset [
<!ENTITY build-tool-maven-link-title "Quarkus - Guide">
<!ENTITY build-tool-maven-link-href "https://quarkus.io/guides/maven-tooling#build-tool-maven">
]>
<ruleset xmlns="http://windup.jboss.org/schema/jboss-ruleset" id="javaee-faces-to-quarkus"
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>
This ruleset gives hints to migrate JAX-RS applications to Quarkus extension
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-javaee,3.0.0.Final" />
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final" />
<addon id="org.jboss.windup.rules,windup-rules-xml,3.0.0.Final" />
</dependencies>
<sourceTechnology id="java-ee" />
<targetTechnology id="quarkus" />
</metadata>
<rules>
<rule id="javaee-faces-to-quarkus-00000">
<when>
<xmlfile in="pom.xml" matches="/m:project/m:dependencies/m:dependency[m:groupId/text() = 'org.jboss.spec.javax.faces']">
<namespace prefix="m" uri="http://maven.apache.org/POM/4.0.0" />
</xmlfile>
</when>
<perform>
<hint title="Replace JSF Dependency with MyFaces" effort="1" category-id="mandatory">
<message>
<![CDATA[
JSF Dependencies with groupId `org.jboss.spec.javax.faces` should be replaced with
```
<!-- Quarkus MyFaces dependencies -->
<dependency>
<groupId>org.apache.myfaces.core.extensions.quarkus</groupId>
<artifactId>myfaces-quarkus</artifactId>
<version>4.0.1</version>
</dependency>
<!-- Quarkus Faces utilities and components extensions -->
<dependency>
<groupId>io.quarkiverse.primefaces</groupId>
<artifactId>quarkus-primefaces</artifactId>
<version>3.13.1</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.omnifaces</groupId>
<artifactId>quarkus-omnifaces</artifactId>
<version>4.2.0</version>
</dependency>
```
]]>
</message>
<link title="Apache MyFaces: Getting Started on Quarkus" href="https://myfaces.apache.org/#/coregettingstarted?id=quarkus" />
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,69 @@
</hint>
</perform>
</rule>
<rule id="javaee-pom-to-quarkus-00070">
<when>
<or>
<xmlfile in="pom.xml" matches="/m:project/m:dependencies/m:dependency[m:artifactId/text() = 'jakarta.persistence-api']">
<namespace prefix="m" uri="http://maven.apache.org/POM/4.0.0" />
</xmlfile>
<xmlfile in="pom.xml" matches="/m:project/m:dependencies/m:dependency/m:groupId[contains(text(),'org.hibernate')]">
<namespace prefix="m" uri="http://maven.apache.org/POM/4.0.0" />
</xmlfile>
</or>
</when>
<perform>
<hint title="Configure Quarkus hibernate-orm" effort="1" category-id="mandatory">
<message>
<![CDATA[
Configure Quarkus 'hibernate-orm` and jakarta persistence.
Add the `quarkus-hibernate-orm` section and one for your preferred jdbc solution to the `pom.xml` file, eg for postgres:
```
<!-- Hibernate ORM specific dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
</dependency>
<!-- JDBC driver dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
```
]]>
</message>
<link title="Using hibernate-orm and jakarta persistence" href="https://quarkus.io/guides/hibernate-orm" />
</hint>
</perform>
</rule>
<rule id="javaee-pom-to-quarkus-00080">
<when>
<project>
<artifact groupId="junit" artifactId="junit" />
</project>
</when>
<perform>
<hint title="Use Quarkus junit artifact" effort="1" category-id="mandatory">
<message>
<![CDATA[
Use Quarkus junit artifact:
```
<!-- Quarkus junit specific dependency -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
```
]]>
</message>
<link title="Quarkus - Testing your application" href="https://quarkus.io/guides/getting-started-testing" />
<link title="Testing your Quarkus application with JUnit" href="https://access.redhat.com/documentation/en-us/red_hat_build_of_quarkus/1.3/html/getting_started_with_quarkus/proc-quarkus-junit-testing_quarkus-getting-started" />
</hint>
</perform>
</rule>
</rules>
</ruleset>
20 changes: 20 additions & 0 deletions rules/rules-reviewed/quarkus/java-ee/jaxrs-to-quarkus.windup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,25 @@
</hint>
</perform>
</rule>
<rule id="jaxrs-to-quarkus-00020">
<when>
<and>
<javaclass references="javax.ws.rs.ApplicationPath">
<location>ANNOTATION</location>
</javaclass>
<javaclass references="javax.ws.rs.core.Application">
<location>INHERITANCE</location>
</javaclass>
</and>
</when>
<perform>
<hint title="JAX-RS activation is no longer necessary" effort="1" category-id="optional">
<message>
JAX-RS activation is no longer necessary. You can set a root path like this but you don't have to.
</message>
<link title="Quarkus - Guide" href="https://quarkus.io/guides/resteasy-reactive#declaring-endpoints-uri-mapping" />
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,30 @@
<fail message="[cdi-to-quarkus-groovy-00030] Transitive dependency `javax.inject:javax.inject` hint was not found!" />
</perform>
</rule>
<rule id="cdi-to-quarkus-00040-test">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="In Quarkus, you can skip the @Produces annotation completely"/>
</iterable-filter>
</not>
</when>
<perform>
<fail message="[cdi-to-quarkus-00040] @Produces hint was not found!" />
</perform>
</rule>
<rule id="cdi-to-quarkus-00050-test">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="Stateless EJBs can be converted to a cdi bean by replacing"/>
</iterable-filter>
</not>
</when>
<perform>
<fail message="[cdi-to-quarkus-00050] stateless bean conversion hint was not found!" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sample;

import javax.ejb.Stateless;

@Stateless
public class HelloEJB {

String createHelloMessage(String name) {
return "Hello " + name + "!";
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package sample;

import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Produces;

@Dependent
public class HelloService {

@Produces
String createHelloMessage(String name) {
return "Hello " + name + "!";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.spec.javax.xml.bind</groupId>
<artifactId>jboss-jaxb-api_2.3_spec</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.3_spec</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruletest id="dependency-removal-for-quarkus-tests"
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/*</testDataPath>
<rulePath>../dependency-removal-for-quarkus.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="dependency-removal-for-quarkus-00000-test">
<when>
<not>
<iterable-filter size="4">
<hint-exists message="Non-quarkus dependencies are no longer required and can be removed"/>
</iterable-filter>
</not>
</when>
<perform>
<fail message="[dependency-removal-for-quarkus-00000] Dependency removal hint was not found!" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
Loading

0 comments on commit 7969042

Please sign in to comment.