2025 init

This commit is contained in:
Romain Lefeuvre
2025-11-18 14:41:54 +01:00
commit 7b185c9c0c
19 changed files with 417 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
# Use PMD designer
## Download JavaFX
If JavaFX is not installed you can download it [here](https://gluonhq.com/products/javafx/).
Check the current version of your JDK by running ```java --version``` and download the corresponding version ("Minimum JDK" column).
* Java 17 => JavaFX 21
* Java 11 => JavaDX 17
## Set up JavaFX
Before using `designer` you need to specify JavaFX path.
#### Linux/Unix
```shell
$ export JAVAFX_HOME=path/to/javafx-sdk-{version}
```
#### Windows
```shell
$ set JAVAFX_HOME=path\to\javafx-sdk-{version}
```
## Run designer
#### Linux/Unix
```shell
$ run.sh designer
```
#### Windows
```shell
$ pmd.bat designer
```

View File

@@ -0,0 +1,25 @@
# Extending PMD
Use XPath to define a new rule for PMD to prevent complex code. The rule should detect the use of three or more nested `if` statements in Java programs so it can detect patterns like the following:
```Java
if (...) {
...
if (...) {
...
if (...) {
....
}
}
}
```
Notice that the nested `if`s may not be direct children of the outer `if`s. They may be written, for example, inside a `for` loop or any other statement.
Write below the XML definition of your rule.
You can find more information on extending PMD in the following link: https://pmd.github.io/latest/pmd_userdocs_extending_writing_rules_intro.html, as well as help for using `pmd-designer` [here](https://github.com/selabs-ur1/VV-ISTIC-TP2/blob/master/exercises/designer-help.md).
Use your rule with different projects and describe you findings below. See the [instructions](../sujet.md) for suggestions on the projects to use.
## Answer

9
exercises/jp-cc.md Normal file
View File

@@ -0,0 +1,9 @@
# Cyclomatic Complexity with JavaParser
With the help of JavaParser implement a program that computes the Cyclomatic Complexity (CC) of all methods in a given Java project. The program should take as input the path to the source code of the project. It should produce a report in the format of your choice (TXT, CSV, Markdown, HTML, etc.) containing a table showing for each method: the package and name of the declaring class, the name of the method, the types of the parameters and the value of CC.
Your application should also produce a histogram showing the distribution of CC values in the project. Compare the histogram of two or more projects.
Include in this repository the code of your application. Remove all unnecessary files like compiled binaries. Do include the reports and plots you obtained from different projects. See the [instructions](../sujet.md) for suggestions on the projects to use.
You may use [javaparser-starter](../code/javaparser-starter) as a starting point.

11
exercises/jp-tcc.md Normal file
View File

@@ -0,0 +1,11 @@
# Class cohesion with JavaParser
With the help of JavaParser implement a program that computes the Tight Class Cohesion (TCC) for each class in a given Java project. The program should take as input the path to the source code of the project. It should produce a report in the format of your choice (TXT, CSV, Markdown, HTML, etc.) containing a table showing for each class: the package, name and TCC value.
Your application should also produce a histogram showing the distribution of CC values in the project. Compare the histogram of two or more projects.
Finally, your application should also produce the dependency graph of each class (cf. example [here](https://people.irisa.fr/Benoit.Combemale/pub/course/vv/vv-textbook-v0.1.pdf#cohesion-graph)). The graph should be written using the [GraphViz DOT format](https://www.graphviz.org/)
Ignore inherited members to compute TCC of a class.
Include in this repository the code of your application. Remove all unnecessary files like compiled binaries. Do include the reports and plots you obtained from different projects. See the [instructions](../sujet.md) for suggestions on the projects to use.
You may use [javaparser-starter](../code/javaparser-starter) as a starting point.

29
exercises/no-getter.md Normal file
View File

@@ -0,0 +1,29 @@
# No getter!
With the help of JavaParser implement a program that obtains the private fields of public classes that have no public getter in a Java project.
A field has a public getter if, in the same class, there is a public method that simply returns the value of the field and whose name is `get<name-of-the-field>`.
For example, in the following class:
```Java
class Person {
private int age;
private String name;
public String getName() { return name; }
public boolean isAdult() {
return age > 17;
}
}
```
`name` has a public getter, while `age` doesn't.
The program should take as input the path to the source code of the project. It should produce a report in the format of your choice (TXT, CSV, Markdown, HTML, etc.) that lists for each detected field: its name, the name of the declaring class and the package of the declaring class.
Include in this repository the code of your application. Remove all unnecessary files like compiled binaries. See the [instructions](../sujet.md) for suggestions on the projects to use.
*Disclaimer* In a real project not all fields need to be accessed with a public getter.

18
exercises/pmd-help.md Normal file
View File

@@ -0,0 +1,18 @@
# PMD
### Requirement
* Java 8 or above
### Installation
* download latest release https://github.com/pmd/pmd/releases/download/pmd_releases%2F7.5.0/pmd-dist-7.5.0-bin.zip
* unzip
* add the bin folder to your path
### Usage
(Instruction for linux use ```pmd.bat``` for windows)
* Do not hesitate to have a look on the help page ```pmd -h```
* Same thing for the check help page```pmd check -h```
* Run the analysis ```pmd check -f text -R rulesets/java/quickstart.xml -d [PROJECT_PATH] -r [REPORT_FILE_PATH]```
For more information consult the instructions given in https://pmd.github.io/pmd/pmd_userdocs_installation.html

8
exercises/tcc-vs-lcc.md Normal file
View File

@@ -0,0 +1,8 @@
# TCC *vs* LCC
Explain under which circumstances *Tight Class Cohesion* (TCC) and *Loose Class Cohesion* (LCC) metrics produce the same value for a given Java class. Build an example of such as class and include the code below or find one example in an open-source project from Github and include the link to the class below. Could LCC be lower than TCC for any given class? Explain.
A refresher on TCC and LCC is available in the [course notes](https://oscarlvp.github.io/vandv-classes/#cohesion-graph).
## Answer

6
exercises/using-pmd.md Normal file
View File

@@ -0,0 +1,6 @@
# Using PMD
Pick a Java project from Github (see the [instructions](../sujet.md) for suggestions). Run PMD on its source code using any ruleset (see the [pmd install instruction](./pmd-help.md)). Describe below an issue found by PMD that you think should be solved (true positive) and include below the changes you would add to the source code. Describe below an issue found by PMD that is not worth solving (false positive). Explain why you would not solve this issue.
## Answer