Skip to content

Commit

Permalink
Add some new JavaEE to Quarkus rules (#78)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Manuel Leflet Estrada <[email protected]>
  • Loading branch information
jmle authored Jul 24, 2024
1 parent 9bc9035 commit 04d41f0
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 17 deletions.
74 changes: 74 additions & 0 deletions default/generated/quarkus/200-ee-to-quarkus.windup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
- category: potential
customVariables: []
description: '@Stateless annotation must be replaced'
effort: 1
labels:
- konveyor.io/source=java-ee
- konveyor.io/source=jakarta-ee
- konveyor.io/target=quarkus
links:
- title: Quarkus CDI reference
url: https://quarkus.io/guides/cdi-reference
message: Stateless EJBs can be converted to a CDI bean by replacing the `@Stateless`
annotation with a scope eg `@ApplicationScoped`
ruleID: ee-to-quarkus-00000
when:
or:
- java.referenced:
location: ANNOTATION
pattern: javax.ejb.Stateless
- java.referenced:
location: ANNOTATION
pattern: jakarta.ejb.Stateless
- category: mandatory
customVariables: []
description: '@Stateful annotation must be replaced'
effort: 3
labels:
- konveyor.io/source=java-ee
- konveyor.io/source=jakarta-ee
- konveyor.io/target=quarkus
links:
- title: Quarkus CDI reference
url: https://quarkus.io/guides/cdi-reference
message: |-
Stateful EJBs can be converted to a CDI bean by replacing the `@Stateful` annotation with a bean-defining annotation
that encompasses the appropriate scope (e.g., `@ApplicationScoped`). `@Stateful` EJBs often translate to `@SessionScoped`
beans (a scope which requires activating the `quarkus-undertow` extension), but the appropriate scope may differ based
on your application architecture. Review your application's requirements to determine the appropriate scope.
Note that it is recommended, as a good practice, to keep state external from the service in Quarkus.
ruleID: ee-to-quarkus-00010
when:
or:
- java.referenced:
location: ANNOTATION
pattern: javax.ejb.Stateful
- java.referenced:
location: ANNOTATION
pattern: jakarta.ejb.Stateful
- category: mandatory
customVariables: []
description: Method should be marked as @Transactional
effort: 3
labels:
- konveyor.io/source=java-ee
- konveyor.io/source=jakarta-ee
- konveyor.io/target=quarkus
links:
- title: Quarkus CDI reference
url: https://quarkus.io/guides/cdi-reference
message: |-
Any EJB method has container-manager transactions by default, with transaction attribute
`REQUIRED` as a default (a transaction is started if one is not already in progress). Methods that were part of
an EJB bean to be migrated to CDI must be annotated with `@Transactional`, or be marked as transactional
in any other way (i.e, by annotating the class).
ruleID: ee-to-quarkus-00020
when:
or:
- java.referenced:
location: ANNOTATION
pattern: javax.ejb*
- java.referenced:
location: ANNOTATION
pattern: jakarta.ejb*
83 changes: 83 additions & 0 deletions default/generated/quarkus/201-persistence-to-quarkus.windup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
- category: optional
customVariables: []
description: Move persistence config to a properties file
effort: 1
labels:
- konveyor.io/source=java-ee
- konveyor.io/source=jakarta-ee
- konveyor.io/target=quarkus
links:
- title: Using Hibernate ORM and Jakarta persistence
url: https://quarkus.io/guides/hibernate-orm#persistence-xml
message: "It is recommended to move persistence related configuration from an XML
file to a properties one.\n This allows centralization of the configuration in
Quarkus. Check the link for more information.\n \n \n Datasource and persistence
configurations in XML can be substituted with a single centralized properties
file. Here is an example of a translation:\n \n The following datasource configuration:\n
```\n <datasources xmlns=\"http://www.jboss.org/ironjacamar/schema\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n
xsi:schemaLocation=\"http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd\">\n
<!-- The datasource is bound into JNDI at this location. We reference\n this in
META-INF/persistence.xml -->\n <datasource jndi-name=\"java:jboss/datasources/TasksJsfQuickstartDS\"\n
pool-name=\"tasks-jsf-quickstart\" enabled=\"true\"\n use-java-context=\"true\">\n
<connection-url>jdbc:h2:mem:tasks-jsf-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>\n
<driver>h2</driver>\n <security>\n <user-name>sa</user-name>\n <password>sa</password>\n
</security>\n </datasource>\n </datasources>\n ```\n along with the following
persistence configuration:\n ```\n <persistence version=\"2.1\"\n xmlns=\"http://xmlns.jcp.org/xml/ns/persistence\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"\n
http://xmlns.jcp.org/xml/ns/persistence\n http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd\">\n
<persistence-unit name=\"primary\">\n <!-- We use a different datasource for tests,
so as to not overwrite\n production data. This is an unmanaged data source, backed
by H2, an in memory\n database. Production applications should use a managed datasource.
-->\n <!-- The datasource is deployed as WEB-INF/test-ds.xml,\n you can find it
in the source at src/test/resources/test-ds.xml -->\n <jta-data-source>java:jboss/datasources/TasksJsfQuickstartDS</jta-data-source>\n
<properties>\n <!-- Properties for Hibernate -->\n <property name=\"hibernate.hbm2ddl.auto\"
value=\"create-drop\" />\n <property name=\"hibernate.show_sql\" value=\"false\"
/>\n </properties>\n </persistence-unit>\n </persistence>\n ```\n can be translated
to:\n ```\n quarkus.datasource.jdbc.url=jdbc:h2:mem:tasks-jsf-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1\n
quarkus.datasource.db-kind=h2\n quarkus.datasource.username=sa\n quarkus.datasource.password=sa\n\n
quarkus.hibernate-orm.database.generation=drop-and-create\n ```"
ruleID: persistence-to-quarkus-00000
when:
or:
- builtin.file:
pattern: persistence\.xml
- builtin.file:
pattern: .*-ds\.xml
- category: potential
customVariables: []
description: '@Produces cannot annotate an EntityManager'
effort: 1
labels:
- konveyor.io/source=java-ee
- konveyor.io/source=jakarta-ee
- konveyor.io/target=quarkus
links:
- title: Using Hibernate ORM and Jakarta persistence
url: https://quarkus.io/guides/hibernate-orm#persistence-xml
- title: Setting up and configuring Hibernate ORM
url: https://quarkus.io/guides/hibernate-orm#setting-up-and-configuring-hibernate-orm
message: "In JavaEE/JakartaEE, using `@PersistenceContext` was needed in order to
inject a data source. Quarkus, on the other hand,\n will create the bean automatically
just by correctly setting up your datasource, so the `@PersistenceContext` annotation can be removed. \nThis also makes having a `@Produces`
annotation\n on the `EntityManager` illegal in Quarkus.\n \n If you are using
a `@Produces` annotation for your EntityManager, and it is not needed after configuring
your datasource, remove it and `@Inject` the EntityManager.\n Otherwise, if the
producer is still needed, please create a qualification for your produced `EntityManager`,
as well as every injection point for the EM.\n \n For instance, you can create
an `ExtendedContext` qualifier:\n ```\n @Qualifier\n @Target({{ ElementType.TYPE,
ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }})\n @Retention(RetentionPolicy.RUNTIME)\n
public @interface ExtendedContext {{ ... }}\n ```\n and then inject your entity
managers:\n ```\n @ExtendedContext\n public EntityManager getEm() {{\n return
em;\n }}\n ```"
ruleID: persistence-to-quarkus-00011
when:
and:
- java.referenced:
location: IMPORT
pattern: javax.enterprise.inject.Produces
as: file
ignore: true
- java.referenced:
location: IMPORT
pattern: javax.persistence.EntityManager
from: file
29 changes: 29 additions & 0 deletions default/generated/quarkus/202-remote-ejb-to-quarkus.windup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
- category: mandatory
customVariables: []
description: Remote EJBs are not supported in Quarkus
effort: 1
labels:
- konveyor.io/source=java-ee
- konveyor.io/source=jakarta-ee
- konveyor.io/target=quarkus
message: |-
Remote EJBs are not supported in Quarkus, and therefore its use must be removed and replaced with REST functionality. In order to do this:
1. Replace the `@Remote` annotation on the class with a `@jakarta.ws.rs.Path("<endpoint>")` annotation. An endpoint must be added to the annotation in place of `<endpoint>` to specify the actual path to the REST service.
2. Remove `@Stateless` annotations if present. Given that REST services are stateless by nature, it makes it unnecessary.
3. For every public method on the EJB being converted, do the following:
- In case the method has no input parameters, annotate the method with `@jakarta.ws.rs.GET`; otherwise annotate it with `@jakarta.ws.rs.POST` instead.
- Annotate the method with `@jakarta.ws.rs.Path("<endpoint>")` and give it a proper endpoint path. As a rule of thumb, the method name can be used as endpoint, for instance:
```
@Path("/increment")
public void increment() {{ ... }}
```
- Add `@jakarta.ws.rs.QueryParam("<param-name>")` to any method parameters if needed, where `<param-name>` is a name for the parameter.
ruleID: remote-ejb-to-quarkus-00000
when:
or:
- java.referenced:
location: ANNOTATION
pattern: javax.ejb.Remote
- java.referenced:
location: ANNOTATION
pattern: jakarta.ejb.Remote
17 changes: 0 additions & 17 deletions default/generated/quarkus/210-cdi-to-quarkus.windup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,3 @@
java.referenced:
location: ANNOTATION
pattern: javax.enterprise.inject.Produces
- category: potential
customVariables: []
description: Stateless annotation can be replaced with scope
effort: 1
labels:
- konveyor.io/source=java-ee
- konveyor.io/target=quarkus
links:
- title: Quarkus CDI reference
url: https://quarkus.io/guides/cdi-reference
message: Stateless EJBs can be converted to a cdi bean by replacing the `@Stateless`
annotation with a scope eg `@ApplicationScoped`
ruleID: cdi-to-quarkus-00050
when:
java.referenced:
location: ANNOTATION
pattern: javax.ejb.Stateless

0 comments on commit 04d41f0

Please sign in to comment.