Skip to content

Commit

Permalink
Fix sonar warnings (#274)
Browse files Browse the repository at this point in the history
* Upgrade dependencies

* Fix startup failure under Linux

java.lang.UnsupportedOperationException: Unable to load glass GTK library.
        at com.sun.glass.ui.gtk.GtkApplication.lambda$new$5(GtkApplication.java:176)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:319)
        at com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:163)

* Add changelog entry

* Add prev/next buttons to monthly report

* Fix indentation

* Fix uitest

* Add changelog entry

* Disable null analysis

* Improve test stabilitiy

* Fix build error in vscode

* Reduce log verbosity

* Poll for condition

* Avoid warning during uitests

* Improve logging

* Disable uitest

* Archive test reports

* Mark test as flaky

* Archive test results

* Fix sonar findings

* Fix archiving reports

* Revert changes

* Fix sonar finding

* Disable null analysis for eclipse

* Update codeql build

---------

Co-authored-by: kaklakariada <[email protected]>
  • Loading branch information
kaklakariada and kaklakariada authored Apr 14, 2024
1 parent 20fb4d7 commit c3a7c0a
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 74 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ jobs:
run: |
./gradlew build --info --warning-mode=summary -PskipFlakyTests=true -PjavaVersion=${{ matrix.java }}
- name: Archive executable JAR
uses: actions/upload-artifact@v4
if: ${{ env.DEFAULT_JAVA == matrix.java && env.DEFAULT_OS == matrix.os }}
with:
name: executable-jar
path: jfxui/build/libs/white-rabbit-fx-*.jar
if-no-files-found: error

- name: Archive test reports for ${{ matrix.os }} using Java ${{ matrix.java }}
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: test-reports-${{ matrix.os }}-java-${{ matrix.java }}
path: "**/build/reports/tests/*/**"
if-no-files-found: error

- name: Sonar analysis
if: ${{ env.DEFAULT_JAVA == matrix.java && env.DEFAULT_OS == matrix.os && env.SONAR_TOKEN != null }}
run: |
Expand All @@ -60,13 +76,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: Archive executable JAR for ${{ matrix.java }}
uses: actions/upload-artifact@v4
if: ${{ env.DEFAULT_JAVA == matrix.java && env.DEFAULT_OS == matrix.os }}
with:
name: packages
path: jfxui/build/libs/white-rabbit-fx-*.jar

- name: Build native package for ${{ runner.os }} using Java ${{ matrix.java }}
if: ${{ env.DEFAULT_JAVA == matrix.java }}
run: |
Expand Down
33 changes: 20 additions & 13 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@ name: "CodeQL"

on:
push:
branches: [ main ]
branches: [ "main" ]
pull_request:
branches: [ main ]
branches: [ "main" ]
schedule:
- cron: '0 7 * * 6'
- cron: '18 19 * * 5'

jobs:
analyze:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
name: Analyze
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-latest
timeout-minutes: 360
permissions:
contents: read
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
language: ['java']

include:
- language: java-kotlin
build-mode: none # This mode only analyzes Java. Set this to 'autobuild' or 'manual' to analyze Kotlin too.
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2

- uses: actions/setup-java@v4
with:
distribution: 'temurin'
Expand All @@ -42,9 +48,10 @@ jobs:
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v3
build-mode: ${{ matrix.build-mode }}
queries: security-extended,security-and-quality

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
10 changes: 5 additions & 5 deletions jfxui/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annota
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.lambda.genericSignature=do not generate
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
Expand Down Expand Up @@ -107,16 +107,16 @@ org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingMethodWithoutSuperInvocation=ignore
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
Expand All @@ -131,7 +131,7 @@ org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.tasks=warning
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public class DailyProjectReportViewer

private final Stage primaryStage;

public DailyProjectReportViewer(Stage primaryStage, UiStateService uiState, AppService appService,
UiActions uiActions,
ProjectReport report)
public DailyProjectReportViewer(final Stage primaryStage, final UiStateService uiState, final AppService appService,
final UiActions uiActions,
final ProjectReport report)
{
this.primaryStage = primaryStage;
this.uiState = uiState;
Expand All @@ -75,14 +75,14 @@ private Node[] getExportButtons()
.toArray(Node[]::new);
}

private Button createExportButton(AppPlugin plugin)
private Button createExportButton(final AppPlugin plugin)
{
final String pluginId = plugin.getId();
final EventHandler<ActionEvent> action = e -> exportReport(plugin);
return UiWidget.button(pluginId + "-export-button", "Export to " + pluginId, action);
}

