Added a jQAssistant rule to detect not properly configured service providers.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/fd00b28a Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/fd00b28a Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/fd00b28a Branch: refs/heads/master Commit: fd00b28aa815c74e25e2f731c0c20afcfb87a19d Parents: c4af789 Author: Oliver B. Fischer <ple...@apache.org> Authored: Sun Apr 26 00:02:09 2015 +0200 Committer: Oliver B. Fischer <ple...@apache.org> Committed: Sun Apr 26 00:02:09 2015 +0200 ---------------------------------------------------------------------- jqassistant/default.xml | 1 + jqassistant/serviceloader-rules.xml | 42 +++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/fd00b28a/jqassistant/default.xml ---------------------------------------------------------------------- diff --git a/jqassistant/default.xml b/jqassistant/default.xml index 222a685..f35def2 100644 --- a/jqassistant/default.xml +++ b/jqassistant/default.xml @@ -56,5 +56,6 @@ under the License. <includeConstraint refId="naming:namingOfPropertyConverters"/> <includeConstraint refId="naming:namingOfPropertyFilters"/> <includeConstraint refId="serviceLoader:correctServiceLoaderNaming"/> + <includeConstraint refId="serviceLoader:ServiceImplementationsMustBeListedInServiceConfigurations"/> </group> </jqa:jqassistant-rules> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/fd00b28a/jqassistant/serviceloader-rules.xml ---------------------------------------------------------------------- diff --git a/jqassistant/serviceloader-rules.xml b/jqassistant/serviceloader-rules.xml index 808b7b2..346ebb8 100644 --- a/jqassistant/serviceloader-rules.xml +++ b/jqassistant/serviceloader-rules.xml @@ -50,4 +50,44 @@ under the License. ]]></cypher> </constraint> -</jqa:jqassistant-rules> \ No newline at end of file + <constraint id="serviceLoader:ServiceImplementationsMustBeListedInServiceConfigurations" + severity="info"> + <requiresConcept refId="java:AnonymousInnerType"/> + <requiresConcept refId="serviceLoader:SPI"/> + <description>All property converter implementations must be declared in a service loader file.</description> + <cypher><![CDATA[ + MATCH + (impl)-[:IMPLEMENTS*]->(spi:SPI) + + WHERE + NOT (:ServiceLoader)-[:CONTAINS]->(impl) + AND NOT impl:Anonymous:Inner + AND (impl.abstract=false OR impl.abstract IS NULL) + + // Ignore SPI implementations without a default constructor + // We assume that the developer of this class had to implement for some reason + // this interface but not intended it to be used as service provider + AND NOT (impl)-[:DECLARES]->(:Constructor)-[:HAS]->(:Parameter) + + // Do not pay attention to test utilities. We rely on the name of the class + AND NOT (impl.name =~ 'Test.*' OR impl.name =~ '.*\\$Test.*' + OR impl.name =~'.*Test\\$.*') + + AND NOT impl.fqn IN [// All classes of the builder MUST not use the SPI mechanism + 'org.apache.tamaya.builder.ProgrammaticConfigurationContext', + // See TAMAYA-77 and TAMAYA-78, Oliver B. Fischer, 2015-04-25 + 'org.apache.tamaya.core.internal.DefaultConfigurationContextBuilder' + ] + + RETURN + impl.fqn AS undeclaredService + ]]></cypher> + </constraint> + + <!-- @todo + Constraints to be defined + - Empty service configurations + + --> + +</jqa:jqassistant-rules>