in cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java [435:587]
private static GroupResult handleGroup(RootConfiguration rootConfiguration, ProgressHandleWrapper w, GlobalConfiguration globalConfig, List<String> config) throws IOException {
Iterable<? extends HintDescription> hints;
if (rootConfiguration.rootFolders.isEmpty()) {
return GroupResult.NOTHING_TO_DO;
}
WarningsAndErrors wae = new WarningsAndErrors();
ProgressHandleWrapper progress = w.startNextPartWithEmbedding(1);
Preferences settings = globalConfig.configurationPreferences != null ? globalConfig.configurationPreferences : new MemoryPreferences();
HintsSettings hintSettings = HintsSettings.createPreferencesBasedHintsSettings(settings, globalConfig.useDefaultEnabledSetting, null);
if (globalConfig.hint != null) {
hints = findHints(rootConfiguration.sourceCP, rootConfiguration.binaryCP, globalConfig.hint, hintSettings);
} else if (globalConfig.hintFile != null) {
FileObject hintFileFO = FileUtil.toFileObject(globalConfig.hintFile);
assert hintFileFO != null;
hints = PatternConvertor.create(hintFileFO.asText());
for (HintDescription hd : hints) {
hintSettings.setEnabled(hd.getMetadata(), true);
}
} else {
hints = readHints(rootConfiguration.sourceCP, rootConfiguration.binaryCP, hintSettings, settings, globalConfig.runDeclarative);
if (globalConfig.runDeclarativeTests) {
Set<String> enabledHints = new HashSet<>();
for (HintDescription desc : hints) {
enabledHints.add(desc.getMetadata().id);
}
ClassPath combined = ClassPathSupport.createProxyClassPath(rootConfiguration.sourceCP, rootConfiguration.binaryCP);
Map<FileObject, FileObject> testFiles = new HashMap<>();
for (FileObject upgrade : combined.findAllResources("META-INF/upgrade")) {
for (FileObject c : upgrade.getChildren()) {
if (c.getExt().equals("test")) {
FileObject hintFile = FileUtil.findBrother(c, "hint");
for (HintMetadata hm : DeclarativeHintRegistry.parseHintFile(hintFile).keySet()) {
if (enabledHints.contains(hm.id)) {
testFiles.put(c, hintFile);
break;
}
}
}
}
}
for (Entry<FileObject, FileObject> e : testFiles.entrySet()) {
TestCase[] testCases = TestParser.parse(e.getKey().asText()); //XXX: encoding
try {
Map<TestCase, Collection<String>> testResult = TestPerformer.performTest(e.getValue(), e.getKey(), testCases, new AtomicBoolean());
for (TestCase tc : testCases) {
List<String> expected = Arrays.asList(tc.getResults());
List<String> actual = new ArrayList<>(testResult.get(tc));
if (!expected.equals(actual)) {
int pos = tc.getTestCaseStart();
String id = "test-failure";
ErrorDescription ed = ErrorDescriptionFactory.createErrorDescription(id, Severity.ERROR, "Actual results did not match the expected test results. Actual results: " + expected, null, ErrorDescriptionFactory.lazyListForFixes(Collections.<Fix>emptyList()), e.getKey(), pos, pos);
print(ed, wae, Collections.singletonMap(id, id));
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
if (config != null && !config.isEmpty()) {
Iterator<? extends HintDescription> hit = hints.iterator();
HintDescription hd = hit.next();
if (hit.hasNext()) {
System.err.println("--config cannot specified when more than one hint is specified");
return GroupResult.FAILURE;
}
Preferences prefs = hintSettings.getHintPreferences(hd.getMetadata());
boolean stop = false;
for (String c : config) {
int assign = c.indexOf('=');
if (assign == (-1)) {
System.err.println("configuration option is missing '=' (" + c + ")");
stop = true;
continue;
}
prefs.put(c.substring(0, assign), c.substring(assign + 1));
}
if (stop) {
return GroupResult.FAILURE;
}
}
String sourceLevel = rootConfiguration.sourceLevel;
if (!Pattern.compile(ACCEPTABLE_SOURCE_LEVEL_PATTERN).matcher(sourceLevel).matches()) {
System.err.println("unrecognized source level specification: " + sourceLevel);
return GroupResult.FAILURE;
}
if (globalConfig.apply && !hints.iterator().hasNext()) {
return GroupResult.NO_HINTS_FOUND;
}
RootConfiguration prevConfig = currentRootConfiguration.get();
PatchDescription patch;
if (globalConfig.patchFile != null) {
patch = createPatchDescription(rootConfiguration, globalConfig.patchFile);
if (patch.file2AddedLines.isEmpty()) {
return GroupResult.SUCCESS;
}
hints = filterHints(hints, patch);
} else {
patch = null;
}
try {
currentRootConfiguration.set(rootConfiguration);
try {
ProgressHandleWrapper nestedProgress = progress.startNextPartWithEmbedding(1, 1);
BatchSearch.Scope scope = Scopes.specifiedFoldersScope(rootConfiguration.rootFolders.toArray(new Folder[0]));
BatchResult occurrences = BatchSearch.findOccurrences(hints, scope, nestedProgress, hintSettings);
occurrences = filterBatchResult(occurrences, patch);
if (globalConfig.apply) {
apply(nestedProgress, occurrences, globalConfig.out);
return GroupResult.SUCCESS; //TODO: WarningsAndErrors?
} else {
findOccurrences(nestedProgress, occurrences, hints, wae);
if (wae.errors != 0 || (wae.warnings != 0 && globalConfig.failOnWarnings)) {
return GroupResult.FAILURE;
} else {
return GroupResult.SUCCESS;
}
}
} catch (IOException t) {
throw new UncheckedIOException(t);
}
} finally {
currentRootConfiguration.set(prevConfig);
}
}