diff --git a/3rd-dependencies/listDeps.sh b/3rd-dependencies/listDeps.sh old mode 100644 new mode 100755 diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java index 50f3f4cad..490b2d102 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java @@ -16,8 +16,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties; */ @ConfigurationProperties("hawkbit.artifact.url") public class ArtifactUrlHandlerProperties { - private static final String DEFAULT_IP_LOCALHOST = "127.0.0.1"; - private static final String LOCALHOST = "localhost"; private final Http http = new Http(); private final Https https = new Https(); @@ -54,227 +52,45 @@ public class ArtifactUrlHandlerProperties { } } - /** - * Interface for declaring common properties through all supported protocols - * pattern. - */ - public interface ProtocolProperties { - /** - * @return the hostname value to resolve in the pattern. - */ - String getHostname(); - - /** - * @return the IP address value to resolve in the pattern. - */ - String getIp(); - - /** - * @return the port value to resolve in the pattern. - */ - String getPort(); - - /** - * @return the pattern to build the URL. - */ - String getPattern(); - - /** - * @return true if the {@link ProtocolProperties} is - * enabled. - */ - boolean isEnabled(); - } - /** * Object to hold the properties for the HTTP protocol. */ - public static class Http implements ProtocolProperties { - private String hostname = LOCALHOST; - private String ip = DEFAULT_IP_LOCALHOST; - private String port = ""; - /** - * An ant-URL pattern with placeholder to build the URL on. The URL can - * have specific artifact placeholder. - */ - private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}"; + public static class Http extends DefaultProtocolProperties { /** - * Enables HTTP URI generation in DDI and DMF. + * Constructor. */ - private boolean enabled = true; - - @Override - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(final boolean enabled) { - this.enabled = enabled; - } - - @Override - public String getHostname() { - return hostname; - } - - public void setHostname(final String hostname) { - this.hostname = hostname; - } - - @Override - public String getIp() { - return ip; - } - - public void setIp(final String ip) { - this.ip = ip; - } - - @Override - public String getPattern() { - return pattern; - } - - public void setPattern(final String urlPattern) { - this.pattern = urlPattern; - } - - @Override - public String getPort() { - return port; - } - - public void setPort(final String port) { - this.port = port; + public Http() { + setPattern( + "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}"); } } /** * Object to hold the properties for the HTTP protocol. */ - public static class Https implements ProtocolProperties { - private String hostname = LOCALHOST; - private String ip = DEFAULT_IP_LOCALHOST; - private String port = ""; - /** - * An ant-URL pattern with placeholder to build the URL on. The URL can - * have specific artifact placeholder. - */ - private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}"; + public static class Https extends DefaultProtocolProperties { /** - * Enables HTTPS URI generation in DDI and DMF. + * Constructor. */ - private boolean enabled = true; - - @Override - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(final boolean enabled) { - this.enabled = enabled; - } - - @Override - public String getHostname() { - return hostname; - } - - public void setHostname(final String hostname) { - this.hostname = hostname; - } - - @Override - public String getIp() { - return ip; - } - - public void setIp(final String ip) { - this.ip = ip; - } - - @Override - public String getPattern() { - return pattern; - } - - public void setPattern(final String urlPattern) { - this.pattern = urlPattern; - } - - @Override - public String getPort() { - return port; - } - - public void setPort(final String port) { - this.port = port; + public Https() { + setPattern( + "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}"); } } /** * Object to hold the properties for the HTTP protocol. */ - public static class Coap implements ProtocolProperties { - private String hostname = LOCALHOST; - private String ip = DEFAULT_IP_LOCALHOST; - private String port = "5683"; - /** - * An ant-URL pattern with placeholder to build the URL on. The URL can - * have specific artifact placeholder. - */ - private String pattern = "{protocol}://{ip}:{port}/fw/{tenant}/{targetId}/sha1/{artifactSHA1}"; + public static class Coap extends DefaultProtocolProperties { /** - * Enables CoAP URI generation in DMF. + * Constructor. */ - private boolean enabled = true; - - @Override - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(final boolean enabled) { - this.enabled = enabled; - } - - @Override - public String getHostname() { - return hostname; - } - - public void setHostname(final String hostname) { - this.hostname = hostname; - } - - @Override - public String getIp() { - return ip; - } - - public void setIp(final String ip) { - this.ip = ip; - } - - @Override - public String getPattern() { - return pattern; - } - - public void setPattern(final String urlPattern) { - this.pattern = urlPattern; - } - - @Override - public String getPort() { - return port; - } - - public void setPort(final String port) { - this.port = port; + public Coap() { + setPattern("{protocol}://{ip}:{port}/fw/{tenant}/{targetId}/sha1/{artifactSHA1}"); + setPort("5683"); } } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/DefaultProtocolProperties.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/DefaultProtocolProperties.java new file mode 100644 index 000000000..9d053104c --- /dev/null +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/DefaultProtocolProperties.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.api; + +/** + * Object to hold the properties for the base protocols. + */ +public class DefaultProtocolProperties implements ProtocolProperties { + // The IP address is not hardcoded. It's the default value, if the IP + // address is not configured. + @SuppressWarnings("squid:S1313") + private static final String DEFAULT_IP_LOCALHOST = "127.0.0.1"; + private static final String LOCALHOST = "localhost"; + + private String hostname = LOCALHOST; + private String ip = DEFAULT_IP_LOCALHOST; + private String port = ""; + /** + * An ant-URL pattern with placeholder to build the URL on. The URL can have + * specific artifact placeholder. + */ + private String pattern; + + /** + * Enables protocol. + */ + private boolean enabled = true; + + @Override + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(final boolean enabled) { + this.enabled = enabled; + } + + @Override + public String getHostname() { + return hostname; + } + + public void setHostname(final String hostname) { + this.hostname = hostname; + } + + @Override + public String getIp() { + return ip; + } + + public void setIp(final String ip) { + this.ip = ip; + } + + @Override + public String getPattern() { + return pattern; + } + + public void setPattern(final String urlPattern) { + this.pattern = urlPattern; + } + + @Override + public String getPort() { + return port; + } + + public void setPort(final String port) { + this.port = port; + } +} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java index 0072f2fbd..53f6492d1 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java @@ -13,7 +13,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import org.eclipse.hawkbit.api.ArtifactUrlHandlerProperties.ProtocolProperties; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -61,7 +60,7 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { for (final Entry entry : entrySet) { if (entry.getKey().equals(PORT_PLACEHOLDER)) { urlPattern = urlPattern.replace(":{" + entry.getKey() + "}", - Strings.isNullOrEmpty(entry.getValue()) ? "" : ":" + entry.getValue()); + Strings.isNullOrEmpty(entry.getValue()) ? "" : (":" + entry.getValue())); } else { urlPattern = urlPattern.replace("{" + entry.getKey() + "}", entry.getValue()); } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ProtocolProperties.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ProtocolProperties.java new file mode 100644 index 000000000..c4a9556b7 --- /dev/null +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ProtocolProperties.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.api; + +/** + * Interface for declaring common properties through all supported protocols + * pattern. + */ +public interface ProtocolProperties { + /** + * @return the hostname value to resolve in the pattern. + */ + String getHostname(); + + /** + * @return the IP address value to resolve in the pattern. + */ + String getIp(); + + /** + * @return the port value to resolve in the pattern. + */ + String getPort(); + + /** + * @return the pattern to build the URL. + */ + String getPattern(); + + /** + * @return true if the {@link ProtocolProperties} is enabled. + */ + boolean isEnabled(); +} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java index 5b58ea53e..9338bcbe7 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java @@ -13,7 +13,7 @@ import org.springframework.cache.CacheManager; /** * - * + * A cache interface which handles multi tenancy. */ public interface TenancyCacheManager extends CacheManager { diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java index 435f1b2e1..055d9bf6c 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java @@ -67,7 +67,7 @@ public class TenantAwareCacheManager implements TenancyCacheManager { public Collection getCacheNames() { String currentTenant = tenantAware.getCurrentTenant(); if (currentTenant == null) { - return null; + return Collections.emptyList(); } currentTenant = currentTenant.toUpperCase(); diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/DurationHelper.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/DurationHelper.java index 5968f4420..befd00c5d 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/DurationHelper.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/DurationHelper.java @@ -27,7 +27,7 @@ public final class DurationHelper { * the defined min/max range. * */ - public static class DurationRangeValidator { + public static final class DurationRangeValidator { final Duration min; final Duration max; diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index dae5772e6..bbd7b6b48 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -55,8 +55,8 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { /** * Constructor. * - * @param messageConverter - * message converter + * @param rabbitTemplate + * the rabbitTemplate */ @Autowired public AmqpMessageDispatcherService(final RabbitTemplate rabbitTemplate) { diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index f26d7f3f7..7a452c603 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -107,6 +107,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService { super(defaultTemplate); } + // Method is not unused. It is called by the spring rabbit listener. + @SuppressWarnings("squid:UnusedPrivateMethod") @RabbitListener(queues = "${hawkbit.dmf.rabbitmq.receiverQueue}", containerFactory = "listenerContainerFactory") private Message onMessage(final Message message, @Header(MessageHeaderKey.TYPE) final String type, @Header(MessageHeaderKey.TENANT) final String tenant) { @@ -417,7 +419,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { } } - private void checkContentTypeJson(final Message message) { + private static void checkContentTypeJson(final Message message) { final MessageProperties messageProperties = message.getMessageProperties(); if (messageProperties.getContentType() != null && messageProperties.getContentType().contains("json")) { return; diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/BaseAmqpService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/BaseAmqpService.java index 76870ac93..3c5b78e01 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/BaseAmqpService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/BaseAmqpService.java @@ -38,16 +38,6 @@ public class BaseAmqpService { this.rabbitTemplate = rabbitTemplate; } - /** - * Clean message properties before sending a message. - * - * @param message - * the message to cleaned up - */ - protected void cleanMessageHeaderProperties(final Message message) { - message.getMessageProperties().getHeaders().remove(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME); - } - /** * Is needed to convert a incoming message to is originally object type. * @@ -67,7 +57,7 @@ public class BaseAmqpService { return (T) rabbitTemplate.getMessageConverter().fromMessage(message); } - private boolean isMessageBodyEmpty(final Message message) { + private static boolean isMessageBodyEmpty(final Message message) { return message == null || message.getBody() == null || message.getBody().length == 0; }