Skip to content

Commit 74567bf

Browse files
committed
Fix PMD
1 parent d3a24c4 commit 74567bf

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

eclipse-store-afs-ibm-cos/src/main/java/software/xdev/eclipse/store/afs/ibm/access/SingleAccessManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private boolean isNotThisTokenFile(final S3ObjectSummary s3ObjectSummary)
213213
return !s3ObjectSummary.getKey().equals(this.token.getFileName());
214214
}
215215

216-
@SuppressWarnings("MagicNumber")
216+
@SuppressWarnings({"MagicNumber", "PMD.ReplaceJavaUtilCalendar", "PMD.ReplaceJavaUtilDate"})
217217
private boolean isOldTokenFile(final S3ObjectSummary s3ObjectSummary)
218218
{
219219
final Calendar deadlineForOldToken = Calendar.getInstance();

eclipse-store-afs-ibm-cos/src/main/java/software/xdev/eclipse/store/afs/ibm/cos/types/CosConnector.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
import java.io.IOException;
2323
import java.nio.Buffer;
2424
import java.nio.ByteBuffer;
25+
import java.util.Collections;
2526
import java.util.List;
27+
import java.util.Map;
28+
import java.util.WeakHashMap;
2629
import java.util.regex.Pattern;
2730
import java.util.stream.Stream;
2831
import java.util.stream.StreamSupport;
@@ -95,6 +98,9 @@ class Default
9598
extends BlobStoreConnector.Abstract<S3ObjectSummary>
9699
implements CosConnector
97100
{
101+
private static final Map<String, Pattern> PREFIX_PATTERN_CACHE =
102+
Collections.synchronizedMap(new WeakHashMap<>());
103+
98104
public static final int READ_LIMIT = Integer.MAX_VALUE;
99105
private final AmazonS3 s3;
100106

@@ -112,11 +118,14 @@ class Default
112118
this.s3 = s3;
113119
}
114120

121+
@SuppressWarnings("PMD.AvoidRecompilingPatterns")
115122
@Override
116123
protected Stream<S3ObjectSummary> blobs(final BlobStorePath file)
117124
{
118125
final String prefix = toBlobKeyPrefix(file);
119-
final Pattern pattern = Pattern.compile(blobKeyRegex(prefix));
126+
final Pattern pattern = PREFIX_PATTERN_CACHE.computeIfAbsent(
127+
prefix,
128+
s -> Pattern.compile(blobKeyRegex(s)));
120129
final ListObjectsV2Request request = new ListObjectsV2Request()
121130
.withBucketName(file.container())
122131
.withPrefix(prefix);

eclipse-store-afs-ibm-cos/src/main/java/software/xdev/eclipse/store/afs/ibm/cos/types/CosPathValidator.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ static CosPathValidator New()
3030

3131
class Default implements CosPathValidator
3232
{
33+
private static final Pattern LOWERCASE_NUMBERS_PERIOD_DASHES =
34+
Pattern.compile("[a-z0-9\\.\\-]*");
35+
private static final Pattern LOWERCASE_NUMBER =
36+
Pattern.compile("[a-z0-9]");
37+
private static final Pattern IP_ADDRESS_STYLE =
38+
Pattern.compile(
39+
"^((0|1\\d?\\d?|2[0-4]?\\d?|25[0-5]?|[3-9]\\d?)\\.){3}(0|1\\d?\\d?|2[0-4]?\\d?|25[0-5]?|[3-9]\\d?)$");
40+
3341
Default()
3442
{
3543
super();
@@ -54,13 +62,13 @@ void validateBucketName(final String bucketName)
5462
{
5563
throw new IllegalArgumentException("bucket name must be between 3 and 63 characters long");
5664
}
57-
if(!Pattern.matches("[a-z0-9\\.\\-]*", bucketName))
65+
if(!LOWERCASE_NUMBERS_PERIOD_DASHES.matcher(bucketName).matches())
5866
{
5967
throw new IllegalArgumentException(
6068
"bucket name can contain only lowercase letters, numbers, periods (.) and dashes (-)"
6169
);
6270
}
63-
if(!Pattern.matches("[a-z0-9]", bucketName.substring(0, 1)))
71+
if(LOWERCASE_NUMBER.matcher(bucketName.substring(0, 1)).matches())
6472
{
6573
throw new IllegalArgumentException("bucket name must begin with a lowercase letters or a number");
6674
}
@@ -77,10 +85,7 @@ void validateBucketName(final String bucketName)
7785
{
7886
throw new IllegalArgumentException("bucket name cannot have dashes adjacent to periods (.- or -.)");
7987
}
80-
if(Pattern.matches(
81-
"^((0|1\\d?\\d?|2[0-4]?\\d?|25[0-5]?|[3-9]\\d?)\\.){3}(0|1\\d?\\d?|2[0-4]?\\d?|25[0-5]?|[3-9]\\d?)$",
82-
bucketName
83-
))
88+
if(IP_ADDRESS_STYLE.matcher(bucketName).matches())
8489
{
8590
throw new IllegalArgumentException("bucket name must not be in an IP address style");
8691
}

eclipse-store-afs-ibm-cos/src/test/java/software/xdev/eclipse/store/afs/ibm/access/CosAccessCommunicatorLocal.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public synchronized boolean checkIfFileExists(final String fileName)
5353
return this.existingFiles.containsKey(fileName);
5454
}
5555

56+
@SuppressWarnings("PMD.ReplaceJavaUtilDate")
5657
@Override
5758
public synchronized void createEmptyFile(final String fileName)
5859
{

eclipse-store-afs-ibm-cos/src/test/java/software/xdev/eclipse/store/afs/ibm/access/SingleAccessManagerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public void run()
116116
* Starts a lot of threads which all want the same, single access. If they all finish without deadlock and no
117117
* Access-files are left, the test is successful.
118118
*/
119-
@SuppressWarnings("PMD.LambdaCanBeMethodReference") // Multiple options for Lambda
119+
@SuppressWarnings({"PMD.LambdaCanBeMethodReference", "PMD.AvoidFutureGetWithoutTimeout"})
120+
// Multiple options for Lambda
120121
@Test
121122
void waitForAndReserveSingleAccessWaitingNeededManyManagers()
122123
{
@@ -140,6 +141,8 @@ void waitForAndReserveSingleAccessWaitingNeededManyManagers()
140141

141142
// Only the last manager is allowed to still have the AccessToken file
142143
Assertions.assertEquals(1, this.communicator.getExistingFilesWithPrefix().size());
144+
145+
executor.shutdown();
143146
}
144147

145148
@Test

0 commit comments

Comments
 (0)