From 10750c3a7c7525f405b028832e0a521293f799ca Mon Sep 17 00:00:00 2001 From: Jeff Gaston Date: Tue, 27 Jun 2017 17:59:01 +0000 Subject: Revert "Add ClassnameMatcher in preparation to pass into Instrumenter for filtering" This reverts commit bbe2e9a9b2c9f829bc5e906c218244205c5bfbab. Reason for revert: moving filtering out of Jacoco and into Make Change-Id: I58b9c4eb1fc6d6984cf7cb4b9dd74bdbcf4f8956 --- .../agent/rt/internal/CoverageTransformer.java | 8 ++- .../core/matcher/IncludeExcludeMatcherTest.java | 75 -------------------- .../jacoco/core/matcher/WildcardMatcherTest.java | 44 ++++++------ .../org/jacoco/core/matcher/ClassnameMatcher.java | 80 ---------------------- .../jacoco/core/matcher/IncludeExcludeMatcher.java | 67 ------------------ .../src/org/jacoco/core/matcher/Predicate.java | 24 ------- .../org/jacoco/core/matcher/WildcardMatcher.java | 5 +- .../src/org/jacoco/report/check/Rule.java | 2 +- 8 files changed, 30 insertions(+), 275 deletions(-) delete mode 100644 org.jacoco.core.test/src/org/jacoco/core/matcher/IncludeExcludeMatcherTest.java delete mode 100644 org.jacoco.core/src/org/jacoco/core/matcher/ClassnameMatcher.java delete mode 100644 org.jacoco.core/src/org/jacoco/core/matcher/IncludeExcludeMatcher.java delete mode 100644 org.jacoco.core/src/org/jacoco/core/matcher/Predicate.java diff --git a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java index cbd6a62b..2cb16fed 100644 --- a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java +++ b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java @@ -120,14 +120,16 @@ public class CoverageTransformer implements ClassFileTransformer { if (!inclNoLocationClasses && !hasSourceLocation(protectionDomain)) { return false; } - if (exclClassloader.apply(loader.getClass().getName())) { + if (exclClassloader.matches(loader.getClass().getName())) { return false; } } return !classname.startsWith(AGENT_PREFIX) && - includes.apply(classname) && - !excludes.apply(classname); + + includes.matches(classname) && + + !excludes.matches(classname); } /** diff --git a/org.jacoco.core.test/src/org/jacoco/core/matcher/IncludeExcludeMatcherTest.java b/org.jacoco.core.test/src/org/jacoco/core/matcher/IncludeExcludeMatcherTest.java deleted file mode 100644 index e0268956..00000000 --- a/org.jacoco.core.test/src/org/jacoco/core/matcher/IncludeExcludeMatcherTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Jeffry Gaston - initial API and implementation - * - *******************************************************************************/ -package org.jacoco.core.matcher; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class IncludeExcludeMatcherTest { - - @Test - public void testEmpty() { - assertTrue(new IncludeExcludeMatcher().apply("includeMe")); - } - - @Test - public void testSingleExclude() { - IncludeExcludeMatcher matcher = new IncludeExcludeMatcher() - .exclude(new WildcardMatcher("excluded")); - assertTrue(matcher.apply("included")); - assertFalse(matcher.apply("excluded")); - } - - @Test - public void testMultipleExcludes() { - IncludeExcludeMatcher matcher = new IncludeExcludeMatcher().exclude( - new WildcardMatcher("excluded")) - .exclude(new WildcardMatcher("excluded2")); - assertTrue(matcher.apply("included")); - assertFalse(matcher.apply("excluded")); - assertFalse(matcher.apply("excluded2")); - } - - @Test - public void testSingleInclude() { - IncludeExcludeMatcher matcher = new IncludeExcludeMatcher() - .include(new WildcardMatcher("include me")); - assertTrue(matcher.apply("include me")); - assertFalse(matcher.apply("not me")); - } - - @Test - public void testIncludesAndExcludes() { - IncludeExcludeMatcher matcher = new IncludeExcludeMatcher() - .include(new WildcardMatcher("inclusion1")) - .include(new WildcardMatcher("me too")) - .exclude(new WildcardMatcher("not me")) - .exclude(new WildcardMatcher("nope")); - assertTrue(matcher.apply("inclusion1")); - assertTrue(matcher.apply("me too")); - assertFalse(matcher.apply("not me")); - assertFalse(matcher.apply("nope")); - assertFalse(matcher.apply("other")); - } - - @Test - public void testExcludedInclusion() { - IncludeExcludeMatcher matcher = new IncludeExcludeMatcher() - .include(new WildcardMatcher("a")) - .exclude(new WildcardMatcher("a")); - assertFalse(matcher.apply("a")); - assertFalse(matcher.apply("b")); - } - -} diff --git a/org.jacoco.core.test/src/org/jacoco/core/matcher/WildcardMatcherTest.java b/org.jacoco.core.test/src/org/jacoco/core/matcher/WildcardMatcherTest.java index baf1dc2b..0d0a9c0a 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/matcher/WildcardMatcherTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/matcher/WildcardMatcherTest.java @@ -20,53 +20,53 @@ public class WildcardMatcherTest { @Test public void testEmpty() { - assertTrue(new WildcardMatcher("").apply("")); - assertFalse(new WildcardMatcher("").apply("abc")); + assertTrue(new WildcardMatcher("").matches("")); + assertFalse(new WildcardMatcher("").matches("abc")); } @Test public void testExact() { - assertTrue(new WildcardMatcher("abc/def.txt").apply("abc/def.txt")); + assertTrue(new WildcardMatcher("abc/def.txt").matches("abc/def.txt")); } @Test public void testCaseSensitive() { - assertFalse(new WildcardMatcher("abcdef").apply("abcDef")); - assertFalse(new WildcardMatcher("ABCDEF").apply("AbCDEF")); + assertFalse(new WildcardMatcher("abcdef").matches("abcDef")); + assertFalse(new WildcardMatcher("ABCDEF").matches("AbCDEF")); } @Test public void testQuote() { - assertFalse(new WildcardMatcher("rst.xyz").apply("rstAxyz")); - assertTrue(new WildcardMatcher("(x)+").apply("(x)+")); + assertFalse(new WildcardMatcher("rst.xyz").matches("rstAxyz")); + assertTrue(new WildcardMatcher("(x)+").matches("(x)+")); } @Test public void testWildcards() { - assertTrue(new WildcardMatcher("*").apply("")); - assertTrue(new WildcardMatcher("*").apply("java/lang/Object")); - assertTrue(new WildcardMatcher("*Test").apply("jacoco/MatcherTest")); - assertTrue(new WildcardMatcher("Matcher*").apply("Matcher")); - assertTrue(new WildcardMatcher("Matcher*").apply("MatcherTest")); - assertTrue(new WildcardMatcher("a*b*a").apply("a-b-b-a")); - assertFalse(new WildcardMatcher("a*b*a").apply("alaska")); - assertTrue(new WildcardMatcher("Hello?orld").apply("HelloWorld")); - assertFalse(new WildcardMatcher("Hello?orld").apply("HelloWWWorld")); - assertTrue(new WildcardMatcher("?aco*").apply("jacoco")); + assertTrue(new WildcardMatcher("*").matches("")); + assertTrue(new WildcardMatcher("*").matches("java/lang/Object")); + assertTrue(new WildcardMatcher("*Test").matches("jacoco/MatcherTest")); + assertTrue(new WildcardMatcher("Matcher*").matches("Matcher")); + assertTrue(new WildcardMatcher("Matcher*").matches("MatcherTest")); + assertTrue(new WildcardMatcher("a*b*a").matches("a-b-b-a")); + assertFalse(new WildcardMatcher("a*b*a").matches("alaska")); + assertTrue(new WildcardMatcher("Hello?orld").matches("HelloWorld")); + assertFalse(new WildcardMatcher("Hello?orld").matches("HelloWWWorld")); + assertTrue(new WildcardMatcher("?aco*").matches("jacoco")); } @Test public void testMultiExpression() { - assertTrue(new WildcardMatcher("Hello:World").apply("World")); - assertTrue(new WildcardMatcher("Hello:World").apply("World")); - assertTrue(new WildcardMatcher("*Test:*Foo").apply("UnitTest")); + assertTrue(new WildcardMatcher("Hello:World").matches("World")); + assertTrue(new WildcardMatcher("Hello:World").matches("World")); + assertTrue(new WildcardMatcher("*Test:*Foo").matches("UnitTest")); } @Test public void testDollar() { - assertTrue(new WildcardMatcher("*$*").apply("java/util/Map$Entry")); + assertTrue(new WildcardMatcher("*$*").matches("java/util/Map$Entry")); assertTrue(new WildcardMatcher("*$$$*") - .apply("org/example/Enity$$$generated123")); + .matches("org/example/Enity$$$generated123")); } } diff --git a/org.jacoco.core/src/org/jacoco/core/matcher/ClassnameMatcher.java b/org.jacoco.core/src/org/jacoco/core/matcher/ClassnameMatcher.java deleted file mode 100644 index 939bd5fe..00000000 --- a/org.jacoco.core/src/org/jacoco/core/matcher/ClassnameMatcher.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Jeffry Gaston - initial API and implementation - * - *******************************************************************************/ - -package org.jacoco.core.matcher; - -import java.util.List; - -import org.objectweb.asm.ClassReader; - -/** - * A ClassnameMatcher matches ClassReader objects based on their class name - */ -public class ClassnameMatcher implements Predicate { - private IncludeExcludeMatcher matcher = new IncludeExcludeMatcher(); - - /** - * Includes the given pattern from the matches of this matcher - * @param pattern to include - * @return this object (for chaining) - */ - public ClassnameMatcher include(String pattern) { - matcher.include(new WildcardMatcher(pattern)); - return this; - } - - /** - * Adds the given patterns as inclusions for this matcher - * @param patterns patterns to include - * @return this object (for chaining) - */ - public ClassnameMatcher include(List patterns) { - for (String pattern : patterns) { - include(pattern); - } - return this; - } - - /** - * As the given pattern as an exclusion for this matcher - * @param pattern pattern to exclude - * @return this object (for chaining) - */ - public ClassnameMatcher exclude(String pattern) { - matcher.exclude(new WildcardMatcher(pattern)); - return this; - } - - /** - * As the given patterns as exclusions for this matcher - * @param patterns patterns to include - * @return this object (for chaining) - */ - public ClassnameMatcher exclude(List patterns) { - for (String pattern : patterns) { - exclude(pattern); - } - return this; - } - - - /** - * Tells whether this matcher matches this class reader - * @param classReader the reader to match - * @return whether this matcher matches - */ - @Override - public boolean apply(ClassReader classReader) { - return matcher.apply(classReader.getClassName().replaceAll("/", ".")); - } - -} diff --git a/org.jacoco.core/src/org/jacoco/core/matcher/IncludeExcludeMatcher.java b/org.jacoco.core/src/org/jacoco/core/matcher/IncludeExcludeMatcher.java deleted file mode 100644 index 50f1d886..00000000 --- a/org.jacoco.core/src/org/jacoco/core/matcher/IncludeExcludeMatcher.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Jeffry Gaston - initial API and implementation - * - *******************************************************************************/ -package org.jacoco.core.matcher; - -import java.util.ArrayList; -import java.util.List; - -/** - * An IncludeExcludeMatcher matches a given input if - * at least one inclusion matches and no exclusions match. - */ -public class IncludeExcludeMatcher implements Predicate { - private List> inclusions = new ArrayList>(); - private List> exclusions = new ArrayList>(); - - /** - * Includes the given matcher - * @param inclusion new matcher to include - * @return this object (for chaining several calls) - */ - public IncludeExcludeMatcher include(Predicate inclusion) { - inclusions.add(inclusion); - return this; - } - - /** - * Excludes a given matcher - * @param exclusion - * @return this object (for chaining several calls) - */ - public IncludeExcludeMatcher exclude(Predicate exclusion) { - exclusions.add(exclusion); - return this; - } - - /** - * Tells whether this matcher matches this string - * @param input the string match - * @return whether the matcher matches - */ - @Override - public boolean apply(T input) { - // doesn't match if an exclusion matches - for (Predicate exclusion : exclusions) { - if (exclusion.apply(input)) { - return false; - } - } - // does match if an inclusion matches - for (Predicate inclusion : inclusions) { - if (inclusion.apply(input)) { - return true; - } - } - // no match; choose a default based on whether any includes were given - return (inclusions.size() == 0); - } -} diff --git a/org.jacoco.core/src/org/jacoco/core/matcher/Predicate.java b/org.jacoco.core/src/org/jacoco/core/matcher/Predicate.java deleted file mode 100644 index 14d084b1..00000000 --- a/org.jacoco.core/src/org/jacoco/core/matcher/Predicate.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Jeffry Gaston - initial API and implementation - * - *******************************************************************************/ -package org.jacoco.core.matcher; - -/** - * A simple interface telling whether a predicate matches an input. - * Once the minimum supported version of Java is Java 1.8, then this can be replaced with the - * built-in Java predicate. - * While it could work to add a dependency on a library providing a similar interface, we prefer - * to keep the number of dependencies low, to avoid forcing other dependencies onto - * any builds that depend on Jacoco. - */ -public interface Predicate { - boolean apply(final T s); -} diff --git a/org.jacoco.core/src/org/jacoco/core/matcher/WildcardMatcher.java b/org.jacoco.core/src/org/jacoco/core/matcher/WildcardMatcher.java index 6ae20c4f..9e7bd871 100644 --- a/org.jacoco.core/src/org/jacoco/core/matcher/WildcardMatcher.java +++ b/org.jacoco.core/src/org/jacoco/core/matcher/WildcardMatcher.java @@ -18,7 +18,7 @@ import java.util.regex.Pattern; * Multiple expressions can be separated with a colon (:). In this case the * expression matches if at least one part matches. */ -public class WildcardMatcher implements Predicate { +public class WildcardMatcher { private final Pattern pattern; @@ -67,8 +67,7 @@ public class WildcardMatcher implements Predicate { * string to test * @return true, if the expression matches */ - @Override - public boolean apply(final String s) { + public boolean matches(final String s) { return pattern.matcher(s).matches(); } diff --git a/org.jacoco.report/src/org/jacoco/report/check/Rule.java b/org.jacoco.report/src/org/jacoco/report/check/Rule.java index f424e81f..acf90586 100644 --- a/org.jacoco.report/src/org/jacoco/report/check/Rule.java +++ b/org.jacoco.report/src/org/jacoco/report/check/Rule.java @@ -116,7 +116,7 @@ public final class Rule { } boolean matches(final String name) { - return includesMatcher.apply(name) && !excludesMatcher.apply(name); + return includesMatcher.matches(name) && !excludesMatcher.matches(name); } } -- cgit v1.2.3 From fcf5caec3dd6cbd161b22f5500d73ef22bf4b447 Mon Sep 17 00:00:00 2001 From: Jeff Gaston Date: Tue, 27 Jun 2017 20:14:39 +0000 Subject: Revert "Move WildcardMatcher into new 'matcher' package" This reverts commit 8da25e49bc72ec3a2455080c53c0dc2006decd7d. Reason for revert: moving filtering out of Jacoco and into Make Change-Id: I976ae531b8bdd15b87c4c7fcfb1899d379bbc929 --- .../agent/rt/internal/CoverageTransformer.java | 2 +- .../jacoco/core/matcher/WildcardMatcherTest.java | 72 --------------------- .../jacoco/core/runtime/WildcardMatcherTest.java | 72 +++++++++++++++++++++ .../org/jacoco/core/matcher/WildcardMatcher.java | 74 ---------------------- .../src/org/jacoco/core/runtime/AgentOptions.java | 1 - .../org/jacoco/core/runtime/WildcardMatcher.java | 74 ++++++++++++++++++++++ .../src/org/jacoco/report/check/Rule.java | 2 +- 7 files changed, 148 insertions(+), 149 deletions(-) delete mode 100644 org.jacoco.core.test/src/org/jacoco/core/matcher/WildcardMatcherTest.java create mode 100644 org.jacoco.core.test/src/org/jacoco/core/runtime/WildcardMatcherTest.java delete mode 100644 org.jacoco.core/src/org/jacoco/core/matcher/WildcardMatcher.java create mode 100644 org.jacoco.core/src/org/jacoco/core/runtime/WildcardMatcher.java diff --git a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java index 2cb16fed..53d12387 100644 --- a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java +++ b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java @@ -19,7 +19,7 @@ import java.security.ProtectionDomain; import org.jacoco.core.instr.Instrumenter; import org.jacoco.core.runtime.AgentOptions; import org.jacoco.core.runtime.IRuntime; -import org.jacoco.core.matcher.WildcardMatcher; +import org.jacoco.core.runtime.WildcardMatcher; /** * Class file transformer to instrument classes for code coverage analysis. diff --git a/org.jacoco.core.test/src/org/jacoco/core/matcher/WildcardMatcherTest.java b/org.jacoco.core.test/src/org/jacoco/core/matcher/WildcardMatcherTest.java deleted file mode 100644 index 0d0a9c0a..00000000 --- a/org.jacoco.core.test/src/org/jacoco/core/matcher/WildcardMatcherTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Marc R. Hoffmann - initial API and implementation - * - *******************************************************************************/ -package org.jacoco.core.matcher; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class WildcardMatcherTest { - - @Test - public void testEmpty() { - assertTrue(new WildcardMatcher("").matches("")); - assertFalse(new WildcardMatcher("").matches("abc")); - } - - @Test - public void testExact() { - assertTrue(new WildcardMatcher("abc/def.txt").matches("abc/def.txt")); - } - - @Test - public void testCaseSensitive() { - assertFalse(new WildcardMatcher("abcdef").matches("abcDef")); - assertFalse(new WildcardMatcher("ABCDEF").matches("AbCDEF")); - } - - @Test - public void testQuote() { - assertFalse(new WildcardMatcher("rst.xyz").matches("rstAxyz")); - assertTrue(new WildcardMatcher("(x)+").matches("(x)+")); - } - - @Test - public void testWildcards() { - assertTrue(new WildcardMatcher("*").matches("")); - assertTrue(new WildcardMatcher("*").matches("java/lang/Object")); - assertTrue(new WildcardMatcher("*Test").matches("jacoco/MatcherTest")); - assertTrue(new WildcardMatcher("Matcher*").matches("Matcher")); - assertTrue(new WildcardMatcher("Matcher*").matches("MatcherTest")); - assertTrue(new WildcardMatcher("a*b*a").matches("a-b-b-a")); - assertFalse(new WildcardMatcher("a*b*a").matches("alaska")); - assertTrue(new WildcardMatcher("Hello?orld").matches("HelloWorld")); - assertFalse(new WildcardMatcher("Hello?orld").matches("HelloWWWorld")); - assertTrue(new WildcardMatcher("?aco*").matches("jacoco")); - } - - @Test - public void testMultiExpression() { - assertTrue(new WildcardMatcher("Hello:World").matches("World")); - assertTrue(new WildcardMatcher("Hello:World").matches("World")); - assertTrue(new WildcardMatcher("*Test:*Foo").matches("UnitTest")); - } - - @Test - public void testDollar() { - assertTrue(new WildcardMatcher("*$*").matches("java/util/Map$Entry")); - assertTrue(new WildcardMatcher("*$$$*") - .matches("org/example/Enity$$$generated123")); - } - -} diff --git a/org.jacoco.core.test/src/org/jacoco/core/runtime/WildcardMatcherTest.java b/org.jacoco.core.test/src/org/jacoco/core/runtime/WildcardMatcherTest.java new file mode 100644 index 00000000..10e012c4 --- /dev/null +++ b/org.jacoco.core.test/src/org/jacoco/core/runtime/WildcardMatcherTest.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Marc R. Hoffmann - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.runtime; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class WildcardMatcherTest { + + @Test + public void testEmpty() { + assertTrue(new WildcardMatcher("").matches("")); + assertFalse(new WildcardMatcher("").matches("abc")); + } + + @Test + public void testExact() { + assertTrue(new WildcardMatcher("abc/def.txt").matches("abc/def.txt")); + } + + @Test + public void testCaseSensitive() { + assertFalse(new WildcardMatcher("abcdef").matches("abcDef")); + assertFalse(new WildcardMatcher("ABCDEF").matches("AbCDEF")); + } + + @Test + public void testQuote() { + assertFalse(new WildcardMatcher("rst.xyz").matches("rstAxyz")); + assertTrue(new WildcardMatcher("(x)+").matches("(x)+")); + } + + @Test + public void testWildcards() { + assertTrue(new WildcardMatcher("*").matches("")); + assertTrue(new WildcardMatcher("*").matches("java/lang/Object")); + assertTrue(new WildcardMatcher("*Test").matches("jacoco/MatcherTest")); + assertTrue(new WildcardMatcher("Matcher*").matches("Matcher")); + assertTrue(new WildcardMatcher("Matcher*").matches("MatcherTest")); + assertTrue(new WildcardMatcher("a*b*a").matches("a-b-b-a")); + assertFalse(new WildcardMatcher("a*b*a").matches("alaska")); + assertTrue(new WildcardMatcher("Hello?orld").matches("HelloWorld")); + assertFalse(new WildcardMatcher("Hello?orld").matches("HelloWWWorld")); + assertTrue(new WildcardMatcher("?aco*").matches("jacoco")); + } + + @Test + public void testMultiExpression() { + assertTrue(new WildcardMatcher("Hello:World").matches("World")); + assertTrue(new WildcardMatcher("Hello:World").matches("World")); + assertTrue(new WildcardMatcher("*Test:*Foo").matches("UnitTest")); + } + + @Test + public void testDollar() { + assertTrue(new WildcardMatcher("*$*").matches("java/util/Map$Entry")); + assertTrue(new WildcardMatcher("*$$$*") + .matches("org/example/Enity$$$generated123")); + } + +} diff --git a/org.jacoco.core/src/org/jacoco/core/matcher/WildcardMatcher.java b/org.jacoco.core/src/org/jacoco/core/matcher/WildcardMatcher.java deleted file mode 100644 index 9e7bd871..00000000 --- a/org.jacoco.core/src/org/jacoco/core/matcher/WildcardMatcher.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Marc R. Hoffmann - initial API and implementation - * - *******************************************************************************/ -package org.jacoco.core.matcher; - -import java.util.regex.Pattern; - -/** - * Matches strings against ?/* wildcard expressions. - * Multiple expressions can be separated with a colon (:). In this case the - * expression matches if at least one part matches. - */ -public class WildcardMatcher { - - private final Pattern pattern; - - /** - * Creates a new matcher with the given expression. - * - * @param expression - * wildcard expressions - */ - public WildcardMatcher(final String expression) { - final String[] parts = expression.split("\\:"); - final StringBuilder regex = new StringBuilder(expression.length() * 2); - boolean next = false; - for (final String part : parts) { - if (next) { - regex.append('|'); - } - regex.append('(').append(toRegex(part)).append(')'); - next = true; - } - pattern = Pattern.compile(regex.toString()); - } - - private static CharSequence toRegex(final String expression) { - final StringBuilder regex = new StringBuilder(expression.length() * 2); - for (final char c : expression.toCharArray()) { - switch (c) { - case '?': - regex.append(".?"); - break; - case '*': - regex.append(".*"); - break; - default: - regex.append(Pattern.quote(String.valueOf(c))); - break; - } - } - return regex; - } - - /** - * Matches the given string against the expressions of this matcher. - * - * @param s - * string to test - * @return true, if the expression matches - */ - public boolean matches(final String s) { - return pattern.matcher(s).matches(); - } - -} diff --git a/org.jacoco.core/src/org/jacoco/core/runtime/AgentOptions.java b/org.jacoco.core/src/org/jacoco/core/runtime/AgentOptions.java index 6b4fb0c5..cf575127 100644 --- a/org.jacoco.core/src/org/jacoco/core/runtime/AgentOptions.java +++ b/org.jacoco.core/src/org/jacoco/core/runtime/AgentOptions.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.regex.Pattern; -import org.jacoco.core.matcher.WildcardMatcher; /** * Utility to create and parse options for the runtime agent. Options are diff --git a/org.jacoco.core/src/org/jacoco/core/runtime/WildcardMatcher.java b/org.jacoco.core/src/org/jacoco/core/runtime/WildcardMatcher.java new file mode 100644 index 00000000..221e6ea5 --- /dev/null +++ b/org.jacoco.core/src/org/jacoco/core/runtime/WildcardMatcher.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Marc R. Hoffmann - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.runtime; + +import java.util.regex.Pattern; + +/** + * Matches strings against ?/* wildcard expressions. + * Multiple expressions can be separated with a colon (:). In this case the + * expression matches if at least one part matches. + */ +public class WildcardMatcher { + + private final Pattern pattern; + + /** + * Creates a new matcher with the given expression. + * + * @param expression + * wildcard expressions + */ + public WildcardMatcher(final String expression) { + final String[] parts = expression.split("\\:"); + final StringBuilder regex = new StringBuilder(expression.length() * 2); + boolean next = false; + for (final String part : parts) { + if (next) { + regex.append('|'); + } + regex.append('(').append(toRegex(part)).append(')'); + next = true; + } + pattern = Pattern.compile(regex.toString()); + } + + private static CharSequence toRegex(final String expression) { + final StringBuilder regex = new StringBuilder(expression.length() * 2); + for (final char c : expression.toCharArray()) { + switch (c) { + case '?': + regex.append(".?"); + break; + case '*': + regex.append(".*"); + break; + default: + regex.append(Pattern.quote(String.valueOf(c))); + break; + } + } + return regex; + } + + /** + * Matches the given string against the expressions of this matcher. + * + * @param s + * string to test + * @return true, if the expression matches + */ + public boolean matches(final String s) { + return pattern.matcher(s).matches(); + } + +} diff --git a/org.jacoco.report/src/org/jacoco/report/check/Rule.java b/org.jacoco.report/src/org/jacoco/report/check/Rule.java index acf90586..f34c6cdf 100644 --- a/org.jacoco.report/src/org/jacoco/report/check/Rule.java +++ b/org.jacoco.report/src/org/jacoco/report/check/Rule.java @@ -15,7 +15,7 @@ import java.util.ArrayList; import java.util.List; import org.jacoco.core.analysis.ICoverageNode.ElementType; -import org.jacoco.core.matcher.WildcardMatcher; +import org.jacoco.core.runtime.WildcardMatcher; /** * A rule applies for a certain element type and can define any number of limits -- cgit v1.2.3 From 538809f567aed4d19e14bdb4a4e867d48ccf1b86 Mon Sep 17 00:00:00 2001 From: Jeff Gaston Date: Mon, 26 Jun 2017 17:33:59 -0700 Subject: Copy jacoco-cli into dist directory Test: m -j ANDROID_COMPILE_WITH_JACK=false EMMA_INSTRUMENT=true dist && stat out/dist/jacoco-cli.jar Bug: 36792868 Change-Id: Ifa3a235a09ee586109e6fa7fa1df5045d870ab8b --- Android.mk | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Android.mk b/Android.mk index 1804e6df..5ba54801 100644 --- a/Android.mk +++ b/Android.mk @@ -68,6 +68,13 @@ LOCAL_STATIC_JAVA_LIBRARIES := jacoco-asm-host args4j-2.0.28 include $(BUILD_HOST_JAVA_LIBRARY) +# include jacoco-cli in the dist directory to enable running it to generate a code-coverage report +ifeq ($(ANDROID_COMPILE_WITH_JACK),false) +ifeq ($(EMMA_INSTRUMENT),true) +$(call dist-for-goals, dist_files, $(LOCAL_INSTALLED_MODULE)) +endif +endif + # # Build asm-5.0.1 as a static library for the device -- cgit v1.2.3