14
14
import com .intellij .openapi .progress .ProgressIndicator ;
15
15
import com .intellij .openapi .progress .ProgressManager ;
16
16
import com .intellij .openapi .util .TextRange ;
17
+ import com .intellij .openapi .vfs .VirtualFile ;
17
18
import com .intellij .psi .PsiFile ;
18
19
import com .intellij .util .DocumentUtil ;
19
20
import com .intellij .util .execution .ParametersListUtil ;
@@ -55,7 +56,7 @@ private static ProblemHighlightType severityToHighlightType(@NotNull final Strin
55
56
}
56
57
57
58
// TODO: make configurable
58
- private static final boolean VERBOSE_LOG = false ;
59
+ private static final int VERBOSE_LOG = 0 ;
59
60
private static final String INCONCLUSIVE_TEXT = ":inconclusive" ;
60
61
61
62
@ NotNull
@@ -65,10 +66,11 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
65
66
@ NotNull final String cppcheckOutput ,
66
67
@ NotNull final String sourceFileName ) throws IOException , SAXException , ParserConfigurationException {
67
68
68
- if (VERBOSE_LOG ) {
69
+ final VirtualFile vFile = psiFile .getVirtualFile ();
70
+ if (VERBOSE_LOG >= 1 ) {
69
71
// TODO: provide XML output via a "Show Cppcheck output" action - event log messages are truncated
70
- CppcheckNotification .send ("execution output for " + psiFile . getVirtualFile () .getCanonicalPath (),
71
- cppcheckOutput ,
72
+ CppcheckNotification .send ("finished analysis for " + vFile .getCanonicalPath (),
73
+ "" ,
72
74
NotificationType .INFORMATION );
73
75
}
74
76
@@ -127,7 +129,7 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
127
129
}
128
130
129
131
// suppress this warning for headers until Cppcheck handles them in a better way
130
- if (SupportedExtensions .isHeaderFile (psiFile . getVirtualFile () ) && id .equals ("unusedStructMember" )) {
132
+ if (SupportedExtensions .isHeaderFile (vFile ) && id .equals ("unusedStructMember" )) {
131
133
continue ;
132
134
}
133
135
@@ -150,7 +152,7 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
150
152
151
153
// ignore entries without location e.g. missingIncludeSystem
152
154
if (location == null ) {
153
- CppcheckNotification .send ("no location for " + psiFile . getVirtualFile () .getCanonicalPath (),
155
+ CppcheckNotification .send ("no location for " + vFile .getCanonicalPath (),
154
156
id + " " + severity + " " + inconclusive + " " + errorMessage ,
155
157
NotificationType .ERROR );
156
158
continue ;
@@ -167,6 +169,12 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
167
169
column = Integer .parseInt (columnAttr .getNodeValue ());
168
170
}
169
171
172
+ if (VERBOSE_LOG >= 4 ) {
173
+ CppcheckNotification .send (id + " for " + vFile .getCanonicalPath (),
174
+ id + " " + severity + " " + inconclusive + " " + errorMessage + " " + fileName + " " + lineNumber + " " + column ,
175
+ NotificationType .INFORMATION );
176
+ }
177
+
170
178
// If a file #include's header files, Cppcheck will also run on the header files and print
171
179
// any errors. These errors don't apply to the current file and should not be drawn. They can
172
180
// be distinguished by checking the file name.
@@ -176,7 +184,7 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
176
184
177
185
// Cppcheck error
178
186
if (lineNumber <= 0 || lineNumber > document .getLineCount ()) {
179
- CppcheckNotification .send ("line number out-of-bounds for " + psiFile . getVirtualFile () .getCanonicalPath (),
187
+ CppcheckNotification .send ("line number out-of-bounds for " + vFile .getCanonicalPath (),
180
188
id + " " + severity + " " + inconclusive + " " + errorMessage + " " + fileName + " " + lineNumber + " " + column ,
181
189
NotificationType .ERROR );
182
190
continue ;
@@ -201,20 +209,27 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
201
209
202
210
private static final int TIMEOUT_MS = 60 * 1000 ;
203
211
204
- public static String executeCommandOnFile (@ NotNull final String command ,
212
+ public static String executeCommandOnFile (@ NotNull final VirtualFile vFile ,
213
+ @ NotNull final String command ,
205
214
@ NotNull final String options ,
206
- @ NotNull final String filePath ,
215
+ @ NotNull final File filePath ,
207
216
final String cppcheckMisraPath ) throws CppcheckError , ExecutionException {
208
217
final GeneralCommandLine cmd = new GeneralCommandLine ()
209
218
.withExePath (command )
210
219
.withParameters (ParametersListUtil .parse (options ))
211
- .withParameters (ParametersListUtil .parse ("\" " + filePath + "\" " ));
220
+ .withParameters (ParametersListUtil .parse ("\" " + filePath . getAbsolutePath () + "\" " ));
212
221
213
222
// Need to be able to get python from the system env
214
223
if (cppcheckMisraPath != null && !cppcheckMisraPath .isEmpty ()) {
215
224
cmd .withParentEnvironmentType (GeneralCommandLine .ParentEnvironmentType .SYSTEM );
216
225
}
217
226
227
+ if (VERBOSE_LOG >= 2 ) {
228
+ CppcheckNotification .send ("options for " + vFile .getCanonicalPath (),
229
+ cmd .getCommandLineString (),
230
+ NotificationType .INFORMATION );
231
+ }
232
+
218
233
final CapturingProcessHandler processHandler = new CapturingProcessHandler (cmd );
219
234
final ProgressIndicator indicator = ProgressManager .getInstance ().getProgressIndicator ();
220
235
final ProcessOutput output = processHandler .runProcessWithProgressIndicator (
0 commit comments