diff --git a/.gitignore b/.gitignore index 105e4a627e84f2ffabd10653c4945b944b812a10..f4ef5105ba5f37f03fdbe6a5f5da0c6d8341444a 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 2b3d3d4681bb727ba93535a691a0f66166703004..c4d150f884221e9ebaabc3409586245ea9282518 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/battery/src/main/java/fr/ufrst/m1info/gl/tpariney/Battery.java b/battery/src/main/java/fr/ufrst/m1info/gl/tpariney/Battery.java index 2b68abeb35818232aabc403d07acd760b73a7c99..f5c0bdcb77274da2fdfaa43f119696852b9db245 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 + + true + + 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 8cab53fb66947473701bb0f0cf651c118c886872..34baeea7f9f8a60230e1f61a61aa6087a146e50d 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 e53de5177258e8c8bbdbebca4239b162c02e1157..81d0bc053b1e88db48f14b6db14b3d72d0d6f285 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 c6b65da6edcfe9437a903f6eda6d0efe5d5df4c4..fc6b350bb741bbc7be82ec1795cea31691217e03 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 8b7f6b25448ef1fd7bf9bd1b59d6c36440cbd32c..419abf43c0a8f342e6c94750e865329c1fedd732 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 deleted file mode 100644 index 6a649e497cc42428bd61404a7e492b1af48d5748..0000000000000000000000000000000000000000 --- 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 b6ecf91a4fcfb2aee48d43fb618ac5433453f7ef..0000000000000000000000000000000000000000 --- 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 ); - } -}