Skip to content

Commit

Permalink
WINDUPRULE-613: fix moved components rule (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmelko authored Jun 24, 2020
1 parent ec79376 commit f3cd8af
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public void configure() {
.to("browse:orderReceived")
.to("direct:order")
.to("seda:next")
.to("controlbus:route?routeId=mainRoute&action=stop&async=true")
.to("language:simple:classpath:org/apache/camel/component/language/mysimplescript.txt")
.to("timer:bye");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
<route>
<from uri="dataset:foo"/>
<to uri="direct-vm:bar"></to>

</route>
<route>
<from uri="scheduler://foo?delay=60s"/>
<unmarshal ref="myJaxb"/>
<to uri="seda:next"/>
<to uri="controlbus:route?routeId=mainRoute&amp;action=stop&amp;async=true"/>
<to uri="stub:smtp://somehost.foo.com?user=windup"/>
</route>
<route>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
<route>
<from uri="dataset:foo"/>
<marshal ref="myJaxb"/>
<to uri="controlbus:route?routeId=mainRoute&amp;action=stop&amp;async=true"/>
<to uri="direct-vm:bar"></to>
<multicast>
<to uri="controlbus:route?routeId=mainRoute&amp;action=stop&amp;async=true"/>
<to uri="direct-vm:bar"></to>
</multicast>

</route>
<route>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<when>
<not>
<iterable-filter size="1">
<hint-exists message="`*camel-rest`, `camel-dataformat`, `camel-direct-vm`, `camel-log`, `camel-direct`, `camel-validator`, `camel-language`, `camel-zip-deflater`, `camel-scheduler`, `camel-timer`, `camel-ref`, `camel-file`, `camel-vm`, `camel-stub`, `camel-xslt`, `camel-dataset`, `camel-bean`, `camel-browse.*`" />
<hint-exists message="`*camel-rest`, `camel-dataformat`, `camel-direct-vm`, `camel-log`, `camel-direct`, `camel-validator`, `camel-language`, `camel-zip-deflater`, `camel-scheduler`, `camel-timer`, `camel-ref`, `camel-file`, `camel-vm`, `camel-stub`, `camel-xslt`, `camel-controlbus`, `camel-dataset`, `camel-bean`, `camel-browse.*`" />
</iterable-filter>
</not>
</when>
Expand Down
50 changes: 23 additions & 27 deletions rules-reviewed/camel3/camel2/xml-moved-components.windup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ final String FROM_FILES_IN_PROJECT = "filesInProject"
/*
returns xpath condition that counts elements
*/
String countXpath(String... elements) {

String countXpath(String... elements) {
StringBuilder sb = new StringBuilder("//*[( ")
for (i = 0; i < elements.length; i++) {
sb.append("count(c:" + elements[i] + ")")
Expand All @@ -48,7 +49,7 @@ static String componentNameExpression(String componentName) {
}

static String componentNameXpath(String component) {
return "//*/c:route/*[starts-with(@uri, '$component:')]"
return "//*/c:route//*[starts-with(@uri, '$component:')]"
}

final Map<String, String[]> movedComponents = [
Expand All @@ -57,6 +58,7 @@ final Map<String, String[]> movedComponents = [
"bean" : [componentNameXpath("bean"), componentNameExpression("bean")],
"direct" : [componentNameXpath("direct"), componentNameExpression("direct")],
"xslt" : [componentNameXpath("xslt"), componentNameExpression("xslt")],
"controlbus" : [componentNameXpath("controlbus"), componentNameExpression("controlbus")],
"browse" : [componentNameXpath("browse"), componentNameExpression("browse")],
"dataset" : [componentNameXpath("dataset"), componentNameExpression("dataset")],
"direct-vm" : [componentNameXpath("direct-vm"), componentNameExpression("direct-vm")],
Expand All @@ -72,7 +74,7 @@ final Map<String, String[]> movedComponents = [
"validator" : [componentNameXpath("validator"), componentNameExpression("validator")],
"vm" : [componentNameXpath("vm"), componentNameExpression("vm")],
"rest" : [countXpath("rest", "get", "post", "put", "delete"), "rest({*})"],
"xslt " : [countXpath("xpath"), ".xpath({*})"],
"xslt " : [countXpath("xpath"), ".xpath({*})"],
"zip-deflater" : [countXpath("zip"), ".zip({*})"],
"zip-deflater ": [countXpath("gzip"), ".gzip({*})"],
"dataformat " : [countXpath("marshal,unmarshal,dataformats"), ".marshal({*})"],
Expand All @@ -88,13 +90,6 @@ final BiFunction<String, String, Boolean> isThereArtifactId = { String xmlDepend
xmlDependenciesBlock.contains("<artifactId>camel-$component</artifactId>" as CharSequence)
}

final BiFunction<String, String, Condition> xmlCondition = { String component, String namespace ->
XmlFile.from(FROM_XML_FILES_IN_PROJECT)
.matchesXpath("//*/c:route/*[starts-with(@uri, '$component:')]")
.namespace("c", namespace)
.as("$component-$namespace")
}

final BiFunction<String, String, Condition> xmlConditionWithXpath = { String xpath, String namespace ->
XmlFile.from(FROM_XML_FILES_IN_PROJECT)
.matchesXpath(xpath)
Expand Down Expand Up @@ -125,28 +120,29 @@ ruleSet("xml-moved-components-groovy")
final String xmlDependenciesBlock = payload.getSourceSnippit()
// rules xml-moved-components-0000{0-2}
movedComponents.keySet().stream()
.filter { component -> !isThereArtifactId.apply(xmlDependenciesBlock, component.replaceAll("\\s","")) }
.filter { component -> !isThereArtifactId.apply(xmlDependenciesBlock, component.replaceAll("\\s", "")) }
.filter { component ->
(movedComponents[component][0] != "" ? xmlCondition.apply(movedComponents[component][0], "http://camel.apache.org/schema/spring").evaluate(event, context) : false) ||
(movedComponents[component][0] != "" ? xmlConditionWithXpath.apply(movedComponents[component][0], "http://camel.apache.org/schema/spring").evaluate(event, context) : false) ||
(movedComponents[component][0] != "" ? xmlConditionWithXpath.apply(movedComponents[component][0],
"http://camel.apache.org/schema/blueprint").evaluate(event, context) : false) ||
(movedComponents[component][1] != "" ? javaConditionMatches.apply(movedComponents[component][1]).evaluate(event, context) : false)
}
.each { component -> usedComponents.add(component.replaceAll("\\s","")) }

String components = usedComponents.stream()
.map { component -> "`camel-$component`" }.toArray().toString()

((Hint) Hint.titled("Modularization of camel-core")
.withText(" $components components were moved out of `camel-core` to separate artifacts. Maven users of Apache Camel can keep using the dependency `camel-core`" +
"which has transitive dependencies on all of its modules, except for `camel-main`" +
"and therefore no migration is needed. However, users who want to trim the size of the classes on the classpath," +
"can use fine grained Maven dependencies on only the modules needed.")
.withIssueCategory(optionalIssueCategory)
.with(modularizationLink)
.withEffort(1))
.perform(event, context, payload)

.each { component -> usedComponents.add(component.replaceAll("\\s", "")) }

if (usedComponents.size() > 0) {
String components = usedComponents.stream()
.map { component -> "`camel-$component`" }.toArray().toString()
((Hint) Hint.titled("Modularization of camel-core")
.withText(" $components components were moved out of `camel-core` to separate artifacts. Maven users of Apache Camel can keep using the dependency `camel-core`" +
"which has transitive dependencies on all of its modules, except for `camel-main`" +
"and therefore no migration is needed. However, users who want to trim the size of the classes on the classpath," +
"can use fine grained Maven dependencies on only the modules needed.")
.withIssueCategory(optionalIssueCategory)
.with(modularizationLink)
.withEffort(1))
.perform(event, context, payload)

}
}
})
.withId("xml-moved-components-groovy-00000")

0 comments on commit f3cd8af

Please sign in to comment.