83
by Analysis of software systems using jQAssistant and Neo4j EPOST Tech Talk & JUG BerlinBrandenburg Dirk Mahler

Analysis of software systems using jQAssistant and Neo4j

Embed Size (px)

DESCRIPTION

Vortrag zur statischen Codeanalyse mit jQAssistant vor der JUG Berlin-Brandenburg beim E-Post Techtalk mit Dirk Mahler

Citation preview

Page 1: Analysis of software systems using jQAssistant and Neo4j

by  

Analysis of software systems using jQAssistant and Neo4j

E-­‐POST  Tech  Talk  &    JUG  Berlin-­‐Brandenburg  

 Dirk  Mahler  

Page 2: Analysis of software systems using jQAssistant and Neo4j

2  

AGENDA

§ About  Structures,  Rules  And  Code  §  So4ware  As  A  Graph  § Demo#1  §  jQAssistant  § Demo#2  

Page 3: Analysis of software systems using jQAssistant and Neo4j

About Structures, Rules And Code

Analysis  of  soAware  systems  using  jQAssistant  and  Neo4j  

3  

Page 4: Analysis of software systems using jQAssistant and Neo4j

4  

§  Sketch  of  an  architecture  

Page 5: Analysis of software systems using jQAssistant and Neo4j

5  

§  Sketch  of  an  architecture  

My  Big  Fat  Demo  ApplicaJon  

Page 6: Analysis of software systems using jQAssistant and Neo4j

6  

§  Sketch  of  an  architecture  -  Business  modules  

Shopping  Cart  Usermanagement  

Page 7: Analysis of software systems using jQAssistant and Neo4j

7  

§  Sketch  of  an  architecture  - Allowed  dependencies  between  business  modules  

Shopping  Cart  Usermanagement  

Page 8: Analysis of software systems using jQAssistant and Neo4j

8  

§  Sketch  of  an  architecture  -  Technical  layering  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

Page 9: Analysis of software systems using jQAssistant and Neo4j

9  

§  Sketch  of  an  architecture  - Allowed  dependencies  between  technical  layers  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

Page 10: Analysis of software systems using jQAssistant and Neo4j

10  

§  Sketch  of  an  architecture  - Allowed  dependencies  between  business  modules  and  technical  layers  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

Page 11: Analysis of software systems using jQAssistant and Neo4j

11  

§  Sketch  of  an  architecture  - Allowed  dependencies  between  business  modules  and  technical  layers  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

Page 12: Analysis of software systems using jQAssistant and Neo4j

12  

§  Sketch  of  an  architecture  - AbstracJon  between  layers  (API  vs.  ImplementaJon)  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

Page 13: Analysis of software systems using jQAssistant and Neo4j

13  

§  Sketch  of  an  architecture  -  Forbidden  dependency  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

Page 14: Analysis of software systems using jQAssistant and Neo4j

14  

§  Sketch  of  an  architecture  - Allowed  external  dependencies  per  layer  

JSF-­‐UI   REST  

EJB  

JPA  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

Page 15: Analysis of software systems using jQAssistant and Neo4j

§  TranslaJon  of  architecture  rules  into  the  project  structure  -  Java  language  element:  Package  

org.jqassistant.demo  

15  

Page 16: Analysis of software systems using jQAssistant and Neo4j

§  TranslaJon  of  architecture  rules  into  the  project  structure  -  Java  language  element:  Package  

- DefiniJon  of  business  modules  on  „top  level“  

16  

Shopping  Cart  „org.jqassistant.demo.cart“  

Usermanagement  „org.jqassistant.demo.user“  

Page 17: Analysis of software systems using jQAssistant and Neo4j

17  

§  TranslaJon  of  architecture  rules  into  the  project  structure  -  Java  language  element:  Package  

-  Technical  layers  §  …demo.cart.ui  §  …demo.cart.rest  §  …demo.cart.logic  §  …demo.cart.persistence  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

Page 18: Analysis of software systems using jQAssistant and Neo4j

18  

§  TranslaJon  of  architecture  rules  into  the  project  structure  -  Java  language  element:  Package  

-  Technical  layers  §  …demo.cart.ui  §  …demo.cart.rest  §  …demo.cart.logic.api  §  …demo.cart.logic.impl  §  …demo.cart.persistence.api  §  …demo.cart.persistence.impl  

