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

Static analysis #5

Merged
merged 32 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3d442f4
Create static_analysis.yml
Hybeee May 6, 2024
28daafc
first commit
Hybeee May 6, 2024
014ac7e
build file change
Hybeee May 6, 2024
d431574
Nomad class override added
Hybeee May 6, 2024
8b14772
triggering sonarcloud test
Hybeee May 6, 2024
a6ee7d7
Character.java analysed
Hybeee May 6, 2024
d9b923a
City.java analysed and corrected
Hybeee May 6, 2024
81ec829
Field.java analysed and corrected
Hybeee May 6, 2024
0f78fef
Game.java analysed and corrected
Hybeee May 6, 2024
dc777e9
Mechanic.java analysed and corrected
Hybeee May 6, 2024
f7bf207
Node.java analysed and corrected
Hybeee May 6, 2024
df03cad
Pipe.java analysed and corrected
Hybeee May 6, 2024
02f0974
Pump.java analysed and corrected
Hybeee May 6, 2024
cc397bd
Source.java analysed and corrected
Hybeee May 6, 2024
0d896dd
Step.java analysed and corrected
Hybeee May 6, 2024
ad901bd
CityView.cs analysed and corrected
Hybeee May 7, 2024
a15cc0c
IView analysed and corrected
Hybeee May 7, 2024
d276673
IView.java analysed and corrected
Hybeee May 7, 2024
098eea4
SourceView.java analysed and updated
Hybeee May 7, 2024
631b5bc
PipeView.java and PipeView.java analysed and corrected
Hybeee May 7, 2024
d813383
NomadView.java analysed and corrected
Hybeee May 7, 2024
32f3fe6
NodeView.java analysed and corrected
Hybeee May 7, 2024
ad73928
MechanicView.java analysed
Hybeee May 7, 2024
b5f3bee
MechanicView documentation correction
Hybeee May 7, 2024
c1567ee
GameFrame.java analysed and corrected
Hybeee May 7, 2024
27bf787
Drawer.java analysed and corrected
Hybeee May 7, 2024
082a769
TastClass.java analysed
Hybeee May 7, 2024
4e4ee54
TesterMain.java analysed
Hybeee May 7, 2024
ceb360a
Main.java analysed and corrected
Hybeee May 7, 2024
d5f7852
CommandInterpreter.java analysed and corrected
Hybeee May 7, 2024
ae3b3cb
verdict
Hybeee May 7, 2024
c26a50a
Merge branch 'main' into static-analysis
Hybeee May 17, 2024
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
37 changes: 37 additions & 0 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: SonarCloud
on:
push:
branches:
- static-analysis
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
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=BME-MIT-IET_iet-hf-2024-bomboclat
141 changes: 141 additions & 0 deletions doc/static_analysis.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.organization>bme-mit-iet-org</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class CommandInterpreter {

static boolean run = true;

static public void WriteToFile(String filename, String data) {
public static void WriteToFile(String filename, String data) {
try {
File f = new File(filename);
f.createNewFile();
Expand All @@ -52,7 +52,7 @@ static public void WriteToFile(String filename, String data) {
}
}

static public void Add(String[] cmd) {
public static void Add(String[] cmd) {
String output = "";

if(cmd[1].equals("mechanic")) {
Expand Down Expand Up @@ -481,9 +481,8 @@ public static void set(String[] cmd) {
}

output = String.format("Pump %d has been modified.\n", Integer.parseInt(cmd[2]));
// pumps.add(pump);
} else if(cmd[1].equals("pipe")) {
Pipe pipe = pipes.get(Integer.parseInt(cmd[2]));;
Pipe pipe = pipes.get(Integer.parseInt(cmd[2]));

for(int i = 0; i < cmd.length; i++) {
if(cmd[i].equals("-endpoint")) {
Expand Down Expand Up @@ -760,7 +759,7 @@ public static void init(String[] cmd) {
}

public static void read(String[] cmd) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
try (Stream<String> lines = Files.lines(Paths.get(cmd[1]))) {
result = lines.collect(Collectors.toList());
} catch (IOException ie) {
Expand Down Expand Up @@ -796,7 +795,7 @@ public static void test(String[] cmd) {



List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
result.clear();
try (Stream<String> lines = Files.lines(Paths.get("temp.txt"))) {
result = lines.collect(Collectors.toList());
Expand All @@ -806,7 +805,7 @@ public static void test(String[] cmd) {
}


List<String> expected = new ArrayList<String>();
List<String> expected = new ArrayList<>();
expected.clear();
try (Stream<String> lines = Files.lines(Paths.get("tests/test" + i + "expected.txt"))) {
expected = lines.collect(Collectors.toList());
Expand Down Expand Up @@ -837,15 +836,15 @@ public static void test(String[] cmd) {



List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
try (Stream<String> lines = Files.lines(Paths.get("temp.txt"))) {
result = lines.collect(Collectors.toList());
} catch (IOException ie) {
System.out.println("Invalid file");
}


List<String> expected = new ArrayList<String>();
List<String> expected = new ArrayList<>();
try (Stream<String> lines = Files.lines(Paths.get("tests/test" + cmd[1] + "expected.txt"))) {
expected = lines.collect(Collectors.toList());
} catch (IOException ie) {
Expand Down Expand Up @@ -979,24 +978,24 @@ public static void placepipe(String[] cmd) {
public static void main(String[] args) {

commands.put("exit", (String[] cmd) -> run = false);
commands.put("add", (String[] cmd) -> Add(cmd));
commands.put("delete", (String [] cmd) -> delete(cmd));
commands.put("list", (String [] cmd) -> list(cmd));
commands.put("set", (String[] cmd) -> set(cmd));
commands.put("move", (String[] cmd) -> move(cmd));
commands.put("fix", (String[] cmd) -> fix(cmd));
commands.put("changepump", (String[] cmd) -> changepump(cmd));
commands.put("lube", (String[] cmd) -> lube(cmd));
commands.put("glue", (String[] cmd) -> glue(cmd));
commands.put("placepump", (String[] cmd) -> placepump(cmd));
commands.put("pickuppipe", (String[] cmd) -> pickuppipe(cmd));
commands.put("pickuppump", (String[] cmd) -> pickuppump(cmd));
commands.put("init", (String[] cmd) -> init(cmd));
commands.put("read", (String[] cmd) -> read(cmd));
commands.put("test", (String[] cmd) -> test(cmd));
commands.put("drill", (String[] cmd) -> drill(cmd));
commands.put("simulate_step", (String[] cmd) -> simulate_step(cmd));
commands.put("placepipe", (String[] cmd) -> placepipe(cmd));
commands.put("add", CommandInterpreter::Add);
commands.put("delete", CommandInterpreter::delete);
commands.put("list", CommandInterpreter::list);
commands.put("set", CommandInterpreter::set);
commands.put("move", CommandInterpreter::move);
commands.put("fix", CommandInterpreter::fix);
commands.put("changepump", CommandInterpreter::changepump);
commands.put("lube", CommandInterpreter::lube);
commands.put("glue", CommandInterpreter::glue);
commands.put("placepump", CommandInterpreter::placepump);
commands.put("pickuppipe", CommandInterpreter::pickuppipe);
commands.put("pickuppump", CommandInterpreter::pickuppump);
commands.put("init", CommandInterpreter::init);
commands.put("read", CommandInterpreter::read);
commands.put("test", CommandInterpreter::test);
commands.put("drill", CommandInterpreter::drill);
commands.put("simulate_step", CommandInterpreter::simulate_step);
commands.put("placepipe", CommandInterpreter::placepipe);

while(run){
try {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/hu/bomboclat/Game/City.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void Step(boolean rnd) {
* Visszaadja, hogy hány pontja van a szerelőknek vagyis a consumed értékét.
* @return A szerelők pontjai, a consumed tagváltozó értéke.
*/
@Override
public int getMechanicPoint(){
return consumed;
}
Expand All @@ -52,6 +53,7 @@ public int getMechanicPoint(){
* @param m a csövet felvenni kívánó szerelő játékos.
* @return A függvény a felvett cső objektumot adja vissza.
*/
@Override
public Pipe PickUpPipe(Mechanic m){
Pipe returnPipe = new Pipe();
PipeView pv = new PipeView(returnPipe);
Expand All @@ -71,9 +73,9 @@ public Pipe PickUpPipe(Mechanic m){
* A városból új pumpákat tudnak felvenni ezzel a függvénnyel.
* @return A függvény a felvett pumpa objektumot adja vissza.
*/
@Override
public Pump PickUpPump() {
Pump p = new Pump();
return p;
return new Pump();
}


Expand Down
12 changes: 6 additions & 6 deletions src/main/java/hu/bomboclat/Game/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
/**
* A karakterek által használható mezőket reprezentáló osztály.
*/
abstract public class Field{
public abstract class Field{
/**Az adott mezőn álló játékosok. */
protected List<Character> players;

/**Field konstruktora. */
public Field(){
protected Field(){
players=new ArrayList<>();
}

Expand All @@ -25,7 +25,7 @@ public Field(){
* @param d Irány, amelyből a szomszédot lekérik.
* @return Az adott irányból a szomszédos mező, vagy ha az adott irányba nincs érvényes mező, nullt ad vissza.
*/
abstract public Field getNeighbour(int d);
public abstract Field getNeighbour(int d);

/**
* Leveszi a paraméterben kapott karaktert a mezőről, vagyis eltávolítja a players listából.
Expand Down Expand Up @@ -138,7 +138,7 @@ public boolean Lube(){
* Ebben az esetben virtuális függvényként jelenik meg, a leszármazottakban felül kell definiálni
* @return Szomszédok száma
*/
abstract public int getNeighbourCount();
public abstract int getNeighbourCount();

public boolean getSlippery() {
return false;
Expand All @@ -148,11 +148,11 @@ public boolean getSlippery() {
* Absztrakt függvény, amelyek a leszármazottakban vannak megvalósítva.
* @return Visszaadja az adott objektumhoz tartozó IView-t implementáló osztályt reprezentáló objektumot.
*/
abstract public IView getView();
public abstract IView getView();

/**
* Absztrakt függvény, amelyek a leszármazottakban vannak megvalósítva.
* Beállítja a leszármazotthoz tartozó view objektumot a paraméterben megkapott objektumra.
*/
abstract public void setView(IView view);
public abstract void setView(IView view);
}
8 changes: 4 additions & 4 deletions src/main/java/hu/bomboclat/Game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public int getStep_count() {
public Game(int _all_rounds){
round_count = 0;
all_rounds = _all_rounds;
characters = new ArrayList<Character>();
characters = new ArrayList<>();
currPlayfield = null;
}

Expand All @@ -74,7 +74,7 @@ public Game(int _all_rounds, GameFrame f){
frame = f;
round_count = 0;
all_rounds = _all_rounds;
characters = new ArrayList<Character>();
characters = new ArrayList<>();
currPlayfield = null;
}

Expand All @@ -84,15 +84,15 @@ public Game(int _all_rounds, GameFrame f){
public Game(){
round_count = 0;
all_rounds = 10;
characters = new ArrayList<Character>();
characters = new ArrayList<>();
currPlayfield = null;
}

/**
* Elindítja a játékmenetet.
*/
public List<IView> StartGame(int _characters){
List<IView> ret = new ArrayList<IView>();
List<IView> ret = new ArrayList<>();
round_count = 0;
currPlayfield = new Playfield();

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/hu/bomboclat/Game/Mechanic.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public Mechanic(int nMoves, Field nField){
* Megkísérli megjavítani az adott mezőt, amin éppen áll függetlenül
* attól, hogy az cső vagy pumpa.
*/
@Override
public boolean Fix(){
boolean ret =field.Fix();
if(ret){
Expand All @@ -83,6 +84,7 @@ public boolean Fix(){
/**
* A szerelő leteszi a kezáben lévő pumpát, arra a csőre, amin áll
*/
@Override
public boolean PlacePump(){
if(pump_in_hand != null){
pump_in_hand = field.PlacePump(pump_in_hand);
Expand All @@ -98,6 +100,7 @@ public boolean PlacePump(){
/**
* A szerelő beköti a kezében lévő csövet abba a pumpába, amin áll
*/
@Override
public boolean PlacePipe(){
field.PlacePipe(this);
if(pipe_in_hand == null){
Expand All @@ -111,6 +114,7 @@ public boolean PlacePipe(){
* játékos egy ciszternában pumpát szeretne a kezébe venni. Ekkor felvesz egy
* pumpát, amivel a kezében mozoghat a pályán.
*/
@Override
public void PickUpPump(){
boolean emptyHanded = false;
if(pump_in_hand == null){
Expand All @@ -127,6 +131,7 @@ public void PickUpPump(){
* annak az egyik végét) arról a mezőről, amelyen áll, majd ha ez sikerül, a cső
* vége a kezébe kerül, ezzel tud tovább mozogni.
*/
@Override
public void PickUpPipe(){
boolean emptyHanded = false;
boolean oneEnd = false;
Expand Down Expand Up @@ -183,7 +188,6 @@ public int GetPipeEnd(){
*/
public void SetPipeInHand(Pipe pipe){
pipe_in_hand = pipe;
//pipeEnd = 0;
}

/**
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/hu/bomboclat/Game/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* A csőhálózat csomópontjait reprezentáló osztály.
*/
abstract public class Node extends Field implements Stepable{
public abstract class Node extends Field implements Stepable{
/**
* A csomópontba befutó csövek.
*/
Expand All @@ -16,7 +16,7 @@ abstract public class Node extends Field implements Stepable{
/**
* Node konstruktora.
*/
public Node(){
protected Node(){
edges=new ArrayList<>();
}

Expand All @@ -26,14 +26,14 @@ public Node(){
* @return Az adott irányból a szomszédos mező, vagy ha az adott irányba nincs érvényes mező, nullt ad vissza.
*/
public Field getNeighbour(int d){
return edges.get(d).has_player == true ? null : edges.get(d);
return edges.get(d).has_player ? null : edges.get(d);
}

/**
* Absztrakt függvény, nincs implementálva.
* @param rnd ha igaz, akkor nemdeterminisztikusan működik
* public abstract void Step(boolean rnd) ez volt a függvény, sonarlint kitöröltette.
*/
public abstract void Step(boolean rnd);

/**
* Összeszámolja a szerelők pontját a városba folyt
Expand All @@ -49,6 +49,7 @@ public int getMechanicPoint(){
* @param m mechanic típusú játékos, aki az adott node(leszármazottan) áll.
* @return a felvett cső
*/
@Override
public Pipe PickUpPipe(Mechanic m){
return null;
}
Expand All @@ -57,6 +58,7 @@ public Pipe PickUpPipe(Mechanic m){
* A leszármazottakban van felüldefiniálva abban az esetben ha lehet rájuk letenni/hozzájuk adni csövet.
* @param m a mechanic típusú játékos, aki leteszi a kezéből a csövet.
*/
@Override
public void PlacePipe(Mechanic m){
return;
}
Expand All @@ -65,6 +67,7 @@ public void PlacePipe(Mechanic m){
* Hozzáaadja az paraméterként kapott csövet az edges listához (a szomszédaihoz).
* @param p Az paraméterként kapott cső.
*/
@Override
public void addEdge(Pipe p){
edges.add(p);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/hu/bomboclat/Game/Nomad.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void setNotActive()
* A szabotőr csúszóssá teszi a csövet, amin áll
* @return Igaz, ha sikerült csúszóssá tenni a csövet
*/
@Override
public boolean Lube(){
boolean ret = this.field.Lube();
if(ret){
Expand Down
Loading
Loading