Skip to content

Commit 0e87463

Browse files
authored
Merge pull request #82 from bosch-io/fix/remove_quava_dep
Remove quava dependency
2 parents e9bd8c3 + 068558b commit 0e87463

File tree

6 files changed

+16
-37
lines changed

6 files changed

+16
-37
lines changed

CONTRIBUTING.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Please read this if you intend to contribute to the project.
2323

2424
### Utility library usage
2525

26-
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.
26+
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.
2727

2828
So we kindly ask contributors:
2929

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

38-
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)).
39-
40-
Examples:
41-
42-
* Prefer `Arrays.asList(...)` from JDK over guava's `Lists.newArrayList(...)`
43-
* Prefer `StringUtils` from Spring over guava's `Strings` Apache's `StringUtils`
44-
4537
### Test documentation
4638

4739
Please documented the test cases that you contribute by means of [Allure](http://allure.qatools.ru) annotations and proper test method naming.

hawkbit-device-simulator/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@
115115
<groupId>io.github.openfeign</groupId>
116116
<artifactId>feign-jackson</artifactId>
117117
</dependency>
118-
<dependency>
119-
<groupId>com.google.guava</groupId>
120-
<artifactId>guava</artifactId>
121-
</dependency>
122118
<dependency>
123119
<groupId>org.apache.httpcomponents</groupId>
124120
<artifactId>httpclient</artifactId>

hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java

+8-13
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
import java.security.MessageDigest;
2020
import java.security.NoSuchAlgorithmException;
2121
import java.util.ArrayList;
22+
import java.util.HexFormat;
2223
import java.util.List;
2324
import java.util.concurrent.ScheduledExecutorService;
2425
import java.util.concurrent.TimeUnit;
2526
import java.util.stream.Collectors;
2627

28+
import org.apache.commons.io.IOUtils;
2729
import org.apache.http.client.methods.CloseableHttpResponse;
2830
import org.apache.http.client.methods.HttpGet;
2931
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@@ -45,9 +47,6 @@
4547
import org.springframework.util.CollectionUtils;
4648
import org.springframework.util.StringUtils;
4749

48-
import com.google.common.io.BaseEncoding;
49-
import com.google.common.io.ByteStreams;
50-
5150
/**
5251
* Update simulation handler.
5352
*/
@@ -267,7 +266,7 @@ private UpdateStatus readAndCheckDownloadUrl(final String url, final String gate
267266
return new UpdateStatus(ResponseStatus.ERROR, message);
268267
}
269268

270-
sha1HashResult = BaseEncoding.base16().lowerCase().encode(md.digest());
269+
sha1HashResult = HexFormat.of().withLowerCase().formatHex(md.digest());
271270
}
272271

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

283282
private static long getOverallRead(final CloseableHttpResponse response, final MessageDigest md)
284283
throws IOException {
285-
286-
long overallread;
287-
288-
try (final OutputStream os = ByteStreams.nullOutputStream();
289-
final BufferedOutputStream bos = new BufferedOutputStream(new DigestOutputStream(os, md))) {
290-
291-
try (BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent())) {
292-
overallread = ByteStreams.copy(bis, bos);
284+
long overallread = 0;
285+
try (final BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent())) {
286+
final byte[] buff = new byte[4 *1024];
287+
for (int read; (read = bis.read(buff)) != -1; overallread += read) {
288+
md.update(buff, 0, read);
293289
}
294290
}
295-
296291
return overallread;
297292
}
298293

hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.eclipse.hawkbit.simulator;
1111

1212
import java.util.ArrayList;
13+
import java.util.Arrays;
1314
import java.util.List;
1415
import java.util.Optional;
1516
import java.util.Random;
@@ -21,8 +22,6 @@
2122
import org.springframework.boot.context.properties.ConfigurationProperties;
2223
import org.springframework.stereotype.Component;
2324

24-
import com.google.common.base.Splitter;
25-
2625
/**
2726
* General simulator service properties.
2827
*
@@ -32,7 +31,7 @@
3231
// Exception for squid:S2245 : not security relevant random number generation
3332
@SuppressWarnings("squid:S2245")
3433
public class SimulationProperties {
35-
private static final Splitter SPLITTER = Splitter.on(',').omitEmptyStrings().trimResults();
34+
3635
private static final Random RANDOM = new Random();
3736

3837
private String defaultTenant = "DEFAULT";
@@ -110,7 +109,9 @@ public String getRandom() {
110109
}
111110

112111
private String getRandomElement() {
113-
final List<String> options = SPLITTER.splitToList(random);
112+
final List<String> options = Arrays.stream(random.split(","))
113+
.map(String::trim)
114+
.filter(s -> !s.isEmpty()).toList();
114115
return options.get(RANDOM.nextInt(options.size()));
115116
}
116117
}

hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.eclipse.hawkbit.simulator.amqp;
1111

1212
import java.time.Duration;
13+
import java.util.HashMap;
1314
import java.util.Map;
1415

1516
import org.eclipse.hawkbit.simulator.DeviceSimulatorRepository;
@@ -29,8 +30,6 @@
2930
import org.springframework.context.annotation.Bean;
3031
import org.springframework.context.annotation.Configuration;
3132

32-
import com.google.common.collect.Maps;
33-
3433
/**
3534
* The spring AMQP configuration to use a AMQP for communication with SP update
3635
* server.
@@ -81,7 +80,7 @@ Queue receiverConnectorQueueFromHawkBit(final AmqpProperties amqpProperties) {
8180
}
8281

8382
private static Map<String, Object> getTTLMaxArgs() {
84-
final Map<String, Object> args = Maps.newHashMapWithExpectedSize(2);
83+
final Map<String, Object> args = new HashMap<>(2);
8584
args.put("x-message-ttl", Duration.ofDays(1).toMillis());
8685
args.put("x-max-length", 100_000);
8786
return args;

hawkbit-example-mgmt-simulator/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,5 @@
6161
<groupId>io.github.openfeign</groupId>
6262
<artifactId>feign-jackson</artifactId>
6363
</dependency>
64-
<dependency>
65-
<groupId>com.google.guava</groupId>
66-
<artifactId>guava</artifactId>
67-
</dependency>
6864
</dependencies>
6965
</project>

0 commit comments

Comments
 (0)