Skip to content

Commit 0a74f7d

Browse files
committed
Allow to configure how many threads should be used.
1 parent 5d46cf3 commit 0a74f7d

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/main/java/com/intellij/plugins/bodhi/pmd/PMDConfigurationForm.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public class PMDConfigurationForm {
5050

5151
public static final String STATISTICS_URL = "Statistics URL";
5252
private static final String[] columnNames = new String[] {"Option", "Value"};
53-
private static final String[] optionNames = new String[] {"Target JDK", STATISTICS_URL};
54-
private static final String[] defaultValues = new String[] {"17", ""};
53+
private static final String[] optionNames = new String[] {"Target JDK", STATISTICS_URL, "Threads"};
54+
private static final String[] defaultValues = new String[] {"17", "", "1"};
5555
private static final String STAT_URL_MSG = "Fill in Statistics URL endpoint to export anonymous PMD-Plugin usage statistics";
5656
private static final String STAT_URL_MSG_SUCCESS = "Could connect, will use Statistics URL endpoint to export anonymous PMD-Plugin usage statistics";
5757

@@ -253,9 +253,11 @@ public void setValueAt(Object aValue, int row, int column) {
253253
super.setValueAt(aValue, row, column);
254254
boolean origIsMod = isModified;
255255
isModified = isModified || !orig.equals(aValue);
256-
// row 1: statistics URL
257-
if (row == 1) {
258-
validateStatUrl((String) aValue, row, column, orig, origIsMod);
256+
switch (row) {
257+
// row 1: statistics URL
258+
case 1: validateStatUrl((String) aValue, row, column, orig, origIsMod);
259+
// row 2: threads
260+
case 2: validateThreads((String) aValue, row, column, orig, origIsMod);
259261
}
260262
}
261263

@@ -292,6 +294,23 @@ private void validateStatUrl(String url, int row, int column, Object orig, boole
292294
}
293295
table1.setToolTipText(statUrlMsg);
294296
}
297+
298+
private void validateThreads(String threads, int row, int column, Object orig, boolean origIsMod) {
299+
boolean ok = true;
300+
try {
301+
int asInt = Integer.parseInt(threads);
302+
if (asInt < 1) {
303+
ok = false;
304+
}
305+
} catch (NumberFormatException ne) {
306+
ok = false;
307+
}
308+
if (!ok) {
309+
super.setValueAt(orig, row, column);
310+
table1.setToolTipText("Must be an positive integer");
311+
isModified = origIsMod;
312+
}
313+
}
295314
}
296315

297316
private class MyListModel extends AbstractListModel {

src/main/java/com/intellij/plugins/bodhi/pmd/core/PMDResultCollector.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,13 @@ private PMDConfiguration getPmdConfig(String ruleSets, Map<String, String> optio
125125
pmdConfig.addRuleSet(ruleSets);
126126
pmdConfig.setReportFile(File.createTempFile("pmd", "report").getAbsolutePath());
127127
pmdConfig.setShowSuppressedViolations(true);
128-
pmdConfig.setThreads(0);
128+
129+
String threads = options.get("Threads");
130+
if (threads == null || threads.equals("1")) {
131+
pmdConfig.setThreads(0); // 0 is a special value invoking in single thread mood
132+
} else {
133+
pmdConfig.setThreads(Integer.parseInt(threads));
134+
}
129135
return pmdConfig;
130136
}
131137

0 commit comments

Comments
 (0)