Static Analysis of Java with Moose

Christopher FUHRMAN
Professor in Software and IT Engineering
École de technologie supérieure (ETS)

tiny.cc/moose-tuto supporting this blog entry.

Technologies

    
     

Pharo

  • Language (inspired by Smalltalk)
  • Platform (immersive programming)
    • Image-based platform (like VirtualBox)
  • Moose is a set of tools running in Pharo

Overview

Example from my blog, Analyzing Java with Moose 8

Preliminaries

Install the following for this tutorial

  • java (command in path) JRE v. 8+
  • git (command in path)

Pharo Preliminaries

  • Install and run the Pharo Launcher.
  • Copy Moose-8 image from the Inria CI: New Image Templates > Official distributions > Moose Suite 8.0 (development version) > Create image
  • Launch the image once it has downloaded.

Cloning a project from GitHub

Cloning a project from GitHub

Clone using

git clone ...

-or-

Clone with MooseEasyUtility. In a Moose Playground (CTRL+O+W):

javaProjectFileRef := MooseEasyUtility cloneGitHubRepo:
    'https://github.com/bethrobson/Head-First-Design-Patterns'.

Creating a Moose Model (FAMIX)

Creating a Moose Model (FAMIX)

We will parse Java source to a Moose Model using VerveineJ.

  1. Install VerveineJ in a Moose Playground as follows:
verveineJFileRef := MooseEasyUtility cloneGitHubRepo:
    'https://github.com/moosetechnology/VerveineJ'.

You can also install it by cloning the repo in a command line.

Creating a Moose Model (FAMIX)

  1. Start the FamixMaker tool in the menu Moose > Moose Tools > Famix Maker to produce a tmp/HFDP.mse Moose Model

Loading model in Moose

Loading model in Moose

In a Moose Playground, execute:

"Load the moose Model with some error checking"
| mseFileRef mseStream mooseModel |
mseFileRef := 'tmp/HFDP.mse' asFileReference. "Generated by FamixMaker"
mseStream := mseFileRef readStream.
mseStream
	ifNotNil: [ 
		mooseModel := MooseModel importFromMSEStream: mseStream. 
		mooseModel rootFolder:
      'tmp/MooseEasyRepos/bethrobson__Head-First-Design-Patterns'.
		mooseModel install. "So it appears in the Panel"
		mseStream close. ]
	ifNil: [ self error: 
    'Could not load MSE file into Moose: ' , mseFileRef asString ].

Visualizing the model (PlantUML)

Visualizing the model (PlantUML)

  • Click Moose > Moose Projects > Load PlantUML Gizmo to load the project.

  • Invoke the GUI with the following command in a Moose Playground:

    PUGizmoForMoose open.
    

Visualizing the model (PlantUML)

The following browser should appear:

Visualizing the model (PlantUML)

See the blog entry for details.

Analyzing the model

Analyzing the model

There are some other ways to use Pharo to do analyses on a Java model. Benoît Verhaeghe has a complementary blog entry to show such analyses.

Execute the following in a Moose Playground:

Metacello new
    githubUser: 'badetitou' project: 'OOAnalysis' commitish: 'master' path: '.';
    baseline: 'OOAnalysis';
    load

Analyzing the model

<scripts > in OOAnalysis/OOCriticsVisu:

Analyzing the model

Write your own analyses in Pharo/Moose.

Learn more Pharo:

Analyzing the model

Write your own analyses in Pharo/Moose.

Learn more Moose:

  • MooseQuery for advanced queries in Moose models
  • GitMiner has a few classes to do static analysis

Analyzing the model

Write your own analyses in Pharo/Moose.

Analyze other languages (experimental):

Feedback

Please leave me feedback at the bottom of the blog entry, or via email: Christopher.Fuhrman@etsmtl.ca