You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/04/06 13:56:34 UTC

[GitHub] [flink] JingGe commented on a diff in pull request #19377: [FLINK-27048][test] Add ArchUnit rule that connectors should only depend on public API

JingGe commented on code in PR #19377:
URL: https://github.com/apache/flink/pull/19377#discussion_r843980119


##########
flink-architecture-tests/flink-architecture-tests-production/src/main/java/org/apache/flink/architecture/rules/ConnectorRules.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.flink.architecture.rules;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.annotation.Internal;
+
+import com.tngtech.archunit.base.DescribedPredicate;
+import com.tngtech.archunit.core.domain.JavaClass;
+import com.tngtech.archunit.junit.ArchTest;
+import com.tngtech.archunit.lang.ArchRule;
+import com.tngtech.archunit.thirdparty.com.google.common.base.Joiner;
+
+import static com.tngtech.archunit.base.DescribedPredicate.not;
+import static com.tngtech.archunit.core.domain.JavaModifier.PUBLIC;
+import static com.tngtech.archunit.core.domain.properties.HasModifiers.Predicates.modifier;
+import static com.tngtech.archunit.library.freeze.FreezingArchRule.freeze;
+import static org.apache.flink.architecture.common.GivenJavaClasses.noJavaClassesThat;
+import static org.apache.flink.architecture.common.SourcePredicates.areProductionCode;
+
+/** Rules for Flink connectors. */
+public class ConnectorRules {
+    private static final String[] CONNECTOR_PACKAGES = {
+        "org.apache.flink.connector..", "org.apache.flink.streaming.connectors.."
+    };
+
+    private static DescribedPredicate<JavaClass> areNotPublicAndResideOutsideOfPackages(
+            String... packageIdentifiers) {
+        return JavaClass.Predicates.resideOutsideOfPackages(packageIdentifiers)
+                .and(not(modifier(PUBLIC)))
+                .as(
+                        "are not public and reside outside of packages ['%s']",
+                        Joiner.on("', '").join(packageIdentifiers));
+    }
+
+    @ArchTest
+    public static final ArchRule CONNECTOR_CLASSES_ONLY_DEPEND_ON_PUBLIC_API =
+            freeze(
+                    noJavaClassesThat(areProductionCode())
+                            .and()
+                            .resideInAnyPackage(CONNECTOR_PACKAGES)
+                            .and()
+                            .arePublic()
+                            .and()
+                            .areNotAnnotatedWith(Internal.class)
+                            .and()
+                            .areNotAnnotatedWith(Deprecated.class)
+                            .and()
+                            .areNotAnnotatedWith(Experimental.class)
+                            .should()
+                            .dependOnClassesThat(

Review Comment:
   hmmm, does the code mean "Connector production code should depend on non public API outside of CONNECTOR_PACKAGES"?



##########
flink-architecture-tests/flink-architecture-tests-production/src/main/java/org/apache/flink/architecture/rules/ConnectorRules.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.flink.architecture.rules;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.annotation.Internal;
+
+import com.tngtech.archunit.base.DescribedPredicate;
+import com.tngtech.archunit.core.domain.JavaClass;
+import com.tngtech.archunit.junit.ArchTest;
+import com.tngtech.archunit.lang.ArchRule;
+import com.tngtech.archunit.thirdparty.com.google.common.base.Joiner;
+
+import static com.tngtech.archunit.base.DescribedPredicate.not;
+import static com.tngtech.archunit.core.domain.JavaModifier.PUBLIC;
+import static com.tngtech.archunit.core.domain.properties.HasModifiers.Predicates.modifier;
+import static com.tngtech.archunit.library.freeze.FreezingArchRule.freeze;
+import static org.apache.flink.architecture.common.GivenJavaClasses.noJavaClassesThat;
+import static org.apache.flink.architecture.common.SourcePredicates.areProductionCode;
+
+/** Rules for Flink connectors. */
+public class ConnectorRules {
+    private static final String[] CONNECTOR_PACKAGES = {
+        "org.apache.flink.connector..", "org.apache.flink.streaming.connectors.."
+    };
+
+    private static DescribedPredicate<JavaClass> areNotPublicAndResideOutsideOfPackages(
+            String... packageIdentifiers) {
+        return JavaClass.Predicates.resideOutsideOfPackages(packageIdentifiers)
+                .and(not(modifier(PUBLIC)))
+                .as(
+                        "are not public and reside outside of packages ['%s']",
+                        Joiner.on("', '").join(packageIdentifiers));
+    }
+
+    @ArchTest
+    public static final ArchRule CONNECTOR_CLASSES_ONLY_DEPEND_ON_PUBLIC_API =
+            freeze(
+                    noJavaClassesThat(areProductionCode())
+                            .and()
+                            .resideInAnyPackage(CONNECTOR_PACKAGES)
+                            .and()
+                            .arePublic()
+                            .and()
+                            .areNotAnnotatedWith(Internal.class)
+                            .and()
+                            .areNotAnnotatedWith(Deprecated.class)
+                            .and()
+                            .areNotAnnotatedWith(Experimental.class)

Review Comment:
   Both Internal and experimental classes should follow this rule too.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org