1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 572648: Handle cases of empty (EOF) JSON files

Change-Id: I10fae3542ae75120dad0a59b52aaf7b34a67d8e9
This commit is contained in:
Jonah Graham 2021-04-07 09:39:20 -04:00
parent 22ed0e0ae6
commit 2073d47084
13 changed files with 32 additions and 8 deletions

View file

@ -326,6 +326,12 @@ public class CompilationDatabaseParser extends LanguageSettingsSerializableProvi
Messages.CompilationDatabaseParser_ErrorProcessingCompilationDatabase, e));
}
if (compileCommands == null) {
throw new CoreException(new Status(Status.ERROR, ManagedBuilderCorePlugin.PLUGIN_ID,
Messages.CompilationDatabaseParser_ErrorProcessingCompilationDatabase,
new NullPointerException(Messages.CompilationDatabaseParser_StillNull)));
}
AbstractBuildCommandParser outputParser;
try {
outputParser = getBuildCommandParser(cfgDescription, getBuildParserId());

View file

@ -27,6 +27,8 @@ public class Messages extends NLS {
public static String CompilationDatabaseParser_ProgressParsingBuildCommands;
public static String CompilationDatabaseParser_ProgressParsingJSONFile;
public static String CompilationDatabaseParser_StillNull;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);

View file

@ -18,4 +18,5 @@ CompilationDatabaseParser_Job=Discover Compilation Database language settings
CompilationDatabaseParser_ProgressApplyingEntries=Applying language setting entries
CompilationDatabaseParser_ProgressExcludingFiles=Excluding files not in compilation database. Checking %d/%d (Estimate)
CompilationDatabaseParser_ProgressParsingBuildCommands=Parsing build commands (%d/%d)
CompilationDatabaseParser_ProgressParsingJSONFile=Parsing JSON file
CompilationDatabaseParser_ProgressParsingJSONFile=Parsing JSON file
CompilationDatabaseParser_StillNull=Compilation database (usually compile_commands.json) appears to be empty

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.eclipse.cdt.meson.core;singleton:=true
Bundle-Version: 1.1.0.qualifier
Bundle-Version: 1.1.100.qualifier
Bundle-Activator: org.eclipse.cdt.meson.core.Activator
Bundle-Vendor: %provider
Require-Bundle: org.eclipse.core.runtime,

View file

@ -336,6 +336,11 @@ public class MesonBuildConfiguration extends CBuildConfiguration {
try (FileReader reader = new FileReader(commandsFile.toFile())) {
Gson gson = new Gson();
CompileCommand[] commands = gson.fromJson(reader, CompileCommand[].class);
if (commands == null) {
throw new CoreException(Activator.errorStatus(
String.format(Messages.MesonBuildConfiguration_ProcCompCmds, project.getName()),
new NullPointerException(Messages.MesonBuildConfiguration_StillNull)));
}
Map<String, CompileCommand> dedupedCmds = new HashMap<>();
for (CompileCommand command : commands) {
dedupedCmds.put(command.getFile(), command);

View file

@ -32,6 +32,8 @@ public class Messages extends NLS {
public static String MesonBuildConfiguration_ProcCompCmds;
public static String MesonBuildConfiguration_ProcCompJson;
public static String MesonBuildConfiguration_StillNull;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);

View file

@ -24,5 +24,4 @@ MesonBuildConfiguration_RunningMesonFailure=Failure running meson: %s
MesonBuildConfiguration_RunningNinjaFailure=Failure running ninja: %s
MesonBuildConfiguration_NoNinjaFileToClean=No ninja.build file so clean has nothing to do
MesonBuildConfiguration_NoNinjaFile=Meson did not create a ninja.build file so build cannot complete
MesonBuildConfiguration_StillNull=Compilation database (usually compile_commands.json) appears to be empty

View file

@ -4,7 +4,7 @@ Bundle-Name: %bundleName
Bundle-Description: %bundleDescription
Bundle-Copyright: %Bundle-Copyright
Bundle-SymbolicName: org.eclipse.cdt.cmake.is.core;singleton:=true
Bundle-Version: 1.0.100.qualifier
Bundle-Version: 1.0.200.qualifier
Bundle-Vendor: %Bundle-Vendor
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-11

View file

@ -22,6 +22,6 @@
<artifactId>org.eclipse.cdt.cmake.is.core</artifactId>
<!-- always use .qualifier in manifest, we do not plan to publish this plugin
to a maven repo. (The repository version is a different thing) -->
<version>1.0.100-SNAPSHOT</version>
<version>1.0.200-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -171,6 +171,12 @@ public class CompileCommandsJsonParser {
// parse file...
Gson gson = new Gson();
CommandEntry[] sourceFileInfos = gson.fromJson(in, CommandEntry[].class);
if (sourceFileInfos == null) {
final String msg = String.format(Messages.CompileCommandsJsonParser_errmsg_empty_json, jsonDiskFile,
WORKBENCH_WILL_NOT_KNOW_ALL_MSG);
createMarker(jsonFile, msg);
return false;
}
for (CommandEntry sourceFileInfo : sourceFileInfos) {
processCommandEntry(sourceFileInfo, jsonFile);
}

View file

@ -19,6 +19,7 @@ import org.eclipse.osgi.util.NLS;
*/
/* package */ public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.cmake.is.core.messages"; //$NON-NLS-1$
public static String CompileCommandsJsonParser_errmsg_empty_json;
public static String CompileCommandsJsonParser_errmsg_file_not_found;
public static String CompileCommandsJsonParser_errmsg_no_parser_for_commandline;
public static String CompileCommandsJsonParser_errmsg_not_json;

View file

@ -11,6 +11,7 @@
# Contributors:
# Martin Weber - initial API and implementation
###############################################################################
CompileCommandsJsonParser_errmsg_empty_json=File '%1$s' appears to be an empty file. %2$s
CompileCommandsJsonParser_errmsg_file_not_found=File '%1$s' was not created in the build. %2$s
CompileCommandsJsonParser_errmsg_no_parser_for_commandline=No parser for command '%1$s'. %2$s
CompileCommandsJsonParser_errmsg_not_json=File '%1$s' does not seem to be in JSON format. %2$s

View file

@ -644,9 +644,10 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
scannerInfoCache = gson.fromJson(reader, ScannerInfoCache.class);
} catch (IOException e) {
CCorePlugin.log(e);
scannerInfoCache = new ScannerInfoCache();
}
} else {
}
if (scannerInfoCache == null) {
scannerInfoCache = new ScannerInfoCache();
}
scannerInfoCache.initCache();