Repository: karaf Updated Branches: refs/heads/master ca2a0a71e -> 4feb8827c
[KARAF-4418] Ability to exclude a set of features from the verify goal Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/4feb8827 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/4feb8827 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/4feb8827 Branch: refs/heads/master Commit: 4feb8827c120cdca222ef1f1eb3c95b61edc877e Parents: ca2a0a7 Author: Guillaume Nodet <[email protected]> Authored: Tue May 9 15:57:35 2017 +0200 Committer: Guillaume Nodet <[email protected]> Committed: Tue May 9 15:57:56 2017 +0200 ---------------------------------------------------------------------- .../org/apache/karaf/tooling/VerifyMojo.java | 45 +++++++++++++------ .../apache/karaf/tooling/VerifyMojoTest.java | 46 ++++++++++++++++++++ 2 files changed, 78 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/4feb8827/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java index e94aa00..1d74d9e 100644 --- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java +++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java @@ -114,7 +114,7 @@ public class VerifyMojo extends MojoSupport { protected Set<String> descriptors; @Parameter(property = "features") - protected Set<String> features; + protected List<String> features; @Parameter(property = "framework") protected Set<String> framework; @@ -313,18 +313,7 @@ public class VerifyMojo extends MojoSupport { } } if (features != null && !features.isEmpty()) { - StringBuilder sb = new StringBuilder(); - for (String feature : features) { - if (sb.length() > 0) { - sb.append("|"); - } - String p = feature.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*"); - sb.append(p); - if (!feature.contains("/")) { - sb.append("/.*"); - } - } - Pattern pattern = Pattern.compile(sb.toString()); + Pattern pattern = getPattern(features); for (Iterator<Feature> iterator = featuresToTest.iterator(); iterator.hasNext();) { Feature feature = iterator.next(); String id = feature.getName() + "/" + feature.getVersion(); @@ -394,6 +383,36 @@ public class VerifyMojo extends MojoSupport { } } + static Pattern getPattern(List<String> features) { + StringBuilder sb = new StringBuilder(); + boolean prevIsNeg = false; + for (String feature : features) { + if (sb.length() > 0 && !prevIsNeg) { + sb.append("|"); + } + sb.append("("); + feature = feature.trim(); + boolean negative = feature.startsWith("!"); + if (negative) { + feature = feature.substring("!".length()); + sb.append("(?!"); + } + String p = feature.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*"); + sb.append(p); + if (!feature.contains("/")) { + sb.append("/.*"); + } + if (negative) { + sb.append(")"); + } + prevIsNeg = negative; + } + for (String feature : features) { + sb.append(")"); + } + return Pattern.compile(sb.toString()); + } + private void verifyResolution(DownloadManager manager, final Map<String, Features> repositories, Set<String> features, Hashtable<String, String> properties) throws MojoExecutionException { try { Bundle systemBundle = getSystemBundle(getMetadata(properties, "metadata#")); http://git-wip-us.apache.org/repos/asf/karaf/blob/4feb8827/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/VerifyMojoTest.java ---------------------------------------------------------------------- diff --git a/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/VerifyMojoTest.java b/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/VerifyMojoTest.java new file mode 100644 index 0000000..78683e1 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/VerifyMojoTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.karaf.tooling; + +import org.apache.karaf.tooling.VerifyMojo; +import org.junit.Test; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.regex.Pattern; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class VerifyMojoTest { + + @Test + public void testFeaturePattern() { + Pattern pattern = VerifyMojo.getPattern(Arrays.asList("foobiz", "!foo*", "bar", "!ba*", "*")); + assertTrue(pattern.matcher("foobiz/1.0").matches()); + assertFalse(pattern.matcher("foobaz/1.0").matches()); + assertTrue(pattern.matcher("bar/1.0").matches()); + assertFalse(pattern.matcher("baz/1.0").matches()); + assertTrue(pattern.matcher("biz/1.0").matches()); + + pattern = VerifyMojo.getPattern(Arrays.asList("!hibernate", " *")); + assertTrue(pattern.matcher("framework/4.2.0.SNAPSHOT").matches()); + } + +}
