sjwiesman commented on a change in pull request #17133: URL: https://github.com/apache/flink/pull/17133#discussion_r703811326
########## File path: flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/architecture/ApiRules.java ########## @@ -0,0 +1,93 @@ +/* + * 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.testutils.architecture; + +import org.apache.flink.annotation.Public; +import org.apache.flink.annotation.PublicEvolving; + +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.lang.syntax.ArchRuleDefinition.methods; +import static org.apache.flink.testutils.architecture.Predicates.areAnnotatedWithAtLeastOneOf; +import static org.apache.flink.testutils.architecture.Predicates.haveLeafArgumentTypes; +import static org.apache.flink.testutils.architecture.Predicates.haveLeafReturnTypes; + +/** Architecture rules for APIs. */ +public class ApiRules { + + /** + * Ensure that public methods marked {@link Public} only use return and argument types which are + * also marked {@link Public}. + * + * <p>Note that 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 = + methods() + .that() + .areDeclaredInClassesThat() + .areAnnotatedWith(Public.class) + .and() + .arePublic() + .should( + haveLeafReturnTypes( + resideOutsideOfPackage("org.apache.flink..") + .or( + areAnnotatedWithAtLeastOneOf( + Public.class, Deprecated.class)))) + .andShould( + haveLeafArgumentTypes( + resideOutsideOfPackage("org.apache.flink..") + .or( + areAnnotatedWithAtLeastOneOf( + Public.class, Deprecated.class)))); + + /** + * Ensure that public methods marked {@link Public} or {@link PublicEvolving} only use return + * and argument types which are also marked {@link Public} or {@link PublicEvolving}. + */ + @ArchTest + public static final ArchRule PUBLIC_EVOLVING_API_METHODS_USE_ONLY_PUBLIC_EVOLVING_API_TYPES = Review comment: Not a review, I was just peaking around at how this works. In general the only allow list is: - org.apache.flink.* but _not_ org.apache.flink.shaded (!) - java.* - scala.* (only in the scala api's) - Kryo, but only right [here](https://github.com/apache/flink/blob/99c2a415e9eeefafacf70762b6f54070f7911ceb/flink-core/src/main/java/org/apache/flink/api/common/ExecutionConfig.java#L720-L812 ) and I would consider this a historical oddity And then connectors will often expose some number of classes from their underlying client. For example, the Kafka serde classes expose ConsumerRecord and ProducerRecord. ########## File path: flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/architecture/ApiRules.java ########## @@ -0,0 +1,93 @@ +/* + * 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.testutils.architecture; + +import org.apache.flink.annotation.Public; +import org.apache.flink.annotation.PublicEvolving; + +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.lang.syntax.ArchRuleDefinition.methods; +import static org.apache.flink.testutils.architecture.Predicates.areAnnotatedWithAtLeastOneOf; +import static org.apache.flink.testutils.architecture.Predicates.haveLeafArgumentTypes; +import static org.apache.flink.testutils.architecture.Predicates.haveLeafReturnTypes; + +/** Architecture rules for APIs. */ +public class ApiRules { + + /** + * Ensure that public methods marked {@link Public} only use return and argument types which are + * also marked {@link Public}. + * + * <p>Note that 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 = + methods() + .that() + .areDeclaredInClassesThat() + .areAnnotatedWith(Public.class) + .and() + .arePublic() + .should( + haveLeafReturnTypes( + resideOutsideOfPackage("org.apache.flink..") + .or( + areAnnotatedWithAtLeastOneOf( + Public.class, Deprecated.class)))) + .andShould( + haveLeafArgumentTypes( + resideOutsideOfPackage("org.apache.flink..") + .or( + areAnnotatedWithAtLeastOneOf( + Public.class, Deprecated.class)))); + + /** + * Ensure that public methods marked {@link Public} or {@link PublicEvolving} only use return + * and argument types which are also marked {@link Public} or {@link PublicEvolving}. + */ + @ArchTest + public static final ArchRule PUBLIC_EVOLVING_API_METHODS_USE_ONLY_PUBLIC_EVOLVING_API_TYPES = Review comment: Not a review, I was just peaking around at how this works. In general the only allow list is: - org.apache.flink.* but _not_ org.apache.flink.shaded (!) - java.* - scala.* (only in the scala api's) - Kryo, but only right [here](https://github.com/apache/flink/blob/99c2a415e9eeefafacf70762b6f54070f7911ceb/flink-core/src/main/java/org/apache/flink/api/common/ExecutionConfig.java#L720-L812 ), but I would consider this a historical oddity And then connectors will often expose some number of classes from their underlying client. For example, the Kafka serde classes expose ConsumerRecord and ProducerRecord. ########## File path: flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/testutils/architecture/ApiRules.java ########## @@ -0,0 +1,93 @@ +/* + * 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.testutils.architecture; + +import org.apache.flink.annotation.Public; +import org.apache.flink.annotation.PublicEvolving; + +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.lang.syntax.ArchRuleDefinition.methods; +import static org.apache.flink.testutils.architecture.Predicates.areAnnotatedWithAtLeastOneOf; +import static org.apache.flink.testutils.architecture.Predicates.haveLeafArgumentTypes; +import static org.apache.flink.testutils.architecture.Predicates.haveLeafReturnTypes; + +/** Architecture rules for APIs. */ +public class ApiRules { + + /** + * Ensure that public methods marked {@link Public} only use return and argument types which are + * also marked {@link Public}. + * + * <p>Note that 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 = + methods() + .that() + .areDeclaredInClassesThat() + .areAnnotatedWith(Public.class) + .and() + .arePublic() + .should( + haveLeafReturnTypes( + resideOutsideOfPackage("org.apache.flink..") + .or( + areAnnotatedWithAtLeastOneOf( + Public.class, Deprecated.class)))) + .andShould( + haveLeafArgumentTypes( + resideOutsideOfPackage("org.apache.flink..") + .or( + areAnnotatedWithAtLeastOneOf( + Public.class, Deprecated.class)))); + + /** + * Ensure that public methods marked {@link Public} or {@link PublicEvolving} only use return + * and argument types which are also marked {@link Public} or {@link PublicEvolving}. + */ + @ArchTest + public static final ArchRule PUBLIC_EVOLVING_API_METHODS_USE_ONLY_PUBLIC_EVOLVING_API_TYPES = Review comment: Not a review, I was just peaking around at how this works. In general the only allow list is: - org.apache.flink.* but _not_ org.apache.flink.shaded (!) - java.* - scala.* (only in the scala api's) - Kryo, but only right [here](https://github.com/apache/flink/blob/99c2a415e9eeefafacf70762b6f54070f7911ceb/flink-core/src/main/java/org/apache/flink/api/common/ExecutionConfig.java#L720-L812 ), I would consider this a historical oddity And then connectors will often expose some number of classes from their underlying client. For example, the Kafka serde classes expose ConsumerRecord and ProducerRecord. -- 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]
