Skip to content

Commit 158bc28

Browse files
committed
feat(developer): add LicenseFile as property of package
Adds license file to .kps, kmp.json, kmc-package, package editor, and new project templates. The intent is for LICENSE.md to be the file used, and for any keyboards on keymanapp/keyboards, it should always be a standard MIT license.
1 parent 0305cd0 commit 158bc28

File tree

9 files changed

+141
-43
lines changed

9 files changed

+141
-43
lines changed

common/schemas/kps/kps.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<xs:element minOccurs="0" maxOccurs="1" name="ExecuteProgram" type="xs:string" />
3232
<xs:element minOccurs="0" maxOccurs="1" name="ReadMeFile" type="xs:string" />
3333
<xs:element minOccurs="0" maxOccurs="1" name="GraphicFile" type="xs:string" />
34+
<xs:element minOccurs="0" maxOccurs="1" name="LicenseFile" type="xs:string" />
3435
<xs:element minOccurs="0" maxOccurs="1" name="MSIFileName" type="xs:string" />
3536
<xs:element minOccurs="0" maxOccurs="1" name="MSIOptions" type="xs:string" />
3637
<xs:element minOccurs="0" maxOccurs="1" name="FollowKeyboardVersion" type="km-empty" />

common/web/types/src/package/kmp-json-file.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface KmpJsonFileSystem {
1717
export interface KmpJsonFileOptions {
1818
readmeFile?: string;
1919
graphicFile?: string;
20+
licenseFile?: string;
2021
executeProgram?: string;
2122
msiFilename?: string;
2223
msiOptions?: string;

common/web/types/src/package/kps-file.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface KpsFileOptions {
4141
followKeyboardVersion?: string;
4242
readMeFile?: string;
4343
graphicFile?: string;
44+
licenseFile?: string;
4445
executeProgram?: string;
4546
msiFileName?: string;
4647
msiOptions?: string;

common/windows/delphi/packages/PackageInfo.pas

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ TPackageOptions = class(TPackageBaseObject)
149149
FExecuteProgram: WideString;
150150
FReadmeFile: TPackageContentFile;
151151
FGraphicFile: TPackageContentFile;
152+
FLicenseFile: TPackageContentFile;
152153
FLoadLegacy: Boolean;
153154
procedure SetReadmeFile(const Value: TPackageContentFile);
154155
procedure SetExecuteProgram(Value: WideString);
@@ -158,6 +159,9 @@ TPackageOptions = class(TPackageBaseObject)
158159
EventType: TPackageNotifyEventType; var FAllow: Boolean);
159160
procedure ReadmeRemoved(Sender: TObject;
160161
EventType: TPackageNotifyEventType; var FAllow: Boolean);
162+
procedure SetLicenseFile(const Value: TPackageContentFile);
163+
procedure LicenseRemoved(Sender: TObject;
164+
EventType: TPackageNotifyEventType; var FAllow: Boolean);
161165
public
162166
constructor Create(APackage: TPackage); override;
163167
destructor Destroy; override;
@@ -173,6 +177,7 @@ TPackageOptions = class(TPackageBaseObject)
173177
property ExecuteProgram: WideString read FExecuteProgram write SetExecuteProgram;
174178
property ReadmeFile: TPackageContentFile read FReadmeFile write SetReadmeFile;
175179
property GraphicFile: TPackageContentFile read FGraphicFile write SetGraphicFile;
180+
property LicenseFile: TPackageContentFile read FLicenseFile write SetLicenseFile;
176181
end;
177182

178183
{ Package Information }
@@ -561,6 +566,7 @@ implementation
561566
SJSON_Options_ExecuteProgram = 'executeProgram';
562567
SJSON_Options_ReadMeFile = 'readmeFile';
563568
SJSON_Options_GraphicFile = 'graphicFile';
569+
SJSON_Options_LicenseFile = 'licenseFile';
564570

565571
SJSON_Registry = 'registry';
566572
SJSON_Registry_Root = 'root';
@@ -655,6 +661,9 @@ procedure TPackageOptions.Assign(Source: TPackageOptions);
655661
if Assigned(Source.GraphicFile)
656662
then GraphicFile := Package.Files.FromFileName(Source.GraphicFile.FileName)
657663
else GraphicFile := nil;
664+
if Assigned(Source.LicenseFile)
665+
then LicenseFile := Package.Files.FromFileName(Source.LicenseFile.FileName)
666+
else LicenseFile := nil;
658667
end;
659668

660669
constructor TPackageOptions.Create(APackage: TPackage);
@@ -668,6 +677,7 @@ destructor TPackageOptions.Destroy;
668677
begin
669678
ReadmeFile := nil;
670679
GraphicFile := nil;
680+
LicenseFile := nil;
671681
inherited Destroy;
672682
end;
673683

@@ -681,14 +691,21 @@ procedure TPackageOptions.GraphicRemoved(Sender: TObject; EventType: TPackageNot
681691
FGraphicFile := nil;
682692
end;
683693

694+
procedure TPackageOptions.LicenseRemoved(Sender: TObject; EventType: TPackageNotifyEventType; var FAllow: Boolean);
695+
begin
696+
FLicenseFile := nil;
697+
end;
698+
684699
procedure TPackageOptions.LoadXML(ARoot: IXMLNode);
685700
begin
686701
FileVersion := XmlVarToStr(ARoot.ChildNodes['System'].ChildNodes['FileVersion'].NodeValue);
687702
ExecuteProgram := XmlVarToStr(ARoot.ChildNodes['Options'].ChildNodes['ExecuteProgram'].NodeValue);
688703
ReadmeFile := Package.Files.FromFileName(XmlVarToStr(ARoot.ChildNodes['Options'].ChildNodes['ReadMeFile'].NodeValue));
689704
GraphicFile := Package.Files.FromFileName(XmlVarToStr(ARoot.ChildNodes['Options'].ChildNodes['GraphicFile'].NodeValue));
705+
LicenseFile := Package.Files.FromFileName(XmlVarToStr(ARoot.ChildNodes['Options'].ChildNodes['LicenseFile'].NodeValue));
690706
if Assigned(ReadmeFile) then ReadmeFile.AddNotifyObject(ReadmeRemoved);
691707
if Assigned(GraphicFile) then GraphicFile.AddNotifyObject(GraphicRemoved);
708+
if Assigned(LicenseFile) then LicenseFile.AddNotifyObject(LicenseRemoved);
692709
end;
693710

694711
procedure TPackageOptions.SaveXML(ARoot: IXMLNode);
@@ -699,6 +716,8 @@ procedure TPackageOptions.SaveXML(ARoot: IXMLNode);
699716
ARoot.ChildNodes['Options'].ChildNodes['ReadMeFile'].NodeValue := ReadmeFile.RelativeFileName;
700717
if Assigned(GraphicFile) then
701718
ARoot.ChildNodes['Options'].ChildNodes['GraphicFile'].NodeValue := GraphicFile.RelativeFileName;
719+
if Assigned(LicenseFile) then
720+
ARoot.ChildNodes['Options'].ChildNodes['LicenseFile'].NodeValue := LicenseFile.RelativeFileName;
702721
end;
703722

704723
procedure TPackageOptions.LoadIni(AIni: TIniFile);
@@ -709,6 +728,7 @@ procedure TPackageOptions.LoadIni(AIni: TIniFile);
709728
GraphicFile := Package.Files.FromFileName(AIni.ReadString('Package', 'GraphicFile', ''));
710729
if Assigned(ReadmeFile) then ReadmeFile.AddNotifyObject(ReadmeRemoved);
711730
if Assigned(GraphicFile) then GraphicFile.AddNotifyObject(GraphicRemoved);
731+
// LicenseFile not supported in ini
712732
end;
713733

714734
procedure TPackageOptions.LoadJSON(ARoot: TJSONObject);
@@ -722,8 +742,10 @@ procedure TPackageOptions.LoadJSON(ARoot: TJSONObject);
722742
ExecuteProgram := GetJsonValueString(FOptions, SJSON_Options_ExecuteProgram);
723743
ReadmeFile := Package.Files.FromFileName(GetJsonValueString(FOptions, SJSON_Options_ReadMeFile));
724744
GraphicFile := Package.Files.FromFileName(GetJsonValueString(FOptions, SJSON_Options_GraphicFile));
745+
LicenseFile := Package.Files.FromFileName(GetJsonValueString(FOptions, SJSON_Options_LicenseFile));
725746
if Assigned(ReadmeFile) then ReadmeFile.AddNotifyObject(ReadmeRemoved);
726747
if Assigned(GraphicFile) then GraphicFile.AddNotifyObject(GraphicRemoved);
748+
if Assigned(LicenseFile) then LicenseFile.AddNotifyObject(LicenseRemoved);
727749
end;
728750

729751
procedure TPackageOptions.SaveIni(AIni: TIniFile);
@@ -734,6 +756,7 @@ procedure TPackageOptions.SaveIni(AIni: TIniFile);
734756
AIni.WriteString('Package', 'ReadMeFile', ReadmeFile.RelativeFileName);
735757
if Assigned(GraphicFile) then
736758
AIni.WriteString('Package', 'GraphicFile', GraphicFile.RelativeFileName);
759+
// licenseFile not supported in ini
737760
end;
738761

739762
procedure TPackageOptions.SaveJSON(ARoot: TJSONObject);
@@ -753,6 +776,8 @@ procedure TPackageOptions.SaveJSON(ARoot: TJSONObject);
753776
FOptions.AddPair(SJSON_Options_ReadMeFile, ReadmeFile.RelativeFileName);
754777
if Assigned(GraphicFile) then
755778
FOptions.AddPair(SJSON_Options_GraphicFile, GraphicFile.RelativeFileName);
779+
if Assigned(LicenseFile) then
780+
FOptions.AddPair(SJSON_Options_LicenseFile, LicenseFile.RelativeFileName);
756781
end;
757782

758783
procedure TPackageOptions.SetExecuteProgram(Value: WideString);
@@ -780,6 +805,19 @@ procedure TPackageOptions.SetGraphicFile(const Value: TPackageContentFile);
780805
end;
781806
end;
782807

808+
procedure TPackageOptions.SetLicenseFile(const Value: TPackageContentFile);
809+
begin
810+
if Assigned(FLicenseFile) then FLicenseFile.RemoveNotifyObject(LicenseRemoved);
811+
if not Assigned(Value) then
812+
FLicenseFile := nil
813+
else
814+
begin
815+
if Value.Package <> Package then raise EPackageInfo.CreateFmt(SGraphicNotOwnedCorrectly, [Value]);
816+
FLicenseFile := Value;
817+
FLicenseFile.AddNotifyObject(LicenseRemoved);
818+
end;
819+
end;
820+
783821
procedure TPackageOptions.SetReadmeFile(const Value: TPackageContentFile);
784822
begin
785823
if Assigned(FReadmeFile) then FReadmeFile.RemoveNotifyObject(ReadmeRemoved);

developer/src/kmc-package/src/compiler/kmp-compiler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ export class KmpCompiler {
7777
if(kps.options.readMeFile) {
7878
kmp.options.readmeFile = /[/\\]?([^/\\]*)$/.exec(kps.options.readMeFile)[1];
7979
}
80+
if(kps.options.licenseFile) {
81+
kmp.options.licenseFile = /[/\\]?([^/\\]*)$/.exec(kps.options.licenseFile)[1];
82+
}
8083
}
8184

8285
//

developer/src/kmconvert/Keyman.Developer.System.KeyboardProjectTemplate.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ procedure TKeyboardProjectTemplate.WriteKPS;
285285
kps.Files.Add(f);
286286
kps.Options.ReadmeFile := f;
287287

288+
// Add license
289+
f := TPackageContentFile.Create(kps);
290+
f.FileName := BasePath + ID + '\' + SFile_LicenseMD;
291+
kps.Files.Add(f);
292+
kps.Options.LicenseFile := f;
293+
288294
// Add metadata about the keyboard
289295
pk := TPackageKeyboard.Create(kps);
290296
pk.Name := Name;

developer/src/kmconvert/Keyman.Developer.System.ModelProjectTemplate.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ procedure TModelProjectTemplate.WriteKPS;
179179
kps.Files.Add(f);
180180
kps.Options.ReadmeFile := f;
181181

182+
// Add license
183+
f := TPackageContentFile.Create(kps);
184+
f.FileName := BasePath + ID + '\' + SFile_LicenseMD;
185+
kps.Files.Add(f);
186+
kps.Options.LicenseFile := f;
187+
182188
// Add metadata about the lexical model
183189
plm := TPackageLexicalModel.Create(kps);
184190
plm.Name := Name;

0 commit comments

Comments
 (0)