diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/api/client/DistributionSetResource.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/api/client/DistributionSetResource.java index 747432cd0..62c987ae8 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/api/client/DistributionSetResource.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/api/client/DistributionSetResource.java @@ -20,10 +20,11 @@ import feign.RequestLine; /** * Client binding for the Distribution resource of the management API. */ +@FunctionalInterface public interface DistributionSetResource { /** - * Creates a list of distrbution sets. + * Creates a list of distribution sets. * * @param sets * the request body java bean containing the necessary attributes diff --git a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java index 3f203f94f..02fb22725 100644 --- a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java +++ b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/MongoConfiguration.java @@ -51,7 +51,7 @@ public class MongoConfiguration extends AbstractMongoConfiguration { @Autowired(required = false) private MongoClientOptions options; - private Mongo mongo; + private Mongo mongoConnection; @Override public String getDatabaseName() { @@ -59,12 +59,12 @@ public class MongoConfiguration extends AbstractMongoConfiguration { } /** - * Closes mongo client when destroyd. + * Closes mongo client when destroyed. */ @PreDestroy public void close() { - if (this.mongo != null) { - this.mongo.close(); + if (this.mongoConnection != null) { + this.mongoConnection.close(); } } @@ -76,14 +76,14 @@ public class MongoConfiguration extends AbstractMongoConfiguration { if (properties.getPort() != null) { LOG.debug("Create mongo by properties (host: {}, port: {})", uri.getHosts().get(0), properties.getPort()); - this.mongo = new MongoClient(Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())), - uri.getOptions()); + this.mongoConnection = new MongoClient( + Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())), uri.getOptions()); } else { LOG.debug("Create mongo by URI : {}", uri); - this.mongo = new MongoClient(uri); + this.mongoConnection = new MongoClient(uri); } - return this.mongo; + return this.mongoConnection; } /* diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java index eb70f235b..80624054a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java @@ -233,7 +233,7 @@ public class Action extends BaseEntity implements Comparable { * checks if the {@link #forcedTime} is hit by the given * {@code hitTimeMillis}, by means if the given milliseconds are greater * than the forcedTime. - * + * * @param hitTimeMillis * the milliseconds, mostly the * {@link System#currentTimeMillis()} @@ -274,7 +274,7 @@ public class Action extends BaseEntity implements Comparable { /* * (non-Javadoc) - * + * * @see java.lang.Object#toString() */ @Override @@ -284,11 +284,11 @@ public class Action extends BaseEntity implements Comparable { /* * (non-Javadoc) - * + * * @see java.lang.Object#hashCode() */ @Override - public int hashCode() { + public int hashCode() { // NOSONAR - as this is generated final int prime = 31; int result = super.hashCode(); result = prime * result + ((actionType == null) ? 0 : actionType.hashCode()); @@ -301,12 +301,12 @@ public class Action extends BaseEntity implements Comparable { /* * (non-Javadoc) - * + * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(final Object obj) { // NOSONAR - as this is generated - // code + if (this == obj) { return true; } @@ -384,7 +384,7 @@ public class Action extends BaseEntity implements Comparable { /** * The action type for this action relation. - * + * * * * diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java index 3028be775..63a858a7d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java @@ -71,7 +71,7 @@ public class DistributionSetTag extends Tag { /* * (non-Javadoc) - * + * * @see java.lang.Object#hashCode() */ @Override @@ -84,11 +84,11 @@ public class DistributionSetTag extends Tag { /* * (non-Javadoc) - * + * * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(final Object obj) { + public boolean equals(final Object obj) { // NOSONAR - as this is generated if (this == obj) { return true; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java index d6664ac59..35e0c4e99 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java @@ -129,11 +129,11 @@ public class ExternalArtifact extends Artifact { /* * (non-Javadoc) - * + * * @see java.lang.Object#hashCode() */ @Override - public int hashCode() { + public int hashCode() { // NOSONAR - as this is generated final int prime = 31; int result = super.hashCode(); result = prime * result + this.getClass().getName().hashCode(); @@ -142,11 +142,11 @@ public class ExternalArtifact extends Artifact { /* * (non-Javadoc) - * + * * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(final Object obj) { + public boolean equals(final Object obj) { // NOSONAR - as this is generated if (this == obj) { return true; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java index f6ed40e79..56d92c8e1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java @@ -92,11 +92,11 @@ public class ExternalArtifactProvider extends NamedEntity { /* * (non-Javadoc) - * + * * @see java.lang.Object#hashCode() */ @Override - public int hashCode() { + public int hashCode() { // NOSONAR - as this is generated final int prime = 31; int result = super.hashCode(); result = prime * result + this.getClass().getName().hashCode(); @@ -105,11 +105,11 @@ public class ExternalArtifactProvider extends NamedEntity { /* * (non-Javadoc) - * + * * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(final Object obj) { + public boolean equals(final Object obj) { // NOSONAR - as this is generated if (this == obj) { return true; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java index a5ad493b9..baa4ee1f0 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java @@ -75,11 +75,11 @@ public class LocalArtifact extends Artifact { /* * (non-Javadoc) - * + * * @see java.lang.Object#hashCode() */ @Override - public int hashCode() { + public int hashCode() { // NOSONAR - as this is generated final int prime = 31; int result = super.hashCode(); result = prime * result + this.getClass().getName().hashCode(); @@ -88,11 +88,11 @@ public class LocalArtifact extends Artifact { /* * (non-Javadoc) - * + * * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(final Object obj) { + public boolean equals(final Object obj) { // NOSONAR - as this is generated if (this == obj) { return true; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java index a3685df66..49e73f749 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java @@ -257,7 +257,7 @@ public class SoftwareModule extends NamedVersionedEntity { * @see java.lang.Object#hashCode() */ @Override - public int hashCode() { + public int hashCode() { // NOSONAR - as this is generated final int prime = 31; int result = super.hashCode(); result = prime * result + this.getClass().getName().hashCode(); @@ -270,7 +270,7 @@ public class SoftwareModule extends NamedVersionedEntity { * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(final Object obj) { + public boolean equals(final Object obj) { // NOSONAR - as this is generated if (this == obj) { return true; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/push/AsyncVaadinServletConfiguration.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/push/AsyncVaadinServletConfiguration.java index 6eb6761e6..89ff3413e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/push/AsyncVaadinServletConfiguration.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/push/AsyncVaadinServletConfiguration.java @@ -32,6 +32,7 @@ import com.vaadin.spring.boot.internal.VaadinServletConfigurationProperties; @Import(VaadinServletConfiguration.class) public class AsyncVaadinServletConfiguration extends VaadinServletConfiguration { + @Override @Bean protected ServletRegistrationBean vaadinServletRegistration() { return createServletRegistrationBean(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/CustomFile.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/CustomFile.java index 9b29c780a..ff350511a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/CustomFile.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/CustomFile.java @@ -72,7 +72,7 @@ public class CustomFile implements Serializable { /** * Initialize details. - * + * * @param fileName * uploaded file name * @param baseSoftwareModuleName @@ -138,7 +138,7 @@ public class CustomFile implements Serializable { } /** - * + * * @return the isValid */ public Boolean getIsValid() { @@ -170,11 +170,11 @@ public class CustomFile implements Serializable { /* * (non-Javadoc) - * + * * @see java.lang.Object#hashCode() */ @Override - public int hashCode() { + public int hashCode() { // NOSONAR - as this is generated final int prime = 31; int result = 1; result = prime * result + (fileName == null ? 0 : fileName.hashCode()); @@ -183,7 +183,7 @@ public class CustomFile implements Serializable { /* * (non-Javadoc) - * + * * @see java.lang.Object#equals(java.lang.Object) */ @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java index fa7130d23..f3b68bce6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java @@ -8,9 +8,6 @@ */ package org.eclipse.hawkbit.ui.management.dstable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -39,8 +36,6 @@ import com.google.common.base.Strings; * Simple implementation of generics bean query which dynamically loads a batch * of beans. * - * - * */ public class DistributionBeanQuery extends AbstractBeanQuery { @@ -55,7 +50,7 @@ public class DistributionBeanQuery extends AbstractBeanQuery /** * Bean query for retrieving beans/objects of type. - * + * * @param definition * query definition * @param queryConfig @@ -92,8 +87,9 @@ public class DistributionBeanQuery extends AbstractBeanQuery /** * Load all the Distribution set. - * - * @parm startIndex as page start + * + * @param startIndex + * as page start * @param count * as total data */ @@ -193,15 +189,4 @@ public class DistributionBeanQuery extends AbstractBeanQuery return distributionSetManagement; } - private void writeObject(final ObjectOutputStream out) throws IOException { - out.defaultWriteObject(); - out.writeObject(firstPageDistributionSets); - } - - @SuppressWarnings("unchecked") - private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); - firstPageDistributionSets = (Page) in.readObject(); - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index 8ba60ec51..fa4022a3e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -14,6 +14,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.nio.charset.Charset; @@ -62,15 +63,13 @@ import com.vaadin.ui.Upload.SucceededListener; /** * Bulk target upload handler. - * - * * */ public class BulkUploadHandler extends CustomComponent implements SucceededListener, FailedListener, Receiver, StartedListener { /** - * * + * */ private static final long serialVersionUID = -1273494705754674501L; private static final Logger LOG = LoggerFactory.getLogger(BulkUploadHandler.class); @@ -103,7 +102,7 @@ public class BulkUploadHandler extends CustomComponent final TargetBulkUpdateWindowLayout targetBulkUpdateWindowLayout; /** - * + * * @param targetBulkUpdateWindowLayout * @param targetManagement * @param managementUIState @@ -152,7 +151,7 @@ public class BulkUploadHandler extends CustomComponent /* * (non-Javadoc) - * + * * @see com.vaadin.ui.Upload.Receiver#receiveUpload(java.lang.String, * java.lang.String) */ @@ -173,7 +172,7 @@ public class BulkUploadHandler extends CustomComponent /* * (non-Javadoc) - * + * * @see * com.vaadin.ui.Upload.FailedListener#uploadFailed(com.vaadin.ui.Upload. * FailedEvent) @@ -185,7 +184,7 @@ public class BulkUploadHandler extends CustomComponent /* * (non-Javadoc) - * + * * @see * com.vaadin.ui.Upload.SucceededListener#uploadSucceeded(com.vaadin.ui. * Upload.SucceededEvent) @@ -199,7 +198,7 @@ public class BulkUploadHandler extends CustomComponent final SucceededEvent event; /** - * + * * @param event */ public UploadAsync(final SucceededEvent event) { @@ -208,15 +207,18 @@ public class BulkUploadHandler extends CustomComponent @Override public void run() { - BufferedReader reader = null; long innerCounter = 0; String line; - if (tempFile != null) { - try { + if (tempFile == null) { + return; + } + + try (InputStream tempStream = new FileInputStream(tempFile)) { + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(tempStream, Charset.defaultCharset()))) { LOG.info("Bulk file upload started"); final double totalFileSize = getTotalNumberOfLines(); - reader = new BufferedReader( - new InputStreamReader(new FileInputStream(tempFile), Charset.defaultCharset())); + /** * Once control is in upload succeeded method automatically * upload button is re-enabled. To disable the button firing @@ -232,21 +234,16 @@ public class BulkUploadHandler extends CustomComponent // Clearing after assignments are done managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().clear(); - } catch (final FileNotFoundException e) { - LOG.error("File not found with name {}", tempFile.getName(), e); } catch (final IOException e) { LOG.error("Error reading file {}", tempFile.getName(), e); } finally { - try { - if (null != reader) { - reader.close(); - resetCounts(); - deleteFile(); - } - } catch (final IOException e) { - LOG.error("Error while reading file ", e); - } + resetCounts(); + deleteFile(); } + } catch (final FileNotFoundException e) { + LOG.error("Temporary file not found with name {}", tempFile.getName(), e); + } catch (final IOException e) { + LOG.error("Error while opening temorary file ", e); } } @@ -307,24 +304,19 @@ public class BulkUploadHandler extends CustomComponent } private double getTotalNumberOfLines() { - InputStreamReader inputStreamReader; - BufferedReader readerForSize = null; + double totalFileSize = 0; - try { - inputStreamReader = new InputStreamReader(new FileInputStream(tempFile), Charset.defaultCharset()); - readerForSize = new BufferedReader(inputStreamReader); - totalFileSize = readerForSize.lines().count(); + try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(tempFile), + Charset.defaultCharset())) { + try (BufferedReader readerForSize = new BufferedReader(inputStreamReader)) { + totalFileSize = readerForSize.lines().count(); + } } catch (final FileNotFoundException e) { LOG.error("Error reading file {}", tempFile.getName(), e); - } finally { - if (readerForSize != null) { - try { - readerForSize.close(); - } catch (final IOException e) { - LOG.error("Error while closing reader of file {}", tempFile.getName(), e); - } - } + } catch (final IOException e) { + LOG.error("Error while closing reader of file {}", tempFile.getName(), e); } + return totalFileSize; } @@ -449,7 +441,7 @@ public class BulkUploadHandler extends CustomComponent private static class NullOutputStream extends OutputStream { /** * null output stream. - * + * * @param i * byte */ @@ -468,7 +460,7 @@ public class BulkUploadHandler extends CustomComponent /* * (non-Javadoc) - * + * * @see * com.vaadin.ui.Upload.StartedListener#uploadStarted(com.vaadin.ui.Upload * .StartedEvent)