Dirk Mahler - Yes, we scan! Análise de software usando JQAssistant e Neo4jj - #oowBR #JavaOneBR

Preview:

Citation preview

by

Yes We Scan! Software Analysis Using

jQAssistant And Neo4j

JavaOne Latin AmericaSão Paulo 2016

Dirk Mahler

2

AGENDA

Black Boxes Called Artifacts jQAssistant Software As A Graph Let’s Explore Libraries!

Black Boxes Called Artifacts

Yes We Scan!Software Analysis Using jQAssistant And Neo4j

3

4

Artifact Result of a build/integration processes Black Box – What does it hide?

Let‘s open it!

Person.java

@Entitypublic class Person {private String name;

}

pom.xml

<dependency><groupId>org.eclipse.persistence</groupId><artifactId>persistence-api</artifactId><version>2.1.0</version>

</dependency>

person.sql

create table PERSON (id number, name varchar(255)

model.jar

/com/acme/model/Person.class/META-INF/persistence.xml

acme.war

/index.xhtml/WEB-INF/lib/model.jar

5

The Idea

Scan software structures

Store in a database

Execute queries Explore

Add high level concepts

Find constraint violations

Create reports

Database

jQAssistant

Yes We Scan!Software Analysis Using jQAssistant And Neo4j

6

7

http://jQAssistant.org

Open Source: GPLv3

Current release: 1.1.3 initiated: 03/2013 first stable release: 04/2015

Neo4j Community Edition http://neo4j.org embedded, no installation necessary

8

Command Line/

Maven

Scan

Analyze

Report

Plugins

Plugins

Plugins

9

Getting Started – Command Line

unzip jqassistant.distribution-1.x.x.zip cd jqassistant.distribution-1.x.x/bin

jqassistant.sh scan –f model.jar jqassistant.sh scan –f acme.war jqassistant.sh scan –f acme.ear jqassistant.sh scan –u http://somewhere.com/acme.ear jqassistant.sh scan –u maven:repository::http://host/releases

jqassistant.sh scan –u rdbms:schema::jdbc:oracle:thin:user/secret@host:1521:sid

jqassistant.sh server http://localhost:7474

10

Getting Started – Maven Project

<build><plugins><plugin>

<groupId>com.buschmais.jqassistant.scm</groupId><artifactId>jqassistant-maven-plugin</artifactId><version>1.x.x</version>

</plugin></plugins>

</build>

mvn install jqassistant:scan mvn jqassistant:server

http://localhost:7474

11

Available scanner plugins

Plugin API is public

*.class

RDBMS Schema

GitJaCoCo

FindBugsCheckStyle

LiquibaseJAR, WAR, EARZIP

application.xmlweb.xml

MANIFEST.MF /META-INF/services/*

beans.xml

pom.xml surefire-reports.xml

GZ

*.properties

*.xsd

M2 Repository

*.yaml

Software As A Graph

Yes We Scan!Software Analysis Using jQAssistant And Neo4j

12

13

All we need is… Nodes Labels Properties Relationships

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

Type

EXTENDS

fqn:com.acme.model.Person

CONTAINS

Package

name:com

CONTAINS

Package

name:acme

CONTAINS

Package

name:model

Class

Type

CONTAINS

fqn:com.acme.model.PersonAnnotation ANNOTATED_BYType

OF_TYPE

fqn:javax.persistence.Entity

REQUIRES

Field

DECLARES

name:name

Type

OF_TYPE

fqn:int

REQUIRES

Maven

CONTAINS

fileName: /META-INF/maven/com.acme.model/pom.xml

Pom

Java

CONTAINS

Archive

fileName:model.jar

Artifact

Web Application

fileName:acme.warArchive

ArtifactCONTAINS

group:org.eclipse.persistencename:persistence-api

version: 2.1.0

Artifact

scope:compileDECLARES_DEPENDENCY

15

TypeType

Class

EXTENDS

Explore an application using queries Which class extends from another class?

Let‘s convert this to ASCII art… () as nodes

-[]-> as directed relationships

16

TypeType

Class

EXTENDS

Explore an application using queries Which class extends from another class?

Let‘s convert this to ASCII art… () as nodes

-[]-> as directed relationships

()-[]->()

17

C2Type

C1Type

Class

EXTENDS

Explore an application using queries Which class extends from another class?

Let‘s convert this to ASCII art… () as nodes

-[]-> as directed relationships

(c1)-[]->(c2)

18

C2Type

C1Type

Class

EXTENDS

Explore an application using queries Which class extends from another class?

Let‘s convert this to ASCII art… () as nodes

-[]-> as directed relationships

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

19

Explore an application using queries Which class extends from another class?

Let‘s convert this to ASCII art… () as nodes

-[]-> as directed relationships

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

C2Type

C1Type

Class

EXTENDS

20

Explore an application using queries Which class extends from another class?

Pattern matching is the core principle of Cypher

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

RETURNc1.fqn, c2.fqn

C2Type

C1Type

Class

EXTENDS

Let’s Explore Libraries!

Yes We Scan!Software Analysis Using jQAssistant And Neo4j

21

22

Examples Artifacts and Maven descriptors API changes between releases

Declared deprecations Thrown exceptions Anti-Patterns Structural problems (metrics) Declared members

Depth of inheritance hierarchies

Cyclomatic complexity

Fan In/Fan Out of classes and packages

Package Cycles

Live Demo

Yes We Scan!Software Analysis Using jQAssistant And Neo4j

23

https://jqassistant.org/yes-we-scan-exploring-libraries/

24

Holistic and extensible view on code structures Graph data model

Plugin architecture

Flexible exploration of structures using queries Expressive query language - Cypher

Powerful searches beyond IDE capabilities

Individual metrics and visualization

Web: jqassistant.org

Twitter: @jqassistant

Google Group: jQAssistant

Stackoverflow Tag: jQAssistant

Thank You! – Questions?

by