Skip to content

Commit 9c0bdbb

Browse files
committed
Java: add a test exercising Spring component liveness detection
The existing Spring stubs are expanded sufficiently to support the needed annotations and a few referenced classes and exceptions.
1 parent e3b9b0a commit 9c0bdbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1557
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| com.semmle.a |
2+
| com.semmle.b |
3+
| com.semmle.c |
4+
| com.semmle.d |
5+
| com.semmle.e |
6+
| com.semmle.h |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import java
2+
import semmle.code.java.frameworks.spring.Spring
3+
import SpringProfiles
4+
5+
from SpringBasePackage basePackage
6+
select basePackage
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| com/semmle/e/DeadProfileComponent.java:8:14:8:33 | DeadProfileComponent | dead |
2+
| com/semmle/e/LiveConfiguration.java:16:14:16:30 | LiveConfiguration | live |
3+
| com/semmle/e/LiveProfileComponent.java:8:14:8:33 | LiveProfileComponent | live |
4+
| com/semmle/e/LiveRestController.java:12:14:12:31 | LiveRestController | live |
5+
| com/semmle/f/DeadConfiguration.java:9:14:9:30 | DeadConfiguration | dead |
6+
| com/semmle/g/ProfileComponent.java:6:14:6:29 | ProfileComponent | dead |
7+
| com/semmle/h/WebXMLLiveConfiguration.java:11:14:11:36 | WebXMLLiveConfiguration | live |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import java
2+
import semmle.code.java.frameworks.spring.Spring
3+
import SpringProfiles
4+
5+
from SpringComponent springComponent, string isLive
6+
where if springComponent.isLive() then isLive = "live" else isLive = "dead"
7+
select springComponent, isLive
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| !annotationProfile | annotationProfile | inactive |
2+
| annotationProfile | annotationProfile | active |
3+
| sometimesEnabledProfile | sometimesEnabledProfile | active |
4+
| xmlConfigurationProfile | xmlConfigurationProfile | inactive |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import java
2+
import semmle.code.java.frameworks.spring.Spring
3+
import SpringProfiles
4+
5+
from SpringProfileExpr springProfileExpr, string active
6+
where if springProfileExpr.isActive() then active = "active" else active = "inactive"
7+
select springProfileExpr, springProfileExpr.getProfile(), active
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java
2+
import semmle.code.java.frameworks.spring.Spring
3+
4+
/**
5+
* Mark the XML configuration profile as never enabled. This should allow us to deduce that the
6+
* com.semmle.g.ProfileComponent is dead, because com.semmle.g is only a base package in the
7+
* profile-config.xml file, which is only enabled if xmlConfigurationProfile is enabled.
8+
*/
9+
class XMLConfigurationProfile extends NeverEnabledSpringProfile {
10+
XMLConfigurationProfile() { this = "xmlConfigurationProfile" }
11+
}
12+
13+
/**
14+
* Mark the annotation profile as always enabled. This should allow us to deduce that the
15+
* com.semmle.e.DeadProfileComponent is dead, because the profile is "!annotationProfile", and that
16+
* com.semmle.e.LiveProfileComponent is live, because the profile is "annotationProfile".
17+
*/
18+
class AnnotationProfile extends AlwaysEnabledSpringProfile {
19+
AnnotationProfile() { this = "annotationProfile" }
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
5+
6+
<!-- Java-based annotation-driven Spring container definition -->
7+
<context-param>
8+
<param-name>contextClass</param-name>
9+
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
10+
</context-param>
11+
12+
<!-- Location of Java @Configuration classes that configure the components that makeup this application -->
13+
<context-param>
14+
<param-name>contextConfigLocation</param-name>
15+
<param-value>com.semmle.h</param-value>
16+
</context-param>
17+
</web-app>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.semmle.d;
2+
3+
public interface DMarkerClass {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.semmle.e;
2+
3+
import org.springframework.context.annotation.Profile;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
@Profile({"!annotationProfile"})
8+
public class DeadProfileComponent {}

0 commit comments

Comments
 (0)