@@ -81,6 +81,16 @@ public FilenameComponents(string filename) {
81
81
public static string [ ] TOKEN_DOTNET_TARGETS = new [ ] { "dotnet-" } ;
82
82
// Prefix which indicates this file is a package manifest.
83
83
public static string [ ] TOKEN_MANIFEST = new [ ] { "manifest" } ;
84
+ // Prefix which allows a manifest to specify a human readable package name.
85
+ // If the name begins with a digit [0-9] the numeric letters at the start of the string
86
+ // are used to order the priority of the package alias.
87
+ // For example, given the names:
88
+ // - "0current name"
89
+ // - "1old name"
90
+ // - "another alias"
91
+ // will create the list of names ["current name", "old name", "another alias"] where
92
+ // "current name" is the current display name of the package.
93
+ public static string [ ] TOKEN_MANIFEST_NAME = new [ ] { "manifestname-" } ;
84
94
// Prefix which identifies the canonical name of this Linux library.
85
95
public static string [ ] TOKEN_LINUX_LIBRARY_BASENAME = new [ ] { "linuxlibname-" } ;
86
96
// Prefix which identifies the original path of a file when the package was exported.
@@ -171,6 +181,8 @@ static public Dictionary<string, string>
171
181
new Regex ( "^(editor|" + String . Join (
172
182
"|" , ( new List < string > ( BUILD_TARGET_NAME_TO_ENUM_NAME . Keys ) ) . ToArray ( ) ) +
173
183
")$" , RegexOptions . IgnoreCase ) ;
184
+ // Regular expression which matches an index in a manifest name field.
185
+ private static Regex MANIFEST_NAME_REGEX = new Regex ( "^([0-9]+)(.*)" ) ;
174
186
175
187
/// <summary>
176
188
/// Get a set of build target names mapped to supported BuildTarget
@@ -287,6 +299,18 @@ public static string ScriptingRuntimeDotNetVersion {
287
299
/// </summary>
288
300
public bool isManifest = false ;
289
301
302
+ /// <summary>
303
+ /// Offset subtracted from entries inserted in customManifestNames.
304
+ /// </summary>
305
+ private const int CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET = Int32 . MaxValue / 2 ;
306
+
307
+ /// <summary>
308
+ /// Backing store for aliases of the manifest name, the current package name is always
309
+ /// first in the set. This contains only values parsed from manifestname labels,
310
+ /// the ManifestName property is used to retrieve the preferred manifest name.
311
+ /// </summary>
312
+ public SortedList < int , string > customManifestNames = new SortedList < int , string > ( ) ;
313
+
290
314
/// <summary>
291
315
/// Set if this references an asset which is handled by PluginManager.
292
316
/// </summary>
@@ -307,6 +331,27 @@ public static string ScriptingRuntimeDotNetVersion {
307
331
/// </summary>
308
332
public string exportPath = "" ;
309
333
334
+ /// <summary>
335
+ /// If this is a manifest, get the display name.
336
+ /// </summary>
337
+ /// <returns>If this file is a manifest, returns the display name of the manifest,
338
+ /// null otherwise.</returns>
339
+ public string ManifestName {
340
+ get {
341
+ string name = null ;
342
+ bool hasManifestNames = customManifestNames != null &&
343
+ customManifestNames . Count > 0 ;
344
+ if ( isManifest || hasManifestNames ) {
345
+ if ( hasManifestNames ) {
346
+ name = customManifestNames . Values [ 0 ] ;
347
+ } else {
348
+ name = ( new FilenameComponents ( filenameCanonical ) ) . basenameNoExtension ;
349
+ }
350
+ }
351
+ return name ;
352
+ }
353
+ }
354
+
310
355
/// <summary>
311
356
/// Parse metadata from filename and store in this class.
312
357
/// </summary>
@@ -413,7 +458,24 @@ private bool StringListMatchesRegex(IEnumerable<string> items, Regex regEx) {
413
458
/// <returns>true if the token is parsed, false otherwise.</returns>
414
459
private bool ParseToken ( string token , string prefix = null ) {
415
460
prefix = prefix ?? "" ;
416
- var values = MatchPrefixesGetValues ( token , TOKEN_MANIFEST , prefix ) ;
461
+ var values = MatchPrefixesGetValues ( token , TOKEN_MANIFEST_NAME , prefix ) ;
462
+ if ( values != null ) {
463
+ var name = String . Join ( FIELD_SEPARATOR [ 0 ] . ToString ( ) , values ) ;
464
+ var nameMatch = MANIFEST_NAME_REGEX . Match ( name ) ;
465
+ int order = CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET - customManifestNames . Count ;
466
+ if ( nameMatch . Success ) {
467
+ int parsedOrder ;
468
+ if ( Int32 . TryParse ( nameMatch . Groups [ 1 ] . Value , out parsedOrder ) ) {
469
+ order = parsedOrder - CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET ;
470
+ }
471
+ name = nameMatch . Groups [ 2 ] . Value ;
472
+ }
473
+ customManifestNames . Remove ( order ) ;
474
+ customManifestNames . Add ( order , name ) ;
475
+ isManifest = true ;
476
+ return true ;
477
+ }
478
+ values = MatchPrefixesGetValues ( token , TOKEN_MANIFEST , prefix ) ;
417
479
if ( values != null ) {
418
480
isManifest = true ;
419
481
return true ;
@@ -622,6 +684,18 @@ public void UpdateAssetLabels() {
622
684
if ( isManifest ) {
623
685
labels . Add ( CreateLabel ( TOKEN_MANIFEST [ 0 ] , null ) ) ;
624
686
}
687
+ if ( customManifestNames != null && customManifestNames . Count > 0 ) {
688
+ foreach ( var indexAndName in customManifestNames ) {
689
+ int order = indexAndName . Key + CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET ;
690
+ var name = indexAndName . Value ;
691
+ if ( order < CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET ) {
692
+ labels . Add ( CreateLabel ( TOKEN_MANIFEST_NAME [ 0 ] , order . ToString ( ) + name ,
693
+ preserve : true ) ) ;
694
+ } else {
695
+ labels . Add ( CreateLabel ( TOKEN_MANIFEST_NAME [ 0 ] , name , preserve : true ) ) ;
696
+ }
697
+ }
698
+ }
625
699
var uniqueLabels = new HashSet < string > ( labels ) ;
626
700
labels = new List < string > ( uniqueLabels ) ;
627
701
if ( ! uniqueLabels . SetEquals ( new HashSet < string > ( currentLabels ) ) ) {
0 commit comments