Allow <mvnd.builder.rule> entries to be separated by whitespace

This commit is contained in:
Peter Palaga
2020-08-20 17:33:19 +02:00
parent 72ef7d9ea1
commit e59649d353
2 changed files with 37 additions and 2 deletions

View File

@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.enterprise.inject.Default;
import javax.inject.Inject;
@@ -65,6 +66,7 @@ public class SmartBuilder implements Builder {
public static final String MVND_BUILDER_RULES_PROVIDER_SCRIPT = "mvnd.builder.rules.provider.script";
private final Logger logger = LoggerFactory.getLogger(getClass());
static final Pattern mvndRuleSanitizerPattern = Pattern.compile("[,\\s]+");
private final LifecycleModuleBuilder moduleBuilder;
@@ -138,8 +140,12 @@ public class SmartBuilder implements Builder {
session.getAllProjects().forEach(p -> {
String rule = p.getProperties().getProperty(MVND_BUILDER_RULE);
if (rule != null && !rule.trim().isEmpty()) {
list.add(rule + " before " + p.getGroupId() + ":" + p.getArtifactId());
if (rule != null) {
rule = rule.trim();
if (!rule.isEmpty()) {
rule = mvndRuleSanitizerPattern.matcher(rule).replaceAll(",");
list.add(rule + " before " + p.getGroupId() + ":" + p.getArtifactId());
}
}
});
String rules = null;

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2019 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.fuse.mvnd.builder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class SmartBuilderTest {
@Test
void mvndRuleSanitizerPattern() {
String actual = SmartBuilder.mvndRuleSanitizerPattern.matcher("foo bar,baz,\n foo \n\n bar\n ".trim())
.replaceAll(",");
Assertions.assertEquals("foo,bar,baz,foo,bar", actual);
}
}