Use Matcher from pre-compiled Pattern rather than String for replaceAll

Closes gh-14483
This commit is contained in:
durigon
2018-09-16 11:42:49 +09:00
committed by Andy Wilkinson
parent 11016bc7f4
commit 7aaeefbc0e
8 changed files with 44 additions and 10 deletions

View File

@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Pattern;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
@@ -62,6 +63,8 @@ import org.springframework.boot.loader.tools.Repackager.MainClassTimeoutWarningL
@Mojo(name = "repackage", defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
public class RepackageMojo extends AbstractDependencyFilterMojo {
private static final Pattern WHITE_SPACE_PATTERN = Pattern.compile("\\s+");
/**
* The Maven project.
* @since 1.0
@@ -312,7 +315,8 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
}
private String removeLineBreaks(String description) {
return (description != null) ? description.replaceAll("\\s+", " ") : null;
return (description != null)
? WHITE_SPACE_PATTERN.matcher(description).replaceAll(" ") : null;
}
private void putIfMissing(Properties properties, String key,