JSF-­‐UI   REST  

Business  Logic  

Persistence  

Page 19: Analysis of software systems using jQAssistant and Neo4j

19  

§  Package  Names  - All  packages  in  a  Maven  module  must  be  prefixed  with  ${groupId}.${arJfactId}    -  Example:  groupId=org.jqassistant  arJfactId=demo    =>  org.jqassistant.demo  

Page 20: Analysis of software systems using jQAssistant and Neo4j

20  

§  Class  Names  - Message  Driven  Beans  must  have  a  suffix  „MDB“.  

Page 21: Analysis of software systems using jQAssistant and Neo4j

21  

§  Class  locaJon  -  JPA  enJJes  must  be  located  in  „api.model“  packages.  

Page 22: Analysis of software systems using jQAssistant and Neo4j

22  

§  Test  design  -  Every  test  method  must  contain  at  least  one  asserJon.  -  Each  asserJon  must  provide  a  human  readable  message.  

Page 23: Analysis of software systems using jQAssistant and Neo4j

23  

§ AbstracJon  -  Remote  APIs  must  be  interfaces  declaring  only  primiJves  or  immutables  as  parameter  or  return  types.  

 - OSGi-­‐Bundles  must  only  export  dedicated  API  packages.  

Page 24: Analysis of software systems using jQAssistant and Neo4j

24  

Source  Code  Java,  ProperJes,  

XML,  YML  

Maintainability   Erosion  Complexity  

„Code  Quality“  

Page 25: Analysis of software systems using jQAssistant and Neo4j

25  

Source  Code  Java,  ProperJes,  

XML,  YML  

People  Architect,  Developer,  

Test  

DocumentaJon  UML,  Wiki,    readme.txt  

Tooling  Compiler,  StaJc  Code  

Analysis,  CI  

Page 26: Analysis of software systems using jQAssistant and Neo4j

26  

§  Source  Code  –  AbstracJon  levels  

Folder,  File  File  System  

Package,  Class,  Field,  Method,  AnnotaJon  Java  

AbstracJon,  Immutable,  Factory  Design  

Module,  Layer,  Dependency  Architecture  

Page 27: Analysis of software systems using jQAssistant and Neo4j

27  

§  Source  Code  –  Automated  validaJon  

Folder,  File  File  System  

Package,  Class,  Field,  Method,  AnnotaJon  Java  

AbstracJon,  Immutable,  Factory  Design  

Module,  Layer,  Dependency  Architecture  

Page 28: Analysis of software systems using jQAssistant and Neo4j

28  

§  Java  elements  represent  higher  level  concepts  -  Package  ó  Module  - Annotated  Class  ó  EnJty  

§  Constraints  apply  to  these  concepts  -  JPA  enJJes  must  be  located  in  „api.model“  packages  

 

Page 29: Analysis of software systems using jQAssistant and Neo4j

29  

§ Visibility  of  concepts  and  constraints  

-  Explicit  §  @Test  

-  Implicit  §  Every  test  method  must  contain  at  least  one  asserJon.  

-  Invisible  §  java.uJl.Calendar  must  not  be  used  directly.  

Page 30: Analysis of software systems using jQAssistant and Neo4j

30  

§  Concepts  and  Constraints  - How  to  make  them  visible?  -  Is  there  a  language  to  describe  them?  

Page 31: Analysis of software systems using jQAssistant and Neo4j

Software As A Graph

Analysis  of  soAware  systems  using  jQAssistant  and  Neo4j  

31  

Page 32: Analysis of software systems using jQAssistant and Neo4j

32  

§  All  we  need  is…  -  Nodes    -  Labels    -  ProperJes    -  RelaJonships  

§ Modeling  is  just…  -  Taking  a  pen  -  Drawing  the  structures  on  a  whiteboard  (i.e.  the  database)  

§ We  don‘t  need…  -  Foreign  keys  -  Tables  and  schemas  -  Knowledge  in  graph  theory  

Page 33: Analysis of software systems using jQAssistant and Neo4j

Project  

ArJfact  

Maven  

CONTAINS  

Package  

name:org  

CONTAINS  

Package  

name:jqassistant   CONTAINS  

Package  

name:usermanagement  

Package  

CONTAINS  

name:api  

Package  

CONTAINS  

name:model  

name:demo  

CONTAINS  

