Feature/fix sonar warnings (#1226)

* Fixed sonar warnings

- "Cognitive Complexity"
- "Do not use replaceAll when not using a regex"
- java:S5869 - Character classes in regular expressions should not contain the same character twice
- Improved bad name
- Typos
- reduced code duplications
- Replaced hand-made wait-utility with Awaitility
- Log messages
- Duplicate code
- Typos
- Removed Thread.sleep, instead relaxed check condition
- Removed use of deprecated API
- Removed use of deprecated API
- Added supress-warnings as I do not see a better way to write the tests
- Removed Thread.sleep / redundant functionality to Awaitility
- Fixed other warnings (use isZero, isEmpty, hasToString)
- Removed/Reduced duplicate code
- Added generics
- Fixed asserts
- removed: field.setAccessible(true) actually should not be needed for public static fields!
- Too long constructor passes arguments in wrong order - how surprisingly...
- Clean-up use of varargs arguments
- Fixed regex
- Fixed typos and other minor stuff
- Making public constructors protected in abstract classes
- Swapped expected and asserted argument
- volatile not enough for syncing threads
- volatile not enough for syncing threads
- out-commented code
- Made regex not-greedy, added tests for verification
- Avoid exposure of thread-local member var

Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io>

* Fixed Sonar warnings

* License header fix

Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io>

* License header fix #2

Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io>

* Fixing review findings

Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io>

* Fixing tests

- Fixed '&' usage in javadoc and typos
- Fixing some warnings

Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io>
This commit is contained in:
Peter Vigier
2022-01-31 21:59:46 +01:00
committed by GitHub
parent 5443b5df9c
commit 44a85f20eb
98 changed files with 2583 additions and 2702 deletions

View File

@@ -8,15 +8,15 @@
*/
package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.Identifiable;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Target;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.Identifiable;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Target;
/**
* Generic deployment event for the Multi-Assignments feature. The event payload
* holds a list of controller IDs identifying the targets which are affected by
@@ -33,7 +33,7 @@ public abstract class MultiActionEvent extends RemoteTenantAwareEvent implements
/**
* Default constructor.
*/
public MultiActionEvent() {
protected MultiActionEvent() {
// for serialization libs like jackson
}
@@ -47,7 +47,7 @@ public abstract class MultiActionEvent extends RemoteTenantAwareEvent implements
* @param actions
* the actions involved
*/
public MultiActionEvent(String tenant, String applicationId, List<Action> actions) {
protected MultiActionEvent(String tenant, String applicationId, List<Action> actions) {
super(applicationId, tenant, applicationId);
this.controllerIds.addAll(getControllerIdsFromActions(actions));
this.actionIds.addAll(getIdsFromActions(actions));

View File

@@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.repository.event.remote.entity;
import java.util.Objects;
import org.eclipse.hawkbit.repository.model.Action;
/**
@@ -16,15 +18,18 @@ import org.eclipse.hawkbit.repository.model.Action;
public abstract class AbstractActionEvent extends RemoteEntityEvent<Action> {
private static final long serialVersionUID = 1L;
private Long targetId;
private Long rolloutId;
private Long rolloutGroupId;
private final Long targetId;
private final Long rolloutId;
private final Long rolloutGroupId;
/**
* Default constructor.
*/
public AbstractActionEvent() {
protected AbstractActionEvent() {
// for serialization libs like jackson
this.targetId = null;
this.rolloutId = null;
this.rolloutGroupId = null;
}
/**
@@ -41,7 +46,7 @@ public abstract class AbstractActionEvent extends RemoteEntityEvent<Action> {
* @param applicationId
* the origin application id
*/
public AbstractActionEvent(final Action action, final Long targetId, final Long rolloutId,
protected AbstractActionEvent(final Action action, final Long targetId, final Long rolloutId,
final Long rolloutGroupId, final String applicationId) {
super(action, applicationId);
this.targetId = targetId;
@@ -61,4 +66,21 @@ public abstract class AbstractActionEvent extends RemoteEntityEvent<Action> {
return rolloutGroupId;
}
@Override
public boolean equals(final Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
if (!super.equals(o))
return false;
final AbstractActionEvent that = (AbstractActionEvent) o;
return Objects.equals(targetId, that.targetId) && Objects.equals(rolloutId, that.rolloutId)
&& Objects.equals(rolloutGroupId, that.rolloutGroupId);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), targetId, rolloutId, rolloutGroupId);
}
}

View File

@@ -8,26 +8,28 @@
*/
package org.eclipse.hawkbit.repository.event.remote.entity;
import java.util.Objects;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
/**
* TenantAwareEvent definition which is been published in case a rollout group
* has been created for a specific rollout or updated.
*
* Event which is published in case a {@linkplain RolloutGroup} is created or
* updated
*/
public abstract class AbstractRolloutGroupEvent extends RemoteEntityEvent<RolloutGroup> {
private static final long serialVersionUID = 1L;
private Long rolloutId;
private final Long rolloutId;
/**
* Default constructor.
*/
public AbstractRolloutGroupEvent() {
protected AbstractRolloutGroupEvent() {
// for serialization libs like jackson
this.rolloutId = null;
}
public AbstractRolloutGroupEvent(final RolloutGroup rolloutGroup, final Long rolloutId,
protected AbstractRolloutGroupEvent(final RolloutGroup rolloutGroup, final Long rolloutId,
final String applicationId) {
super(rolloutGroup, applicationId);
this.rolloutId = rolloutId;
@@ -37,4 +39,20 @@ public abstract class AbstractRolloutGroupEvent extends RemoteEntityEvent<Rollou
return rolloutId;
}
@Override
public boolean equals(final Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
if (!super.equals(o))
return false;
final AbstractRolloutGroupEvent that = (AbstractRolloutGroupEvent) o;
return Objects.equals(rolloutId, that.rolloutId);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), rolloutId);
}
}

View File

@@ -33,7 +33,7 @@ public abstract class AbstractAssignmentResult<T extends BaseEntity> {
* @param unassignedEntity
* {@link List} of unassigned entity.
*/
public AbstractAssignmentResult(final int alreadyAssigned, final List<? extends T> assignedEntity,
protected AbstractAssignmentResult(final int alreadyAssigned, final List<? extends T> assignedEntity,
final List<? extends T> unassignedEntity) {
this.alreadyAssigned = alreadyAssigned;
this.assignedEntity = assignedEntity;

View File

@@ -156,12 +156,15 @@ public interface Action extends TenantAwareBaseEntity {
}
/**
* Check if action type is either forced or time-forced <i>and</i> force-time is
* exceeded.
*
* @return {@code true} if either the {@link #getActionType()} is
* {@link ActionType#FORCED} or {@link ActionType#TIMEFORCED} but
* then if the {@link #getForcedTime()} has been exceeded otherwise
* always {@code false}
* {@link ActionType#FORCED} or {@link ActionType#TIMEFORCED} but then
* if the {@link #getForcedTime()} has been exceeded otherwise always
* {@code false}
*/
default boolean isForce() {
default boolean isForcedOrTimeForced() {
switch (getActionType()) {
case FORCED:
return true;