七仔的博客

七仔的博客GithubPages分博

0%

python自动判断Maven依赖

python自动判断Maven依赖

python自动判断Maven依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
naee 自动判断Maven依赖
by 陈思奇
time 2019.9.9
methods 填写好下方的项目绝路路径和groupId运行后复制运行结果粘贴到excel即可
"""
import os.path
from xml.dom.minidom import parse

ProjectPath = "D:\project\java\IntelliJ\cathayfuture" # 一定要写绝对路径
yourGroupId = "com.baokang" # 要判断的groupId

excelPast = '服务名\t依赖\n'
rootDir = os.path.abspath(ProjectPath)
for parent, dirnames, filenames in os.walk(rootDir):
for filename in filenames:
if "pom.xml" == filename:
pathfile = os.path.join(parent, filename) # 获得pom文件路径
DOMTree = parse(pathfile)
project = DOMTree.documentElement # project节点
dependencies = project.getElementsByTagName('dependencies') # dependencies节点列表
if dependencies.length == 0:
continue
dependencyList = dependencies[0].getElementsByTagName('dependency') # dependency节点列表
dependencyStr = ''
for dependency in dependencyList:
groupId = dependency.getElementsByTagName('groupId')[0] # groupId节点
if groupId.firstChild.data == yourGroupId: # 判断是否为该groupId
dependencyStr += \
dependency.getElementsByTagName('artifactId')[0].firstChild.data + '\n' # excel字符串拼接
if dependencyStr != '':
dependencyStr = dependencyStr[:len(dependencyStr) - 1] # excel粘贴格式原因
excelPast += parent[parent.rfind("\\") + 1:] + "\t\"" + dependencyStr + "\"\n" # excel字符串拼接
print(excelPast)

此为博主副博客,留言请去主博客,转载请注明出处:https://www.baby7blog.com/myBlog/41.html

欢迎关注我的其它发布渠道