diff --git a/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/storage/metadata/maven/ChecksumMetadataExpirationStrategy.java b/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/storage/metadata/maven/ChecksumMetadataExpirationStrategy.java index 4e9736ef48..1be936073b 100644 --- a/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/storage/metadata/maven/ChecksumMetadataExpirationStrategy.java +++ b/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/storage/metadata/maven/ChecksumMetadataExpirationStrategy.java @@ -25,18 +25,43 @@ public class ChecksumMetadataExpirationStrategy public Decision decide(final RepositoryPath repositoryPath) throws IOException { + Decision decision = decideUsingChecksumAlgorithm(repositoryPath, EncryptionAlgorithmsEnum.SHA1); + if (UNDECIDED.equals(decision)) + { + decision = decideUsingChecksumAlgorithm(repositoryPath, EncryptionAlgorithmsEnum.MD5); + } + return decision; + } + + private RepositoryPath resolveSiblingChecksum(final RepositoryPath repositoryPath, + final EncryptionAlgorithmsEnum checksumAlgorithm) + { + return repositoryPath.resolveSibling( + repositoryPath.getFileName().toString() + checksumAlgorithm.getExtension()); + } + + private String readChecksum(final RepositoryPath checksumRepositoryPath) + throws IOException + { + if (!Files.exists(checksumRepositoryPath)) + { + return null; + } - RepositoryPath checksumRepositoryPath = resolveSiblingChecksum(repositoryPath, EncryptionAlgorithmsEnum.SHA1); + return Files.readAllLines(checksumRepositoryPath).stream().findFirst().orElse(null); + } + + private Decision decideUsingChecksumAlgorithm(final RepositoryPath repositoryPath, + final EncryptionAlgorithmsEnum checksumAlgorithm) throws IOException + { + RepositoryPath checksumRepositoryPath = resolveSiblingChecksum(repositoryPath, checksumAlgorithm); String currentChecksum = readChecksum(checksumRepositoryPath); if (currentChecksum == null) { - checksumRepositoryPath = resolveSiblingChecksum(repositoryPath, EncryptionAlgorithmsEnum.MD5); - currentChecksum = readChecksum(checksumRepositoryPath); - if (currentChecksum == null) - { - logger.debug("Unable to read local checksum for {}, will refetch metadata", repositoryPath.normalize()); - return UNDECIDED; - } + logger.debug("Unable to read local {} checksum for {}, returning " + UNDECIDED.name(), + checksumAlgorithm, + repositoryPath.normalize()); + return UNDECIDED; } proxyRepositoryArtifactResolver.fetchRemoteResource(checksumRepositoryPath); @@ -44,40 +69,26 @@ public Decision decide(final RepositoryPath repositoryPath) throws IOException if (newRemoteChecksum == null) { - logger.debug("Unable to fetch remote checksum for {}, will refetch metadata", repositoryPath.normalize()); + logger.debug("Unable to fetch remote {} checksum for {}, returning " + UNDECIDED.name(), + checksumAlgorithm, + repositoryPath.normalize()); return UNDECIDED; } if (currentChecksum.equals(newRemoteChecksum)) { - logger.debug("Local and remote checksums match for {}, no need to refetch metadata", + logger.debug("Local and remote {} checksums match for {}, no need to refetch metadata", + checksumAlgorithm, repositoryPath.normalize()); return USABLE; } else { - logger.debug("Local and remote checksums differ for {}, will refetch metadata", + logger.debug("Local and remote {} checksums differ for {}, will refetch metadata", + checksumAlgorithm, repositoryPath.normalize()); return EXPIRED; } } - private RepositoryPath resolveSiblingChecksum(final RepositoryPath repositoryPath, - final EncryptionAlgorithmsEnum checksumAlgorithm) - { - return repositoryPath.resolveSibling( - repositoryPath.getFileName().toString() + checksumAlgorithm.getExtension()); - } - - private String readChecksum(final RepositoryPath checksumRepositoryPath) - throws IOException - { - if (!Files.exists(checksumRepositoryPath)) - { - return null; - } - - return Files.readAllLines(checksumRepositoryPath).stream().findFirst().orElse(null); - } - } diff --git a/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/storage/metadata/maven/MetadataExpirationStrategyType.java b/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/storage/metadata/maven/MetadataExpirationStrategyType.java index 84c271d8db..63aa8fecad 100644 --- a/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/storage/metadata/maven/MetadataExpirationStrategyType.java +++ b/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/storage/metadata/maven/MetadataExpirationStrategyType.java @@ -26,7 +26,7 @@ public String describe() public static MetadataExpirationStrategyType ofStrategy(String strategy) { return Stream.of(values()) - .filter(e -> e.strategy.equalsIgnoreCase(strategy)) + .filter(e -> e.strategy.equals(strategy)) .findFirst() .orElse(null); } diff --git a/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/yaml/configuration/repository/MavenRepositoryConfigurationDto.java b/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/yaml/configuration/repository/MavenRepositoryConfigurationDto.java index 4e992c5a14..8b9fb1e967 100644 --- a/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/yaml/configuration/repository/MavenRepositoryConfigurationDto.java +++ b/strongbox-storage/strongbox-storage-layout-providers/strongbox-storage-maven-layout/strongbox-storage-maven-layout-provider/src/main/java/org/carlspring/strongbox/yaml/configuration/repository/MavenRepositoryConfigurationDto.java @@ -23,7 +23,7 @@ public class MavenRepositoryConfigurationDto // defaults to once daily at 2 am private String cronExpression = "0 0 2 * * ?"; - private String metadataExpirationStrategy = MetadataExpirationStrategyType.CHECKSUM.name(); + private String metadataExpirationStrategy = MetadataExpirationStrategyType.CHECKSUM.describe(); @Override public boolean isIndexingEnabled() diff --git a/strongbox-web-forms/src/main/java/org/carlspring/strongbox/forms/configuration/MavenRepositoryConfigurationForm.java b/strongbox-web-forms/src/main/java/org/carlspring/strongbox/forms/configuration/MavenRepositoryConfigurationForm.java index 63d59020a8..7a3eec9e59 100644 --- a/strongbox-web-forms/src/main/java/org/carlspring/strongbox/forms/configuration/MavenRepositoryConfigurationForm.java +++ b/strongbox-web-forms/src/main/java/org/carlspring/strongbox/forms/configuration/MavenRepositoryConfigurationForm.java @@ -22,7 +22,7 @@ public class MavenRepositoryConfigurationForm private String cronExpression; @DescribableEnumValue(type = MetadataExpirationStrategyType.class, - message = "metadataExpirationStrategy must contain one the following strings as value: checksum, refresh") + message = "metadataExpirationStrategy must be equal to either: checksum, refresh") private String metadataExpirationStrategy; public boolean isIndexingEnabled()