|
1 | 1 | /* |
2 | | - * Copyright 2016-2023 DiffPlug |
| 2 | + * Copyright 2016-2025 DiffPlug |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
27 | 27 | import java.util.Objects; |
28 | 28 | import java.util.concurrent.TimeoutException; |
29 | 29 | import java.util.stream.Collectors; |
| 30 | +import java.util.stream.Stream; |
30 | 31 |
|
31 | 32 | import com.diffplug.spotless.ThrowingEx; |
32 | 33 |
|
33 | 34 | final class NpmResourceHelper { |
| 35 | + |
| 36 | + public static final String MD5_STRING_DELIMITER = "@@@"; |
| 37 | + |
34 | 38 | private NpmResourceHelper() { |
35 | 39 | // no instance required |
36 | 40 | } |
@@ -140,9 +144,15 @@ static String md5(File file) { |
140 | 144 | return md5(readUtf8StringFromFile(file)); |
141 | 145 | } |
142 | 146 |
|
143 | | - static String md5(String fileContent) { |
| 147 | + static String md5(String fileContent, String... additionalFileContents) { |
| 148 | + Objects.requireNonNull(fileContent, "fileContent must not be null"); |
| 149 | + Stream<String> additionalFileContentStream = Stream.concat( |
| 150 | + Stream.of(fileContent), |
| 151 | + Stream.of(additionalFileContents)); |
144 | 152 | MessageDigest md = ThrowingEx.get(() -> MessageDigest.getInstance("MD5")); |
145 | | - md.update(fileContent.getBytes(StandardCharsets.UTF_8)); |
| 153 | + String stringToHash = additionalFileContentStream.collect(Collectors.joining(MD5_STRING_DELIMITER)); |
| 154 | + md.update(stringToHash.getBytes(StandardCharsets.UTF_8)); |
| 155 | + |
146 | 156 | byte[] digest = md.digest(); |
147 | 157 | // convert byte array digest to hex string |
148 | 158 | StringBuilder sb = new StringBuilder(); |
|
0 commit comments