Package  

name:demo  

CREATES  

Page 34: Analysis of software systems using jQAssistant and Neo4j

Class  

Type  

CONTAINS  

fqn:org.jqassistant.demo.  usermanagement.api.  model.Person  

name:Person  

Package  

name:usermanagement  

Package  

CONTAINS  

name:api  

Package  

CONTAINS  

name:model  

CONTAINS  

Page 35: Analysis of software systems using jQAssistant and Neo4j

AnnotaJon  

ANNOTATED_BY  

Type  

OF_TYPE  fqn:javax.persistence.EnJty  

Package  

name:usermanagement  

Package  

CONTAINS  

name:api  

Package  

CONTAINS  

name:model  

Class  

Type  

CONTAINS  

fqn:org.jqassistant.demo.  usermanagement.api.  model.Person  

name:Person  

CONTAINS  

Page 36: Analysis of software systems using jQAssistant and Neo4j

Class  

Type  

CONTAINS  

fqn:org.jqassistant.demo.  usermanagement.api.  model.Person  

name:Person  

AnnotaJon  

ANNOTATED_BY  

Type  

OF_TYPE  fqn:javax.persistence.EnJty  

Package  

name:model  

Page 37: Analysis of software systems using jQAssistant and Neo4j

Package  

name:model  

Class  

Type  

CONTAINS  

fqn:org.jqassistant.demo.  usermanagement.api.  model.Person  

name:Person  

Type  

OF_TYPE  fqn:javax.persistence.EnJty  

Type  

EXTENDS  

Class  

fqn:org.jqassistant.demo.  usermanagement.api.  Model.Customer  

name:Customer  

AnnotaJon  

ANNOTATED_BY  

OF_TYPE  

AnnotaJon  

ANNOTATED_BY  

Page 38: Analysis of software systems using jQAssistant and Neo4j

RETURNS  

READS  

Field  

DECLARES  

name:number  

Package  

name:model  

Class  

Type  

CONTAINS  

fqn:org.jqassistant.demo.  usermanagement.api.  model.Person  

name:Person  

Type  

OF_TYPE  fqn:javax.persistence.EnJty  

Type  

EXTENDS  

Class  

fqn:org.jqassistant.demo.  usermanagement.api.  Model.Customer  

name:Customer  

Type  

OF_TYPE  

fqn:int  

DECLARES  

Method  

name:getNumber()  signature:int  getNumber()  

AnnotaJon  

ANNOTATED_BY  

OF_TYPE  

AnnotaJon  

ANNOTATED_BY  

Page 39: Analysis of software systems using jQAssistant and Neo4j

40  

Type  Type  

Class  

EXTENDS  

§  Explore  an  applicaJon  using  queries  - Which  class  extends  from  another  class?  

§  Let‘s  convert  this  to  ASCII  art…    -  ()  as  nodes  -  -­‐[]-­‐>  as  directed  relaJonships  

Page 40: Analysis of software systems using jQAssistant and Neo4j

41  

Type  Type  

Class  

EXTENDS  

§  Explore  an  applicaJon  using  queries  - Which  class  extends  from  another  class?  

§  Let‘s  convert  this  to  ASCII  art…    -  ()  as  nodes  -  -­‐[]-­‐>  as  directed  relaJonships  

()-­‐[]-­‐>()

Page 41: Analysis of software systems using jQAssistant and Neo4j

42  

C2  Type  

C1  Type  

Class  

EXTENDS  

§  Explore  an  applicaJon  using  queries  - Which  class  extends  from  another  class?  

§  Let‘s  convert  this  to  ASCII  art…    -  ()  as  nodes  -  -­‐[]-­‐>  as  directed  relaJonships  

(c1)-­‐[]-­‐>(c2)

Page 42: Analysis of software systems using jQAssistant and Neo4j

43  

C2  Type  

C1  Type  

Class  

EXTENDS  

§  Explore  an  applicaJon  using  queries  - Which  class  extends  from  another  class?  

§  Let‘s  convert  this  to  ASCII  art…    -  ()  as  nodes  -  -­‐[]-­‐>  as  directed  relaJonships  

(c1)-­‐[:EXTENDS]-­‐>(c2)

Page 43: Analysis of software systems using jQAssistant and Neo4j

44  

§  Explore  an  applicaJon  using  queries  - Which  class  extends  from  another  class?  

