-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpringBatchAnalysis.py
More file actions
148 lines (117 loc) · 9.36 KB
/
SpringBatchAnalysis.py
File metadata and controls
148 lines (117 loc) · 9.36 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
'''
Created on 2 feb 2017
@author: TGU
'''
import cast.analysers.jee
from cast.analysers import Bookmark
from xml.dom import minidom
class SpringBatchAnalysis(cast.analysers.jee.Extension):
def __init__(self):
self.NbSpringBatchJobCreated = 0
self.NbSpringBatchStepCreated = 0
def start_analysis(self,options):
#Save in the _local base the XML files
cast.analysers.log.info('Starting Spring Batch analysis')
cast.analysers.log.info('=============== xpath batch ')
options.handle_xml_with_xpath('/beans') # Spring Batch files
def end_analysis(self):
cast.analysers.log.info('Number of Spring job objects created : ' + str(self.NbSpringBatchJobCreated))
cast.analysers.log.info('Number of Spring step objects created : ' + str(self.NbSpringBatchStepCreated))
def start_xml_file(self,file):
xmlfilepath = file.get_path()
if not file.get_path() or len(xmlfilepath.strip()) == 0:
return
if "web.xml" in xmlfilepath or "pom.xml" in xmlfilepath:
return
cast.analysers.log.info('Scanning XML file : ' + xmlfilepath)
self.analyseXMLSpringBatchFile(xmlfilepath, file)
def analyseXMLSpringBatchFile(self, xmlfilepath, file):
cast.analysers.log.info('Scanning XML Spring Batch files ... : ' + xmlfilepath)
with minidom.parse(xmlfilepath) as doc:
root = doc.documentElement
for SpringBatch_job in root.getElementsByTagName('batch:job'):
job_id = SpringBatch_job.getAttribute('id')
cast.analysers.log.info('job Id : ' + job_id)
objectJob = cast.analysers.CustomObject()
objectJob.set_name(job_id)
objectJob.set_type('SpringBatchJob')
objectJob.set_parent(file)
objectJob.save()
self.NbSpringBatchJobCreated += 1
bookmark = Bookmark(file, 1, 1, -1, -1) # TODO : find exact position
objectJob.save_position(bookmark)
for SpringBatch_step in SpringBatch_job.getElementsByTagName('batch:step'):
step_id = SpringBatch_step.getAttribute('id')
cast.analysers.log.info('==== step id : ' + step_id)
objectStep = cast.analysers.CustomObject()
objectStep.set_name(step_id)
objectStep.set_type('SpringBatchStep')
objectStep.set_parent(objectJob)
objectStep.save()
self.NbSpringBatchStepCreated += 1
bookmark = Bookmark(file, 1, 1, -1, -1) # TODO : find exact position
objectStep.save_position(bookmark)
tasklet_chunk = ''
for SpringBatch_tasklet in SpringBatch_step.getElementsByTagName('batch:tasklet'):
step_tasklet = SpringBatch_tasklet.getAttribute('ref')
cast.analysers.log.info('======== tasklet ref : ' + step_tasklet)
step_tasklet_transaction_manager = SpringBatch_tasklet.getAttribute('transaction-manager')
cast.analysers.log.info('======== tasklet transaction-manager : ' + step_tasklet_transaction_manager)
for SpringBatch_tasklet_chunk in SpringBatch_tasklet.getElementsByTagName('chunk'):
step_tasklet_chunk_reader = SpringBatch_tasklet_chunk.getAttribute('reader')
cast.analysers.log.info('======== tasklet chunk reader : ' + step_tasklet_chunk_reader)
tasklet_chunk += step_tasklet_chunk_reader + "#"
step_tasklet_chunk_writer = SpringBatch_tasklet_chunk.getAttribute('writer')
cast.analysers.log.info('======== tasklet chunk writer : ' + step_tasklet_chunk_writer)
tasklet_chunk += step_tasklet_chunk_writer + "#"
step_tasklet_chunk_processor = SpringBatch_tasklet_chunk.getAttribute('processor')
cast.analysers.log.info('======== tasklet chunk processor : ' + step_tasklet_chunk_processor)
tasklet_chunk += step_tasklet_chunk_processor + "#"
cast.analysers.log.info('======== tasklet chunk : ' + tasklet_chunk)
for SpringBatch_tasklet_chunk in SpringBatch_tasklet.getElementsByTagName('batch:chunk'):
step_tasklet_chunk_reader = SpringBatch_tasklet_chunk.getAttribute('reader')
cast.analysers.log.info('======== tasklet chunk reader : ' + step_tasklet_chunk_reader)
tasklet_chunk += step_tasklet_chunk_reader + "#"
step_tasklet_chunk_writer = SpringBatch_tasklet_chunk.getAttribute('writer')
cast.analysers.log.info('======== tasklet chunk writer : ' + step_tasklet_chunk_writer)
tasklet_chunk += step_tasklet_chunk_writer + "#"
step_tasklet_chunk_processor = SpringBatch_tasklet_chunk.getAttribute('processor')
cast.analysers.log.info('======== tasklet chunk processor : ' + step_tasklet_chunk_processor)
tasklet_chunk += step_tasklet_chunk_processor + "#"
cast.analysers.log.info('======== tasklet chunk : ' + tasklet_chunk)
for SpringBatch_tasklet in SpringBatch_step.getElementsByTagName('tasklet'):
step_tasklet = SpringBatch_tasklet.getAttribute('ref')
cast.analysers.log.info('======== tasklet ref : ' + step_tasklet)
step_tasklet_transaction_manager = SpringBatch_tasklet.getAttribute('transaction-manager')
cast.analysers.log.info('======== tasklet transaction-manager : ' + step_tasklet_transaction_manager)
for SpringBatch_tasklet_chunk in SpringBatch_tasklet.getElementsByTagName('chunk'):
step_tasklet_chunk_reader = SpringBatch_tasklet_chunk.getAttribute('reader')
cast.analysers.log.info('======== tasklet chunk reader : ' + step_tasklet_chunk_reader)
tasklet_chunk += step_tasklet_chunk_reader + "#"
step_tasklet_chunk_writer = SpringBatch_tasklet_chunk.getAttribute('writer')
cast.analysers.log.info('======== tasklet chunk writer : ' + step_tasklet_chunk_writer)
tasklet_chunk += step_tasklet_chunk_writer + "#"
step_tasklet_chunk_processor = SpringBatch_tasklet_chunk.getAttribute('processor')
cast.analysers.log.info('======== tasklet chunk processor : ' + step_tasklet_chunk_processor)
tasklet_chunk += step_tasklet_chunk_processor + "#"
cast.analysers.log.info('======== tasklet chunk : ' + tasklet_chunk)
for SpringBatch_tasklet_chunk in SpringBatch_tasklet.getElementsByTagName('batch:chunk'):
step_tasklet_chunk_reader = SpringBatch_tasklet_chunk.getAttribute('reader')
cast.analysers.log.info('======== tasklet chunk reader : ' + step_tasklet_chunk_reader)
tasklet_chunk += step_tasklet_chunk_reader + "#"
step_tasklet_chunk_writer = SpringBatch_tasklet_chunk.getAttribute('writer')
cast.analysers.log.info('======== tasklet chunk writer : ' + step_tasklet_chunk_writer)
tasklet_chunk += step_tasklet_chunk_writer + "#"
step_tasklet_chunk_processor = SpringBatch_tasklet_chunk.getAttribute('processor')
cast.analysers.log.info('======== tasklet chunk processor : ' + step_tasklet_chunk_processor)
tasklet_chunk += step_tasklet_chunk_processor + "#"
cast.analysers.log.info('======== tasklet chunk : ' + tasklet_chunk)
objectStep.save_property('SpringBatchStep.step_tasklet', str(step_tasklet))
objectStep.save_property('SpringBatchStep.step_tasklet_transaction_manager', str(step_tasklet_transaction_manager))
objectStep.save_property('SpringBatchStep.step_tasklet_chunk', str(tasklet_chunk))
step_next = ''
for SpringBatch_next in SpringBatch_step.getElementsByTagName('batch:next'):
next_to = SpringBatch_next.getAttribute('to')
step_next += next_to + "#"
cast.analysers.log.info('======== next to : ' + next_to)
objectStep.save_property('SpringBatchStep.step_next', str(step_next))