From 5138ca8b551aa5e98cafa4530ffb019eac993226 Mon Sep 17 00:00:00 2001 From: tpariney Date: Fri, 24 Oct 2025 11:17:45 +0200 Subject: [PATCH 1/3] Apply autoformatting --- .../fr/ufrst/m1info/gl/tpariney/Battery.java | 8 +- .../tpariney/InsufficientChargeException.java | 8 +- .../m1info/gl/tpariney/BatteryUnitTest.java | 6 +- .../java/fr/ufrst/m1info/gl/tpariney/App.java | 2 +- pom.xml | 11 + .../gl/tpariney/RoadBookCalculator.java | 3 +- .../tpariney/UndefinedRoadbookException.java | 8 +- .../fr/ufrst/m1info/gl/tpariney/Robot.java | 212 +++++++++--------- .../gl/tpariney/UnlandedRobotException.java | 8 +- .../java/fr/ufrst/m1info/gl/tpariney/App.java | 6 +- .../m1info/gl/tparineymates/AppTest.java | 8 +- 11 files changed, 146 insertions(+), 134 deletions(-) diff --git a/battery/src/main/java/fr/ufrst/m1info/gl/tpariney/Battery.java b/battery/src/main/java/fr/ufrst/m1info/gl/tpariney/Battery.java index 2b68abe..f5c0bdc 100644 --- a/battery/src/main/java/fr/ufrst/m1info/gl/tpariney/Battery.java +++ b/battery/src/main/java/fr/ufrst/m1info/gl/tpariney/Battery.java @@ -18,7 +18,7 @@ public class Battery { } private static float chargeFunction(float charge) { - return charge*1.1f + 1; + return charge * 1.1f + 1; } public void setUp() { @@ -31,7 +31,7 @@ public class Battery { }, 0, CHARGE_TOP); } - public float getChargeLevel(){ + public float getChargeLevel() { return chargeLevel; } @@ -43,10 +43,10 @@ public class Battery { public long timeToSufficientCharge(double neededEnergy) { int clock = 0; float charge = chargeLevel; - while (chargemaven-release-plugin 3.1.1 + + org.openrewrite.maven + rewrite-maven-plugin + 6.18.0 + + true + + org.openrewrite.java.format.AutoFormat + + + diff --git a/roadBook/src/main/java/fr/ufrst/m1info/gl/tpariney/RoadBookCalculator.java b/roadBook/src/main/java/fr/ufrst/m1info/gl/tpariney/RoadBookCalculator.java index 8cab53f..34baeea 100644 --- a/roadBook/src/main/java/fr/ufrst/m1info/gl/tpariney/RoadBookCalculator.java +++ b/roadBook/src/main/java/fr/ufrst/m1info/gl/tpariney/RoadBookCalculator.java @@ -18,7 +18,8 @@ public class RoadBookCalculator { if (directionList.contains(direction)) { instructions.add(Instruction.FORWARD); return calculateRoadBook(direction, MapTools.nextForwardPosition(position, direction), destination, instructions); - } else { + } + else { instructions.add(Instruction.TURNRIGHT); return calculateRoadBook(MapTools.clockwise(direction), position, destination, instructions); } diff --git a/roadBook/src/main/java/fr/ufrst/m1info/gl/tpariney/UndefinedRoadbookException.java b/roadBook/src/main/java/fr/ufrst/m1info/gl/tpariney/UndefinedRoadbookException.java index e53de51..81d0bc0 100644 --- a/roadBook/src/main/java/fr/ufrst/m1info/gl/tpariney/UndefinedRoadbookException.java +++ b/roadBook/src/main/java/fr/ufrst/m1info/gl/tpariney/UndefinedRoadbookException.java @@ -4,11 +4,11 @@ package fr.ufrst.m1info.gl.tpariney; public class UndefinedRoadbookException extends Exception { /** - * - */ - private static final long serialVersionUID = 5576550274153253615L; + * + */ + private static final long serialVersionUID = 5576550274153253615L; - public UndefinedRoadbookException() { + public UndefinedRoadbookException() { super("Aucun road book défini"); } } diff --git a/robot/src/main/java/fr/ufrst/m1info/gl/tpariney/Robot.java b/robot/src/main/java/fr/ufrst/m1info/gl/tpariney/Robot.java index c6b65da..fc6b350 100644 --- a/robot/src/main/java/fr/ufrst/m1info/gl/tpariney/Robot.java +++ b/robot/src/main/java/fr/ufrst/m1info/gl/tpariney/Robot.java @@ -6,110 +6,110 @@ import static fr.ufrst.m1info.gl.tpariney.RoadBookCalculator.calculateRoadBook; public class Robot { - private Coordinates position; - private Direction direction; - private boolean isLanded; - private RoadBook roadBook; - private final double energyConsumption; // energie consommée pour la réalisation d'une action dans les conditions - // idéales - private LandSensor landSensor; - private Battery cells; // cells - - public Robot() { - this(1.0, new Battery()); - } - - public Robot(double energyConsumption, Battery cells) { - isLanded = false; - this.energyConsumption = energyConsumption; - this.cells = cells; - } - - public void land(Coordinates landPosition, LandSensor sensor) { - position = landPosition; - direction = Direction.NORTH; - isLanded = true; - landSensor = sensor; - cells.setUp(); - } - - public int getXposition() throws UnlandedRobotException { - if (!isLanded) - throw new UnlandedRobotException(); - return position.getX(); - } - - public int getYposition() throws UnlandedRobotException { - if (!isLanded) - throw new UnlandedRobotException(); - return position.getY(); - } - - public Direction getDirection() throws UnlandedRobotException { - if (!isLanded) - throw new UnlandedRobotException(); - return direction; - } - - public void moveForward() throws UnlandedRobotException, InterruptedException { - if (!isLanded) - throw new UnlandedRobotException(); - Coordinates nextPosition = MapTools.nextForwardPosition(position, direction); - double neededEnergy = landSensor.getPointToPointEnergyCoefficient(position, nextPosition) * energyConsumption; - boolean move = false; - do { - try { - cells.use(neededEnergy); - move = true; - } catch (InsufficientChargeException e) { - long l = cells.timeToSufficientCharge(neededEnergy); - Thread.sleep(l); - } - } while (!move); - position = nextPosition; - } - - public void moveBackward() throws UnlandedRobotException { - if (!isLanded) - throw new UnlandedRobotException(); - position = MapTools.nextBackwardPosition(position, direction); - } - - public void turnLeft() throws UnlandedRobotException { - if (!isLanded) - throw new UnlandedRobotException(); - direction = MapTools.counterclockwise(direction); - } - - public void turnRight() throws UnlandedRobotException { - if (!isLanded) - throw new UnlandedRobotException(); - direction = MapTools.clockwise(direction); - } - - public void setRoadBook(RoadBook roadBook) { - this.roadBook = roadBook; - } - - public void letsGo() throws UnlandedRobotException, UndefinedRoadbookException, InterruptedException { - if (roadBook == null) - throw new UndefinedRoadbookException(); - while (roadBook.hasInstruction()) { - Instruction nextInstruction = roadBook.next(); - if (nextInstruction == Instruction.FORWARD) - moveForward(); - else if (nextInstruction == Instruction.BACKWARD) - moveBackward(); - else if (nextInstruction == Instruction.TURNLEFT) - turnLeft(); - else if (nextInstruction == Instruction.TURNRIGHT) - turnRight(); - } - } - - public void computeRoadTo(Coordinates destination) throws UnlandedRobotException { - if (!isLanded) - throw new UnlandedRobotException(); - setRoadBook(calculateRoadBook(direction, position, destination, new ArrayList<>())); - } + private Coordinates position; + private Direction direction; + private boolean isLanded; + private RoadBook roadBook; + private final double energyConsumption; // energie consommée pour la réalisation d'une action dans les conditions + // idéales + private LandSensor landSensor; + private Battery cells; // cells + + public Robot() { + this(1.0, new Battery()); + } + + public Robot(double energyConsumption, Battery cells) { + isLanded = false; + this.energyConsumption = energyConsumption; + this.cells = cells; + } + + public void land(Coordinates landPosition, LandSensor sensor) { + position = landPosition; + direction = Direction.NORTH; + isLanded = true; + landSensor = sensor; + cells.setUp(); + } + + public int getXposition() throws UnlandedRobotException { + if (!isLanded) + throw new UnlandedRobotException(); + return position.getX(); + } + + public int getYposition() throws UnlandedRobotException { + if (!isLanded) + throw new UnlandedRobotException(); + return position.getY(); + } + + public Direction getDirection() throws UnlandedRobotException { + if (!isLanded) + throw new UnlandedRobotException(); + return direction; + } + + public void moveForward() throws UnlandedRobotException, InterruptedException { + if (!isLanded) + throw new UnlandedRobotException(); + Coordinates nextPosition = MapTools.nextForwardPosition(position, direction); + double neededEnergy = landSensor.getPointToPointEnergyCoefficient(position, nextPosition) * energyConsumption; + boolean move = false; + do { + try { + cells.use(neededEnergy); + move = true; + } catch (InsufficientChargeException e) { + long l = cells.timeToSufficientCharge(neededEnergy); + Thread.sleep(l); + } + } while (!move); + position = nextPosition; + } + + public void moveBackward() throws UnlandedRobotException { + if (!isLanded) + throw new UnlandedRobotException(); + position = MapTools.nextBackwardPosition(position, direction); + } + + public void turnLeft() throws UnlandedRobotException { + if (!isLanded) + throw new UnlandedRobotException(); + direction = MapTools.counterclockwise(direction); + } + + public void turnRight() throws UnlandedRobotException { + if (!isLanded) + throw new UnlandedRobotException(); + direction = MapTools.clockwise(direction); + } + + public void setRoadBook(RoadBook roadBook) { + this.roadBook = roadBook; + } + + public void letsGo() throws UnlandedRobotException, UndefinedRoadbookException, InterruptedException { + if (roadBook == null) + throw new UndefinedRoadbookException(); + while (roadBook.hasInstruction()) { + Instruction nextInstruction = roadBook.next(); + if (nextInstruction == Instruction.FORWARD) + moveForward(); + else if (nextInstruction == Instruction.BACKWARD) + moveBackward(); + else if (nextInstruction == Instruction.TURNLEFT) + turnLeft(); + else if (nextInstruction == Instruction.TURNRIGHT) + turnRight(); + } + } + + public void computeRoadTo(Coordinates destination) throws UnlandedRobotException { + if (!isLanded) + throw new UnlandedRobotException(); + setRoadBook(calculateRoadBook(direction, position, destination, new ArrayList<>())); + } } diff --git a/robot/src/main/java/fr/ufrst/m1info/gl/tpariney/UnlandedRobotException.java b/robot/src/main/java/fr/ufrst/m1info/gl/tpariney/UnlandedRobotException.java index 8b7f6b2..419abf4 100644 --- a/robot/src/main/java/fr/ufrst/m1info/gl/tpariney/UnlandedRobotException.java +++ b/robot/src/main/java/fr/ufrst/m1info/gl/tpariney/UnlandedRobotException.java @@ -6,11 +6,11 @@ package fr.ufrst.m1info.gl.tpariney; public class UnlandedRobotException extends Exception { /** - * - */ - private static final long serialVersionUID = 8808058592281751853L; + * + */ + private static final long serialVersionUID = 8808058592281751853L; - public UnlandedRobotException() { + public UnlandedRobotException() { super("Le robot doit être posé avant tout déplacement"); } } diff --git a/src/main/java/fr/ufrst/m1info/gl/tpariney/App.java b/src/main/java/fr/ufrst/m1info/gl/tpariney/App.java index 6a649e4..39eedb8 100644 --- a/src/main/java/fr/ufrst/m1info/gl/tpariney/App.java +++ b/src/main/java/fr/ufrst/m1info/gl/tpariney/App.java @@ -4,10 +4,10 @@ package fr.ufrst.m1info.gl.tpariney; * Hello world! * */ -public class App +public class App { - public static void main( String[] args ) + public static void main(String[] args) { - System.out.println( "Hello World!" ); + System.out.println("Hello World!"); } } diff --git a/src/test/java/fr/ufrst/m1info/gl/tparineymates/AppTest.java b/src/test/java/fr/ufrst/m1info/gl/tparineymates/AppTest.java index b6ecf91..eb651ff 100644 --- a/src/test/java/fr/ufrst/m1info/gl/tparineymates/AppTest.java +++ b/src/test/java/fr/ufrst/m1info/gl/tparineymates/AppTest.java @@ -7,7 +7,7 @@ import junit.framework.TestSuite; /** * Unit test for simple App. */ -public class AppTest +public class AppTest extends TestCase { /** @@ -15,9 +15,9 @@ public class AppTest * * @param testName name of the test case */ - public AppTest( String testName ) + public AppTest(String testName) { - super( testName ); + super(testName); } /** @@ -33,6 +33,6 @@ public class AppTest */ public void testApp() { - assertTrue( true ); + assertTrue(true); } } -- GitLab From a68cf39ef3d71bac8377786ea07721acacb97dc7 Mon Sep 17 00:00:00 2001 From: tpariney Date: Fri, 24 Oct 2025 11:40:11 +0200 Subject: [PATCH 2/3] Remove unused src folder --- .../java/fr/ufrst/m1info/gl/tpariney/App.java | 13 ------- .../m1info/gl/tparineymates/AppTest.java | 38 ------------------- 2 files changed, 51 deletions(-) delete mode 100644 src/main/java/fr/ufrst/m1info/gl/tpariney/App.java delete mode 100644 src/test/java/fr/ufrst/m1info/gl/tparineymates/AppTest.java diff --git a/src/main/java/fr/ufrst/m1info/gl/tpariney/App.java b/src/main/java/fr/ufrst/m1info/gl/tpariney/App.java deleted file mode 100644 index 39eedb8..0000000 --- a/src/main/java/fr/ufrst/m1info/gl/tpariney/App.java +++ /dev/null @@ -1,13 +0,0 @@ -package fr.ufrst.m1info.gl.tpariney; - -/** - * Hello world! - * - */ -public class App -{ - public static void main(String[] args) - { - System.out.println("Hello World!"); - } -} diff --git a/src/test/java/fr/ufrst/m1info/gl/tparineymates/AppTest.java b/src/test/java/fr/ufrst/m1info/gl/tparineymates/AppTest.java deleted file mode 100644 index eb651ff..0000000 --- a/src/test/java/fr/ufrst/m1info/gl/tparineymates/AppTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package fr.ufrst.m1info.gl.tpariney; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest(String testName) - { - super(testName); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue(true); - } -} -- GitLab From 72db06eb89b944a31ebba226221fd533dcca76c8 Mon Sep 17 00:00:00 2001 From: tpariney Date: Fri, 24 Oct 2025 11:19:23 +0200 Subject: [PATCH 3/3] Split CI in multiple jobs Add autoformat to CI --- .gitignore | 1 + .gitlab-ci.yml | 43 ++++++++++++++++++++++++++++++++++--------- pom.xml | 1 + 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 105e4a6..f4ef510 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea/ +target/ battery/target/ maptools/target/ roadBook/target/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b3d3d4..c4d150f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,5 @@ image: maven:3-openjdk-17 -stages: - - build - variables: MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository" @@ -13,16 +10,44 @@ cache: - $CI_PROJECT_DIR/.m2/repository key: "$CI_BUILD_REF_NAME" -build-job: +stages: + - build + - deploy + +format-job: stage: build script: - chmod +x ./settings.sh - ./settings.sh - - mvn clean jacoco:prepare-agent test jacoco:report install sonar:sonar deploy - -Dsonar.projectKey=tpariney-robot-modules - -Dsonar.projectName=tpariney-robot-modules - -Dsonar.host.url=https://disc.univ-fcomte.fr/cr700-sonarqube - -Dsonar.token=$SONAR_TOKEN + - mvn clean rewrite:dryRun + tags: + - avm_groupe1 + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $CI_COMMIT_TAG + +test-job: + stage: build + script: + - chmod +x ./settings.sh + - ./settings.sh + - mvn clean jacoco:prepare-agent test jacoco:report install + tags: + - avm_groupe1 + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $CI_COMMIT_TAG + +deploy-job: + stage: deploy + script: + - chmod +x ./settings.sh + - ./settings.sh + - mvn clean install sonar:sonar deploy + -Dsonar.projectKey=tpariney-robot-modules + -Dsonar.projectName=tpariney-robot-modules + -Dsonar.host.url=https://disc.univ-fcomte.fr/cr700-sonarqube + -Dsonar.token=$SONAR_TOKEN tags: - avm_groupe1 rules: diff --git a/pom.xml b/pom.xml index 3049857..c9b9853 100644 --- a/pom.xml +++ b/pom.xml @@ -65,6 +65,7 @@ org.openrewrite.java.format.AutoFormat + true -- GitLab