Skip to content

Commit d82e369

Browse files
Let consistency checker yield a return code (#13329)
* Let consistency checker yield a return code See #13328 * Apply suggestions from code review As suggested by @koppor it makes totally sense to always exit with a non-zero exit code in case of issues. Exit code 0 means no issues in linting, exit code 1 means linting issues, exit code 2 means any other issues. Also remove the CLI flag to enable/disable the feature. * Reflect the changes in CHANGELOG.md
1 parent dbbc96c commit d82e369

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
4646
- We improved JabRef's internal document viewer. It now allows text section, searching and highlighting of search terms and page rotation [#13193](https://github.com/JabRef/jabref/pull/13193).
4747
- When importing a PDF, there is no empty entry column shown in the multi merge dialog. [#13132](https://github.com/JabRef/jabref/issues/13132)
4848
- We added a progress dialog to the "Check consistency" action and progress output to the corresponding cli command. [#12487](https://github.com/JabRef/jabref/issues/12487)
49+
- We made the `check-consistency` command of the toolkit always return an exit code; 0 means no issues found, a non-zero exit code reflects any issues, which allows CI to fail in these cases [#13328](https://github.com/JabRef/jabref/issues/13328).
4950

5051
### Fixed
5152

jabkit/src/main/java/org/jabref/JabKit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public static void main(String[] args) {
8585
ArgumentProcessor.getAvailableImportFormats(preferences),
8686
ArgumentProcessor.getAvailableExportFormats(preferences),
8787
WebFetchers.getSearchBasedFetchers(preferences.getImportFormatPreferences(), preferences.getImporterPreferences()));
88-
commandLine.execute(args);
88+
int result = commandLine.execute(args);
89+
System.exit(result);
8990
} catch (Exception ex) {
9091
LOGGER.error("Unexpected exception", ex);
9192
}

jabkit/src/main/java/org/jabref/cli/CheckConsistency.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.Writer;
66
import java.util.List;
77
import java.util.Optional;
8+
import java.util.concurrent.Callable;
89

910
import org.jabref.logic.importer.ParserResult;
1011
import org.jabref.logic.l10n.Localization;
@@ -24,7 +25,7 @@
2425
import static picocli.CommandLine.ParentCommand;
2526

2627
@Command(name = "check-consistency", description = "Check consistency of the library.")
27-
class CheckConsistency implements Runnable {
28+
class CheckConsistency implements Callable<Integer> {
2829
private static final Logger LOGGER = LoggerFactory.getLogger(CheckConsistency.class);
2930

3031
@ParentCommand
@@ -40,20 +41,20 @@ class CheckConsistency implements Runnable {
4041
private String outputFormat;
4142

4243
@Override
43-
public void run() {
44+
public Integer call() {
4445
Optional<ParserResult> parserResult = ArgumentProcessor.importFile(
4546
inputFile,
4647
"bibtex",
4748
argumentProcessor.cliPreferences,
4849
sharedOptions.porcelain);
4950
if (parserResult.isEmpty()) {
5051
System.out.println(Localization.lang("Unable to open file '%0'.", inputFile));
51-
return;
52+
return 2;
5253
}
5354

5455
if (parserResult.get().isInvalid()) {
5556
System.out.println(Localization.lang("Input file '%0' is invalid and could not be parsed.", inputFile));
56-
return;
57+
return 2;
5758
}
5859

5960
if (!sharedOptions.porcelain) {
@@ -95,11 +96,16 @@ public void run() {
9596
writer.flush();
9697
} catch (IOException e) {
9798
LOGGER.error("Error writing results", e);
98-
return;
99+
return 2;
100+
}
101+
102+
if (!result.entryTypeToResultMap().isEmpty()) {
103+
return 1;
99104
}
100105

101106
if (!sharedOptions.porcelain) {
102107
System.out.println(Localization.lang("Consistency check completed"));
103108
}
109+
return 0;
104110
}
105111
}

jabkit/src/test/java/org/jabref/cli/ArgumentProcessorTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,12 @@ void checkConsistency() throws URISyntaxException {
143143
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
144144
System.setOut(new PrintStream(outContent, true));
145145

146-
commandLine.execute(args.toArray(String[]::new));
146+
int executionResult = commandLine.execute(args.toArray(String[]::new));
147147

148148
String output = outContent.toString();
149149
assertTrue(output.contains("Checking consistency for entry type 1 of 1\n"));
150150
assertTrue(output.contains("Consistency check completed"));
151+
assertEquals(0, executionResult);
151152

152153
System.setOut(System.out);
153154
}
@@ -163,10 +164,11 @@ void checkConsistencyPorcelain() throws URISyntaxException {
163164
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
164165
System.setOut(new PrintStream(outContent));
165166

166-
commandLine.execute(args.toArray(String[]::new));
167+
int executionResult = commandLine.execute(args.toArray(String[]::new));
167168

168169
String output = outContent.toString();
169170
assertEquals("", output);
171+
assertEquals(0, executionResult);
170172

171173
System.setOut(System.out);
172174
}

0 commit comments

Comments
 (0)