§  Let‘s  convert  this  to  ASCII  art…    -  ()  as  nodes  -  -­‐[]-­‐>  as  directed  relaJonships  

(c1:Class)-­‐[:EXTENDS]-­‐>(c2:Type)

C2  Type  

C1  Type  

Class  

EXTENDS  

Page 44: Analysis of software systems using jQAssistant and Neo4j

45  

§  Explore  an  applicaJon  using  queries  - Which  class  extends  from  another  class?  

§  Paxern  matching  is  the  core  principle  of  Cypher   MATCH      (c1:Class)-­‐[:EXTENDS]-­‐>(c2:Type)  RETURN      c1.fqn,  c2.fqn  

C2  Type  

C1  Type  

Class  

EXTENDS  

Page 45: Analysis of software systems using jQAssistant and Neo4j

46  

§ Which  classes  contain  the  highest  number  of  methods?  

Page 46: Analysis of software systems using jQAssistant and Neo4j

47  

§ Which  classes  contain  the  highest  number  of  methods?    MATCH      (class:Class)-­‐[:DECLARES]-­‐>(method:Method)

Page 47: Analysis of software systems using jQAssistant and Neo4j

48  

§ Which  classes  contain  the  highest  number  of  methods?    MATCH      (class:Class)-­‐[:DECLARES]-­‐>(method:Method)  RETURN      class.fqn,  count(method)  as  Methods

Page 48: Analysis of software systems using jQAssistant and Neo4j

49  

§ Which  classes  contain  the  highest  number  of  methods?    MATCH      (class:Class)-­‐[:DECLARES]-­‐>(method:Method)  RETURN      class.fqn,  count(method)  as  Methods  ORDER  BY      Methods  DESC

Page 49: Analysis of software systems using jQAssistant and Neo4j

50  

§ Which  classes  contain  the  highest  number  of  methods?    MATCH      (class:Class)-­‐[:DECLARES]-­‐>(method:Method)  RETURN      class.fqn,  count(method)  as  Methods  ORDER  BY      Methods  DESC  LIMIT  20

Page 50: Analysis of software systems using jQAssistant and Neo4j

51  

§ Which  class  has  the  deepest  inheritance  hierarchy?  

Page 51: Analysis of software systems using jQAssistant and Neo4j

52  

§ Which  class  has  the  deepest  inheritance  hierarchy?    MATCH      h=(class:Class)-­‐[:EXTENDS*]-­‐>(super:Type)

Page 52: Analysis of software systems using jQAssistant and Neo4j

53  

§ Which  class  has  the  deepest  inheritance  hierarchy?    MATCH      h=(class:Class)-­‐[:EXTENDS*]-­‐>(super:Type)  RETURN      class.fqn,  length(h)  as  Depth

Page 53: Analysis of software systems using jQAssistant and Neo4j

54  

§ Which  class  has  the  deepest  inheritance  hierarchy?    MATCH      h=(class:Class)-­‐[:EXTENDS*]-­‐>(super:Type)  RETURN      class.fqn,  length(h)  as  Depth  ORDER  BY      Depth  desc

Page 54: Analysis of software systems using jQAssistant and Neo4j

55  

§ Which  class  has  the  deepest  inheritance  hierarchy?    MATCH      h=(class:Class)-­‐[:EXTENDS*]-­‐>(super:Type)  RETURN      class.fqn,  length(h)  as  Depth  ORDER  BY      Depth  desc  LIMIT  20

Page 55: Analysis of software systems using jQAssistant and Neo4j

56  

§ Which  classes  are  affected  by  IOExcepJons?  

MATCH    (e:Type)-­‐[:DECLARES]-­‐>(init:Constructor) WHERE    e.fqn="java.io.IOException" WITH    e,init MATCH    (type:Type)-­‐[:DECLARES]-­‐>(method:Method),    path=(method)-­‐[:INVOKES*]-­‐>(init) RETURN    e,type,path LIMIT  10  

Page 56: Analysis of software systems using jQAssistant and Neo4j

Demo #1

Analysis  of  soAware  systems  using  jQAssistant  and  Neo4j  

57  

Page 57: Analysis of software systems using jQAssistant and Neo4j

jQAssistant

Analysis  of  soAware  systems  using  jQAssistant  and  Neo4j  

58  

Page 58: Analysis of software systems using jQAssistant and Neo4j

59  

§  Project  Homepage  -  hxp://jqassistant.org  

§ Open  Source  - GPL  v3  

§ Milestone  -  1.0.0-­‐M3  (ASL  v2.0),  final  Release:  12/2014  

§ Based  on  Neo4j  2.x  -  Embedded,  no  installaJon  necessary  

Page 59: Analysis of software systems using jQAssistant and Neo4j

60  

Maven  

Scan  

Analyze  

Report  

Plugins  

Plugins  

Plugins  

Page 60: Analysis of software systems using jQAssistant and Neo4j

61  

§ Ge|ng  started   <build>    <plugins>        <plugin>            <groupId>com.buschmais.jqassistant.scm</groupId>            <artifactId>jqassistant-­‐maven-­‐plugin</artifactId>        </plugin>    </plugins> </build> §  mvn  jqassistant:scan §  mvn  jqassistant:server §  mvn  jqassistant:available-­‐rules §  mvn  jqassistant:analyze

Page 61: Analysis of software systems using jQAssistant and Neo4j

62  

§ Analyze    -  ExecuJon  of  rules  

-  Concepts  §  Enrich  data  model  

-  Constraints  §  Detect  violaJons  

- Group  §  Allow  different  execuJon  profiles  

 

Page 62: Analysis of software systems using jQAssistant and Neo4j

63  

Constraint  Group  

Concept   Concept  Concept  

Includes  

Requires   Requires  

Requires  

Page 63: Analysis of software systems using jQAssistant and Neo4j

64  

§  Concept   <jqa:jqassistant-­‐rules  xmlns:jqa="...">    <concept  id="jpa2:Entity">        <description>Labels  all  types  annotated  with              @javax.persistence.Entity  with  JPA  and  ENTITY.          </description>        <cypher><![CDATA[            MATCH                  (t:Type)-­‐[:ANNOTATED_BY]-­‐>()-­‐[:OF_TYPE]-­‐>(a:Type)            WHERE  a.fqn="javax.persistence.Entity"                SET  t:Jpa:Entity              RETURN  t  AS  Entity        ]]></cypher>    </concept> </jqa:jqassistant-­‐rules>

Page 64: Analysis of software systems using jQAssistant and Neo4j

65  

§  Concept   <jqa:jqassistant-­‐rules  xmlns:jqa="...">    <concept  id="jpa2:Entity">        <description>Labels  all  types  annotated  with              @javax.persistence.Entity  with  JPA  and  ENTITY.          </description>        <cypher><![CDATA[            MATCH                  (t:Type)-­‐[:ANNOTATED_BY]-­‐>()-­‐[:OF_TYPE]-­‐>(a:Type)            WHERE  a.fqn="javax.persistence.Entity"                SET  t:Jpa:Entity              RETURN  t  AS  Entity        ]]></cypher>    </concept> </jqa:jqassistant-­‐rules>

Page 65: Analysis of software systems using jQAssistant and Neo4j

66  

§  Concept   <jqa:jqassistant-­‐rules  xmlns:jqa="...">    <concept  id="jpa2:Entity">        <description>Labels  all  types  annotated  with              @javax.persistence.Entity  with  JPA  and  ENTITY.          </description>        <cypher><![CDATA[            MATCH                  (t:Type)-­‐[:ANNOTATED_BY]-­‐>()-­‐[:OF_TYPE]-­‐>(a:Type)            WHERE  a.fqn="javax.persistence.Entity"                SET  t:Jpa:Entity              RETURN  t  AS  Entity        ]]></cypher>    </concept> </jqa:jqassistant-­‐rules>

Page 66: Analysis of software systems using jQAssistant and Neo4j

67  

§  Concept  

Class  

Type  

fqn.org.jqassistant:demo.  usermanagement.api.  model.Person  

name:Person  

AnnotaJon  

ANNOTATED_BY  

Type  

OF_TYPE  fqn:javax.persistence.EnJty  

Type  

EXTENDS  

Class  

fqn.org.jqassistant:demo.  usermanagement.api.  Model.Customer  

name:Customer  

AnnotaJon  

ANNOTATED_BY  

OF_TYPE  

Page 67: Analysis of software systems using jQAssistant and Neo4j

68  

§  Concept  

Class  

Type  

