6
6
package com .magento .idea .magento2uct .execution ;
7
7
8
8
import com .intellij .codeInspection .ProblemDescriptor ;
9
+ import com .intellij .execution .process .ProcessAdapter ;
10
+ import com .intellij .execution .process .ProcessEvent ;
9
11
import com .intellij .execution .process .ProcessHandler ;
12
+ import com .intellij .json .psi .JsonFile ;
10
13
import com .intellij .openapi .application .ApplicationManager ;
14
+ import com .intellij .openapi .editor .Document ;
11
15
import com .intellij .openapi .project .Project ;
12
16
import com .intellij .openapi .vfs .VfsUtil ;
13
17
import com .intellij .openapi .vfs .VirtualFile ;
14
18
import com .intellij .psi .PsiDirectory ;
19
+ import com .intellij .psi .PsiDocumentManager ;
15
20
import com .intellij .psi .PsiFile ;
16
21
import com .intellij .psi .PsiManager ;
17
22
import com .jetbrains .php .lang .psi .PhpFile ;
23
+ import com .magento .idea .magento2uct .execution .output .ReportBuilder ;
24
+ import com .magento .idea .magento2uct .execution .output .Summary ;
25
+ import com .magento .idea .magento2uct .execution .output .UctReportOutputUtil ;
18
26
import com .magento .idea .magento2uct .execution .process .OutputWrapper ;
19
27
import com .magento .idea .magento2uct .execution .scanner .ModuleFilesScanner ;
20
28
import com .magento .idea .magento2uct .execution .scanner .ModuleScanner ;
@@ -51,6 +59,15 @@ public GenerateUctReportCommand(
51
59
this .output = output ;
52
60
this .process = process ;
53
61
settingsService = UctSettingsService .getInstance (project );
62
+
63
+ this .process .addProcessListener (new ProcessAdapter () {
64
+
65
+ @ Override
66
+ public void processTerminated (final @ NotNull ProcessEvent event ) {
67
+ super .processTerminated (event );
68
+ output .write ("\n Process finished with exit code " + event .getExitCode () + "\n " );
69
+ }
70
+ });
54
71
}
55
72
56
73
/**
@@ -74,9 +91,15 @@ public void execute() {
74
91
rootDirectory ,
75
92
new ExcludeMagentoBundledFilter ()
76
93
);
94
+ final Summary summary = new Summary (
95
+ settingsService .getCurrentVersion (),
96
+ settingsService .getTargetVersion ()
97
+ );
98
+ final ReportBuilder reportBuilder = new ReportBuilder (project );
77
99
78
100
ApplicationManager .getApplication ().executeOnPooledThread (() -> {
79
101
ApplicationManager .getApplication ().runReadAction (() -> {
102
+ summary .trackProcessStarted ();
80
103
for (final ComponentData componentData : scanner ) {
81
104
if (process .isProcessTerminated ()) {
82
105
return ;
@@ -87,6 +110,7 @@ public void execute() {
87
110
if (!(psiFile instanceof PhpFile )) {
88
111
continue ;
89
112
}
113
+ final String filename = psiFile .getVirtualFile ().getPath ();
90
114
final UctProblemsHolder fileProblemsHolder = inspectionManager .run (psiFile );
91
115
92
116
if (fileProblemsHolder == null ) {
@@ -98,7 +122,7 @@ public void execute() {
98
122
outputUtil .printModuleName (componentData .getName ());
99
123
isModuleHeaderPrinted = true ;
100
124
}
101
- outputUtil .printProblemFile (psiFile . getVirtualFile (). getPath () );
125
+ outputUtil .printProblemFile (filename );
102
126
}
103
127
104
128
for (final ProblemDescriptor descriptor
@@ -107,15 +131,47 @@ public void execute() {
107
131
descriptor
108
132
);
109
133
if (code != null ) {
134
+ final SupportedIssue issue = SupportedIssue .getByCode (code );
135
+
136
+ if (issue != null ) {
137
+ final String errorMessage = descriptor
138
+ .getDescriptionTemplate ()
139
+ .substring (6 )
140
+ .trim ();
141
+ summary .addToSummary (issue .getLevel ());
142
+ reportBuilder .addIssue (
143
+ descriptor .getLineNumber () + 1 ,
144
+ filename ,
145
+ errorMessage ,
146
+ issue
147
+ );
148
+ }
110
149
outputUtil .printIssue (descriptor , code );
111
150
}
112
151
}
113
152
}
114
153
}
115
- if (scanner .getModuleCount () == 0 ) {
116
- output .print (output .wrapInfo ("Couldn't find modules to analyse" ).concat ("\n " ));
154
+ summary .trackProcessFinished ();
155
+ summary .setProcessedModules (scanner .getModuleCount ());
156
+ outputUtil .printSummary (summary );
157
+ reportBuilder .addSummary (summary );
158
+ });
159
+
160
+ ApplicationManager .getApplication ().invokeLaterOnWriteThread (() -> {
161
+ final JsonFile report = reportBuilder .build ();
162
+
163
+ if (report != null ) {
164
+ final PsiDocumentManager psiDocumentManager = PsiDocumentManager .getInstance (
165
+ project
166
+ );
167
+ final Document document = psiDocumentManager .getDocument (report );
168
+
169
+ if (document != null ) {
170
+ psiDocumentManager .commitDocument (document );
171
+ }
172
+ outputUtil .printReportFile (report .getVirtualFile ().getPath ());
173
+ process .destroyProcess ();
117
174
}
118
- process .destroyProcess ();
119
175
});
120
176
});
121
177
}
@@ -139,65 +195,4 @@ public void execute() {
139
195
140
196
return PsiManager .getInstance (project ).findDirectory (targetDirVirtualFile );
141
197
}
142
-
143
- private static final class UctReportOutputUtil {
144
-
145
- private static final String ISSUE_FORMAT = " * {SEVERITY}[{code}] Line {line}: {message}" ;
146
- private final OutputWrapper stdout ;
147
-
148
- /**
149
- * UCT report styled output util.
150
- *
151
- * @param output OutputWrapper
152
- */
153
- public UctReportOutputUtil (final @ NotNull OutputWrapper output ) {
154
- stdout = output ;
155
- }
156
-
157
- /**
158
- * Print module name header.
159
- *
160
- * @param moduleName String
161
- */
162
- public void printModuleName (final @ NotNull String moduleName ) {
163
- final String moduleNameLine = "Module Name: " .concat (moduleName );
164
- stdout .print ("\n \n " + stdout .wrapInfo (moduleNameLine ).concat ("\n " ));
165
- stdout .print (stdout .wrapInfo ("-" .repeat (moduleNameLine .length ())).concat ("\n " ));
166
- }
167
-
168
- /**
169
- * Print problem file header.
170
- *
171
- * @param filePath String
172
- */
173
- public void printProblemFile (final @ NotNull String filePath ) {
174
- final String file = "File: " .concat (filePath );
175
- stdout .print ("\n " .concat (stdout .wrapInfo (file )).concat ("\n " ));
176
- stdout .print (stdout .wrapInfo ("-" .repeat (file .length ())).concat ("\n \n " ));
177
- }
178
-
179
- /**
180
- * Print issue message.
181
- *
182
- * @param descriptor ProblemDescriptor
183
- * @param code int
184
- */
185
- public void printIssue (final @ NotNull ProblemDescriptor descriptor , final int code ) {
186
- final String errorMessage = descriptor .getDescriptionTemplate ().substring (6 ).trim ();
187
- final SupportedIssue issue = SupportedIssue .getByCode (code );
188
-
189
- if (issue == null ) {
190
- return ;
191
- }
192
-
193
- final String output = ISSUE_FORMAT
194
- .replace ("{SEVERITY}" , issue .getLevel ().getFormattedLabel ())
195
- .replace ("{code}" , Integer .toString (code ))
196
- .replace ("{line}" , Integer .toString (descriptor .getLineNumber () + 1 ))
197
- .replace ("{message}" , errorMessage )
198
- .concat ("\n " );
199
-
200
- stdout .print (output );
201
- }
202
- }
203
198
}
0 commit comments