- Fixed ParseElements() callsin Package constructor
- Added release element parsing - Converted PackIndexEntry to modern C#(6) syntax
This commit is contained in:
Родитель
bf578ca490
Коммит
b44a82547a
|
@ -81,7 +81,7 @@ namespace CMSIS.Pack.PackDescription
|
|||
retVal.SupportContact = pkgElement.Element( "supportContact" )?.Value;
|
||||
retVal.License = pkgElement.Element( "license" )?.Value;
|
||||
|
||||
ParseElements( pkgElement.Element( "releases" ), "release", retVal.Keywords, Keyword.ParseFrom );
|
||||
ParseElements( pkgElement.Element( "releases" ), "release", retVal.Releases, Release.ParseFrom );
|
||||
ParseElements( pkgElement.Element( "keywords" ), "keyword", retVal.Keywords, Keyword.ParseFrom );
|
||||
ParseElements( pkgElement.Element( "generators" ), "generator", retVal.Generators, Generator.ParseFrom );
|
||||
ParseElements( pkgElement.Element( "devices" ), "family", retVal.Devices, DeviceFamily.ParseFrom );
|
||||
|
@ -89,7 +89,7 @@ namespace CMSIS.Pack.PackDescription
|
|||
ParseElements( pkgElement.Element( "taxonomy" ), "description", retVal.Taxonomy, TaxonomyDescription.ParseFrom );
|
||||
ParseElements( pkgElement.Element( "apis" ), "api", retVal.Apis, Api.ParseFrom );
|
||||
ParseElements( pkgElement.Element( "conditions" ), "condition", retVal.Conditions, Condition.ParseFrom );
|
||||
ParseElements( pkgElement.Element( "examples" ), "example", retVal.Conditions, Condition.ParseFrom );
|
||||
ParseElements( pkgElement.Element( "examples" ), "example", retVal.Examples, Example.ParseFrom );
|
||||
// TODO: figure out plan to deal with multiple child element types in components element (component, bundle)
|
||||
ParseElements( pkgElement.Element( "components" ), "component", retVal.Components, Component.ParseFrom );
|
||||
|
||||
|
|
|
@ -7,14 +7,6 @@ namespace CMSIS.Pack.PackDescription
|
|||
{
|
||||
internal static class Parsers
|
||||
{
|
||||
internal static bool IsIntegerScaleChar( char arg )
|
||||
{
|
||||
return arg == 'k'
|
||||
|| arg == 'K'
|
||||
|| arg == 'm'
|
||||
|| arg == 'M';
|
||||
}
|
||||
|
||||
internal static Parser<int> Integer( int minDigits, int maxDigitis )
|
||||
{
|
||||
return from value in Parse.Digit.Repeat( minDigits, maxDigitis ).Text( )
|
||||
|
@ -25,23 +17,32 @@ namespace CMSIS.Pack.PackDescription
|
|||
// However, many PDSC files in the wild only have one, thus this
|
||||
// parser handles the incorrectly formed dates
|
||||
internal static Parser<DateTime> DateTime = from year in Integer( 4, 4 )
|
||||
from sep in Parse.Char( '-' )
|
||||
from month in Integer( 1, 2 )
|
||||
from sep2 in Parse.Char( '-' )
|
||||
from day in Integer( 1, 2 )
|
||||
select new DateTime( year, month, day );
|
||||
from sep in Parse.Char( '-' )
|
||||
from month in Integer( 1, 2 )
|
||||
from sep2 in Parse.Char( '-' )
|
||||
from day in Integer( 1, 2 )
|
||||
select new DateTime( year, month, day );
|
||||
|
||||
internal static Parser<double> Double = from value in Parse.Decimal
|
||||
select double.Parse( value, CultureInfo.CurrentCulture );
|
||||
select double.Parse( value, CultureInfo.CurrentCulture );
|
||||
|
||||
internal static Parser<double> ScaledInteger = from value in Parse.Digit.AtLeastOnce( ).Text( )
|
||||
from scale in ScaledIntMultiplier
|
||||
select ( double )int.Parse( value ) * scale;
|
||||
from scale in ScaledIntMultiplier
|
||||
select ( double )int.Parse( value ) * scale;
|
||||
|
||||
static Parser<int> ScaledIntMultiplier = Parse.Chars( 'k', 'K' ).Return( 1024 )
|
||||
.Or( Parse.Chars( 'm', 'M' ).Return( 1024 * 1024 ) )
|
||||
.Or( Parse.Return( 1 ) );
|
||||
internal static Parser<int> ScaledIntMultiplier = Parse.Chars( 'k', 'K' ).Return( 1024 )
|
||||
.Or( Parse.Chars( 'm', 'M' ).Return( 1024 * 1024 ) )
|
||||
.Or( Parse.Return( 1 ) );
|
||||
|
||||
internal static Parser<double> NonConformantDecimal = ScaledInteger.Or( Double );
|
||||
|
||||
internal static bool IsIntegerScaleChar( char arg )
|
||||
{
|
||||
return arg == 'k'
|
||||
|| arg == 'K'
|
||||
|| arg == 'm'
|
||||
|| arg == 'M';
|
||||
}
|
||||
|
||||
static Parser<double> NonConformantDecimal = ScaledInteger.Or( Double );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace CMSIS.Pack.PackDescription
|
||||
{
|
||||
public class Release
|
||||
{
|
||||
public SemanticVersion Version { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
public static Release ParseFrom( XElement release )
|
||||
{
|
||||
return new Release();
|
||||
return new Release()
|
||||
{ Version = SemanticVersion.Parse( release.Attribute("version").Value )
|
||||
, Description = release.Value
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,84 +17,70 @@ namespace CMSIS.Pack
|
|||
{
|
||||
/// <summary>Creates a new PackIndexEntry from data read out of the index</summary>
|
||||
/// <param name="descriptorUri">Base URI for the pack</param>
|
||||
/// <param name="packName">Name of the pack in VENDOR.NAME form</param>
|
||||
/// <param name="packDescriptiorFileName">Name of the pack in VENDOR.NAME form</param>
|
||||
/// <param name="packVersion">Pack version (in semantic Version 2.0 form)</param>
|
||||
public PackIndexEntry( string descriptorUri, string packName, string packVersion )
|
||||
public PackIndexEntry( string descriptorUri, string packDescriptiorFileName, string packVersion )
|
||||
{
|
||||
if( string.IsNullOrWhiteSpace( descriptorUri ) )
|
||||
throw new ArgumentException( "Non empty string required", nameof( descriptorUri ) );
|
||||
|
||||
if( string.IsNullOrWhiteSpace( packName ) )
|
||||
throw new ArgumentException( "Non empty string required", nameof( packName ) );
|
||||
if( string.IsNullOrWhiteSpace( packDescriptiorFileName ) )
|
||||
throw new ArgumentException( "Non empty string required", nameof( packDescriptiorFileName ) );
|
||||
|
||||
if( string.IsNullOrWhiteSpace( packVersion ) )
|
||||
throw new ArgumentException( "Non empty string required", nameof( packVersion ) );
|
||||
|
||||
Url = CreateUriWithTrailingSeperator( descriptorUri );
|
||||
PdscName = packName;
|
||||
PdscName = packDescriptiorFileName;
|
||||
var parts = PdscName.Trim().Split( '.' );
|
||||
if( parts.Length != 3 )
|
||||
throw new ArgumentException( "Invalid pack name format", nameof( packName ) );
|
||||
throw new ArgumentException( "Invalid pack name format", nameof( packDescriptiorFileName ) );
|
||||
|
||||
PackName = Path.ChangeExtension( PdscName, Version + ".pack" );
|
||||
PdscUrl = new Uri( Url, PdscName );
|
||||
PackUrl = new Uri( Url, PackName );
|
||||
|
||||
Vendor = parts[ 0 ];
|
||||
Name = parts[ 1 ];
|
||||
if( !SemanticVersion.TryParse( packVersion, out Version_ ) )
|
||||
SemanticVersion version;
|
||||
if( !SemanticVersion.TryParse( packVersion, out version ) )
|
||||
throw new ArgumentException( "Invalid semantic version provided", nameof( packVersion ) );
|
||||
}
|
||||
Version = version;
|
||||
LocalPath = Path.Combine( Vendor, Name, Version.ToString( ) );
|
||||
}
|
||||
|
||||
/// <summary>File name of the pack file this reference is for</summary>
|
||||
/// <remarks>
|
||||
/// The file name is of the form: VENDOR.NAME.VERSION.pack
|
||||
/// </remarks>
|
||||
public string PackName
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.ChangeExtension( PdscName, Version + ".pack" );
|
||||
}
|
||||
}
|
||||
public string PackName { get; }
|
||||
|
||||
/// <summary>Vendor name parsed out of the PackName from the index</summary>
|
||||
public string Vendor { get; private set; }
|
||||
public string Vendor { get; }
|
||||
|
||||
/// <summary>Name of the pack parsed out of the Pack name from the index</summary>
|
||||
public string Name { get; private set; }
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>Name of the PDSC file for this pack</summary>
|
||||
/// <remarks>
|
||||
/// The PDSC filename takes the form: VENDOR.NAME.pdsc
|
||||
/// </remarks>
|
||||
public string PdscName { get; private set; }
|
||||
public string PdscName { get; }
|
||||
|
||||
/// <summary>Full URL of the Package Description (PDSC) file for this pack</summary>
|
||||
public Uri PdscUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Uri( Url, PdscName );
|
||||
}
|
||||
}
|
||||
public Uri PdscUrl { get; }
|
||||
|
||||
/// <summary>FULL URL of the Package file for this pack</summary>
|
||||
public Uri PackUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Uri( Url, PackName );
|
||||
}
|
||||
}
|
||||
public Uri PackUrl { get; }
|
||||
|
||||
/// <summary>Base URI for this pack read from the index</summary>
|
||||
public Uri Url { get; private set; }
|
||||
public Uri Url { get; }
|
||||
|
||||
/// <summary>Version of the pack</summary>
|
||||
public SemanticVersion Version { get { return Version_; } }
|
||||
private readonly SemanticVersion Version_;
|
||||
public SemanticVersion Version { get; }
|
||||
|
||||
public string LocalPath
|
||||
{
|
||||
get { return Path.Combine( Vendor, Name, Version.ToString( ) ); }
|
||||
}
|
||||
/// <summary>Relative path for the pack in the local repository in VENDOR\NAME\VERSION form</summary>
|
||||
public string LocalPath { get; }
|
||||
|
||||
/// <summary>Retrieves the contents of the Package Description file</summary>
|
||||
/// <returns>string containing the XML content of the description</returns>
|
||||
|
|
|
@ -246,7 +246,7 @@ namespace CMSIS.Pack
|
|||
/// portion of the version is included or not. The Build Metadata is the only portion of the semantic
|
||||
/// version that does not participate in precedence evaluation for comparing versions.
|
||||
/// </remarks>
|
||||
public string ToString( bool includeBuildMetadata)
|
||||
public string ToString( bool includeBuildMetadata )
|
||||
{
|
||||
var bldr = new StringBuilder( string.Format( CultureInfo.InvariantCulture, "{0}.{1}.{2}", Major, Minor, Patch ) );
|
||||
if( PreReleaseParts.Count > 0 )
|
||||
|
|
Загрузка…
Ссылка в новой задаче