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:
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.api;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Container for variables available to the {@link ArtifactUrlHandler}.
|
||||
*
|
||||
@@ -107,59 +109,22 @@ public class URLPlaceholder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((artifactId == null) ? 0 : artifactId.hashCode());
|
||||
result = prime * result + ((filename == null) ? 0 : filename.hashCode());
|
||||
result = prime * result + ((sha1Hash == null) ? 0 : sha1Hash.hashCode());
|
||||
result = prime * result + ((softwareModuleId == null) ? 0 : softwareModuleId.hashCode());
|
||||
return result;
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
final SoftwareData that = (SoftwareData) o;
|
||||
return Objects.equals(softwareModuleId, that.softwareModuleId)
|
||||
&& Objects.equals(filename, that.filename)
|
||||
&& Objects.equals(artifactId, that.artifactId)
|
||||
&& Objects.equals(sha1Hash, that.sha1Hash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final SoftwareData other = (SoftwareData) obj;
|
||||
if (artifactId == null) {
|
||||
if (other.artifactId != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!artifactId.equals(other.artifactId)) {
|
||||
return false;
|
||||
}
|
||||
if (filename == null) {
|
||||
if (other.filename != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!filename.equals(other.filename)) {
|
||||
return false;
|
||||
}
|
||||
if (sha1Hash == null) {
|
||||
if (other.sha1Hash != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!sha1Hash.equals(other.sha1Hash)) {
|
||||
return false;
|
||||
}
|
||||
if (softwareModuleId == null) {
|
||||
if (other.softwareModuleId != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!softwareModuleId.equals(other.softwareModuleId)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
public int hashCode() {
|
||||
return Objects.hash(softwareModuleId, filename, artifactId, sha1Hash);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getTenant() {
|
||||
@@ -183,65 +148,18 @@ public class URLPlaceholder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((controllerId == null) ? 0 : controllerId.hashCode());
|
||||
result = prime * result + ((softwareData == null) ? 0 : softwareData.hashCode());
|
||||
result = prime * result + ((targetId == null) ? 0 : targetId.hashCode());
|
||||
result = prime * result + ((tenant == null) ? 0 : tenant.hashCode());
|
||||
result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode());
|
||||
return result;
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
final URLPlaceholder that = (URLPlaceholder) o;
|
||||
return tenantId.equals(that.tenantId) && Objects.equals(controllerId, that.controllerId) && Objects.equals(
|
||||
targetId, that.targetId) && Objects.equals(softwareData, that.softwareData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final URLPlaceholder other = (URLPlaceholder) obj;
|
||||
if (controllerId == null) {
|
||||
if (other.controllerId != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!controllerId.equals(other.controllerId)) {
|
||||
return false;
|
||||
}
|
||||
if (softwareData == null) {
|
||||
if (other.softwareData != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!softwareData.equals(other.softwareData)) {
|
||||
return false;
|
||||
}
|
||||
if (targetId == null) {
|
||||
if (other.targetId != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!targetId.equals(other.targetId)) {
|
||||
return false;
|
||||
}
|
||||
if (tenant == null) {
|
||||
if (other.tenant != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!tenant.equals(other.tenant)) {
|
||||
return false;
|
||||
}
|
||||
if (tenantId == null) {
|
||||
if (other.tenantId != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!tenantId.equals(other.tenantId)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
public int hashCode() {
|
||||
return Objects.hash(tenantId, controllerId, targetId, softwareData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -98,25 +99,23 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository {
|
||||
|
||||
protected void deleteTempFile(final String tempFile) {
|
||||
final File file = new File(tempFile);
|
||||
|
||||
if (file.exists() && !file.delete()) {
|
||||
LOG.error("Could not delete temp file {}", file);
|
||||
try {
|
||||
Files.deleteIfExists(file.toPath());
|
||||
} catch (IOException e) {
|
||||
LOG.error("Could not delete temp file {} ({})", file, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected String storeTempFile(final InputStream content) throws IOException {
|
||||
final File file = createTempFile();
|
||||
|
||||
try (final OutputStream outputstream = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
ByteStreams.copy(content, outputstream);
|
||||
outputstream.flush();
|
||||
}
|
||||
|
||||
return file.getPath();
|
||||
}
|
||||
|
||||
private static File createTempFile() {
|
||||
|
||||
try {
|
||||
return File.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);
|
||||
} catch (final IOException e) {
|
||||
@@ -160,5 +159,4 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository {
|
||||
protected static String sanitizeTenant(final String tenant) {
|
||||
return tenant.trim().toUpperCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.cache;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.Cache.ValueWrapper;
|
||||
import org.springframework.cache.CacheManager;
|
||||
@@ -27,7 +28,6 @@ public class DefaultDownloadIdCache implements DownloadIdCache {
|
||||
* @param cacheManager
|
||||
* the underlying cache-manager to store the download-ids
|
||||
*/
|
||||
@Autowired
|
||||
public DefaultDownloadIdCache(final CacheManager cacheManager) {
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
@@ -49,9 +49,9 @@ public class DefaultDownloadIdCache implements DownloadIdCache {
|
||||
}
|
||||
|
||||
private Cache getCache() {
|
||||
if (cacheManager instanceof TenancyCacheManager) {
|
||||
return ((TenancyCacheManager) cacheManager).getDirectCache(DOWNLOAD_ID_CACHE);
|
||||
}
|
||||
return cacheManager.getCache(DOWNLOAD_ID_CACHE);
|
||||
final Cache cache = (cacheManager instanceof TenancyCacheManager)
|
||||
? ((TenancyCacheManager) cacheManager).getDirectCache(DOWNLOAD_ID_CACHE)
|
||||
: cacheManager.getCache(DOWNLOAD_ID_CACHE);
|
||||
return Objects.requireNonNull(cache, "Cache(s) returned by cache-manager must not be null!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public abstract class AbstractServerRtException extends RuntimeException {
|
||||
* @param error
|
||||
* detail
|
||||
*/
|
||||
public AbstractServerRtException(final SpServerError error) {
|
||||
protected AbstractServerRtException(final SpServerError error) {
|
||||
super(error.getMessage());
|
||||
this.error = error;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public abstract class AbstractServerRtException extends RuntimeException {
|
||||
* @param error
|
||||
* detail
|
||||
*/
|
||||
public AbstractServerRtException(final String message, final SpServerError error) {
|
||||
protected AbstractServerRtException(final String message, final SpServerError error) {
|
||||
super(message);
|
||||
this.error = error;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public abstract class AbstractServerRtException extends RuntimeException {
|
||||
* @param cause
|
||||
* of the exception
|
||||
*/
|
||||
public AbstractServerRtException(final String message, final SpServerError error, final Throwable cause) {
|
||||
protected AbstractServerRtException(final String message, final SpServerError error, final Throwable cause) {
|
||||
super(message, cause);
|
||||
this.error = error;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public abstract class AbstractServerRtException extends RuntimeException {
|
||||
* @param cause
|
||||
* of the exception
|
||||
*/
|
||||
public AbstractServerRtException(final SpServerError error, final Throwable cause) {
|
||||
protected AbstractServerRtException(final SpServerError error, final Throwable cause) {
|
||||
super(error.getMessage(), cause);
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user