Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[releases/6.3.z] WINDUPRULE-1018: new ruleset for eap8 log4j removed (#1016) #1025

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions rules/rules-reviewed/eap8/eap7/log4j-removed.windup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?xml version="1.0"?>
<ruleset xmlns="http://windup.jboss.org/schema/jboss-ruleset" id="log4j-removed"
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 use log4j which is no longer bundled within EAP8
</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="eap" versionRange="[6,8)" />
<targetTechnology id="eap" versionRange="[8,)" />
</metadata>
<rules>
<rule id="log4j-removed-00001">
<when>

<and>
<javaclass references="org.apache.log4j.Logger">
<location>IMPORT</location>
</javaclass>
<not>
<or>
<file filename="log4j.xml"/>
<file filename="log4j.properties"/>
<file filename="jboss-log4j.xml"/>
</or>
</not>
<not>
<or>
<project>
<artifact groupId="log4j" artifactId="log4j" />
</project>
<dependency groupId="log4j" artifactId="log4j" />
<file filename="log4j.jar"/>
</or>
</not>
</and>
</when>
<perform>
<hint title="Log4j version 1 is not longer provided in EAP8" effort="1" category-id="mandatory">
<message>Log4j usage without configuration files</message>
<link href="https://access.redhat.com/articles/6973120" title="Migration: Apache Log4j version 1 is not longer provided in EAP 8"/>
</hint>
</perform>
</rule>
<rule id="log4j-removed-00002">
<when>
<not>
<or>
<project>
<artifact groupId="log4j" artifactId="log4j" />
</project>
<dependency groupId="log4j" artifactId="log4j" />
<file filename="log4j.jar"/>
</or>
</not>
<and>
<javaclass references="org.apache.log4j.Logger">
<location>IMPORT</location>
</javaclass>
</and>
</when>
<perform>
<hint title="Log4j version 1 is not longer provided in EAP8" effort="1" category-id="mandatory">
<message>Log4j usage without including `log4j.jar`</message>
<link href="https://access.redhat.com/articles/6973120" title="Migration: Apache Log4j version 1 is not longer provided in EAP 8"/>
</hint>
</perform>
</rule>
<rule id="log4j-removed-00003">
<when>
<not>
<or>
<project>
<artifact groupId="log4j" artifactId="log4j" />
</project>
<dependency groupId="log4j" artifactId="log4j" />
<file filename="log4j.jar"/>
</or>
</not>
<and>
<file filename="{config-filename}"/>
</and>
</when>
<perform>
<hint title="Log4j version 1 is not longer provided in EAP8" effort="1" category-id="mandatory">
<message>Log4j configuration without including `log4j.jar`</message>
<link href="https://access.redhat.com/articles/6973120" title="Migration: Apache Log4j version 1 is not longer provided in EAP 8"/>
</hint>
</perform>
<where param="config-filename">
<matches pattern="(log4j.xml|log4j.properties|jboss-log4j.xml)"/>
</where>
</rule>
<rule id="log4j-removed-00004">
<when>
<not>
<or>
<project>
<artifact groupId="log4j" artifactId="log4j" />
</project>
<dependency groupId="log4j" artifactId="log4j" />
<file filename="log4j.jar"/>
</or>
</not>
<and>
<filecontent pattern="custom-handler{*}org.apache.log4j.{*}Appender" filename="{*}.xml"/>
</and>
</when>
<perform>
<hint title="Log4j version 1 is not longer provided in EAP8" effort="1" category-id="mandatory">
<message>Log4j custom-handler using appender</message>
<link href="https://access.redhat.com/articles/6973120" title="Migration: Apache Log4j version 1 is not longer provided in EAP 8"/>
</hint>
</perform>
</rule>
<rule id="log4j-removed-00005">
<when>
<not>
<or>
<project>
<artifact groupId="log4j" artifactId="log4j" />
</project>
<dependency groupId="log4j" artifactId="log4j" />
<file filename="log4j.jar"/>
</or>
</not>
<and>
<or>
<filecontent pattern="org.jboss.log4j.logmanager" filename="jboss-deployment-structure.xml"/>
<filecontent pattern="org.jboss.log4j.logmanager" filename="Manifest.MF"/>
</or>
</and>
</when>
<perform>
<hint title="Log4j version 1 is not longer provided in EAP8" effort="1" category-id="mandatory">
<message>Log4j module dependency declaration</message>
<link href="https://access.redhat.com/articles/6973120" title="Migration: Apache Log4j version 1 is not longer provided in EAP 8"/>
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import org.apache.log4j.Logger;

public class Test {

public static void main(String[] args) {
Logger logger = new Logger();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dependencies: org.jboss.log4j.logmanager
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import org.apache.log4j.Logger;

public class Test {

public static void main(String[] args) {
Logger logger = new Logger();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.jboss.log4j.logmanager" export="FALSE"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<subsystem xmlns="urn:jboss:domain:logging:1.2">
<custom-handler name="log4jAppender" class="org.apache.log4j.FileAppender" module="org.apache.log4j">
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<level name="INFO"/>
<properties>
<property name="append" value="true"/>
<property name="file" value="${jboss.server.log.dir}/log4j.log"/>
<property name="immediateFlush" value="true"/>
</properties>
</custom-handler>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="log4jAppender"/>
</handlers>
</root-logger>
</subsystem>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruletest id="log4j-removed-no-config-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/log4j-removed-no-config/</testDataPath>
<rulePath>../log4j-removed.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="log4j-removed-00001-test">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="Log4j usage without configuration files"/>
</iterable-filter>
</not>
</when>
<perform>
<fail message="[log4j-removed-00001] The hint was not found!" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
60 changes: 60 additions & 0 deletions rules/rules-reviewed/eap8/eap7/tests/log4j-removed.windup.test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0"?>
<ruletest id="log4j-removed-with-config-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/log4j-removed-with-config/</testDataPath>
<rulePath>../log4j-removed.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="log4j-removed-00002-test">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="Log4j usage without including `log4j.jar`"/>
</iterable-filter>
</not>
</when>
<perform>
<fail message="[log4j-removed-00002] The hint was not found!" />
</perform>
</rule>
<rule id="log4j-removed-00003-test">
<when>
<not>
<iterable-filter size="3">
<hint-exists message="Log4j configuration without including `log4j.jar`"/>
</iterable-filter>
</not>
</when>
<perform>
<fail message="[log4j-removed-00003] The hint was not found!" />
</perform>
</rule>
<rule id="log4j-removed-00004-test">
<when>
<not>
<iterable-filter size="1">
<hint-exists message="Log4j custom-handler using appender"/>
</iterable-filter>
</not>
</when>
<perform>
<fail message="[log4j-removed-00004] The hint was not found!" />
</perform>
</rule>
<rule id="log4j-removed-00005-test">
<when>
<not>
<iterable-filter size="2">
<hint-exists message="Log4j module dependency declaration"/>
</iterable-filter>
</not>
</when>
<perform>
<fail message="[log4j-removed-00005] The hint was not found!" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>