Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yiicenne
DolphinScheduler
提交
05932bcf
DolphinScheduler
项目概览
yiicenne
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
05932bcf
编写于
8月 10, 2022
作者:
F
fuchanghai
提交者:
GitHub
8月 10, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[fix-11295] remove duplicate classes (#11355)
上级
e9ccaffb
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
6 addition
and
886 deletion
+6
-886
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ParameterUtils.java
.../apache/dolphinscheduler/common/utils/ParameterUtils.java
+2
-7
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/PlaceholderUtils.java
...nscheduler/common/utils/placeholder/PlaceholderUtils.java
+0
-103
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/PropertyPlaceholderHelper.java
...r/common/utils/placeholder/PropertyPlaceholderHelper.java
+0
-211
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtils.java
...eduler/common/utils/placeholder/TimePlaceholderUtils.java
+0
-563
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ParameterUtilsTest.java
...che/dolphinscheduler/common/utils/ParameterUtilsTest.java
+3
-2
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtilsTest.java
...er/common/utils/placeholder/TimePlaceholderUtilsTest.java
+1
-0
未找到文件。
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ParameterUtils.java
浏览文件 @
05932bcf
...
...
@@ -18,21 +18,17 @@
package
org.apache.dolphinscheduler.common.utils
;
import
org.apache.dolphinscheduler.common.Constants
;
import
org.apache.dolphinscheduler.common.enums.CommandType
;
import
org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils
;
import
org.apache.dolphinscheduler.common.utils.placeholder.PlaceholderUtils
;
import
org.apache.dolphinscheduler.common.utils.placeholder.TimePlaceholderUtils
;
import
org.apache.dolphinscheduler.plugin.task.api.model.Property
;
import
org.apache.dolphinscheduler.plugin.task.api.parser.PlaceholderUtils
;
import
org.apache.dolphinscheduler.plugin.task.api.parser.TimePlaceholderUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
...
...
@@ -113,7 +109,6 @@ public class ParameterUtils {
return
null
;
}
StringBuffer
newValue
=
new
StringBuffer
(
templateStr
.
length
());
Matcher
matcher
=
DATE_PARSE_PATTERN
.
matcher
(
templateStr
);
...
...
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/PlaceholderUtils.java
已删除
100644 → 0
浏览文件 @
e9ccaffb
/*
* 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.dolphinscheduler.common.utils.placeholder
;
import
java.util.Map
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* placeholder utils
*/
public
class
PlaceholderUtils
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PlaceholderUtils
.
class
);
/**
* Prefix of the position to be replaced
*/
public
static
final
String
PLACEHOLDER_PREFIX
=
"${"
;
/**
* The suffix of the position to be replaced
*/
public
static
final
String
PLACEHOLDER_SUFFIX
=
"}"
;
/**
* Replaces all placeholders of format {@code ${name}} with the value returned
* from the supplied {@link PropertyPlaceholderHelper.PlaceholderResolver}.
*
* @param value the value containing the placeholders to be replaced
* @param paramsMap placeholder data dictionary
* @param ignoreUnresolvablePlaceholders ignoreUnresolvablePlaceholders
* @return the supplied value with placeholders replaced inline
*/
public
static
String
replacePlaceholders
(
String
value
,
Map
<
String
,
String
>
paramsMap
,
boolean
ignoreUnresolvablePlaceholders
)
{
//replacement tool, parameter key will be replaced by value,if can't match , will throw an exception
PropertyPlaceholderHelper
strictHelper
=
getPropertyPlaceholderHelper
(
false
);
//Non-strict replacement tool implementation, when the position to be replaced does not get the corresponding value, the current position is ignored, and the next position is replaced.
PropertyPlaceholderHelper
nonStrictHelper
=
getPropertyPlaceholderHelper
(
true
);
PropertyPlaceholderHelper
helper
=
(
ignoreUnresolvablePlaceholders
?
nonStrictHelper
:
strictHelper
);
//the PlaceholderResolver to use for replacement
return
helper
.
replacePlaceholders
(
value
,
new
PropertyPlaceholderResolver
(
value
,
paramsMap
));
}
/**
* Creates a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix.
* @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should
* be ignored ({@code true}) or cause an exception ({@code false})
* @return PropertyPlaceholderHelper
*/
public
static
PropertyPlaceholderHelper
getPropertyPlaceholderHelper
(
boolean
ignoreUnresolvablePlaceholders
)
{
return
new
PropertyPlaceholderHelper
(
PLACEHOLDER_PREFIX
,
PLACEHOLDER_SUFFIX
,
null
,
ignoreUnresolvablePlaceholders
);
}
/**
* Placeholder replacement resolver
*/
private
static
class
PropertyPlaceholderResolver
implements
PropertyPlaceholderHelper
.
PlaceholderResolver
{
private
final
String
value
;
private
final
Map
<
String
,
String
>
paramsMap
;
public
PropertyPlaceholderResolver
(
String
value
,
Map
<
String
,
String
>
paramsMap
)
{
this
.
value
=
value
;
this
.
paramsMap
=
paramsMap
;
}
@Override
public
String
resolvePlaceholder
(
String
placeholderName
)
{
try
{
return
paramsMap
.
get
(
placeholderName
);
}
catch
(
Exception
ex
)
{
logger
.
error
(
"resolve placeholder '{}' in [ {} ]"
,
placeholderName
,
value
,
ex
);
return
null
;
}
}
}
}
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/PropertyPlaceholderHelper.java
已删除
100644 → 0
浏览文件 @
e9ccaffb
/*
* 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.dolphinscheduler.common.utils.placeholder
;
import
static
java
.
util
.
Objects
.
requireNonNull
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
java.util.*
;
/**
* Utility class for working with Strings that have placeholder values in them. A placeholder takes the form
* {@code ${name}}. Using {@code PropertyPlaceholderHelper} these placeholders can be substituted for
* user-supplied values. <p> Values for substitution can be supplied using a {@link Properties} instance or
* using a {@link PlaceholderResolver}.
*
* @author Juergen Hoeller
* @author Rob Harrop
* @since 3.0
*/
public
class
PropertyPlaceholderHelper
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
PropertyPlaceholderHelper
.
class
);
private
static
final
Map
<
String
,
String
>
wellKnownSimplePrefixes
=
new
HashMap
<>(
4
);
static
{
wellKnownSimplePrefixes
.
put
(
"}"
,
"{"
);
wellKnownSimplePrefixes
.
put
(
"]"
,
"["
);
wellKnownSimplePrefixes
.
put
(
")"
,
"("
);
}
private
final
String
placeholderPrefix
;
private
final
String
placeholderSuffix
;
private
final
String
simplePrefix
;
private
final
String
valueSeparator
;
private
final
boolean
ignoreUnresolvablePlaceholders
;
/**
* Creates a new {@code PropertyPlaceholderHelper} that uses the supplied prefix and suffix.
*
* @param placeholderPrefix the prefix that denotes the start of a placeholder
* @param placeholderSuffix the suffix that denotes the end of a placeholder
* @param valueSeparator the separating character between the placeholder variable
* and the associated default value, if any
* @param ignoreUnresolvablePlaceholders indicates whether unresolvable placeholders should
* be ignored ({@code true}) or cause an exception ({@code false})
*/
public
PropertyPlaceholderHelper
(
String
placeholderPrefix
,
String
placeholderSuffix
,
String
valueSeparator
,
boolean
ignoreUnresolvablePlaceholders
)
{
requireNonNull
((
Object
)
placeholderPrefix
,
"'placeholderPrefix' must not be null"
);
requireNonNull
((
Object
)
placeholderSuffix
,
"'placeholderSuffix' must not be null"
);
this
.
placeholderPrefix
=
placeholderPrefix
;
this
.
placeholderSuffix
=
placeholderSuffix
;
String
simplePrefixForSuffix
=
wellKnownSimplePrefixes
.
get
(
this
.
placeholderSuffix
);
if
(
simplePrefixForSuffix
!=
null
&&
this
.
placeholderPrefix
.
endsWith
(
simplePrefixForSuffix
))
{
this
.
simplePrefix
=
simplePrefixForSuffix
;
}
else
{
this
.
simplePrefix
=
this
.
placeholderPrefix
;
}
this
.
valueSeparator
=
valueSeparator
;
this
.
ignoreUnresolvablePlaceholders
=
ignoreUnresolvablePlaceholders
;
}
/**
* Replaces all placeholders of format {@code ${name}} with the value returned
* from the supplied {@link PlaceholderResolver}.
*
* @param value the value containing the placeholders to be replaced
* @param placeholderResolver the {@code PlaceholderResolver} to use for replacement
* @return the supplied value with placeholders replaced inline
*/
public
String
replacePlaceholders
(
String
value
,
PlaceholderResolver
placeholderResolver
)
{
requireNonNull
((
Object
)
value
,
"'value' must not be null"
);
return
parseStringValue
(
value
,
placeholderResolver
,
new
HashSet
<
String
>());
}
protected
String
parseStringValue
(
String
value
,
PlaceholderResolver
placeholderResolver
,
Set
<
String
>
visitedPlaceholders
)
{
StringBuilder
result
=
new
StringBuilder
(
value
);
int
startIndex
=
value
.
indexOf
(
this
.
placeholderPrefix
);
while
(
startIndex
!=
-
1
)
{
int
endIndex
=
findPlaceholderEndIndex
(
result
,
startIndex
);
if
(
endIndex
!=
-
1
)
{
String
placeholder
=
result
.
substring
(
startIndex
+
this
.
placeholderPrefix
.
length
(),
endIndex
);
String
originalPlaceholder
=
placeholder
;
if
(!
visitedPlaceholders
.
add
(
originalPlaceholder
))
{
throw
new
IllegalArgumentException
(
"Circular placeholder reference '"
+
originalPlaceholder
+
"' in property definitions"
);
}
// Recursive invocation, parsing placeholders contained in the placeholder key.
placeholder
=
parseStringValue
(
placeholder
,
placeholderResolver
,
visitedPlaceholders
);
// Now obtain the value for the fully resolved key...
String
propVal
=
placeholderResolver
.
resolvePlaceholder
(
placeholder
);
if
(
propVal
==
null
&&
this
.
valueSeparator
!=
null
)
{
int
separatorIndex
=
placeholder
.
indexOf
(
this
.
valueSeparator
);
if
(
separatorIndex
!=
-
1
)
{
String
actualPlaceholder
=
placeholder
.
substring
(
0
,
separatorIndex
);
String
defaultValue
=
placeholder
.
substring
(
separatorIndex
+
this
.
valueSeparator
.
length
());
propVal
=
placeholderResolver
.
resolvePlaceholder
(
actualPlaceholder
);
if
(
propVal
==
null
)
{
propVal
=
defaultValue
;
}
}
}
if
(
propVal
!=
null
)
{
// Recursive invocation, parsing placeholders contained in the
// previously resolved placeholder value.
propVal
=
parseStringValue
(
propVal
,
placeholderResolver
,
visitedPlaceholders
);
result
.
replace
(
startIndex
,
endIndex
+
this
.
placeholderSuffix
.
length
(),
propVal
);
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
"Resolved placeholder '"
+
placeholder
+
"'"
);
}
startIndex
=
result
.
indexOf
(
this
.
placeholderPrefix
,
startIndex
+
propVal
.
length
());
}
else
if
(
this
.
ignoreUnresolvablePlaceholders
)
{
// Proceed with unprocessed value.
startIndex
=
result
.
indexOf
(
this
.
placeholderPrefix
,
endIndex
+
this
.
placeholderSuffix
.
length
());
}
else
{
throw
new
IllegalArgumentException
(
"Could not resolve placeholder '"
+
placeholder
+
"'"
+
" in value \""
+
value
+
"\""
);
}
visitedPlaceholders
.
remove
(
originalPlaceholder
);
}
else
{
startIndex
=
-
1
;
}
}
return
result
.
toString
();
}
private
int
findPlaceholderEndIndex
(
CharSequence
buf
,
int
startIndex
)
{
int
index
=
startIndex
+
this
.
placeholderPrefix
.
length
();
int
withinNestedPlaceholder
=
0
;
while
(
index
<
buf
.
length
())
{
if
(
substringMatch
(
buf
,
index
,
this
.
placeholderSuffix
))
{
if
(
withinNestedPlaceholder
>
0
)
{
withinNestedPlaceholder
--;
index
=
index
+
this
.
placeholderSuffix
.
length
();
}
else
{
return
index
;
}
}
else
if
(
substringMatch
(
buf
,
index
,
this
.
simplePrefix
))
{
withinNestedPlaceholder
++;
index
=
index
+
this
.
simplePrefix
.
length
();
}
else
{
index
++;
}
}
return
-
1
;
}
/**
* Strategy interface used to resolve replacement values for placeholders contained in Strings.
*/
public
interface
PlaceholderResolver
{
/**
* Resolve the supplied placeholder name to the replacement value.
*
* @param placeholderName the name of the placeholder to resolve
* @return the replacement value, or {@code null} if no replacement is to be made
*/
String
resolvePlaceholder
(
String
placeholderName
);
}
/**
* Test whether the given string matches the given substring
* at the given index.
*
* @param str the original string (or StringBuilder)
* @param index the index in the original string to start matching against
* @param substring the substring to match at the given index
* @return whether the given string matches the given substring
*/
public
static
boolean
substringMatch
(
CharSequence
str
,
int
index
,
CharSequence
substring
)
{
for
(
int
j
=
0
;
j
<
substring
.
length
();
j
++)
{
int
i
=
index
+
j
;
if
(
i
>=
str
.
length
()
||
str
.
charAt
(
i
)
!=
substring
.
charAt
(
j
))
{
return
false
;
}
}
return
true
;
}
}
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtils.java
已删除
100644 → 0
浏览文件 @
e9ccaffb
此差异已折叠。
点击以展开。
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ParameterUtilsTest.java
浏览文件 @
05932bcf
...
...
@@ -17,10 +17,11 @@
package
org.apache.dolphinscheduler.common.utils
;
import
static
org
.
apache
.
dolphinscheduler
.
common
.
utils
.
placeholder
.
TimePlaceholderUtils
.
replacePlaceholders
;
import
static
org
.
apache
.
dolphinscheduler
.
plugin
.
task
.
api
.
parser
.
TimePlaceholderUtils
.
replacePlaceholders
;
import
org.apache.dolphinscheduler.common.Constants
;
import
org.apache.dolphinscheduler.
common.utils.placehold
er.PlaceholderUtils
;
import
org.apache.dolphinscheduler.
plugin.task.api.pars
er.PlaceholderUtils
;
import
java.text.ParseException
;
import
java.util.Date
;
...
...
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtilsTest.java
浏览文件 @
05932bcf
...
...
@@ -18,6 +18,7 @@
package
org.apache.dolphinscheduler.common.utils.placeholder
;
import
org.apache.dolphinscheduler.common.utils.DateUtils
;
import
org.apache.dolphinscheduler.plugin.task.api.parser.TimePlaceholderUtils
;
import
java.util.Date
;
import
java.util.TimeZone
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录