From 2c2ed8f8abe642282bc39e6bad630f37bbfa89fe Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Tue, 5 Nov 2024 11:13:48 +0200 Subject: [PATCH] Code format hawkbit-artifact-repository-filesystem (#1933) Signed-off-by: Marinov Avgustin --- .../README.md | 5 +- .../pom.xml | 77 ++++++++++--------- .../ArtifactFileNotFoundException.java | 1 + .../ArtifactFilesystemConfiguration.java | 3 +- .../ArtifactFilesystemRepository.java | 37 ++++----- .../ArtifactFilesystemRepositoryTest.java | 19 +++-- .../repository/ArtifactFilesystemTest.java | 7 +- 7 files changed, 75 insertions(+), 74 deletions(-) diff --git a/hawkbit-artifact-repository-filesystem/README.md b/hawkbit-artifact-repository-filesystem/README.md index 2c1e51bbb..44d133a4e 100644 --- a/hawkbit-artifact-repository-filesystem/README.md +++ b/hawkbit-artifact-repository-filesystem/README.md @@ -1,11 +1,12 @@ # Eclipse.IoT hawkBit - Artifact Repository File System This module contains the implementation of the `ArtifactRepository` based on the file-system. -It's a very convenient and easy implementation of storing the artifact binaries into the file-system based on the SHA-1 hash naming. +It's a very convenient and easy implementation of storing the artifact binaries into the file-system based on the SHA-1 +hash naming. Due the limit of many file-systems of files within one directory, the files are stored in different sub-directories based on the last four digits of the -SHA1-hash `/basepath/[two digit sha1]/[two digit sha1/sha1-hash-filename]`. +SHA1-hash `/basepath/[two digit sha1]/[two digit sha1/sha1-hash-filename]`. # Compile diff --git a/hawkbit-artifact-repository-filesystem/pom.xml b/hawkbit-artifact-repository-filesystem/pom.xml index ec6c7aadd..5eec0695b 100644 --- a/hawkbit-artifact-repository-filesystem/pom.xml +++ b/hawkbit-artifact-repository-filesystem/pom.xml @@ -9,44 +9,45 @@ SPDX-License-Identifier: EPL-2.0 --> - - 4.0.0 - - org.eclipse.hawkbit - hawkbit-parent - ${revision} - - hawkbit-artifact-repository-filesystem - hawkBit :: Artifact Repository :: Filesystem + + 4.0.0 + + org.eclipse.hawkbit + hawkbit-parent + ${revision} + + hawkbit-artifact-repository-filesystem + hawkBit :: Artifact Repository :: Filesystem - - - org.eclipse.hawkbit - hawkbit-core - ${project.version} - - - org.springframework - spring-core - - - org.springframework.boot - spring-boot-autoconfigure - - - commons-io - commons-io - - - org.springframework.boot - spring-boot-starter-test - test - - - io.qameta.allure - allure-junit5 - test - - + + + org.eclipse.hawkbit + hawkbit-core + ${project.version} + + + org.springframework + spring-core + + + org.springframework.boot + spring-boot-autoconfigure + + + commons-io + commons-io + + + org.springframework.boot + spring-boot-starter-test + test + + + io.qameta.allure + allure-junit5 + test + + diff --git a/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFileNotFoundException.java b/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFileNotFoundException.java index 92e92a76e..c85a2ce32 100644 --- a/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFileNotFoundException.java +++ b/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFileNotFoundException.java @@ -16,6 +16,7 @@ public class ArtifactFileNotFoundException extends RuntimeException { /** * Creates the Exception from it's cause + * * @param cause the original exception */ public ArtifactFileNotFoundException(final Exception cause) { diff --git a/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemConfiguration.java b/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemConfiguration.java index 5b57f1d38..084942e89 100644 --- a/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemConfiguration.java +++ b/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemConfiguration.java @@ -22,8 +22,7 @@ import org.springframework.context.annotation.Configuration; public class ArtifactFilesystemConfiguration { /** - * @param artifactFilesystemProperties - * the artifact file system properties + * @param artifactFilesystemProperties the artifact file system properties * @return Default {@link ArtifactRepository} implementation. */ @Bean diff --git a/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemRepository.java b/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemRepository.java index f728de7c2..4e77ff661 100644 --- a/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemRepository.java +++ b/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemRepository.java @@ -24,10 +24,10 @@ import org.springframework.validation.annotation.Validated; * Implementation of the {@link ArtifactRepository} to store artifacts on the * file-system. The files are stored by their SHA1 hash of the artifact binary. * Duplicate files with the same SHA1 hash will only stored once. - * + * * All files are stored flat in one base directory configured in the * {@link ArtifactFilesystemProperties#getPath()}. - * + * * Due the limit of many file-systems of files within one directory, the files * are stored in different sub-directories based on the last four digits of the * SHA1-hash {@code (/basepath/[two digit sha1]/[two digit sha1])}. @@ -39,10 +39,9 @@ public class ArtifactFilesystemRepository extends AbstractArtifactRepository { /** * Constructor. - * - * @param artifactResourceProperties - * the properties which holds the necessary configuration for the - * file-system repository + * + * @param artifactResourceProperties the properties which holds the necessary configuration for the + * file-system repository */ public ArtifactFilesystemRepository(final ArtifactFilesystemProperties artifactResourceProperties) { this.artifactResourceProperties = artifactResourceProperties; @@ -64,10 +63,22 @@ public class ArtifactFilesystemRepository extends AbstractArtifactRepository { } @Override - protected AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes, final String contentType, final String tempFile) throws IOException { + public void deleteByTenant(final String tenant) { + FileUtils.deleteQuietly(Paths.get(artifactResourceProperties.getPath(), sanitizeTenant(tenant)).toFile()); + } + + @Override + public boolean existsByTenantAndSha1(final String tenant, final String sha1) { + return getFile(tenant, sha1).exists(); + } + + @Override + protected AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes, final String contentType, final String tempFile) + throws IOException { final File file = new File(tempFile); - return renameFileToSHA1Naming(tenant, file, new ArtifactFilesystem(file, base16Hashes.getSha1(), base16Hashes, file.length(), contentType)); + return renameFileToSHA1Naming(tenant, file, + new ArtifactFilesystem(file, base16Hashes.getSha1(), base16Hashes, file.length(), contentType)); } private ArtifactFilesystem renameFileToSHA1Naming(final String tenant, final File file, @@ -95,14 +106,4 @@ public class ArtifactFilesystemRepository extends AbstractArtifactRepository { final String folder2 = sha1.substring(length - 2, length); return Paths.get(artifactResourceProperties.getPath(), sanitizeTenant(tenant), folder1, folder2); } - - @Override - public void deleteByTenant(final String tenant) { - FileUtils.deleteQuietly(Paths.get(artifactResourceProperties.getPath(), sanitizeTenant(tenant)).toFile()); - } - - @Override - public boolean existsByTenantAndSha1(final String tenant, final String sha1) { - return getFile(tenant, sha1).exists(); - } } diff --git a/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemRepositoryTest.java b/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemRepositoryTest.java index ea2f6f9df..73b2c3aec 100644 --- a/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemRepositoryTest.java +++ b/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemRepositoryTest.java @@ -17,6 +17,9 @@ import java.io.IOException; import java.nio.file.Files; import java.util.Random; +import io.qameta.allure.Description; +import io.qameta.allure.Feature; +import io.qameta.allure.Story; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -26,10 +29,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import io.qameta.allure.Description; -import io.qameta.allure.Feature; -import io.qameta.allure.Story; - @Slf4j @Feature("Unit Tests - Artifact File System Repository") @Story("Test storing artifact binaries in the file-system") @@ -121,12 +120,6 @@ public class ArtifactFilesystemRepositoryTest { } } - private AbstractDbArtifact storeRandomArtifact(final byte[] fileContent) { - final String fileName = "filename.tmp"; - final ByteArrayInputStream inputStream = new ByteArrayInputStream(fileContent); - return artifactFilesystemRepository.store(TENANT, inputStream, fileName, "application/txt", null); - } - private static byte[] randomBytes() { final byte[] randomBytes = new byte[20]; final Random ran = new Random(); @@ -134,4 +127,10 @@ public class ArtifactFilesystemRepositoryTest { return randomBytes; } + private AbstractDbArtifact storeRandomArtifact(final byte[] fileContent) { + final String fileName = "filename.tmp"; + final ByteArrayInputStream inputStream = new ByteArrayInputStream(fileContent); + return artifactFilesystemRepository.store(TENANT, inputStream, fileName, "application/txt", null); + } + } diff --git a/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemTest.java b/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemTest.java index cccfbd226..744ad84c4 100644 --- a/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemTest.java +++ b/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/artifact/repository/ArtifactFilesystemTest.java @@ -16,15 +16,14 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; +import io.qameta.allure.Description; +import io.qameta.allure.Feature; +import io.qameta.allure.Story; import org.apache.commons.io.IOUtils; import org.assertj.core.api.Assertions; import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash; import org.junit.jupiter.api.Test; -import io.qameta.allure.Description; -import io.qameta.allure.Feature; -import io.qameta.allure.Story; - @Feature("Unit Tests - Artifact File System Repository") @Story("Test storing artifact binaries in the file-system") public class ArtifactFilesystemTest {