fqn.org.jqassistant:demo.  usermanagement.api.  model.Person  

name:Person  

AnnotaJon  

ANNOTATED_BY  

Type  

OF_TYPE  fqn:javax.persistence.EnJty  

Type  

EXTENDS  

Class  

fqn.org.jqassistant:demo.  usermanagement.api.  Model.Customer  

name:Customer  

AnnotaJon  

ANNOTATED_BY  

OF_TYPE  

EnJty  

EnJty  

Jpa  

Jpa  

Page 68: Analysis of software systems using jQAssistant and Neo4j

69  

§  Constraint   <jqa:jqassistant-­‐rules  xmlns:jqa="...">    <constraint  id="JpaEntitiesInModelPackage">        <requiresConcept  refId="jpa2:Entity"/>        <description>All  JPA  entities  must  be  located  in            packages  named  "model".        </description>        <cypher><![CDATA[            MATCH  (p:Package)-­‐[:CONTAINS]-­‐>(e)            WHERE  e:Jpa  AND  e:Entity  AND  NOT(p.name  =  "model")            RETURN                e  AS  EntityInWrongPackage        ]]></cypher>    </constraint> </jqa:jqassistant-­‐rules>

Page 69: Analysis of software systems using jQAssistant and Neo4j

70  

§  Constraint   <jqa:jqassistant-­‐rules  xmlns:jqa="...">    <constraint  id="JpaEntitiesInModelPackage">        <requiresConcept  refId="jpa2:Entity"/>        <description>All  JPA  entities  must  be  located  in            packages  named  "model".        </description>        <cypher><![CDATA[            MATCH  (p:Package)-­‐[:CONTAINS]-­‐>(e)            WHERE  e:Jpa  AND  e:Entity  AND  NOT(p.name  =  "model")            RETURN                e  AS  EntityInWrongPackage        ]]></cypher>    </constraint> </jqa:jqassistant-­‐rules>

Page 70: Analysis of software systems using jQAssistant and Neo4j

71  

§  Constraint   <jqa:jqassistant-­‐rules  xmlns:jqa="...">    <constraint  id="JpaEntitiesInModelPackage">        <requiresConcept  refId="jpa2:Entity"/>        <description>All  JPA  entities  must  be  located  in            packages  named  "model".        </description>        <cypher><![CDATA[            MATCH  (p:Package)-­‐[:CONTAINS]-­‐>(e)            WHERE  e:Jpa  AND  e:Entity  AND  NOT(p.name  =  "model")            RETURN                e  AS  EntityInWrongPackage        ]]></cypher>    </constraint> </jqa:jqassistant-­‐rules>

Page 71: Analysis of software systems using jQAssistant and Neo4j

72  

§  Constraint   <jqa:jqassistant-­‐rules  xmlns:jqa="...">    <constraint  id="JpaEntitiesInModelPackage">        <requiresConcept  refId="jpa2:Entity"/>        <description>All  JPA  entities  must  be  located  in            packages  named  "model".        </description>        <cypher><![CDATA[            MATCH  (p:Package)-­‐[:CONTAINS]-­‐>(e)            WHERE  e:Jpa  AND  e:Entity  AND  NOT(p.name  =  "model")            RETURN                e  AS  EntityInWrongPackage        ]]></cypher>    </constraint> </jqa:jqassistant-­‐rules>

Page 72: Analysis of software systems using jQAssistant and Neo4j

73  

§ Group   <jqa:jqassistant-­‐rules  xmlns:jqa="...">    <group  id="default">        <includeConstraint              refId="abstractness:ApiMustNotDependOnImplementation"/>        <includeConstraint              refId="JpaEntitiesInModelPackage"/>        <includeConstraint              refId="EjbLocatedInImplementationPackage"/>        <includeConstraint  refId="TestClassNameHasTestSuffix"/>        <includeConstraint  refId="dependency:TypeCycles"/>        <includeConstraint  refId="dependency:ArtifactCycles"/>    </group> </jqa:jqassistant-­‐rules>

Page 73: Analysis of software systems using jQAssistant and Neo4j

74  

