liunaijie commented on code in PR #8600: URL: https://github.com/apache/seatunnel/pull/8600#discussion_r1942358393
########## seatunnel-ci-tools/src/test/java/org/apache/seatunnel/api/ConnectorOptionCheckTest.java: ########## @@ -0,0 +1,233 @@ +/* + * 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.seatunnel.api; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.type.ClassOrInterfaceType; +import lombok.extern.slf4j.Slf4j; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitOption; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Slf4j +public class ConnectorOptionCheckTest { + + private static final String javaPathFragment = + "src" + File.separator + "main" + File.separator + "java"; + private static final String JAVA_FILE_EXTENSION = ".java"; + private static final String CONNECTOR_DIR = "seatunnel-connectors-v2"; + private static final JavaParser JAVA_PARSER = new JavaParser(); + + @Test + public void checkConnectorOptionExist() { + Set<String> connectorOptionFileNames = new HashSet<>(); + try (Stream<Path> paths = Files.walk(Paths.get(".."), FileVisitOption.FOLLOW_LINKS)) { + List<Path> connectorClassPaths = + paths.filter( + path -> { + String pathString = path.toString(); + return pathString.endsWith(JAVA_FILE_EXTENSION) + && pathString.contains(CONNECTOR_DIR) + && pathString.contains(javaPathFragment); + }) + .collect(Collectors.toList()); + connectorClassPaths.forEach( + path -> { + try { + ParseResult<CompilationUnit> parseResult = + JAVA_PARSER.parse(Files.newInputStream(path)); + parseResult + .getResult() + .ifPresent( + compilationUnit -> { + List<ClassOrInterfaceDeclaration> classes = + compilationUnit.findAll( + ClassOrInterfaceDeclaration.class); + for (ClassOrInterfaceDeclaration classDeclaration : + classes) { + if (classDeclaration.isAbstract() + || classDeclaration.isInterface()) { + continue; + } + NodeList<ClassOrInterfaceType> + implementedTypes = + classDeclaration + .getImplementedTypes(); + implementedTypes.forEach( + implementedType -> { + if (implementedType + .getNameAsString() + .equals( + "SeaTunnelSource") + || implementedType + .getNameAsString() + .equals( + "SeaTunnelSink")) { + connectorOptionFileNames.add( + path.getFileName() + .toString() + .replace( + JAVA_FILE_EXTENSION, + "") + .concat( + "Options")); + } + }); + NodeList<ClassOrInterfaceType> extendedTypes = + classDeclaration.getExtendedTypes(); + extendedTypes.forEach( + extendedType -> { + if (extendedType + .getNameAsString() + .equals( + "AbstractSimpleSink") + || extendedType + .getNameAsString() + .equals( + "AbstractSingleSplitSource")) { + connectorOptionFileNames.add( + path.getFileName() + .toString() + .replace( + JAVA_FILE_EXTENSION, + "") + .concat( + "Options")); + } + }); + } + }); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + connectorClassPaths.forEach( + path -> { + String className = + path.getFileName().toString().replace(JAVA_FILE_EXTENSION, ""); + connectorOptionFileNames.remove(className); + }); + connectorOptionFileNames.removeAll(buildWhiteList()); Review Comment: It seems that this might not be necessary. If the `white list size` is smaller than `connectorOptionFileNames.size()`, the following `Assertions.assertEquals(0, connectorOptionFileNames.size())` will fail. On the other hand, if the `white list size` is larger than `connectorOptionFileNames.size()`, removing non-existent `Options` or already removed `Options` won't have any impact. Additionally, if we check for equality of size before calling `connectorOptionFileNames.remove(className)`, the size will never match when the update PR is done and the connector class is removed from the white list. Please correct me if I'm wrong. -- 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]
