Skip to content

Commit

Permalink
Reduce dependency on Guava (#1589)
Browse files Browse the repository at this point in the history
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm committed Feb 2, 2024
1 parent 0ee916e commit bce6967
Show file tree
Hide file tree
Showing 63 changed files with 222 additions and 332 deletions.
8 changes: 1 addition & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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 @@ -33,14 +33,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

Examples:

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

### Test documentation

Please document the test cases that you contribute by means of [Allure](https://docs.qameta.io/allure/) annotations and proper test method naming.
Expand Down
4 changes: 0 additions & 4 deletions hawkbit-artifact-repository-filesystem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
<artifactId>hawkbit-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
Expand All @@ -21,7 +22,6 @@
import org.springframework.validation.annotation.Validated;

import com.google.common.base.Splitter;
import com.google.common.io.Files;

/**
* Implementation of the {@link ArtifactRepository} to store artifacts on the
Expand Down Expand Up @@ -79,7 +79,7 @@ private ArtifactFilesystem renameFileToSHA1Naming(final String tenant, final Fil
if (fileSHA1Naming.exists()) {
FileUtils.deleteQuietly(file);
} else {
Files.move(file, fileSHA1Naming);
Files.move(file.toPath(), fileSHA1Naming.toPath());
}

return new ArtifactFilesystem(fileSHA1Naming, artifact.getArtifactId(), artifact.getHashes(),
Expand Down
4 changes: 0 additions & 4 deletions hawkbit-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>io.protostuff</groupId>
Expand Down
5 changes: 3 additions & 2 deletions hawkbit-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>

<!-- Test -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HexFormat;

import org.apache.commons.io.IOUtils;
import org.eclipse.hawkbit.artifact.repository.model.AbstractDbArtifact;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

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

/**
* Abstract utility class for ArtifactRepository implementations with common
* functionality, e.g. computation of hashes.
Expand Down Expand Up @@ -61,9 +60,11 @@ public AbstractDbArtifact store(final String tenant, final InputStream content,

tempFile = storeTempFile(inputStream);

final String sha1Hash16 = BaseEncoding.base16().lowerCase().encode(mdSHA1.digest());
final String md5Hash16 = BaseEncoding.base16().lowerCase().encode(mdMD5.digest());
final String sha256Hash16 = BaseEncoding.base16().lowerCase().encode(mdSHA256.digest());
final HexFormat hexFormat = HexFormat.of().withLowerCase();

final String sha1Hash16 = hexFormat.formatHex(mdSHA1.digest());
final String md5Hash16 = hexFormat.formatHex(mdMD5.digest());
final String sha256Hash16 = hexFormat.formatHex(mdSHA256.digest());

checkHashes(sha1Hash16, md5Hash16, sha256Hash16, providedHashes);

Expand Down Expand Up @@ -110,7 +111,7 @@ protected void deleteTempFile(final String tempFile) {
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);
IOUtils.copy(content, outputstream);
outputstream.flush();
}
return file.getPath();
Expand Down
4 changes: 0 additions & 4 deletions hawkbit-dmf/hawkbit-dmf-amqp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
package org.eclipse.hawkbit.amqp;

import com.google.common.collect.Maps;
import org.eclipse.hawkbit.api.ArtifactUrlHandler;
import org.eclipse.hawkbit.api.HostnameResolver;
import org.eclipse.hawkbit.cache.DownloadIdCache;
Expand Down Expand Up @@ -54,6 +53,7 @@
import org.springframework.util.ErrorHandler;

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

Expand Down Expand Up @@ -366,10 +366,9 @@ AmqpMessageDispatcherService amqpMessageDispatcherService(final RabbitTemplate r
}

private static Map<String, Object> getTTLMaxArgsAuthenticationQueue() {
final Map<String, Object> args = Maps.newHashMapWithExpectedSize(2);
final Map<String, Object> args = new HashMap<>(2);
args.put("x-message-ttl", Duration.ofSeconds(30).toMillis());
args.put("x-max-length", 1_000);
return args;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package org.eclipse.hawkbit.amqp;

import java.util.ArrayList;
import java.util.List;

import jakarta.annotation.PostConstruct;
Expand All @@ -33,8 +34,6 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;

import com.google.common.collect.Lists;

/**
*
* A controller which handles the DMF AMQP authentication.
Expand Down Expand Up @@ -93,7 +92,7 @@ public void postConstruct() {
}

private void addFilter() {
filterChain = Lists.newArrayListWithExpectedSize(5);
filterChain = new ArrayList<>(5);

final ControllerPreAuthenticatedGatewaySecurityTokenFilter gatewaySecurityTokenFilter = new ControllerPreAuthenticatedGatewaySecurityTokenFilter(
tenantConfigurationManagement, tenantAware, systemSecurityContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
package org.eclipse.hawkbit.amqp;

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

import org.springframework.amqp.core.Queue;
import org.springframework.boot.context.properties.ConfigurationProperties;

import com.google.common.collect.Maps;

/**
* Bean which holds the necessary properties for configuring the AMQP deadletter
* queue.
Expand All @@ -39,7 +38,7 @@ public class AmqpDeadletterProperties {
* @return map which holds the properties
*/
public Map<String, Object> getDeadLetterExchangeArgs(final String exchange) {
final Map<String, Object> args = Maps.newHashMapWithExpectedSize(1);
final Map<String, Object> args = new HashMap<>(1);
args.put("x-dead-letter-exchange", exchange);
return args;
}
Expand All @@ -56,7 +55,7 @@ public Queue createDeadletterQueue(final String queueName) {
}

private Map<String, Object> getTTLArgs() {
final Map<String, Object> args = Maps.newHashMapWithExpectedSize(1);
final Map<String, Object> args = new HashMap<>(1);
args.put("x-message-ttl", getTtl());
return args;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import com.google.common.collect.Iterables;
import org.eclipse.hawkbit.api.ApiType;
import org.eclipse.hawkbit.api.ArtifactUrl;
import org.eclipse.hawkbit.api.ArtifactUrlHandler;
Expand Down Expand Up @@ -79,8 +80,6 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.CollectionUtils;

import com.google.common.collect.Iterables;

/**
* {@link AmqpMessageDispatcherService} create all outgoing AMQP messages and
* delegate the messages to a {@link AmqpMessageSenderService}.
Expand Down
4 changes: 0 additions & 4 deletions hawkbit-dmf/hawkbit-dmf-rabbitmq-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
<artifactId>hawkbit-dmf-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-junit</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions hawkbit-repository/hawkbit-repository-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,5 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import com.google.common.reflect.ClassPath;
import org.junit.jupiter.api.Test;
import org.springframework.security.access.prepost.PreAuthorize;

import com.google.common.reflect.ClassPath;

import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
Expand All @@ -42,8 +40,7 @@ public class RepositoryManagementMethodPreAuthorizeAnnotatedTest {

@Test
@Description("Verifies that repository methods are @PreAuthorize annotated")
public void repositoryManagementMethodsArePreAuthorizedAnnotated()
throws ClassNotFoundException, URISyntaxException, IOException {
public void repositoryManagementMethodsArePreAuthorizedAnnotated() throws IOException {
final List<Class<?>> findInterfacesInPackage = findInterfacesInPackage(getClass().getPackage(),
Pattern.compile(".*Management"));

Expand Down Expand Up @@ -81,8 +78,7 @@ private static void assertDeclaredMethodsContainsPreAuthorizeAnnotations(final C
}
}

private List<Class<?>> findInterfacesInPackage(final Package p, final Pattern includeFilter)
throws URISyntaxException, IOException, ClassNotFoundException {
private List<Class<?>> findInterfacesInPackage(final Package p, final Pattern includeFilter) throws IOException {
return ClassPath.from(Thread.currentThread().getContextClassLoader()).getTopLevelClasses(p.getName()).stream()
.filter(clazzInfo -> includeFilter.matcher(clazzInfo.getSimpleName()).matches())
.map(clazzInfo -> clazzInfo.load()).filter(clazz -> clazz.isInterface()).collect(Collectors.toList());
Expand Down
4 changes: 0 additions & 4 deletions hawkbit-repository/hawkbit-repository-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions hawkbit-repository/hawkbit-repository-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@
<groupId>cz.jirutka.rsql</groupId>
<artifactId>rsql-parser</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package org.eclipse.hawkbit.repository.jpa;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -198,8 +199,6 @@
import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;

import com.google.common.collect.Maps;

/**
* General configuration for hawkBit's Repository.
*
Expand Down Expand Up @@ -483,7 +482,7 @@ public EclipseLinkJpaDialect getJpaDialect() {
@Override
protected Map<String, Object> getVendorProperties() {

final Map<String, Object> properties = Maps.newHashMapWithExpectedSize(7);
final Map<String, Object> properties = new HashMap<>(7);
// Turn off dynamic weaving to disable LTW lookup in static weaving mode
properties.put(PersistenceUnitProperties.WEAVING, "false");
// needed for reports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
package org.eclipse.hawkbit.repository.jpa.aspects;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -29,9 +31,6 @@
import org.springframework.security.access.AccessDeniedException;
import org.springframework.transaction.TransactionSystemException;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
* {@link Aspect} catches persistence exceptions and wraps them to custom
* specific exceptions Additionally it checks and prevents access to certain
Expand All @@ -42,14 +41,14 @@ public class ExceptionMappingAspectHandler implements Ordered {

private static final Logger LOG = LoggerFactory.getLogger(ExceptionMappingAspectHandler.class);

private static final Map<String, String> EXCEPTION_MAPPING = Maps.newHashMapWithExpectedSize(4);
private static final Map<String, String> EXCEPTION_MAPPING = new HashMap<>(4);

/**
* this is required to enable a certain order of exception and to select the
* most specific mappable exception according to the type hierarchy of the
* exception.
*/
private static final List<Class<?>> MAPPED_EXCEPTION_ORDER = Lists.newArrayListWithExpectedSize(4);
private static final List<Class<?>> MAPPED_EXCEPTION_ORDER = new ArrayList<>(4);

static {

Expand Down
Loading

0 comments on commit bce6967

Please sign in to comment.