§ Group   <jqa:jqassistant-­‐rules  xmlns:jqa="...">    <group  id="default">        <includeConstraint              refId="abstractness:ApiMustNotDependOnImplementation"/>        <includeConstraint              refId="JpaEntitiesInModelPackage"/>        <includeConstraint              refId="EjbLocatedInImplementationPackage"/>        <includeConstraint  refId="TestClassNameHasTestSuffix"/>        <includeConstraint  refId="dependency:TypeCycles"/>        <includeConstraint  refId="dependency:ArtifactCycles"/>    </group> </jqa:jqassistant-­‐rules>

Page 74: Analysis of software systems using jQAssistant and Neo4j

75  

§  Plugins  -  Scanner,  Rules,  Report  

- Where‘s  yours?  ContribuJons  welcome!  

JUnit  

Maven  

OSGi   Tycho  

JPA2  

JAX-­‐RS  

Java  7/8   EJB3  

Page 75: Analysis of software systems using jQAssistant and Neo4j

Demo #2

Analysis  of  soAware  systems  using  jQAssistant  and  Neo4j    

76  

Page 76: Analysis of software systems using jQAssistant and Neo4j

77  

§ All  packages  in  a  Maven  module  must  be  prefixed  with  ${groupId}.${arJfactId}  

MATCH    (module:Maven)-­‐[:CREATES]-­‐>(artifact:Artifact) WITH    artifact,  artifact.group  +  "\\."  +  artifact.name  +  "\\..*"  as  prefixPattern MATCH    (artifact)-­‐[:CONTAINS]-­‐>(type:Type) WHERE  NOT    type.fqn  =~  prefixPattern RETURN    type  as  TypeInInvalidPackage

Page 77: Analysis of software systems using jQAssistant and Neo4j

78  

§ Message  Driven  Beans  must  have  a  suffix  „MDB“.  

MATCH    (mdb:MessageDrivenBean) WHERE  NOT    mdb.name  =~  ".*MDB" RETURN    mdb  as  InvalidBean  

Page 78: Analysis of software systems using jQAssistant and Neo4j

79  

§  JPA  enJJes  must  be  located  in  „api.model“  packages.  

MATCH    (p:Package)-­‐[:CONTAINS]-­‐>(e:Jpa:Entity) WHERE  NOT      p.fqn  =~  '.*\\.api\\.model' RETURN    e.fqn  as  Entity  

Page 79: Analysis of software systems using jQAssistant and Neo4j

80  

§  Every  test  method  must  contain  at  least  one  asserJon.  

MATCH    (testType:Type)-­‐[:DECLARES]-­‐>(testMethod:Test:Method) WHERE  NOT    (testMethod)-­‐[:INVOKES*..3]-­‐>(:Method:Assert) RETURN    testType  AS  DeclaringType,    testMethod  AS  Method  

Page 80: Analysis of software systems using jQAssistant and Neo4j

81  

§  Each  asserJon  must  provide  a  human  readable  message.  

MATCH    (testType:Type)-­‐[:DECLARES]-­‐>(testMethod:Method),    (testMethod)-­‐[i:INVOKES]-­‐>(assertMethod:Assert:Method) WHERE  NOT    assertMethod.signature  =~            'void  assert.*\\(java.lang.String,.*\\)' RETURN    i  AS  Invocation,  //  provides  lineNumber    testType  AS  DeclaringType,    testMethod  AS  Method  

Page 81: Analysis of software systems using jQAssistant and Neo4j

82  

§ Remote  APIs  must  be  interfaces  declaring  only  primiJves  or  immutables  as  parameter  or  return  types.  

MATCH    (api:Package:API:Remote),    (api)-­‐[:CONTAINS*]-­‐>(interface:Interface),    (interface)-­‐[:DECLARES]-­‐>(method:Method),    (method)-­‐[:HAS|RETURNS]-­‐>(type:Type) WHERE  NOT    (type:Immutable  OR  type:Primitive) RETURN    interface  AS  InvalidInterface,  type  AS  InvalidType  

Page 82: Analysis of software systems using jQAssistant and Neo4j

83  

§ OSGi-­‐Bundles  must  only  export  dedicated  API  packages.  

MATCH    (bundle:Artifact:Bundle)-­‐[:EXPORTS]-­‐>(package:Package) WHERE  NOT    (package:API) RETURN    package  AS  InvalidExport  

Page 83: Analysis of software systems using jQAssistant and Neo4j

Mail:  [email protected]  

Web:  jqassistant.org  

Twixer:  @jqassistant  

Thank You! – Questions?

by