in src/Sarif/Writers/PrereleaseCompatibilityTransformer.cs [20:219]
public static SarifLog UpdateToCurrentVersion(
string prereleaseSarifLog,
Formatting formatting,
out string updatedLog)
{
bool modifiedLog = false;
updatedLog = null;
var settings = new JsonSerializerSettings
{
Formatting = formatting,
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
};
if (string.IsNullOrEmpty(prereleaseSarifLog)) { return null; }
JObject logObject = JObject.Parse(prereleaseSarifLog);
string version = (string)logObject["version"];
if (version == SarifUtilities.V1_0_0)
{
// V1 is so different that we won't use the JToken-driven, piecemeal conversion that
// the PrereleaseCompatibilityTransformer uses for newer versions. Instead, we'll
// deserialize to the V1 OM, and transform to the V2 OM.
return ConvertV1ToCurrent(prereleaseSarifLog, settings, out updatedLog);
}
string schemaSubVersion = (string)logObject["$schema"];
Dictionary<string, int> fullyQualifiedLogicalNameToIndexMap = null;
Dictionary<string, int> fileLocationKeyToIndexMap = null;
Dictionary<string, int> ruleKeyToIndexMap = null;
switch (version)
{
case "2.1.0":
{
switch (schemaSubVersion)
{
case "http://json.schemastore.org/sarif-2.1.0-beta.1":
case "http://json.schemastore.org/sarif-2.1.0-beta.0":
{
modifiedLog |= ApplyChangesFromTC35(logObject);
goto case "http://json.schemastore.org/sarif-2.1.0-beta.2";
}
case "http://json.schemastore.org/sarif-2.1.0-beta.2":
{
modifiedLog |= ApplyRtm0Changes(logObject);
goto case "http://json.schemastore.org/sarif-2.1.0-rtm.0";
}
case "http://json.schemastore.org/sarif-2.1.0-rtm.0":
case "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.0.json":
{
modifiedLog |= ApplyRtm1Changes(logObject);
goto case "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.4.json";
}
case "http://json.schemastore.org/sarif-2.1.0-rtm.4":
case "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.4.json":
case "http://json.schemastore.org/sarif-2.1.0-rtm.3":
case "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.3.json":
case "http://json.schemastore.org/sarif-2.1.0-rtm.2":
case "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.2.json":
case "http://json.schemastore.org/sarif-2.1.0-rtm.1":
case "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.1.json":
{
modifiedLog |= ApplyRtm5Changes(logObject);
modifiedLog |= UpdateSarifLogVersionAndSchema(logObject);
break;
}
case "http://json.schemastore.org/sarif-2.1.0-rtm.5":
case "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json":
{
// Current schema version. There should be no work to do
break;
}
default:
{
break;
}
}
break;
}
case "2.0.0-csd.2.beta.2019-04-03":
{
modifiedLog |= ApplyChangesFromTC34(logObject);
modifiedLog |= ApplyChangesFromTC35(logObject);
modifiedLog |= ApplyRtm0Changes(logObject);
modifiedLog |= ApplyRtm1Changes(logObject);
modifiedLog |= ApplyRtm5Changes(logObject);
modifiedLog |= UpdateSarifLogVersionAndSchema(logObject);
break;
}
case "2.0.0-csd.2.beta.2019-02-20":
{
modifiedLog |= ApplyChangesFromTC33(logObject);
modifiedLog |= ApplyChangesFromTC34(logObject);
modifiedLog |= ApplyChangesFromTC35(logObject);
modifiedLog |= ApplyRtm0Changes(logObject);
modifiedLog |= ApplyRtm1Changes(logObject);
modifiedLog |= ApplyRtm5Changes(logObject);
modifiedLog |= UpdateSarifLogVersionAndSchema(logObject);
break;
}
case "2.0.0-csd.2.beta.2019-01-24":
case "2.0.0-csd.2.beta.2019-01-24.1":
{
modifiedLog |= ApplyChangesFromTC32(logObject);
modifiedLog |= ApplyChangesFromTC33(logObject);
modifiedLog |= ApplyChangesFromTC34(logObject);
modifiedLog |= ApplyChangesFromTC35(logObject);
modifiedLog |= ApplyRtm0Changes(logObject);
modifiedLog |= ApplyRtm1Changes(logObject);
modifiedLog |= ApplyRtm5Changes(logObject);
modifiedLog |= UpdateSarifLogVersionAndSchema(logObject);
break;
}
case "2.0.0-csd.2.beta.2019-01-09":
{
modifiedLog |= ApplyChangesFromTC31(logObject);
modifiedLog |= ApplyChangesFromTC32(logObject);
modifiedLog |= ApplyChangesFromTC33(logObject);
modifiedLog |= ApplyChangesFromTC34(logObject);
modifiedLog |= ApplyChangesFromTC35(logObject);
modifiedLog |= ApplyRtm0Changes(logObject);
modifiedLog |= ApplyRtm1Changes(logObject);
modifiedLog |= ApplyRtm5Changes(logObject);
modifiedLog |= UpdateSarifLogVersionAndSchema(logObject);
break;
}
case "2.0.0-csd.2.beta.2018-10-10":
case "2.0.0-csd.2.beta.2018-10-10.1":
case "2.0.0-csd.2.beta.2018-10-10.2":
{
// 2.0.0-csd.2.beta.2018-10-10 == changes through SARIF TC #25
modifiedLog |= ApplyChangesFromTC25ThroughTC30(
logObject,
out fullyQualifiedLogicalNameToIndexMap,
out fileLocationKeyToIndexMap,
out ruleKeyToIndexMap);
modifiedLog |= ApplyChangesFromTC31(logObject);
modifiedLog |= ApplyChangesFromTC32(logObject);
modifiedLog |= ApplyChangesFromTC33(logObject);
modifiedLog |= ApplyChangesFromTC34(logObject);
modifiedLog |= ApplyChangesFromTC35(logObject);
modifiedLog |= ApplyRtm0Changes(logObject);
modifiedLog |= ApplyRtm1Changes(logObject);
modifiedLog |= ApplyRtm5Changes(logObject);
modifiedLog |= UpdateSarifLogVersionAndSchema(logObject);
break;
}
default:
{
modifiedLog |= ApplyCoreTransformations(logObject);
modifiedLog |= ApplyChangesFromTC25ThroughTC30(
logObject,
out fullyQualifiedLogicalNameToIndexMap,
out fileLocationKeyToIndexMap,
out ruleKeyToIndexMap);
modifiedLog |= ApplyChangesFromTC31(logObject);
modifiedLog |= ApplyChangesFromTC32(logObject);
modifiedLog |= ApplyChangesFromTC33(logObject);
modifiedLog |= ApplyChangesFromTC34(logObject);
modifiedLog |= ApplyChangesFromTC35(logObject);
modifiedLog |= ApplyRtm0Changes(logObject);
modifiedLog |= ApplyRtm1Changes(logObject);
modifiedLog |= ApplyRtm5Changes(logObject);
modifiedLog |= UpdateSarifLogVersionAndSchema(logObject);
break;
}
}
SarifLog transformedSarifLog = null;
if (fullyQualifiedLogicalNameToIndexMap != null || fileLocationKeyToIndexMap != null || ruleKeyToIndexMap != null)
{
transformedSarifLog = JsonConvert.DeserializeObject<SarifLog>(logObject.ToString());
var indexUpdatingVisitor = new UpdateIndicesFromLegacyDataVisitor(
fullyQualifiedLogicalNameToIndexMap,
fileLocationKeyToIndexMap,
ruleKeyToIndexMap);
indexUpdatingVisitor.Visit(transformedSarifLog);
updatedLog = JsonConvert.SerializeObject(transformedSarifLog, settings);
}
else
{
updatedLog = modifiedLog ? logObject.ToString(formatting) : prereleaseSarifLog;
transformedSarifLog = JsonConvert.DeserializeObject<SarifLog>(updatedLog, settings);
updatedLog = JsonConvert.SerializeObject(transformedSarifLog, formatting);
}
return transformedSarifLog;
}