Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
swiftMtMx
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
isc-v3.1-tmp
swiftMtMx
Commits
247ac523
Commit
247ac523
authored
May 19, 2022
by
chengzhuoshen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
移除掉spring-core依赖
parent
fd4db0c7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
1 additions
and
160 deletions
+1
-160
pom.xml
pom.xml
+0
-5
BeSpiLoader.java
...e/src/main/java/com/brilliance/swift/spi/BeSpiLoader.java
+0
-117
ConcurrentReferenceMap.java
...java/com/brilliance/swift/spi/ConcurrentReferenceMap.java
+0
-4
ClassUtil.java
...re/src/main/java/com/brilliance/swift/util/ClassUtil.java
+1
-16
FileUtil.java
...ore/src/main/java/com/brilliance/swift/util/FileUtil.java
+0
-6
ObjectUtil.java
...e/src/main/java/com/brilliance/swift/util/ObjectUtil.java
+0
-2
ReflectionUtil.java
...c/main/java/com/brilliance/swift/util/ReflectionUtil.java
+0
-10
No files found.
pom.xml
View file @
247ac523
...
...
@@ -70,11 +70,6 @@
<version>
1.9
</version>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-core
</artifactId>
<version>
5.0.5.RELEASE
</version>
</dependency>
<dependency>
<groupId>
com.brilliance.swift
</groupId>
<artifactId>
eibs-container
</artifactId>
<version>
3.5.0
</version>
...
...
swiftCore/src/main/java/com/brilliance/swift/spi/BeSpiLoader.java
deleted
100644 → 0
View file @
fd4db0c7
package
com
.
brilliance
.
swift
.
spi
;
import
com.brilliance.swift.util.ClassUtil
;
import
com.brilliance.swift.util.PropertyUtil
;
import
com.brilliance.swift.util.ReflectionUtil
;
import
com.brilliance.swift.util.StringUtil
;
import
org.springframework.core.OrderComparator
;
import
org.springframework.util.Assert
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* spi加载类
*/
public
class
BeSpiLoader
{
public
static
final
String
SERVICES_RESOURCE_LOCATION
=
"META-INF/be-esb.services"
;
public
static
final
String
COMMA_DELIMITED
=
","
;
static
final
com
.
brilliance
.
swift
.
spi
.
ConcurrentReferenceMap
<
ClassLoader
,
Map
<
String
,
List
<
String
>>>
cache
=
new
ConcurrentReferenceMap
<
ClassLoader
,
Map
<
String
,
List
<
String
>>>();
private
BeSpiLoader
()
{
}
public
static
<
T
>
List
<
T
>
loadBeServices
(
Class
<
T
>
serviceType
,
ClassLoader
classLoader
)
{
return
loadBeServices
(
serviceType
,
classLoader
,
null
,
null
);
}
public
static
<
T
>
List
<
T
>
loadBeServices
(
Class
<
T
>
serviceType
,
ClassLoader
classLoader
,
Object
[]
args
,
Class
[]
argsTypes
)
{
Assert
.
notNull
(
serviceType
,
"'serviceType' must not be null"
);
ClassLoader
classLoaderToUse
=
classLoader
;
if
(
classLoaderToUse
==
null
)
{
classLoaderToUse
=
BeSpiLoader
.
class
.
getClassLoader
();
}
List
<
String
>
serviceImplementationNames
=
loadServiceNames
(
serviceType
,
classLoaderToUse
);
List
<
T
>
result
=
new
ArrayList
<>(
serviceImplementationNames
.
size
());
for
(
String
serviceImplementationName
:
serviceImplementationNames
)
{
result
.
add
(
instantiateService
(
serviceImplementationName
,
serviceType
,
classLoaderToUse
,
args
,
argsTypes
));
}
OrderComparator
.
sort
(
result
);
return
result
;
}
public
static
List
<
String
>
loadServiceNames
(
Class
<?>
serviceType
,
ClassLoader
classLoader
)
{
ClassLoader
classLoaderToUse
=
classLoader
;
if
(
classLoaderToUse
==
null
)
{
classLoaderToUse
=
BeSpiLoader
.
class
.
getClassLoader
();
}
String
serviceTypeName
=
serviceType
.
getName
();
return
loadBeServices
(
classLoaderToUse
).
getOrDefault
(
serviceTypeName
,
Collections
.
emptyList
());
}
private
static
Map
<
String
,
List
<
String
>>
loadBeServices
(
ClassLoader
classLoader
)
{
Map
<
String
,
List
<
String
>>
result
=
cache
.
get
(
classLoader
);
if
(
result
!=
null
)
{
return
result
;
}
try
{
Enumeration
<
URL
>
urls
=
classLoader
.
getResources
(
SERVICES_RESOURCE_LOCATION
);
result
=
new
HashMap
<
String
,
List
<
String
>>();
while
(
urls
.
hasMoreElements
())
{
URL
url
=
urls
.
nextElement
();
Properties
properties
=
PropertyUtil
.
loadProperties
(
url
);
for
(
Map
.
Entry
<?,
?>
entry
:
properties
.
entrySet
())
{
String
serviceTypeName
=
((
String
)
entry
.
getKey
()).
trim
();
String
[]
serviceImplementationNames
=
((
String
)
entry
.
getValue
()).
split
(
COMMA_DELIMITED
);
for
(
String
serviceImplementationName
:
serviceImplementationNames
)
{
if
(
StringUtil
.
isEmpty
(
serviceImplementationName
)){
continue
;
}
result
.
computeIfAbsent
(
serviceTypeName
,
key
->
new
ArrayList
<>())
.
add
(
serviceImplementationName
.
trim
());
}
}
}
// 去重,并且转换为不能修改得list,按key为classLoader缓存到map
result
.
replaceAll
((
serviceType
,
implementations
)
->
implementations
.
stream
().
distinct
()
.
collect
(
Collectors
.
collectingAndThen
(
Collectors
.
toList
(),
Collections:
:
unmodifiableList
)));
cache
.
put
(
classLoader
,
result
);
}
catch
(
IOException
ex
)
{
throw
new
IllegalArgumentException
(
"Unable to load services from location ["
+
SERVICES_RESOURCE_LOCATION
+
"]"
,
ex
);
}
return
result
;
}
@SuppressWarnings
(
"unchecked"
)
private
static
<
T
>
T
instantiateService
(
String
serviceImplementationName
,
Class
<
T
>
serviceType
,
ClassLoader
classLoader
,
Object
[]
args
,
Class
[]
argsTypes
)
{
try
{
Class
<?>
serviceImplementationClass
=
ClassUtil
.
forName
(
serviceImplementationName
,
classLoader
);
if
(!
serviceType
.
isAssignableFrom
(
serviceImplementationClass
))
{
throw
new
IllegalArgumentException
(
"Class ["
+
serviceImplementationName
+
"] is not assignable to type ["
+
serviceType
.
getName
()
+
"]"
);
}
if
(
args
==
null
)
{
return
(
T
)
ReflectionUtil
.
accessibleConstructor
(
serviceImplementationClass
).
newInstance
();
}
else
{
try
{
return
(
T
)
ReflectionUtil
.
accessibleConstructor
(
serviceImplementationClass
,
argsTypes
).
newInstance
(
args
);
}
catch
(
NoSuchMethodException
e
){
//尝试采用无参构造函数创建实例
return
(
T
)
ReflectionUtil
.
accessibleConstructor
(
serviceImplementationClass
).
newInstance
();
}
}
}
catch
(
Throwable
ex
)
{
throw
new
IllegalArgumentException
(
"Unable to instantiate class ["
+
serviceImplementationName
+
"] for type ["
+
serviceType
.
getName
()
+
"]"
,
ex
);
}
}
}
swiftCore/src/main/java/com/brilliance/swift/spi/ConcurrentReferenceMap.java
View file @
247ac523
package
com
.
brilliance
.
swift
.
spi
;
import
com.brilliance.swift.util.ObjectUtil
;
import
org.springframework.util.Assert
;
import
java.lang.ref.Reference
;
import
java.lang.ref.SoftReference
;
...
...
@@ -45,7 +44,6 @@ public class ConcurrentReferenceMap<T, S> {
}
public
S
get
(
Object
key
)
{
Assert
.
notNull
(
key
,
"key must not be null"
);
Reference
<
S
>
sReference
=
cache
.
get
(
key
);
if
(
ObjectUtil
.
isNull
(
sReference
))
{
return
null
;
...
...
@@ -59,8 +57,6 @@ public class ConcurrentReferenceMap<T, S> {
}
public
S
put
(
T
key
,
S
value
)
{
Assert
.
notNull
(
key
,
"key must not be null"
);
Assert
.
notNull
(
value
,
"value must not be null"
);
Reference
<
S
>
oldref
=
null
;
if
(
value
instanceof
Reference
)
{
oldref
=
cache
.
put
(
key
,
(
Reference
<
S
>)
value
);
...
...
swiftCore/src/main/java/com/brilliance/swift/util/ClassUtil.java
View file @
247ac523
...
...
@@ -18,7 +18,6 @@ package com.brilliance.swift.util;
import
com.brilliance.swift.exception.CommonRuntimeException
;
import
org.apache.commons.lang.ClassUtils
;
import
org.springframework.util.Assert
;
import
java.io.Closeable
;
import
java.io.Externalizable
;
...
...
@@ -158,9 +157,7 @@ public abstract class ClassUtil {
* @throws ClassNotFoundException 如果类没有被发现
* @throws LinkageError 如果类文件不能被加载
*/
public
static
Class
<?>
forName
(
String
name
,
ClassLoader
classLoader
)
{
Assert
.
notNull
(
name
,
"Name must not be null"
);
public
static
Class
<?>
forName
(
String
name
,
ClassLoader
classLoader
)
{
Class
<?>
clazz
=
resolvePrimitiveClassName
(
name
);
if
(
clazz
==
null
)
{
clazz
=
commonClassCache
.
get
(
name
);
...
...
@@ -257,8 +254,6 @@ public abstract class ClassUtil {
* @return 如果右侧类型可以赋值给左侧类型,则返回true
*/
public
static
boolean
isAssignable
(
Class
<?>
lhsType
,
Class
<?>
rhsType
)
{
Assert
.
notNull
(
lhsType
,
"Left-hand side type must not be null"
);
Assert
.
notNull
(
rhsType
,
"Right-hand side type must not be null"
);
if
(
lhsType
.
isAssignableFrom
(
rhsType
))
{
return
true
;
}
...
...
@@ -275,7 +270,6 @@ public abstract class ClassUtil {
* 如果给定的类是基础类型则返回相应的基础类型的包装器类型
*/
public
static
Class
<?>
resolvePrimitiveIfNecessary
(
Class
<?>
clazz
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
return
(
clazz
.
isPrimitive
()
&&
clazz
!=
void
.
class
?
primitiveTypeToWrapperMap
.
get
(
clazz
)
:
clazz
);
}
...
...
@@ -283,7 +277,6 @@ public abstract class ClassUtil {
* 获取类型全限定名
*/
public
static
String
getQualifiedName
(
Class
<?>
clazz
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
return
clazz
.
getTypeName
();
}
...
...
@@ -293,7 +286,6 @@ public abstract class ClassUtil {
* 参考{@link Class#getSimpleName()}
*/
public
static
String
getSimpleName
(
Class
<?>
clazz
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
return
clazz
.
getSimpleName
();
}
...
...
@@ -322,7 +314,6 @@ public abstract class ClassUtil {
* 如果类本身是一个接口,它将作为唯一接口数组返回
*/
public
static
Set
<
Class
<?>>
getAllInterfacesForClassAsSet
(
Class
<?>
clazz
,
ClassLoader
classLoader
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
if
(
clazz
.
isInterface
()
&&
isVisible
(
clazz
,
classLoader
))
{
return
Collections
.
singleton
(
clazz
);
}
...
...
@@ -363,8 +354,6 @@ public abstract class ClassUtil {
* @return 方法,如果未找到,则为null
*/
public
static
Method
getMethodIfAvailable
(
Class
<?>
clazz
,
String
methodName
,
Class
<?>...
paramTypes
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
Assert
.
notNull
(
methodName
,
"Method name must not be null"
);
if
(
paramTypes
!=
null
)
{
try
{
return
clazz
.
getMethod
(
methodName
,
paramTypes
);
...
...
@@ -396,8 +385,6 @@ public abstract class ClassUtil {
* @throws IllegalArgumentException 如果方法名称为空或clazz为空
*/
public
static
Method
getStaticMethod
(
Class
<?>
clazz
,
String
methodName
,
Class
<?>...
args
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
Assert
.
notNull
(
methodName
,
"Method name must not be null"
);
try
{
Method
method
=
clazz
.
getMethod
(
methodName
,
args
);
return
Modifier
.
isStatic
(
method
.
getModifiers
())
?
method
:
null
;
...
...
@@ -414,7 +401,6 @@ public abstract class ClassUtil {
* @return 构造函数,或者如果没有找到返回{@code null}
*/
public
static
<
T
>
Constructor
<
T
>
getConstructorIfAvailable
(
Class
<
T
>
clazz
,
Class
<?>...
paramTypes
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
try
{
return
clazz
.
getConstructor
(
paramTypes
);
}
catch
(
NoSuchMethodException
ex
)
{
...
...
@@ -442,7 +428,6 @@ public abstract class ClassUtil {
* @param value 应该分配给目标类型的值
*/
public
static
boolean
isAssignableValue
(
Class
<?>
type
,
Object
value
)
{
Assert
.
notNull
(
type
,
"Type must not be null"
);
return
(
value
!=
null
?
isAssignable
(
type
,
value
.
getClass
())
:
!
type
.
isPrimitive
());
}
}
swiftCore/src/main/java/com/brilliance/swift/util/FileUtil.java
View file @
247ac523
...
...
@@ -3,7 +3,6 @@ package com.brilliance.swift.util;
import
com.brilliance.swift.exception.IORuntimeException
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.util.Assert
;
import
java.io.File
;
import
java.io.FileFilter
;
...
...
@@ -21,7 +20,6 @@ public class FileUtil {
public
static
final
String
URL_PROTOCOL_FILE
=
"file"
;
public
static
URL
getURL
(
String
resourceLocation
)
{
Assert
.
notNull
(
resourceLocation
,
"Resource location must not be null"
);
if
(
resourceLocation
.
startsWith
(
CLASSPATH_URL_PREFIX
))
{
String
path
=
resourceLocation
.
substring
(
CLASSPATH_URL_PREFIX
.
length
());
ClassLoader
cl
=
ClassUtil
.
getDefaultClassLoader
();
...
...
@@ -58,19 +56,15 @@ public class FileUtil {
}
public
static
File
getFile
(
String
path
)
{
Assert
.
notNull
(
path
,
"Resource path must not be null"
);
return
getFile
(
getURL
(
path
));
}
public
static
File
getFile
(
String
rootPath
,
String
childPath
)
{
Assert
.
notNull
(
rootPath
,
"Resource rootPath must not be null"
);
Assert
.
notNull
(
childPath
,
"Resource childPath must not be null"
);
File
rootFile
=
getFile
(
rootPath
);
return
new
File
(
rootFile
,
childPath
);
}
public
static
File
getFile
(
URL
resourceUrl
)
{
Assert
.
notNull
(
resourceUrl
,
"Resource URL must not be null"
);
if
(!
URL_PROTOCOL_FILE
.
equals
(
resourceUrl
.
getProtocol
()))
{
throw
new
IllegalArgumentException
(
"url cannot be resolved to absolute file path "
+
"because it does not reside in the file system: "
+
resourceUrl
);
...
...
swiftCore/src/main/java/com/brilliance/swift/util/ObjectUtil.java
View file @
247ac523
...
...
@@ -16,7 +16,6 @@
package
com
.
brilliance
.
swift
.
util
;
import
org.springframework.util.Assert
;
import
java.lang.reflect.Array
;
import
java.util.Arrays
;
...
...
@@ -111,7 +110,6 @@ public class ObjectUtil {
return
null
;
}
Object
result
=
optional
.
get
();
Assert
.
isTrue
(!(
result
instanceof
Optional
),
"不支持多层Optional使用"
);
return
result
;
}
return
obj
;
...
...
swiftCore/src/main/java/com/brilliance/swift/util/ReflectionUtil.java
View file @
247ac523
...
...
@@ -18,7 +18,6 @@ package com.brilliance.swift.util;
import
com.brilliance.swift.exception.InstantiateException
;
import
com.brilliance.swift.spi.ConcurrentReferenceMap
;
import
org.springframework.util.Assert
;
import
java.lang.reflect.*
;
import
java.util.ArrayList
;
...
...
@@ -164,8 +163,6 @@ public class ReflectionUtil {
* @param dest 目标对象
*/
public
static
void
shallowCopyFieldState
(
final
Object
src
,
final
Object
dest
)
{
Assert
.
notNull
(
src
,
"Source for field copy cannot be null"
);
Assert
.
notNull
(
dest
,
"Destination for field copy cannot be null"
);
if
(!
src
.
getClass
().
isAssignableFrom
(
dest
.
getClass
()))
{
throw
new
IllegalArgumentException
(
"Destination class ["
+
dest
.
getClass
().
getName
()
+
"] must be same or subclass as source class ["
+
src
.
getClass
().
getName
()
+
"]"
);
...
...
@@ -361,8 +358,6 @@ public class ReflectionUtil {
* @return Method 对象,如果没有找到则为null
*/
public
static
Method
findMethod
(
Class
<?>
clazz
,
String
name
,
Class
<?>...
paramTypes
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
Assert
.
notNull
(
name
,
"Method name must not be null"
);
Class
<?>
searchType
=
clazz
;
while
(
searchType
!=
null
)
{
Method
[]
methods
=
(
searchType
.
isInterface
()
?
searchType
.
getMethods
()
:
getDeclaredMethods
(
searchType
));
...
...
@@ -378,7 +373,6 @@ public class ReflectionUtil {
}
private
static
Field
[]
getDeclaredFields
(
Class
<?>
clazz
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
Field
[]
result
=
declaredFieldsCache
.
get
(
clazz
);
if
(
result
==
null
)
{
try
{
...
...
@@ -393,7 +387,6 @@ public class ReflectionUtil {
}
private
static
Method
[]
getDeclaredMethods
(
Class
<?>
clazz
,
boolean
defensive
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
Method
[]
result
=
declaredMethodsCache
.
get
(
clazz
);
if
(
result
==
null
)
{
try
{
...
...
@@ -435,7 +428,6 @@ public class ReflectionUtil {
}
public
static
<
T
>
T
instantiateClass
(
Constructor
<
T
>
ctor
,
Object
...
args
)
{
Assert
.
notNull
(
ctor
,
"Constructor must not be null"
);
try
{
ReflectionUtil
.
makeAccessible
(
ctor
);
return
ctor
.
newInstance
(
args
);
...
...
@@ -490,7 +482,6 @@ public class ReflectionUtil {
* @throws IllegalArgumentException 如果 MethodFilter 参数为null
*/
default
MethodFilter
and
(
MethodFilter
next
)
{
Assert
.
notNull
(
next
,
"Next MethodFilter must not be null"
);
return
method
->
matches
(
method
)
&&
next
.
matches
(
method
);
}
}
...
...
@@ -513,7 +504,6 @@ public class ReflectionUtil {
* @throws IllegalArgumentException 如果 FieldFilter 参数为null
*/
default
FieldFilter
and
(
FieldFilter
next
)
{
Assert
.
notNull
(
next
,
"Next FieldFilter must not be null"
);
return
field
->
matches
(
field
)
&&
next
.
matches
(
field
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment