Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonarcloud integration #37

Merged
merged 3 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Sonarcloud
on:
push:
branches:
- main
pull_request:
types: [ opened, synchronize, reopened ]
branches: [ main ]
jobs:
build:
name: Build
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 16.0.2
uses: actions/setup-java@v3
with:
java-version: '16.0.2'
distribution: 'temurin'
- name: Change wrapper permissions
run: chmod +x ./gradlew
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew build sonarqube --info
15 changes: 14 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ plugins {
id("java")
id("org.springframework.boot") version "2.7.0"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id("org.sonarqube") version "3.4.0.2513"
}

group = "fr.bfr"
version = "2.1.0"
version = "2.1.1"
java.sourceCompatibility = JavaVersion.VERSION_16


Expand Down Expand Up @@ -59,3 +60,15 @@ tasks.jar {
)
}
}

sonarqube {
properties {
properties(
mapOf<String, Any>(
"sonar.projectKey" to "bfresnel_loot-table-poc",
"sonar.organization" to "bfresnel",
"sonar.host.url" to "https://sonarcloud.io",
)
)
}
}
7 changes: 4 additions & 3 deletions src/main/java/fr/bfr/services/LootService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
import fr.bfr.model.DropChance;
import org.springframework.stereotype.Service;

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Service
public class LootService implements LootApi {

private final SecureRandom secureRandom = new SecureRandom();

@Override
public List<Character> pull(List<Character> data, List<DropChance> dropChances, Integer numberOfPull) {
List<Character> pulledCharacters = new ArrayList<>();
List<Character> charactersListWithDropChance = new ArrayList<>();
Random random = new Random();
int counter = 0;

// Setting an array of 100 characters with number of each character matching the chance
Expand All @@ -29,7 +30,7 @@ public List<Character> pull(List<Character> data, List<DropChance> dropChances,
}

while (counter < numberOfPull) {
pulledCharacters.add(charactersListWithDropChance.get(random.nextInt(100)));
pulledCharacters.add(charactersListWithDropChance.get(secureRandom.nextInt(100)));
counter += 1;
}

Expand Down