Skip to content

Commit

Permalink
Merge pull request #82 from bosch-io/fix/remove_quava_dep
Browse files Browse the repository at this point in the history
Remove quava dependency
  • Loading branch information
avgustinmm committed Feb 5, 2024
2 parents e9bd8c3 + 068558b commit 0e87463
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 37 deletions.
10 changes: 1 addition & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please read this if you intend to contribute to the project.

### Utility library usage

hawkBit has currently both [guava](https://github.com/google/guava) and [Apache commons lang](https://commons.apache.org/proper/commons-lang/) on the classpath in several of its modules. However, we see introducing too many utility libraries problematic as we force these as transitive dependencies on hawkBit users. We in fact are looking into reducing them in future not adding new ones.
hawkBit has currently [Apache commons lang](https://commons.apache.org/proper/commons-lang/) on the classpath in several of its modules. However, we see introducing too many utility libraries problematic as we force these as transitive dependencies on hawkBit users. We in fact are looking into reducing them in future not adding new ones.

So we kindly ask contributors:

Expand All @@ -32,16 +32,8 @@ So we kindly ask contributors:
* use utility functions in general based in the following priority:
* use utility functions from JDK if feasible
* use Spring utility classes if feasible
* use [guava](https://github.com/google/guava) if feasible
* use [Apache commons lang](https://commons.apache.org/proper/commons-lang/) if feasible

Note that the guava project for instance often documents where they think that JDK is having a similar functionality (e.g. their thoughts on [Throwables.propagate](https://github.com/google/guava/wiki/Why-we-deprecated-Throwables.propagate)).

Examples:

* Prefer `Arrays.asList(...)` from JDK over guava's `Lists.newArrayList(...)`
* Prefer `StringUtils` from Spring over guava's `Strings` Apache's `StringUtils`

### Test documentation

Please documented the test cases that you contribute by means of [Allure](http://allure.qatools.ru) annotations and proper test method naming.
Expand Down
4 changes: 0 additions & 4 deletions hawkbit-device-simulator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HexFormat;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
Expand All @@ -45,9 +47,6 @@
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import com.google.common.io.BaseEncoding;
import com.google.common.io.ByteStreams;

/**
* Update simulation handler.
*/
Expand Down Expand Up @@ -267,7 +266,7 @@ private UpdateStatus readAndCheckDownloadUrl(final String url, final String gate
return new UpdateStatus(ResponseStatus.ERROR, message);
}

sha1HashResult = BaseEncoding.base16().lowerCase().encode(md.digest());
sha1HashResult = HexFormat.of().withLowerCase().formatHex(md.digest());
}

if (!sha1Hash.equalsIgnoreCase(sha1HashResult)) {
Expand All @@ -282,17 +281,13 @@ private UpdateStatus readAndCheckDownloadUrl(final String url, final String gate

private static long getOverallRead(final CloseableHttpResponse response, final MessageDigest md)
throws IOException {

long overallread;

try (final OutputStream os = ByteStreams.nullOutputStream();
final BufferedOutputStream bos = new BufferedOutputStream(new DigestOutputStream(os, md))) {

try (BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent())) {
overallread = ByteStreams.copy(bis, bos);
long overallread = 0;
try (final BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent())) {
final byte[] buff = new byte[4 *1024];
for (int read; (read = bis.read(buff)) != -1; overallread += read) {
md.update(buff, 0, read);
}
}

return overallread;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.eclipse.hawkbit.simulator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Random;
Expand All @@ -21,8 +22,6 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import com.google.common.base.Splitter;

/**
* General simulator service properties.
*
Expand All @@ -32,7 +31,7 @@
// Exception for squid:S2245 : not security relevant random number generation
@SuppressWarnings("squid:S2245")
public class SimulationProperties {
private static final Splitter SPLITTER = Splitter.on(',').omitEmptyStrings().trimResults();

private static final Random RANDOM = new Random();

private String defaultTenant = "DEFAULT";
Expand Down Expand Up @@ -110,7 +109,9 @@ public String getRandom() {
}

private String getRandomElement() {
final List<String> options = SPLITTER.splitToList(random);
final List<String> options = Arrays.stream(random.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty()).toList();
return options.get(RANDOM.nextInt(options.size()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.eclipse.hawkbit.simulator.amqp;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.hawkbit.simulator.DeviceSimulatorRepository;
Expand All @@ -29,8 +30,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.collect.Maps;

/**
* The spring AMQP configuration to use a AMQP for communication with SP update
* server.
Expand Down Expand Up @@ -81,7 +80,7 @@ Queue receiverConnectorQueueFromHawkBit(final AmqpProperties amqpProperties) {
}

private static Map<String, Object> getTTLMaxArgs() {
final Map<String, Object> args = Maps.newHashMapWithExpectedSize(2);
final Map<String, Object> args = new HashMap<>(2);
args.put("x-message-ttl", Duration.ofDays(1).toMillis());
args.put("x-max-length", 100_000);
return args;
Expand Down
4 changes: 0 additions & 4 deletions hawkbit-example-mgmt-simulator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,5 @@
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>
</project>

0 comments on commit 0e87463

Please sign in to comment.