diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml new file mode 100644 index 0000000..c3b4847 --- /dev/null +++ b/.github/workflows/sonar.yml @@ -0,0 +1,36 @@ +name: SonarCloud +on: + push: + branches: + - master + pull_request: + types: [opened, synchronize, reopened] +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Cache SonarCloud packages + uses: actions/cache@v1 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Maven packages + uses: actions/cache@v1 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=tsaglam_Carcassonne diff --git a/pom.xml b/pom.xml index 2c15805..5b9f853 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,8 @@ UTF-8 11 + tsaglam + https://sonarcloud.io diff --git a/src/main/java/carcassonne/control/ControllerFacade.java b/src/main/java/carcassonne/control/ControllerFacade.java index ea059ed..8c35234 100644 --- a/src/main/java/carcassonne/control/ControllerFacade.java +++ b/src/main/java/carcassonne/control/ControllerFacade.java @@ -5,8 +5,8 @@ import carcassonne.view.GlobalKeyBindingManager; /** - * Facade for the game controller. Allows to call view classes or potentially external services to make requests regarding - * the game flow. + * Facade for the game controller. Allows to call view classes or potentially external services to make requests + * regarding the game flow. * @author Timur Saglam */ public interface ControllerFacade { diff --git a/src/main/java/carcassonne/model/Player.java b/src/main/java/carcassonne/model/Player.java index 2865472..4a46cb3 100644 --- a/src/main/java/carcassonne/model/Player.java +++ b/src/main/java/carcassonne/model/Player.java @@ -184,7 +184,8 @@ public boolean hasEmptyHand() { * Returns a meeple after its job is down. Allows the player to place another meeple. */ public void returnMeeple(Meeple meeple) { - assert placedMeeples.remove(meeple); + boolean isRemoved = placedMeeples.remove(meeple); + assert isRemoved; freeMeeples++; } diff --git a/src/main/java/carcassonne/model/Round.java b/src/main/java/carcassonne/model/Round.java index bea4c50..b971355 100644 --- a/src/main/java/carcassonne/model/Round.java +++ b/src/main/java/carcassonne/model/Round.java @@ -17,7 +17,7 @@ public class Round { private static final String NOTHING = ""; private static final String SQUARE_BRACKETS = "[\\[\\]]"; - + private int activePlayerIndex; private final Grid grid; private Player[] players; diff --git a/src/main/java/carcassonne/model/ai/RuleBasedComparator.java b/src/main/java/carcassonne/model/ai/RuleBasedComparator.java index 58e85b5..c8b9298 100644 --- a/src/main/java/carcassonne/model/ai/RuleBasedComparator.java +++ b/src/main/java/carcassonne/model/ai/RuleBasedComparator.java @@ -46,13 +46,13 @@ public int compare(AbstractCarcassonneMove firstMove, AbstractCarcassonneMove se private int compareMoveType(AbstractCarcassonneMove move) { if (move.involvesMeeplePlacement()) { switch (move.getMeepleType()) { - case CASTLE: - return 3; - case MONASTERY: - return 2; - case ROAD: - return 1; - default: + case CASTLE: + return 3; + case MONASTERY: + return 2; + case ROAD: + return 1; + default: } } return 0; // fields or no meeple placed diff --git a/src/main/java/carcassonne/model/grid/GridDirection.java b/src/main/java/carcassonne/model/grid/GridDirection.java index 4c4291c..392f436 100644 --- a/src/main/java/carcassonne/model/grid/GridDirection.java +++ b/src/main/java/carcassonne/model/grid/GridDirection.java @@ -83,7 +83,7 @@ public GridDirection nextDirectionTo(RotationDirection side) { if (this == CENTER) { return this; } - GridDirection[] cycle = { NORTH, NORTH_EAST, EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, WEST, NORTH_WEST }; + GridDirection[] cycle = {NORTH, NORTH_EAST, EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, WEST, NORTH_WEST}; int position = -2; // error case, sum with parameter side is negative for (int i = 0; i < cycle.length; i++) { if (cycle[i] == this) { // find in cycle @@ -167,6 +167,6 @@ public static List byRow() { * @return a 2D list of of NORTH_WEST, WEST, SOUTH_WEST, NORTH, CENTER, SOUTH, NORTH_EAST, EAST and SOUTH_EAST. */ public static GridDirection[][] values2D() { - return new GridDirection[][] { { NORTH_WEST, WEST, SOUTH_WEST }, { NORTH, CENTER, SOUTH }, { NORTH_EAST, EAST, SOUTH_EAST } }; + return new GridDirection[][] {{NORTH_WEST, WEST, SOUTH_WEST}, {NORTH, CENTER, SOUTH}, {NORTH_EAST, EAST, SOUTH_EAST}}; } } diff --git a/src/main/java/carcassonne/settings/GameSettings.java b/src/main/java/carcassonne/settings/GameSettings.java index 38ad99b..ed8b451 100644 --- a/src/main/java/carcassonne/settings/GameSettings.java +++ b/src/main/java/carcassonne/settings/GameSettings.java @@ -35,12 +35,12 @@ public class GameSettings { private static final String MEEPLE_PATH = "meeple/meeple_"; private static final String PNG = ".png"; private static final String TEMPLATE = "_template"; - private static final String[] DEFAULT_NAMES = { "ONE", "TWO", "THREE", "FOUR", "FIVE" }; + private static final String[] DEFAULT_NAMES = {"ONE", "TWO", "THREE", "FOUR", "FIVE"}; // COLOR CONSTANTS: public static final Color UI_COLOR = new Color(190, 190, 190); - private static final PlayerColor[] DEFAULT_COLORS = { new PlayerColor(30, 26, 197), new PlayerColor(151, 4, 12), new PlayerColor(14, 119, 25), - new PlayerColor(216, 124, 0), new PlayerColor(96, 0, 147) }; + private static final PlayerColor[] DEFAULT_COLORS = {new PlayerColor(30, 26, 197), new PlayerColor(151, 4, 12), new PlayerColor(14, 119, 25), + new PlayerColor(216, 124, 0), new PlayerColor(96, 0, 147)}; // COSMETIC: private final List colors; diff --git a/src/main/java/carcassonne/view/tertiary/GameStatisticsModel.java b/src/main/java/carcassonne/view/tertiary/GameStatisticsModel.java index 825c007..31d1cf1 100644 --- a/src/main/java/carcassonne/view/tertiary/GameStatisticsModel.java +++ b/src/main/java/carcassonne/view/tertiary/GameStatisticsModel.java @@ -14,7 +14,7 @@ public class GameStatisticsModel extends AbstractTableModel { private static final long serialVersionUID = -7138458001360243937L; // generated UID private final Round round; - private static final String[] HEADER = { "Player", "Castle", "Road", "Monastery", "Field", "SCORE" }; + private static final String[] HEADER = {"Player", "Castle", "Road", "Monastery", "Field", "SCORE"}; /** * Creates the game statistics model with the current round. diff --git a/src/main/java/carcassonne/view/tertiary/PlayerSettingsView.java b/src/main/java/carcassonne/view/tertiary/PlayerSettingsView.java index 42ba94a..c8e5f35 100644 --- a/src/main/java/carcassonne/view/tertiary/PlayerSettingsView.java +++ b/src/main/java/carcassonne/view/tertiary/PlayerSettingsView.java @@ -18,7 +18,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; -import javax.swing.ToolTipManager; import carcassonne.model.terrain.TerrainType; import carcassonne.model.tile.TileDistribution; @@ -195,7 +194,7 @@ private JPanel createFortificationPanel() { panel.add(checkBox); return panel; } - + private JPanel createEnclavePanel() { JPanel panel = createBasicPanel(ENCLAVE); panel.setToolTipText(ENCLAVE_TOOL_TIP);