Skip to content

Commit d83e10f

Browse files
authored
Merge pull request #3 from garbbraf/additional_project_file
feat: add an option to include cppcheck project file
2 parents 78a35ec + fc2bc9d commit d83e10f

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/IPreferenceConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public interface IPreferenceConstants {
2323
public static final String P_FOLLOW_SYSTEM_INCLUDES = "followSystemIncludes";
2424
public static final String P_FOLLOW_USER_INCLUDES = "followUserIncludes";
2525
public static final String P_NUMBER_OF_THREADS = "numberOfThreads";
26+
public static final String P_PROJECT_FILE = "projectFile";
2627
public static final String P_AUTOMATIC_UPDATE_CHECK_INTERVAL = "automaticUpdateCheckInterval";
2728
public static final String P_USE_AUTOMATIC_UPDATE_CHECK = "automaticUpdateCheck";
2829
public static final String P_LAST_UPDATE_CHECK = "lastUpdateCheck";

com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/PreferenceInitializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private static void initializeSettingsDefault(IPreferenceStore store) {
3434
store.setDefault(IPreferenceConstants.P_FOLLOW_SYSTEM_INCLUDES, false);
3535
store.setDefault(IPreferenceConstants.P_FOLLOW_USER_INCLUDES, false);
3636
store.setDefault(IPreferenceConstants.P_NUMBER_OF_THREADS, 1);
37+
store.setDefault(IPreferenceConstants.P_PROJECT_FILE, "");
3738
}
3839

3940
private static void initializeProblemsDefault(IPreferenceStore store) {

com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/command/CppcheckCommand.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ public CppcheckCommand(IConsole console, String binaryPath,
124124
}
125125
}
126126

127+
String projectFile = settingsStore.getString(IPreferenceConstants.P_PROJECT_FILE);
128+
if (!projectFile.isEmpty()) {
129+
arguments.add("--project=" + projectFile);
130+
arguments.add("--file-filter=-");
131+
} else {
132+
arguments.add("--file-list=-");
133+
}
134+
127135
if (settingsStore.getBoolean(IPreferenceConstants.P_CHECK_VERBOSE)) {
128136
arguments.add("--verbose");
129137
}
@@ -227,10 +235,9 @@ public void run(Checker checker, IProgressReporter progressReporter,
227235
console.println("=== Input stream for following process ===");
228236
console.println(input);
229237
console.println("=== End of input stream for process ==");
230-
238+
231239
setProcessInputStream(new ByteArrayInputStream(input.getBytes(DEFAULT_CHARSET)));
232-
arguments.add("--file-list=-");
233-
240+
234241
setWorkingDirectory(projectFolder);
235242
CppcheckProcessResultHandler resultHandler = runInternal(
236243
arguments.toArray(new String[0]), advancedArguments,

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public class Messages extends NLS {
6969
public static String SettingsPreferencePage_FollowSystemIncludes;
7070
public static String SettingsPreferencePage_Force;
7171
public static String SettingsPreferencePage_NumberOfThreads;
72+
public static String SettingsPreferencePage_ProjectFile;
73+
public static String SettingsPreferencePage_ProjectFileDialogButton;
7274
public static String SettingsPreferencePage_UnusedFunctions;
7375
public static String SettingsPreferencePage_Verbose;
7476
public static String SuppressFileResolution_Label;

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ SettingsPreferencePage_FollowUserIncludes=Follow user-defined includes (taken fr
4343
SettingsPreferencePage_FollowSystemIncludes=Follow system-defined includes (taken from CDT settings)
4444
SettingsPreferencePage_Force=Force all configurations (--force)
4545
SettingsPreferencePage_NumberOfThreads=Number of threads to use
46+
SettingsPreferencePage_ProjectFile=Project file
47+
SettingsPreferencePage_ProjectFileDialogButton=Browse
4648
SettingsPreferencePage_UnusedFunctions=Check unused functions (disables multiple thread processing)
4749
SettingsPreferencePage_Verbose=Verbose (--verbose)
4850
SettingsPreferencePage_Inconclusive=Enable inconclusive checks. Might lead to false positives (--inconclusive)

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/preferences/SettingsPreferencePage.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
import org.eclipse.jface.preference.BooleanFieldEditor;
77
import org.eclipse.jface.preference.ComboFieldEditor;
88
import org.eclipse.jface.preference.IntegerFieldEditor;
9+
import org.eclipse.jface.preference.StringButtonFieldEditor;
910
import org.eclipse.swt.SWT;
1011
import org.eclipse.swt.widgets.Composite;
1112
import org.eclipse.swt.widgets.Control;
1213
import org.eclipse.swt.widgets.Group;
14+
import org.eclipse.swt.widgets.FileDialog;
1315
import org.eclipse.ui.IWorkbench;
1416
import org.eclipse.ui.IWorkbenchPreferencePage;
1517

1618
import com.googlecode.cppcheclipse.core.CppcheclipsePlugin;
1719
import com.googlecode.cppcheclipse.core.IPreferenceConstants;
20+
import com.googlecode.cppcheclipse.ui.Console;
1821
import com.googlecode.cppcheclipse.ui.Messages;
1922

2023
public class SettingsPreferencePage extends FieldEditorOverlayPage implements
@@ -23,6 +26,7 @@ public class SettingsPreferencePage extends FieldEditorOverlayPage implements
2326
private BooleanFieldEditor allCheck;
2427
private BooleanFieldEditor unusedFunctionsCheck;
2528
private IntegerFieldEditor numberOfThreads;
29+
private StringButtonFieldEditor projectFile;
2630
private List<BooleanFieldEditor> checkEditors;
2731
private Group checkGroup;
2832

@@ -120,6 +124,21 @@ protected void valueChanged(boolean oldValue, boolean newValue) {
120124

121125
@Override
122126
protected void createFieldEditors() {
127+
128+
final FileDialog projectFileDialog = new FileDialog(getShell(), SWT.OPEN);
129+
projectFile = new StringButtonFieldEditor(IPreferenceConstants.P_PROJECT_FILE,
130+
Messages.SettingsPreferencePage_ProjectFile, getFieldEditorParent()) {
131+
132+
@Override
133+
protected String changePressed() {
134+
return projectFileDialog.open();
135+
}
136+
137+
};
138+
projectFile.setChangeButtonText(Messages.SettingsPreferencePage_ProjectFileDialogButton);
139+
projectFile.setEmptyStringAllowed(true);
140+
addField(projectFile);
141+
123142
numberOfThreads = new IntegerFieldEditor(
124143
IPreferenceConstants.P_NUMBER_OF_THREADS,
125144
Messages.SettingsPreferencePage_NumberOfThreads,

0 commit comments

Comments
 (0)