parsePubspecFile method

void parsePubspecFile()

Parse the package pubspec file.

Implementation

void parsePubspecFile() {
  // Parse the package pubspec file
  final pubspecFilepath =
      path.join(packageTopLevel, SbomConstants.sbomPubspecFile);
  var sbomPubspec = '';
  try {
    sbomPubspec = File(pubspecFilepath).readAsStringSync();
  } on FileSystemException {
    valid = false;
    SbomUtilities.error(
        'Cannot read package pubspec file, path is $pubspecFilepath,  cannot continue');

    return;
  }

  var contents = loadYaml(sbomPubspec);
  if (contents == null || contents.isEmpty) {
    valid = false;
    SbomUtilities.error(
        'Package pubspec file is empty, path is $pubspecFilepath,  cannot continue');

    return;
  }
  // Package name
  if (contents.containsKey(SbomConstants.pubspecName)) {
    packageName = contents[SbomConstants.pubspecName];
  } else {
    SbomUtilities.warning(
        'Package name not found in pubspec.yaml file, using default - your SBOM will not validate correctly');
  }
  sbomPubspecContents = contents;
}