Skip to content

Commit

Permalink
[WINDUPRULE-920] Jakarta Faces rule (#894)
Browse files Browse the repository at this point in the history
* [WINDUPRULE-920] Jakarta Faces rule

* [WINDUPRULE-920] Make rule potential

* [WINDUPRULE-920] Add iterable-filter
  • Loading branch information
jmle authored Mar 17, 2023
1 parent 6ceeb54 commit ce5f530
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
39 changes: 39 additions & 0 deletions rules/rules-reviewed/eap8/eap7/jakarta-faces.windup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<ruleset xmlns="http://windup.jboss.org/schema/jboss-ruleset" id="jakarta-faces"
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 provides analysis of Java EE applications that need to change certain Jakarta Faces usages when migrating to EAP 8.
</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" />
</dependencies>
<sourceTechnology id="eap" versionRange="[6,8)" />
<targetTechnology id="eap" versionRange="[8,9)" />
<tag>JakartaEE</tag>
<tag>eap8</tag>
</metadata>
<rules>
<rule id="jakarta-faces-00001">
<when>
<and>
<javaclass references="jakarta.faces.context.FacesContext">
<location>FIELD_DECLARATION</location>
<annotation-type pattern="jakarta.inject.Inject"/>
</javaclass>
<javaclass references="jakarta.faces.context.FacesContext">
<location>RETURN_TYPE</location>
</javaclass>
</and>
</when>
<perform>
<hint title="Producer for creating FacesContext must be removed" effort="1" category-id="potential">
<message>The @Producer for instantiating `FacesContext` is not necessary anymore, as CDI injection for `FacesContext` works out of the box.</message>
<link href="https://access.redhat.com/solutions/6982900" title="WELD-001409: Ambiguous dependencies for type FacesContext with qualifiers @Default when migrating to EAP 8"/>
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import jakarta.inject.Inject;
import jakarta.faces.context.FacesContext;
import jakarta.enterprise.inject.Model;

@Model
public class JSFBean {

@Inject
FacesContext ctx;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import jakarta.faces.context.FacesContext;
import jakarta.enterprise.inject.Produces;
import jakarta.enterprise.context.RequestScoped;

public class Producer {
@Produces
@RequestScoped
public FacesContext produceFacesContext() {
return FacesContext.getCurrentInstance();
}
}
24 changes: 24 additions & 0 deletions rules/rules-reviewed/eap8/eap7/tests/jakarta-faces.windup.test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruletest id="jakarta-faces-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/jakarta-faces</testDataPath>
<rulePath>../jakarta-faces.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="jakarta-faces-00001-test">
<when>
<not>
<iterable-filter size="2">
<hint-exists message="The @Producer for instantiating `FacesContext` is not necessary anymore, as CDI injection for `FacesContext` works out of the box."/>
</iterable-filter>
</not>
</when>
<perform>
<fail message="[jakarta-faces-00001] The hint was not found!"/>
</perform>
</rule>
</rules>
</ruleset>
</ruletest>

0 comments on commit ce5f530

Please sign in to comment.