private void exportReport(AppPlugin plugin)
private void exportReport(final AppPlugin plugin)
{
final var projectReportExporter = plugin.getFeature(ProjectReportExporter.class)
.orElseThrow(() -> new IllegalStateException(
Expand Down Expand Up @@ -126,7 +126,7 @@ private TreeTableView<ReportRow> createTreeTable()
return treeTable;
}

private TreeItem<ReportRow> createDayTreeItem(ProjectReportDay day)
private TreeItem<ReportRow> createDayTreeItem(final ProjectReportDay day)
{
final TreeItem<ReportRow> treeItem = new TreeItem<>(new ReportRow(day));
treeItem.setExpanded(true);
Expand All @@ -146,12 +146,12 @@ public static class ReportRow
private final Duration workingTime;
private final String comment;

private ReportRow(ProjectReportDay day)
private ReportRow(final ProjectReportDay day)
{
this(day, null);
}

private ReportRow(ProjectReportDay day, ProjectReportActivity project)
private ReportRow(final ProjectReportDay day, final ProjectReportActivity project)
{
if (project == null)
{
Expand All @@ -160,7 +160,7 @@ private ReportRow(ProjectReportDay day, ProjectReportActivity project)
this.project = null;
this.workingTime = day.getProjects().stream()
.map(ProjectReportActivity::getWorkingTime)
.reduce((a, b) -> a.plus(b))
.reduce(Duration::plus)
.orElse(Duration.ZERO);
this.comment = day.getComment();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import java.util.Locale;

import org.itsallcode.whiterabbit.api.model.Project;
import org.itsallcode.whiterabbit.jfxui.testutil.JunitTags;
import org.itsallcode.whiterabbit.jfxui.testutil.model.MonthlyProjectReportWindow;
import org.itsallcode.whiterabbit.logic.service.project.ProjectImpl;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testfx.api.FxRobot;
Expand Down Expand Up @@ -76,7 +77,7 @@ void gotoPreviousMonth()
}

@Test
@Disabled("Second month change test is not working")
@Tag(JunitTags.FLAKY) // Second month change test is not working
void gotoNextMonth()
{
time().tickSeparateMinutes(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DayActivities
private final DayData day;
final DayRecord dayRecord;

DayActivities(DayRecord dayRecord, ProjectService projectService, ModelFactory modelFactory)
DayActivities(final DayRecord dayRecord, final ProjectService projectService, final ModelFactory modelFactory)
{
this.modelFactory = modelFactory;
this.day = dayRecord.getJsonDay();
Expand Down Expand Up @@ -75,20 +75,20 @@ private Stream<ActivityData> getActivities()
.stream();
}

private Activity wrapActivity(ActivityData activity, int index)
private Activity wrapActivity(final ActivityData activity, final int index)
{
return new Activity(index, activity, this, projectService);
}

public Optional<Activity> get(int index)
public Optional<Activity> get(final int index)
{
return Optional.ofNullable(day.getActivities())
.filter(list -> list.size() > index)
.map(list -> list.get(index))
.map(a -> wrapActivity(a, index));
}

public void remove(int index)
public void remove(final int index)
{
if (day.getActivities() == null)
{
Expand All @@ -101,7 +101,7 @@ public void remove(int index)
}
}

public void setRemainderActivity(ActivityData activity, boolean remainder)
public void setRemainderActivity(final ActivityData activity, final boolean remainder)
{
if (activity.isRemainder() == remainder)
{
Expand Down Expand Up @@ -132,7 +132,7 @@ private Duration getUnallocatedDuration()
{
final Duration allocatedDuration = getActivities().map(ActivityData::getDuration)
.filter(Objects::nonNull)
.reduce((d1, d2) -> d1.plus(d2))
.reduce(Duration::plus)
.orElse(Duration.ZERO);
return dayRecord.getWorkingTime().minus(allocatedDuration);
}
Expand Down Expand Up @@ -167,7 +167,7 @@ private List<ActivityData> getRemainderActivities()
return getActivities().filter(a -> a.getDuration() == null).collect(toList());
}

public Duration getDuration(Activity activity)
public Duration getDuration(final Activity activity)
{
if (activity.jsonActivity.getDuration() != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.itsallcode.whiterabbit.logic.model;

import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalTime;
Expand All @@ -25,8 +26,9 @@ public class DayRecord implements RowRecord
private final MonthIndex month;
private final DayRecord previousDay;

public DayRecord(ContractTermsService contractTerms, DayData day, DayRecord previousDay, MonthIndex month,
ProjectService projectService, ModelFactory modelFactory)
public DayRecord(final ContractTermsService contractTerms, final DayData day, final DayRecord previousDay,
final MonthIndex month,
final ProjectService projectService, final ModelFactory modelFactory)
{
this.contractTerms = contractTerms;
this.projectService = Objects.requireNonNull(projectService);
Expand Down Expand Up @@ -111,22 +113,16 @@ public DayType getType()

private boolean isWeekend()
{
switch (day.getDate().getDayOfWeek())
{
case SATURDAY:
case SUNDAY:
return true;
default:
return false;
}
final DayOfWeek dayOfWeek = day.getDate().getDayOfWeek();
return dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY;
}

public LocalTime getBegin()
{
return day.getBegin();
}

public void setBegin(LocalTime begin)
public void setBegin(final LocalTime begin)
{
day.setBegin(begin);
}
Expand All @@ -136,7 +132,7 @@ public LocalTime getEnd()
return day.getEnd();
}

public void setEnd(LocalTime end)
public void setEnd(final LocalTime end)
{
day.setEnd(end);
}
Expand All @@ -146,7 +142,7 @@ public Duration getInterruption()
return day.getInterruption() == null ? Duration.ZERO : day.getInterruption();
}

public void setInterruption(Duration interruption)
public void setInterruption(final Duration interruption)
{
day.setInterruption(interruption.isZero() ? null : interruption);
}
Expand All @@ -161,12 +157,12 @@ public String getComment()
return day.getComment();
}

public void setComment(String comment)
public void setComment(final String comment)
{
day.setComment(comment.isEmpty() ? null : comment);
}

public void setType(DayType type)
public void setType(final DayType type)
{
day.setType(Objects.requireNonNull(type, "type"));
}
Expand Down
Loading

0 comments on commit c3a7c0a

Please sign in to comment.