From ff66036e9082e7545ea498454b298855babd2f2e Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Wed, 27 Mar 2024 09:34:28 +0100 Subject: [PATCH] Remove redundant Regex escapes Closes gh-40116 --- .../restart/server/DefaultSourceDirectoryUrlFilter.java | 4 ++-- .../boot/buildpack/platform/docker/type/ImageReference.java | 4 ++-- .../gradle/plugin/JavaPluginActionIntegrationTests.java | 4 ++-- .../testsupport/gradle/testkit/GradleBuildExtension.java | 4 ++-- .../boot/loader/tools/DefaultLaunchScript.java | 4 ++-- .../org/springframework/boot/loader/tools/TestJarFile.java | 4 ++-- .../src/main/groovy/generateGoalsDocumentation.groovy | 6 +++--- .../context/config/StandardConfigDataLocationResolver.java | 4 ++-- .../boot/logging/logback/LogbackLoggingSystemTests.java | 4 ++-- .../springframework/boot/web/server/MimeMappingsTests.java | 4 ++-- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/server/DefaultSourceDirectoryUrlFilter.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/server/DefaultSourceDirectoryUrlFilter.java index 0d16d822211..679504e1564 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/server/DefaultSourceDirectoryUrlFilter.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/server/DefaultSourceDirectoryUrlFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ public class DefaultSourceDirectoryUrlFilter implements SourceDirectoryUrlFilter private static final String[] COMMON_ENDINGS = { "/target/classes", "/bin" }; - private static final Pattern URL_MODULE_PATTERN = Pattern.compile(".*\\/(.+)\\.jar"); + private static final Pattern URL_MODULE_PATTERN = Pattern.compile(".*/(.+)\\.jar"); private static final Pattern VERSION_PATTERN = Pattern.compile("^-\\d+(?:\\.\\d+)*(?:[.-].+)?$"); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImageReference.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImageReference.java index 01a918895a6..983524827c5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImageReference.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImageReference.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ import org.springframework.util.ObjectUtils; */ public final class ImageReference { - private static final Pattern JAR_VERSION_PATTERN = Pattern.compile("^(.*)(\\-\\d+)$"); + private static final Pattern JAR_VERSION_PATTERN = Pattern.compile("^(.*)(-\\d+)$"); private static final String LATEST = "latest"; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java index a9fdff46ee7..e966bdfab6d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/JavaPluginActionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -150,7 +150,7 @@ class JavaPluginActionIntegrationTests { @TestTemplate void productionRuntimeClasspathIsConfiguredWithAttributesThatMatchRuntimeClasspath() { String output = this.gradleBuild.build("build").getOutput(); - Matcher matcher = Pattern.compile("runtimeClasspath: (\\[.*\\])").matcher(output); + Matcher matcher = Pattern.compile("runtimeClasspath: (\\[.*])").matcher(output); assertThat(matcher.find()).as("%s found in %s", matcher, output).isTrue(); String attributes = matcher.group(1); assertThat(output).contains("productionRuntimeClasspath: " + attributes); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuildExtension.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuildExtension.java index 5475518e44f..88c7b8b6d1f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuildExtension.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuildExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ import org.springframework.util.ReflectionUtils; */ public class GradleBuildExtension implements BeforeEachCallback, AfterEachCallback { - private static final Pattern GRADLE_VERSION_PATTERN = Pattern.compile("\\[Gradle .+\\]"); + private static final Pattern GRADLE_VERSION_PATTERN = Pattern.compile("\\[Gradle .+]"); private final Dsl dsl = Dsl.GROOVY; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/DefaultLaunchScript.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/DefaultLaunchScript.java index 33e3f854fdd..9646a6b3fd1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/DefaultLaunchScript.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/DefaultLaunchScript.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ public class DefaultLaunchScript implements LaunchScript { private static final int BUFFER_SIZE = 4096; - private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("\\{\\{(\\w+)(:.*?)?\\}\\}(?!\\})"); + private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("\\{\\{(\\w+)(:.*?)?}}(?!})"); private static final Set FILE_PATH_KEYS = Collections.singleton("inlinedConfScript"); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java index 2ce128cc64f..cb7501aefb1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,7 +90,7 @@ public class TestJarFile { } private File getFilePath(String filename) { - String[] paths = filename.split("\\/"); + String[] paths = filename.split("/"); File file = this.jarSource; for (String path : paths) { file = new File(file, path); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/groovy/generateGoalsDocumentation.groovy b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/groovy/generateGoalsDocumentation.groovy index a7542748de8..c1138beddda 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/groovy/generateGoalsDocumentation.groovy +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/groovy/generateGoalsDocumentation.groovy @@ -8,9 +8,9 @@ private String format(String input) { .replace("
", " ") .replace("\n", " ") .replace(""", '"') - .replaceAll('\\{@code (.*?)\\}', '`$1`') - .replaceAll('\\{@link (.*?)\\}', '`$1`') - .replaceAll('\\{@literal (.*?)\\}', '`$1`') + .replaceAll('\\{@code (.*?)}', '`$1`') + .replaceAll('\\{@link (.*?)}', '`$1`') + .replaceAll('\\{@literal (.*?)}', '`$1`') .replaceAll('(.*?)', '\$1[\$2]') } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataLocationResolver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataLocationResolver.java index 3b314032997..ad95e7a22ec 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataLocationResolver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/StandardConfigDataLocationResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,7 +66,7 @@ public class StandardConfigDataLocationResolver private static final Pattern URL_PREFIX = Pattern.compile("^([a-zA-Z][a-zA-Z0-9*]*?:)(.*$)"); - private static final Pattern EXTENSION_HINT_PATTERN = Pattern.compile("^(.*)\\[(\\.\\w+)\\](?!\\[)$"); + private static final Pattern EXTENSION_HINT_PATTERN = Pattern.compile("^(.*)\\[(\\.\\w+)](?!\\[)$"); private static final String NO_PROFILE = null; diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java index 9e129fc1b5f..61c4a54b4a1 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -582,7 +582,7 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { initialize(loggingInitializationContext, null, null); this.logger.info("Hello world"); assertThat(getLineWithText(output, "Hello world")) - .containsPattern("\\d{4}-\\d{2}\\-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}([-+]\\d{2}:\\d{2}|Z)"); + .containsPattern("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}([-+]\\d{2}:\\d{2}|Z)"); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java index 273b4c64c5e..323924fcba2 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -152,7 +152,7 @@ class MimeMappingsTests { @Test void mimeTypesInDefaultMappingsAreCorrectlyStructured() { String regName = "[A-Za-z0-9!#$&.+\\-^_]{1,127}"; - Pattern pattern = Pattern.compile("^" + regName + "\\/" + regName + "$"); + Pattern pattern = Pattern.compile("^" + regName + "/" + regName + "$"); assertThat(MimeMappings.DEFAULT).allSatisfy((mapping) -> assertThat(mapping.getMimeType()).matches(pattern)); }