From 13f8c8f95720a0299ccfeb23e8f4b44d1734b109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AE=B6=E5=90=8D?= Date: Thu, 28 May 2026 10:18:12 +0800 Subject: [PATCH] Fix SQL license header parsing --- .../common/sql/ClasspathSqlScriptParser.java | 2 +- .../sql/ClasspathSqlScriptParserTest.java | 9 +++++++++ .../resources/sql/indented_license_header.sql | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 dolphinscheduler-common/src/test/resources/sql/indented_license_header.sql diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParser.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParser.java index 224e30acc172..d6684b327254 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParser.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParser.java @@ -116,7 +116,7 @@ private void skipLicenseHeader(LineNumberReader lineNumberReader) throws IOExcep // Skip the empty line, comment line continue; } - if (line.startsWith("*/")) { + if (trimLine.startsWith("*/")) { break; } } diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParserTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParserTest.java index 3cc625c71f8a..5eea77e72dc8 100644 --- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParserTest.java +++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/sql/ClasspathSqlScriptParserTest.java @@ -49,4 +49,13 @@ void testMysqlDdlSql() throws IOException { List allSql = classpathSqlScriptParser.getAllSql(); Assertions.assertEquals("ALTER TABLE t_ds_workflow_definition DROP tenant_id;", allSql.get(0)); } + + @Test + void testIndentedLicenseHeaderSql() throws IOException { + ClasspathSqlScriptParser classpathSqlScriptParser = + new ClasspathSqlScriptParser("sql/indented_license_header.sql"); + List allSql = classpathSqlScriptParser.getAllSql(); + Assertions.assertEquals(1, allSql.size()); + Assertions.assertEquals("SELECT 1;", allSql.get(0)); + } } diff --git a/dolphinscheduler-common/src/test/resources/sql/indented_license_header.sql b/dolphinscheduler-common/src/test/resources/sql/indented_license_header.sql new file mode 100644 index 000000000000..af9e1ea53ffa --- /dev/null +++ b/dolphinscheduler-common/src/test/resources/sql/indented_license_header.sql @@ -0,0 +1,18 @@ +/* + * 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. + */ + +SELECT 1;