Skip to content

Commit f7d8c21

Browse files
authored
Merge pull request #17239 from smowton/smowton/admin/camel-test
Java: add test for Apache Camel dead-code analysis
2 parents d6af999 + 0b56bf9 commit f7d8c21

31 files changed

+732
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/ExpressionClause.java:23:14:23:29 | ExpressionClause | The class ExpressionClause is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/ExpressionClause.class:0:0:0:0 | ExpressionClause<? extends FilterDefinition> | ExpressionClause<? extends FilterDefinition> |
2+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/ExpressionClause.java:23:14:23:29 | ExpressionClause | The class ExpressionClause is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | configure |
3+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/FilterDefinition.java:19:14:19:29 | FilterDefinition | The class FilterDefinition is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/FilterDefinition.java:19:14:19:29 | FilterDefinition | FilterDefinition |
4+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/OutputDefinition.java:22:14:22:29 | OutputDefinition | The class OutputDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/OutputDefinition.class:0:0:0:0 | OutputDefinition<RouteDefinition> | OutputDefinition<RouteDefinition> |
5+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/OutputDefinition.java:22:14:22:29 | OutputDefinition | The class OutputDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/RouteDefinition.java:19:14:19:28 | RouteDefinition | RouteDefinition |
6+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.java:21:23:21:41 | ProcessorDefinition | The class ProcessorDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | configure |
7+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.java:21:23:21:41 | ProcessorDefinition | The class ProcessorDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/OutputDefinition.class:0:0:0:0 | OutputDefinition<RouteDefinition> | OutputDefinition<RouteDefinition> |
8+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.java:21:23:21:41 | ProcessorDefinition | The class ProcessorDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.class:0:0:0:0 | ProcessorDefinition<RouteDefinition> | ProcessorDefinition<RouteDefinition> |
9+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.java:21:23:21:41 | ProcessorDefinition | The class ProcessorDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.class:0:0:0:0 | ProcessorDefinition<Type> | ProcessorDefinition<Type> |
10+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/ProcessorDefinition.java:21:23:21:41 | ProcessorDefinition | The class ProcessorDefinition is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/RouteDefinition.java:19:14:19:28 | RouteDefinition | RouteDefinition |
11+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/RouteDefinition.java:19:14:19:28 | RouteDefinition | The class RouteDefinition is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/model/RouteDefinition.java:19:14:19:28 | RouteDefinition | RouteDefinition |
12+
| com/semmle/camel/DeadTarget.java:4:14:4:23 | DeadTarget | The class DeadTarget is entirely unused. | com/semmle/camel/DeadTarget.java:4:14:4:23 | DeadTarget | DeadTarget |
13+
| com/semmle/camel/DeadTarget.java:9:23:9:25 | Foo | The class Foo is only used from dead code originating at $@. | com/semmle/camel/DeadTarget.java:5:14:5:19 | getFoo | getFoo |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DeadCode/DeadClass.ql
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:41:12:41:16 | value | The method value is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:41:12:41:16 | value | value |
2+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:49:12:49:14 | uri | The method uri is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:49:12:49:14 | uri | uri |
3+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:54:12:54:19 | property | The method property is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:54:12:54:19 | property | property |
4+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:63:12:63:20 | predicate | The method predicate is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/Consume.java:63:12:63:20 | predicate | predicate |
5+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:34:28:34:31 | from | The method from is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | configure |
6+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | The method configure is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | configure |
7+
| ../../../stubs/apache-camel-4.0.6/org/apache/camel/impl/DefaultCamelContext.java:24:15:24:23 | configure | The method configure is entirely unused. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/impl/DefaultCamelContext.java:24:15:24:23 | configure | configure |
8+
| com/semmle/camel/javadsl/CustomRouteBuilder.java:8:15:8:23 | configure | The method configure is only used from dead code originating at $@. | ../../../stubs/apache-camel-4.0.6/org/apache/camel/builder/RouteBuilder.java:38:26:38:34 | configure | configure |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DeadCode/DeadMethod.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Note that the CustomRouteBuilder method is regarded as "dead" because it would normally override a public library method and so be a `LibOverrideMethodEntry`, but because our library stubs are implemented as source code this isn't recognised. Similarly parts of our stubs appear dead. To confirm this is in fact ok, replace the stubs directory with a real Camel jar file.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.semmle.camel;
2+
3+
import org.apache.camel.Consume;
4+
5+
/** Class is live because it is constructed as a bean. Method is live because it is annotated. */
6+
public class AnnotatedTarget {
7+
8+
@Consume(uri = "activemq:test")
9+
public Foo getFoo(Foo foo1) {
10+
return new Foo();
11+
}
12+
13+
public static class Foo {}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.semmle.camel;
2+
3+
/**
4+
* All public methods in this class are considered to be live because this class is registered in a
5+
* {@code <bean ref="...">} tag in a Spring XML defined route.
6+
*/
7+
public class BeanRefTarget {
8+
public Foo applyFoo(Foo foo1) {
9+
return new Foo();
10+
}
11+
12+
public static class Foo {}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.semmle.camel;
2+
3+
/**
4+
* All public methods in this class are considered to be live because this class is registered in a
5+
* {@code <bean beanType="...">} tag in a Spring XML defined route.
6+
*/
7+
public class BeanTypeTarget {
8+
public Foo applyFoo(Foo foo1) {
9+
return new Foo();
10+
}
11+
12+
public static class Foo {}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.semmle.camel;
2+
3+
/** Dead because it is not referenced in the {@code config.xml} file, or in the Java DSL. */
4+
public class DeadTarget {
5+
public Foo getFoo(Foo foo1) {
6+
return new Foo();
7+
}
8+
9+
public static class Foo {}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.semmle.camel;
2+
3+
/** A bean referred to in a method element in the config.xml file. */
4+
public class MethodBean {
5+
public Foo getFoo(Foo foo1) {
6+
return new Foo();
7+
}
8+
9+
public static class Foo {}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.semmle.camel;
2+
3+
/**
4+
* All public methods in this class are considered to be live because this class is registered in a
5+
* {@code <to uri="..">} tag in a Spring XML defined route.
6+
*/
7+
public class ToTarget {
8+
public Foo applyFoo(Foo foo1) {
9+
return new Foo();
10+
}
11+
12+
public static class Foo {}
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.semmle.camel.javadsl;
2+
3+
import org.apache.camel.builder.RouteBuilder;
4+
import org.apache.camel.impl.DefaultCamelContext;
5+
6+
public class CustomRouteBuilder extends RouteBuilder {
7+
@Override
8+
public void configure() throws Exception {
9+
from("direct:test")
10+
.to("bean:dslToTarget")
11+
.bean(DSLBeanTarget.class)
12+
.bean(new DSLBeanObjectTarget())
13+
.beanRef("dslBeanRefTarget")
14+
.filter()
15+
.method("dslMethodBean");
16+
}
17+
18+
public static void main(String[] args) throws Exception {
19+
DefaultCamelContext camelContext = new DefaultCamelContext();
20+
camelContext.addRoutes(new CustomRouteBuilder());
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.semmle.camel.javadsl;
2+
3+
/**
4+
* All public methods in this class are considered to be live because this class is registered in a
5+
* {@code bean(new DSLBeanObjectTarget())} call in a RouteBuilder.
6+
*/
7+
public class DSLBeanObjectTarget {
8+
public Foo applyFoo(Foo foo1) {
9+
return new Foo();
10+
}
11+
12+
public static class Foo {}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.semmle.camel.javadsl;
2+
3+
/**
4+
* All public methods in this class are considered to be live because this class is registered in a
5+
* {@code beanRef("dslBeanRefTarget")} call in a RouteBuilder.
6+
*/
7+
public class DSLBeanRefTarget {
8+
public Foo applyFoo(Foo foo1) {
9+
return new Foo();
10+
}
11+
12+
public static class Foo {}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.semmle.camel.javadsl;
2+
3+
/**
4+
* All public methods in this class are considered to be live because this class is registered in a
5+
* {@code bean(DSLBeanTarget.class)} call in a RouteBuilder.
6+
*/
7+
public class DSLBeanTarget {
8+
public Foo applyFoo(Foo foo1) {
9+
return new Foo();
10+
}
11+
12+
public static class Foo {}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.semmle.camel.javadsl;
2+
3+
/** A bean referred to in the CustomRouteBuilder. */
4+
public class DSLMethodBean {
5+
public Foo getFoo(Foo foo1) {
6+
return new Foo();
7+
}
8+
9+
public static class Foo {}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.semmle.camel.javadsl;
2+
3+
/**
4+
* All public methods in this class are considered to be live because this class is registered in a
5+
* {@code to("bean:dslToTarget")} call in a RouteBuilder.
6+
*/
7+
public class DSLToTarget {
8+
public Foo applyFoo(Foo foo1) {
9+
return new Foo();
10+
}
11+
12+
public static class Foo {}
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:camel="http://camel.apache.org/schema/spring"
4+
xmlns:cxf="http://camel.apache.org/schema/cxf"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="
7+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
8+
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
9+
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
10+
">
11+
12+
<bean id="annotatedTarget" class="com.semmle.camel.AnnotatedTarget"/>
13+
14+
<bean id="dslBeanRefTarget" class="com.semmle.camel.javadsl.DSLBeanRefTarget"/>
15+
<bean id="dslToTarget" class="com.semmle.camel.javadsl.DSLToTarget"/>
16+
<bean id="dslMethodBean" class="com.semmle.camel.javadsl.DSLMethodBean"/>
17+
18+
<bean id="beanRefTarget" class="com.semmle.camel.BeanRefTarget"/>
19+
<bean id="toTarget" class="com.semmle.camel.ToTarget"/>
20+
<bean id="methodBean" class="com.semmle.camel.MethodBean"/>
21+
22+
<camelContext xmlns="http://camel.apache.org/schema/spring">
23+
<route id="wsRoute">
24+
<from uri="cxf:bean:camelTargetEndpoint"/>
25+
<bean ref="beanRefTarget"/>
26+
<bean beanType="com.semmle.camel.BeanTypeTarget"/>
27+
<to uri="bean:toTarget?foo"/>
28+
<filter>
29+
<method ref="methodBean" />
30+
</filter>
31+
</route>
32+
</camelContext>
33+
34+
</beans>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//semmle-extractor-options: --javac-args -cp
2+
//semmle-extractor-options: ${testdir}/../../../stubs/apache-camel-4.0.6/:${testdir}/../../../stubs/jaxb-api-2.3.1/

0 commit comments

Comments
 (0)