Skip to content

Commit

Permalink
Detects Java SE Threads usage (#794)
Browse files Browse the repository at this point in the history
* Java SE Threads

* Adds executor service
  • Loading branch information
agoncal committed Dec 7, 2022
1 parent e74e796 commit 1e2ab58
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<ruleset id="technology-usage-javase" 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>
This ruleset provides statistical summaries of the Java SE APIs.
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final" />
</dependencies>
<phase>PostMigrationRulesPhase</phase>
</metadata>
<rules>
<!-- Threads -->
<rule id="javase-technology-usage-01000">
<when>
<graph-query discriminator="TechnologyTagModel">
<property name="name">Java Threads</property>
</graph-query>
</when>
<perform>
<technology-identified name="Java Threads">
<tag name="Execute"/>
<tag name="Processing"/>
<tag name="Java EE"/>
</technology-identified>
</perform>
</rule>
</rules>
</ruleset>
44 changes: 44 additions & 0 deletions rules/rules-reviewed/technology-usage/javase.windup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0"?>
<ruleset
xmlns="http://windup.jboss.org/schema/jboss-ruleset" id="javase"
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 the Core Java SE APIs.
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final"/>
</dependencies>
</metadata>
<rules>
<!-- Threads -->
<rule id="javase-01000">
<when>
<javaclass references="java.lang.{classes}"/>
</when>
<perform>
<classification title="Threads" category-id="information" effort="0">
<description>The application uses Thread APIs.</description>
</classification>
<technology-tag level="INFORMATIONAL">Java Threads</technology-tag>
</perform>
<where param="classes">
<matches pattern="(Thread|ThreadDeath|ThreadGroup|ThreadLocal|Runnable)"/>
</where>
</rule>
<rule id="javase-01100">
<when>
<javaclass references="java.util.concurrent.{classes}"/>
</when>
<perform>
<classification title="Threads" category-id="information" effort="0">
<description>The application uses Concurrent Executors APIs.</description>
</classification>
<technology-tag level="INFORMATIONAL">Java Threads</technology-tag>
</perform>
<where param="classes">
<matches pattern="(ExecutorService|Executors|Executor|ScheduledExecutorService)"/>
</where>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.jboss.windup.test;

import java.util.concurrent.Executor;

public class Main implements Executor {
public void execute(Runnable r) {
r.run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.jboss.windup.test;

public class Main extends Thread {

public static void main(String[] args) {

Main thread = new Main();
thread.start();
System.out.println("The thread inside the main method!!!");
}

public void run() {
System.out.println("The thread outside the main method!!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruletest id="technology-usage-javase-test" xmlns="http://windup.jboss.org/schema/jboss-ruleset">
<testDataPath>data/javase/</testDataPath>
<rulePath>../javase.windup.xml</rulePath>
<rulePath>../javase-technology-usage.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="javase-technology-usage-01000-test">
<when>
<not>
<technology-statistics-exists name="Java Threads" number-found="1">
<tag name="Execute"/>
<tag name="Processing"/>
<tag name="Java EE"/>
</technology-statistics-exists>
</not>
</when>
<perform>
<fail message="Java Threads Not Found" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>

0 comments on commit 1e2ab58

Please sign in to comment.