From e1734d012acbc43dfd6e250b461f1afba0050dff Mon Sep 17 00:00:00 2001 From: ZackYoung Date: Tue, 30 Jan 2024 13:21:02 +0800 Subject: [PATCH 1/2] add_jar_group --- .../dinky/controller/SystemController.java | 3 +- .../java/org/dinky/service/SystemService.java | 3 +- .../dinky/service/impl/SystemServiceImpl.java | 66 +++++++++++++++---- .../SettingCenter/ClassLoaderJars/index.tsx | 43 +++++++----- .../SettingCenter/ClassLoaderJars/service.ts | 2 +- 5 files changed, 86 insertions(+), 31 deletions(-) diff --git a/dinky-admin/src/main/java/org/dinky/controller/SystemController.java b/dinky-admin/src/main/java/org/dinky/controller/SystemController.java index 253555cc69..8c0dc854b2 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/SystemController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/SystemController.java @@ -26,6 +26,7 @@ import org.dinky.service.SystemService; import java.util.List; +import java.util.Map; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -86,7 +87,7 @@ public Result readFile(@RequestParam String path) { @GetMapping("/queryAllClassLoaderJarFiles") @ApiOperation("Query All ClassLoader Jar Files") - public Result> queryAllClassLoaderJarFiles() { + public Result>> queryAllClassLoaderJarFiles() { return Result.succeed(systemService.queryAllClassLoaderJarFiles()); } } diff --git a/dinky-admin/src/main/java/org/dinky/service/SystemService.java b/dinky-admin/src/main/java/org/dinky/service/SystemService.java index 1da97a4213..67d88612aa 100644 --- a/dinky-admin/src/main/java/org/dinky/service/SystemService.java +++ b/dinky-admin/src/main/java/org/dinky/service/SystemService.java @@ -23,6 +23,7 @@ import org.dinky.data.model.ext.FileNode; import java.util.List; +import java.util.Map; /** * SystemService @@ -46,5 +47,5 @@ public interface SystemService { */ String readFile(String path); - List queryAllClassLoaderJarFiles(); + Map> queryAllClassLoaderJarFiles(); } diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/SystemServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/SystemServiceImpl.java index cfd853dbe9..c4454320ad 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/SystemServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/SystemServiceImpl.java @@ -26,14 +26,25 @@ import org.dinky.utils.TreeUtil; import java.io.File; -import java.net.URL; -import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; +import java.util.jar.Attributes; +import java.util.jar.JarFile; +import java.util.jar.Manifest; +import java.util.stream.Collectors; import org.springframework.stereotype.Service; -import cn.hutool.core.util.ClassLoaderUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.lang.Singleton; +import cn.hutool.core.map.MapUtil; +import cn.hutool.system.JavaRuntimeInfo; +import lombok.extern.slf4j.Slf4j; /** * SystemServiceImpl @@ -41,7 +52,13 @@ * @since 2022/10/15 19:17 */ @Service +@Slf4j public class SystemServiceImpl implements SystemService { + private static final Map> JAR_GROUP_MAP = MapUtil.builder(new HashMap>()) + .put("Dinky", Arrays.asList("org.dinky")) + .put("Flink", Arrays.asList("org.apache.flink")) + .put("CDC", Arrays.asList("com.ververica")) + .build(); @Override public List listLogDir() { @@ -58,16 +75,41 @@ public String readFile(String path) { * @return */ @Override - public List queryAllClassLoaderJarFiles() { - List jarFiles = new ArrayList<>(); - ClassLoader systemClassLoader = ClassLoaderUtil.getSystemClassLoader(); - if (systemClassLoader instanceof URLClassLoader) { - URLClassLoader urlClassLoader = (URLClassLoader) systemClassLoader; - URL[] urlClassLoaderURLs = urlClassLoader.getURLs(); - for (URL url : urlClassLoaderURLs) { - jarFiles.add(url.getFile()); + public Map> queryAllClassLoaderJarFiles() { + Map> result = new LinkedHashMap<>(); + filterJarGroup(result); + return result; + } + + private static void filterJarGroup(Map> result) { + List pathList = + Arrays.asList(Singleton.get(JavaRuntimeInfo.class).getClassPathArray()); + result.put("System", pathList); + List jarList = pathList.stream() + .map(FileUtil::file) + .filter(x -> FileUtil.pathEndsWith(x, ".jar")) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(jarList)) { + for (File file : jarList) { + try (JarFile jarFile = new JarFile(file)) { + Manifest manifest = jarFile.getManifest(); + if (manifest == null) { + continue; + } + Attributes attributes = manifest.getMainAttributes(); + if (attributes != null) { + String groupId = attributes.getValue("Implementation-Vendor-Id"); + JAR_GROUP_MAP.forEach((k, v) -> { + if (v.contains(groupId)) { + result.computeIfAbsent(k, key -> new ArrayList<>()); + result.get(k).add(file.getAbsolutePath()); + } + }); + } + } catch (Exception e) { + log.error("get All ClassLoaderJarFiles error", e); + } } } - return jarFiles; } } diff --git a/dinky-web/src/pages/SettingCenter/ClassLoaderJars/index.tsx b/dinky-web/src/pages/SettingCenter/ClassLoaderJars/index.tsx index 8a865ee3bc..6c02afd510 100644 --- a/dinky-web/src/pages/SettingCenter/ClassLoaderJars/index.tsx +++ b/dinky-web/src/pages/SettingCenter/ClassLoaderJars/index.tsx @@ -18,24 +18,35 @@ */ import CodeShow from '@/components/CustomEditor/CodeShow'; -import { queryClassLoaderJars } from '@/pages/SettingCenter/ClassLoaderJars/service'; -import { l } from '@/utils/intl'; -import { Alert, Space } from 'antd'; -import { useEffect, useState } from 'react'; +import {queryClassLoaderJars} from '@/pages/SettingCenter/ClassLoaderJars/service'; +import {l} from '@/utils/intl'; +import {PageContainer} from '@ant-design/pro-layout'; +import {Alert, Space, Tabs} from 'antd'; +import {useEffect, useState} from 'react'; export default () => { - const [data, setData] = useState(''); + const [data, setData] = useState>(); - useEffect(() => { - queryClassLoaderJars().then((res) => { - if (res && res.length > 0) setData(res.join('\n')); - }); - }, []); + useEffect(() => { + queryClassLoaderJars().then((res) => { + if (res) setData(res); + }); + }, []); - return ( - - - - - ); + return ( + + + {data && + { + return { + key: key, + label: key, + children: , + } + })}/> + + } + + ); }; diff --git a/dinky-web/src/pages/SettingCenter/ClassLoaderJars/service.ts b/dinky-web/src/pages/SettingCenter/ClassLoaderJars/service.ts index c5284c4cc9..fda31a2b7a 100644 --- a/dinky-web/src/pages/SettingCenter/ClassLoaderJars/service.ts +++ b/dinky-web/src/pages/SettingCenter/ClassLoaderJars/service.ts @@ -20,5 +20,5 @@ import { queryDataByParams } from '@/services/BusinessCrud'; export const queryClassLoaderJars = async () => { - return (await queryDataByParams('/api/system/queryAllClassLoaderJarFiles')) ?? []; + return (await queryDataByParams>('/api/system/queryAllClassLoaderJarFiles')) ?? {}; }; From 649cb740746ecc8f95c4e882f7dce2853816d432 Mon Sep 17 00:00:00 2001 From: zackyoungh Date: Tue, 30 Jan 2024 05:54:00 +0000 Subject: [PATCH 2/2] Spotless Apply --- .../SettingCenter/ClassLoaderJars/index.tsx | 62 +++++++++++-------- .../SettingCenter/ClassLoaderJars/service.ts | 6 +- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/dinky-web/src/pages/SettingCenter/ClassLoaderJars/index.tsx b/dinky-web/src/pages/SettingCenter/ClassLoaderJars/index.tsx index 6c02afd510..b1f85be864 100644 --- a/dinky-web/src/pages/SettingCenter/ClassLoaderJars/index.tsx +++ b/dinky-web/src/pages/SettingCenter/ClassLoaderJars/index.tsx @@ -18,35 +18,43 @@ */ import CodeShow from '@/components/CustomEditor/CodeShow'; -import {queryClassLoaderJars} from '@/pages/SettingCenter/ClassLoaderJars/service'; -import {l} from '@/utils/intl'; -import {PageContainer} from '@ant-design/pro-layout'; -import {Alert, Space, Tabs} from 'antd'; -import {useEffect, useState} from 'react'; +import { queryClassLoaderJars } from '@/pages/SettingCenter/ClassLoaderJars/service'; +import { l } from '@/utils/intl'; +import { Alert, Space, Tabs } from 'antd'; +import { useEffect, useState } from 'react'; export default () => { - const [data, setData] = useState>(); + const [data, setData] = useState>(); - useEffect(() => { - queryClassLoaderJars().then((res) => { - if (res) setData(res); - }); - }, []); + useEffect(() => { + queryClassLoaderJars().then((res) => { + if (res) setData(res); + }); + }, []); - return ( - - - {data && - { - return { - key: key, - label: key, - children: , - } - })}/> - - } - - ); + return ( + + + {data && ( + { + return { + key: key, + label: key, + children: ( + + ) + }; + })} + /> + )} + + ); }; diff --git a/dinky-web/src/pages/SettingCenter/ClassLoaderJars/service.ts b/dinky-web/src/pages/SettingCenter/ClassLoaderJars/service.ts index fda31a2b7a..81bb52d41a 100644 --- a/dinky-web/src/pages/SettingCenter/ClassLoaderJars/service.ts +++ b/dinky-web/src/pages/SettingCenter/ClassLoaderJars/service.ts @@ -20,5 +20,9 @@ import { queryDataByParams } from '@/services/BusinessCrud'; export const queryClassLoaderJars = async () => { - return (await queryDataByParams>('/api/system/queryAllClassLoaderJarFiles')) ?? {}; + return ( + (await queryDataByParams>( + '/api/system/queryAllClassLoaderJarFiles' + )) ?? {} + ); };