Airblader commented on a change in pull request #17133:
URL: https://github.com/apache/flink/pull/17133#discussion_r753679075



##########
File path: 
flink-architecture-tests/src/test/java/org/apache/flink/architecture/rules/ApiAnnotationRules.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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 org.apache.flink.annotation.Public;
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.annotation.VisibleForTesting;
+
+import com.tngtech.archunit.base.DescribedPredicate;
+import com.tngtech.archunit.core.domain.JavaMethodCall;
+import com.tngtech.archunit.junit.ArchTest;
+import com.tngtech.archunit.lang.ArchRule;
+
+import static 
com.tngtech.archunit.core.domain.JavaClass.Predicates.resideOutsideOfPackage;
+import static 
com.tngtech.archunit.core.domain.properties.CanBeAnnotated.Predicates.annotatedWith;
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
+import static com.tngtech.archunit.library.freeze.FreezingArchRule.freeze;
+import static org.apache.flink.architecture.common.Conditions.fulfill;
+import static 
org.apache.flink.architecture.common.Conditions.haveLeafArgumentTypes;
+import static 
org.apache.flink.architecture.common.Conditions.haveLeafReturnTypes;
+import static 
org.apache.flink.architecture.common.GivenJavaClasses.javaClassesThat;
+import static 
org.apache.flink.architecture.common.GivenJavaClasses.noJavaClassesThat;
+import static 
org.apache.flink.architecture.common.Predicates.areDirectlyAnnotatedWithAtLeastOneOf;
+import static 
org.apache.flink.architecture.common.SourcePredicates.areJavaClasses;
+import static 
org.apache.flink.architecture.common.SourcePredicates.areProductionCode;
+
+/** Rules for API visibility annotations. */
+public class ApiAnnotationRules {
+
+    @ArchTest
+    public static final ArchRule ANNOTATED_APIS =
+            freeze(
+                    javaClassesThat()
+                            .resideInAPackage("org.apache.flink..api..")
+                            .and()
+                            .resideOutsideOfPackage("..internal..")
+                            .and()
+                            .arePublic()
+                            .should(
+                                    fulfill(
+                                            
areDirectlyAnnotatedWithAtLeastOneOf(
+                                                    Internal.class,
+                                                    Experimental.class,
+                                                    PublicEvolving.class,
+                                                    Public.class,
+                                                    Deprecated.class)))
+                            .as(
+                                    "Classes in API packages should have at 
least one API visibility annotation."));
+
+    /**
+     * This is a stronger requirement than {@link
+     * #PUBLIC_EVOLVING_API_METHODS_USE_ONLY_PUBLIC_EVOLVING_API_TYPES} and 
ensures that {@link
+     * Public} APIs do not use {@link PublicEvolving} APIs.
+     */
+    @ArchTest
+    public static final ArchRule PUBLIC_API_METHODS_USE_ONLY_PUBLIC_API_TYPES =
+            freeze(
+                    methods()
+                            .that()
+                            .areDeclaredInClassesThat(
+                                    
areJavaClasses().and(annotatedWith(Public.class)))
+                            .and()
+                            .arePublic()
+                            .and()
+                            .areNotAnnotatedWith(Internal.class)
+                            .and()
+                            .areNotAnnotatedWith(Deprecated.class)
+                            .should(
+                                    haveLeafReturnTypes(
+                                            
resideOutsideOfPackage("org.apache.flink..")
+                                                    .or(
+                                                            
areDirectlyAnnotatedWithAtLeastOneOf(
+                                                                    
Public.class,
+                                                                    
Deprecated.class))))
+                            .andShould(
+                                    haveLeafArgumentTypes(
+                                            
resideOutsideOfPackage("org.apache.flink..")
+                                                    .or(
+                                                            
areDirectlyAnnotatedWithAtLeastOneOf(
+                                                                    
Public.class,
+                                                                    
Deprecated.class))))
+                            .as(
+                                    "Return and argument types of methods 
annotated with @Public must be annotated with @Public, too."));
+
+    @ArchTest
+    public static final ArchRule 
PUBLIC_EVOLVING_API_METHODS_USE_ONLY_PUBLIC_EVOLVING_API_TYPES =
+            freeze(
+                    methods()
+                            .that()
+                            .areDeclaredInClassesThat(

Review comment:
       Maybe we can expand this to "or the method is annotated PublicEvolving"

##########
File path: 
flink-architecture-tests/src/test/java/org/apache/flink/architecture/rules/ApiAnnotationRules.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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 org.apache.flink.annotation.Public;
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.annotation.VisibleForTesting;
+
+import com.tngtech.archunit.base.DescribedPredicate;
+import com.tngtech.archunit.core.domain.JavaMethodCall;
+import com.tngtech.archunit.junit.ArchTest;
+import com.tngtech.archunit.lang.ArchRule;
+
+import static 
com.tngtech.archunit.core.domain.JavaClass.Predicates.resideOutsideOfPackage;
+import static 
com.tngtech.archunit.core.domain.properties.CanBeAnnotated.Predicates.annotatedWith;
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
+import static com.tngtech.archunit.library.freeze.FreezingArchRule.freeze;
+import static org.apache.flink.architecture.common.Conditions.fulfill;
+import static 
org.apache.flink.architecture.common.Conditions.haveLeafArgumentTypes;
+import static 
org.apache.flink.architecture.common.Conditions.haveLeafReturnTypes;
+import static 
org.apache.flink.architecture.common.GivenJavaClasses.javaClassesThat;
+import static 
org.apache.flink.architecture.common.GivenJavaClasses.noJavaClassesThat;
+import static 
org.apache.flink.architecture.common.Predicates.areDirectlyAnnotatedWithAtLeastOneOf;
+import static 
org.apache.flink.architecture.common.SourcePredicates.areJavaClasses;
+import static 
org.apache.flink.architecture.common.SourcePredicates.areProductionCode;
+
+/** Rules for API visibility annotations. */
+public class ApiAnnotationRules {
+
+    @ArchTest
+    public static final ArchRule ANNOTATED_APIS =
+            freeze(
+                    javaClassesThat()
+                            .resideInAPackage("org.apache.flink..api..")
+                            .and()
+                            .resideOutsideOfPackage("..internal..")
+                            .and()
+                            .arePublic()
+                            .should(
+                                    fulfill(
+                                            
areDirectlyAnnotatedWithAtLeastOneOf(
+                                                    Internal.class,
+                                                    Experimental.class,
+                                                    PublicEvolving.class,
+                                                    Public.class,
+                                                    Deprecated.class)))
+                            .as(
+                                    "Classes in API packages should have at 
least one API visibility annotation."));
+
+    /**
+     * This is a stronger requirement than {@link
+     * #PUBLIC_EVOLVING_API_METHODS_USE_ONLY_PUBLIC_EVOLVING_API_TYPES} and 
ensures that {@link
+     * Public} APIs do not use {@link PublicEvolving} APIs.
+     */
+    @ArchTest
+    public static final ArchRule PUBLIC_API_METHODS_USE_ONLY_PUBLIC_API_TYPES =
+            freeze(
+                    methods()
+                            .that()
+                            .areDeclaredInClassesThat(
+                                    
areJavaClasses().and(annotatedWith(Public.class)))
+                            .and()
+                            .arePublic()
+                            .and()
+                            .areNotAnnotatedWith(Internal.class)
+                            .and()
+                            .areNotAnnotatedWith(Deprecated.class)
+                            .should(
+                                    haveLeafReturnTypes(
+                                            
resideOutsideOfPackage("org.apache.flink..")
+                                                    .or(
+                                                            
areDirectlyAnnotatedWithAtLeastOneOf(
+                                                                    
Public.class,
+                                                                    
Deprecated.class))))
+                            .andShould(
+                                    haveLeafArgumentTypes(
+                                            
resideOutsideOfPackage("org.apache.flink..")
+                                                    .or(
+                                                            
areDirectlyAnnotatedWithAtLeastOneOf(
+                                                                    
Public.class,
+                                                                    
Deprecated.class))))
+                            .as(
+                                    "Return and argument types of methods 
annotated with @Public must be annotated with @Public, too."));
+
+    @ArchTest
+    public static final ArchRule 
PUBLIC_EVOLVING_API_METHODS_USE_ONLY_PUBLIC_EVOLVING_API_TYPES =
+            freeze(
+                    methods()
+                            .that()
+                            .areDeclaredInClassesThat(
+                                    areJavaClasses()
+                                            .and(
+                                                    
areDirectlyAnnotatedWithAtLeastOneOf(
+                                                            Public.class, 
PublicEvolving.class)))
+                            .and()
+                            .arePublic()
+                            .and()
+                            .areNotAnnotatedWith(Internal.class)
+                            .and()
+                            .areNotAnnotatedWith(Deprecated.class)

Review comment:
       Need to exclude Experimental here, too

##########
File path: 
flink-architecture-tests/src/test/java/org/apache/flink/architecture/rules/ApiAnnotationRules.java
##########
@@ -0,0 +1,160 @@
+/*
+ * 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 org.apache.flink.annotation.Public;
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.annotation.VisibleForTesting;
+
+import com.tngtech.archunit.base.DescribedPredicate;
+import com.tngtech.archunit.core.domain.JavaMethodCall;
+import com.tngtech.archunit.junit.ArchTest;
+import com.tngtech.archunit.lang.ArchRule;
+
+import static 
com.tngtech.archunit.core.domain.JavaClass.Predicates.resideOutsideOfPackage;
+import static 
com.tngtech.archunit.core.domain.properties.CanBeAnnotated.Predicates.annotatedWith;
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
+import static com.tngtech.archunit.library.freeze.FreezingArchRule.freeze;
+import static org.apache.flink.architecture.common.Conditions.fulfill;
+import static 
org.apache.flink.architecture.common.Conditions.haveLeafArgumentTypes;
+import static 
org.apache.flink.architecture.common.Conditions.haveLeafReturnTypes;
+import static 
org.apache.flink.architecture.common.GivenJavaClasses.javaClassesThat;
+import static 
org.apache.flink.architecture.common.GivenJavaClasses.noJavaClassesThat;
+import static 
org.apache.flink.architecture.common.Predicates.areDirectlyAnnotatedWithAtLeastOneOf;
+import static 
org.apache.flink.architecture.common.SourcePredicates.areJavaClasses;
+import static 
org.apache.flink.architecture.common.SourcePredicates.areProductionCode;
+
+/** Rules for API visibility annotations. */
+public class ApiAnnotationRules {
+
+    @ArchTest
+    public static final ArchRule ANNOTATED_APIS =
+            freeze(
+                    javaClassesThat()
+                            .resideInAPackage("org.apache.flink..api..")
+                            .and()
+                            .resideOutsideOfPackage("..internal..")
+                            .and()
+                            .arePublic()
+                            .should(
+                                    fulfill(
+                                            
areDirectlyAnnotatedWithAtLeastOneOf(
+                                                    Internal.class,
+                                                    Experimental.class,
+                                                    PublicEvolving.class,
+                                                    Public.class,
+                                                    Deprecated.class)))
+                            .as(
+                                    "Classes in API packages should have at 
least one API visibility annotation."));
+
+    /**
+     * This is a stronger requirement than {@link
+     * #PUBLIC_EVOLVING_API_METHODS_USE_ONLY_PUBLIC_EVOLVING_API_TYPES} and 
ensures that {@link
+     * Public} APIs do not use {@link PublicEvolving} APIs.
+     */
+    @ArchTest
+    public static final ArchRule PUBLIC_API_METHODS_USE_ONLY_PUBLIC_API_TYPES =
+            freeze(
+                    methods()
+                            .that()
+                            .areDeclaredInClassesThat(
+                                    
areJavaClasses().and(annotatedWith(Public.class)))
+                            .and()
+                            .arePublic()
+                            .and()
+                            .areNotAnnotatedWith(Internal.class)
+                            .and()
+                            .areNotAnnotatedWith(Deprecated.class)

Review comment:
       I guess we should also exclude PublicEvolving and Experimental here.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to