[1/2] beam git commit: [BEAM-882, BEAM-883, BEAM-878] Simplified API surface verifications.
Repository: beam Updated Branches: refs/heads/master e21f9ae86 -> 6b31c14fa [BEAM-882,BEAM-883,BEAM-878] Simplified API surface verifications. Project: http://git-wip-us.apache.org/repos/asf/beam/repo Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/cde550fe Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/cde550fe Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/cde550fe Branch: refs/heads/master Commit: cde550fe9b90be5fc9548735d5854359fca6a9cf Parents: e21f9ae Author: Stas Levin Authored: Mon Jan 16 16:20:25 2017 +0200 Committer: Stas Levin Committed: Thu Feb 9 17:40:36 2017 +0200 -- .../org/apache/beam/sdk/util/ApiSurface.java| 446 +-- .../org/apache/beam/SdkCoreApiSurfaceTest.java | 62 +++ .../apache/beam/sdk/util/ApiSurfaceTest.java| 152 ++- .../apache/beam/sdk/io/gcp/ApiSurfaceTest.java | 134 -- .../beam/sdk/io/gcp/GcpApiSurfaceTest.java | 79 5 files changed, 495 insertions(+), 378 deletions(-) -- http://git-wip-us.apache.org/repos/asf/beam/blob/cde550fe/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ApiSurface.java -- diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ApiSurface.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ApiSurface.java index 2040161..9530e88 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ApiSurface.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ApiSurface.java @@ -17,12 +17,21 @@ */ package org.apache.beam.sdk.util; +import static org.hamcrest.Matchers.anyOf; + +import com.google.common.base.Function; import com.google.common.base.Joiner; +import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; +import com.google.common.collect.Ordering; import com.google.common.collect.Sets; import com.google.common.reflect.ClassPath; import com.google.common.reflect.ClassPath.ClassInfo; @@ -45,15 +54,20 @@ import java.util.Collections; import java.util.List; import java.util.Set; import java.util.regex.Pattern; +import javax.annotation.Nonnull; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.StringDescription; +import org.hamcrest.TypeSafeDiagnosingMatcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Represents the API surface of a package prefix. Used for accessing public classes, - * methods, and the types they reference, to control what dependencies are re-exported. + * Represents the API surface of a package prefix. Used for accessing public classes, methods, and + * the types they reference, to control what dependencies are re-exported. * - * For the purposes of calculating the public API surface, exposure includes any public - * or protected occurrence of: + * For the purposes of calculating the public API surface, exposure includes any public or + * protected occurrence of: * * * superclasses @@ -66,45 +80,277 @@ import org.slf4j.LoggerFactory; * wildcard bounds * * - * Exposure is a transitive property. The resulting map excludes primitives - * and array classes themselves. + * Exposure is a transitive property. The resulting map excludes primitives and array classes + * themselves. * - * It is prudent (though not required) to prune prefixes like "java" via the builder - * method {@link #pruningPrefix} to halt the traversal so it does not uselessly catalog references - * that are not interesting. + * It is prudent (though not required) to prune prefixes like "java" via the builder method + * {@link #pruningPrefix} to halt the traversal so it does not uselessly catalog references that are + * not interesting. */ @SuppressWarnings("rawtypes") public class ApiSurface { private static final Logger LOG = LoggerFactory.getLogger(ApiSurface.class); + /** A factory method to create a {@link Class} matcher for classes residing in a given package. */ + public static Matcher> classesInPackage(final String packageName) { +return new Matchers.ClassInPackage(packageName); + } + /** - * Returns an empty {@link ApiSurface}. + * A factory method to create an {@link ApiSurface} matcher, producing a positive match if the + * queried api surface contains ONLY classes described by the provided matchers. */ - public static ApiSurface empty() { -LOG.debug("Returning an empty ApiSurface"); -return new ApiSurface(Collections
[1/2] beam git commit: [BEAM-882, BEAM-883, BEAM-878] Simplified API surface verifications.
Repository: beam Updated Branches: refs/heads/master a1a022d6b -> 26a2c47f4 [BEAM-882,BEAM-883,BEAM-878] Simplified API surface verifications. Project: http://git-wip-us.apache.org/repos/asf/beam/repo Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/29ffaf38 Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/29ffaf38 Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/29ffaf38 Branch: refs/heads/master Commit: 29ffaf3859ba9b4d8ba8529efc96fd5e105e21a3 Parents: a1a022d Author: Stas Levin Authored: Mon Jan 16 16:20:25 2017 +0200 Committer: Kenneth Knowles Committed: Mon Jan 23 13:56:45 2017 -0800 -- .../org/apache/beam/sdk/util/ApiSurface.java| 420 ++- .../org/apache/beam/SdkCoreApiSurfaceTest.java | 61 +++ .../apache/beam/sdk/util/ApiSurfaceTest.java| 152 ++- .../apache/beam/sdk/io/gcp/ApiSurfaceTest.java | 134 -- .../beam/sdk/io/gcp/GcpApiSurfaceTest.java | 76 5 files changed, 484 insertions(+), 359 deletions(-) -- http://git-wip-us.apache.org/repos/asf/beam/blob/29ffaf38/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ApiSurface.java -- diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ApiSurface.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ApiSurface.java index 2040161..b6b0b32 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ApiSurface.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ApiSurface.java @@ -17,12 +17,21 @@ */ package org.apache.beam.sdk.util; +import static org.hamcrest.Matchers.anyOf; + +import com.google.common.base.Function; import com.google.common.base.Joiner; +import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; +import com.google.common.collect.Ordering; import com.google.common.collect.Sets; import com.google.common.reflect.ClassPath; import com.google.common.reflect.ClassPath.ClassInfo; @@ -45,15 +54,20 @@ import java.util.Collections; import java.util.List; import java.util.Set; import java.util.regex.Pattern; +import javax.annotation.Nonnull; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.StringDescription; +import org.hamcrest.TypeSafeDiagnosingMatcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Represents the API surface of a package prefix. Used for accessing public classes, - * methods, and the types they reference, to control what dependencies are re-exported. + * Represents the API surface of a package prefix. Used for accessing public classes, methods, and + * the types they reference, to control what dependencies are re-exported. * - * For the purposes of calculating the public API surface, exposure includes any public - * or protected occurrence of: + * For the purposes of calculating the public API surface, exposure includes any public or + * protected occurrence of: * * * superclasses @@ -66,42 +80,272 @@ import org.slf4j.LoggerFactory; * wildcard bounds * * - * Exposure is a transitive property. The resulting map excludes primitives - * and array classes themselves. + * Exposure is a transitive property. The resulting map excludes primitives and array classes + * themselves. * - * It is prudent (though not required) to prune prefixes like "java" via the builder - * method {@link #pruningPrefix} to halt the traversal so it does not uselessly catalog references - * that are not interesting. + * It is prudent (though not required) to prune prefixes like "java" via the builder method + * {@link #pruningPrefix} to halt the traversal so it does not uselessly catalog references that are + * not interesting. */ @SuppressWarnings("rawtypes") public class ApiSurface { private static final Logger LOG = LoggerFactory.getLogger(ApiSurface.class); + /** A factory method to create a {@link Class} matcher for classes residing in a given package. */ + public static Matcher> classesInPackage(final String packageName) { +return new Matchers.ClassInPackage(packageName); + } + + /** + * A factory method to create an {@link ApiSurface} matcher, producing a positive match if the + * queried api surface contains ONLY classes described by the provided matchers. + */ + public static Matcher containsOnlyClassesMatching( + final Set>> classMatchers) { +return new Matchers.ClassesInSurfaceMatcher(classMatchers); + } +