Skip to content
Snippets Groups Projects
Commit de88ac83 authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

Added PMD and SpotBugs configuration

parent 4ece303f
No related branches found
No related tags found
No related merge requests found
......@@ -10,8 +10,12 @@ Les commandes gradle les plus utiles :
- `gradle checkStyleMain` pour vérifier le style du code principal avec l'outil [checkstyle](https://checkstyle.sourceforge.io/) (rapports dans `build/reports/checkstyle/`).
- `gradle checkStyleTest` pour vérifier le style du code de test avec l'outil [checkstyle](https://checkstyle.sourceforge.io/) (rapports dans `build/reports/checkstyle/`).
- `gradle jacocoTestReport` pour lancer la couverture de code via l'outil [Jacoco](https://www.eclemma.org/jacoco/) (rapports dans `build/reports/jacoco/`).
- `gradle spotbugsMain` pour vérifier la présence de bugs dans le code principal avec l'outil [SpotBugs](https://spotbugs.github.io/) (rapports dans `reports/spotbugs/main/spotbugs.html`).
- `gradle spotbugsTest` pour vérifier la présence de bugs dans le code de test avec l'outil [SpotBugs](https://spotbugs.github.io/) (rapports dans `reports/spotbugs/test/spotbugs.html`).
- `gradle pmdMain` pour faire l'analyse statique du code principal avec l'outil [PMD](https://pmd.github.io/) (rapports dans `reports/pmd`).
- `gradle pmdTest` pour faire l'analyse statique du code de test avec l'outil [PMD](https://pmd.github.io/) (rapports dans `reports/pmd`).
Le fichier `build.gradle` contient la configuration du projet avec notamment la classe contenant la méthode `main` à exécuter.
Le fichier `build.gradle` contient la configuration du projet avec notamment la définition de la classe contenant la méthode `main` à exécuter pour l'application.
## Copyrights
......
......@@ -3,6 +3,8 @@ plugins {
id 'application'
id 'checkstyle'
id 'jacoco'
id 'pmd'
id "com.github.spotbugs" version "5.0.12"
}
group 'fr.univ_amu'
......@@ -19,7 +21,10 @@ repositories {
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter-api:5.9.0',
'org.assertj:assertj-core:3.23.1')
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
implementation 'org.apache.logging.log4j:log4j-api:2.19.0'
implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
}
test {
......@@ -34,7 +39,7 @@ test {
}
application {
mainClass = 'sample.MyJFrame'
mainClass = 'sample.MyJavaFrame'
}
tasks.named('jar') {
......@@ -45,6 +50,34 @@ tasks.named('jar') {
}
}
spotbugs {
reportLevel = 'high'
effort = 'max'
}
spotbugsMain {
reports {
html {
required = true
outputLocation = file("$buildDir/reports/spotbugs/main/spotbugs.html")
stylesheet = 'fancy-hist.xsl'
}
}
}
spotbugsTest {
reports {
html {
required = true
outputLocation = file("$buildDir/reports/spotbugs/test/spotbugs.html")
stylesheet = 'fancy-hist.xsl'
}
}
}
pmd {
consoleOutput = true
sourceSets = [sourceSets.main]
ruleSets = ["category/java/errorprone.xml", "category/java/bestpractices.xml"]
}
\ No newline at end of file
package sample;
import java.io.Serial;
import javax.swing.JFrame;
/**
* An extended version of javax.swing.JFrame containing a panel to draw images.
*/
public class MyJavaFrame extends JFrame {
@Serial
private static final long serialVersionUID = 42L;
/**
* Constructs a new visible frame.
*/
public MyJavaFrame() {
setTitle("Main window");
setSize(400, 400);
......
......@@ -2,27 +2,40 @@ package sample;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.Serial;
import java.text.MessageFormat;
import java.util.Objects;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* An extension of javax.swing.JFrame that can draw images.
*/
public class MyJavaPanel extends JPanel {
@Serial
private static final long serialVersionUID = 4242L;
private transient BufferedImage image;
private BufferedImage image;
/**
* Constructs a new panel that draw an image.
*/
public MyJavaPanel() {
Logger logger = LogManager.getLogger(this.getClass());
logger.debug("Construct a MyJavaPanel");
String path = "image.png";
if (logger.isDebugEnabled()) {
String message = MessageFormat.format("Loading image at path {0}", path);
logger.debug(message);
}
try {
image = ImageIO.read(Objects.requireNonNull(getClass().getResource("image.png")));
} catch (IOException ex) {
System.out.println("problem! image can't be loaded!");
image = ImageIO.read(Objects.requireNonNull(getClass().getResource(path)));
} catch (Exception ex) {
String message = MessageFormat.format("Error: Cannot load image at path: {0}", path);
logger.error(message, ex);
}
}
......
......@@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test;
/**
* A template class for testing with assertJ.
*/
public class TestMyClass {
class TestMyClass {
@Test
void testTrue() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment