Skip to content

Commit

Permalink
API functions CreateProject and CreateCreateProjectParms added
Browse files Browse the repository at this point in the history
  • Loading branch information
aplteam committed Jun 21, 2024
1 parent 6b50385 commit b12f811
Show file tree
Hide file tree
Showing 46 changed files with 241 additions and 96 deletions.
2 changes: 1 addition & 1 deletion APLSource/Admin/DeleteLinksInDocuments_APLFiles.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
⎕NDELETE targetFolder
:EndIf
:Else
∘∘∘ Not implemented (yet?!) ⍝TODO⍝
∘∘∘ Not implemented (yet?!)
:EndIf
:EndIf
1 change: 1 addition & 0 deletions APLSource/Cider/API/CreateCreateProjectParms.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CreateCreateProjectParms{ ##.CreateCreateProjectParms }
1 change: 1 addition & 0 deletions APLSource/Cider/API/CreateProject.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CreateProject{1:shy##.CreateProject }
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rconfigFilename
rConfigFilename
r'cider.config'
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{name}CreateConfigFile(filename name);config;globalCiderConfigFilename;tatinVars
{name}CreateConfigFile(filename name);config;globalCiderConfigFilename;tatinVars
Copies the config template file over and injects the last part of the path of "filename" as "projectSpace"
('The folder already hosts a file "',configFilename,'"')Assert~⎕NEXISTS filename
globalCiderConfigFilenameP.GetCiderGlobalConfigHomeFolder,'cider.config.template'
tatinVarsP.##.TatinVars
('The folder already hosts a file "',ConfigFilename,'"')Assert~⎕NEXISTS filename
globalCiderConfigFilenameGetCiderGlobalConfigHomeFolder,'cider.config.template'
tatinVars##.TatinVars
:If 0=⎕NEXISTS globalCiderConfigFilename
First attempt
globalCiderConfigFilename(⎕NCOPY P.##.F.ExecNfunction)tatinVars.HOME,'/cider.config.template'
globalCiderConfigFilename(⎕NCOPY F.ExecNfunction)tatinVars.HOME,'/cider.config.template'
:ElseIf /{⎕NGET }¨globalCiderConfigFilename(tatinVars.HOME,'/cider.config.template')
Replace by the template if changed
globalCiderConfigFilename(⎕NCOPY('IfExists' 'Replace')P.##.F.ExecNfunction)tatinVars.HOME,'/cider.config.template'
globalCiderConfigFilename(⎕NCOPY('IfExists' 'Replace')F.ExecNfunction)tatinVars.HOME,'/cider.config.template'
:EndIf
config⎕JSON('Dialect' 'JSON5')P.##.F.NGET globalCiderConfigFilename
config⎕JSON('Dialect' 'JSON5')F.NGET globalCiderConfigFilename
:If 0=⎕SE.Link.⎕NC'Version' There was no such function prior to Link 3
:OrIf 3=⊃⊃(//)⎕VFI{/2>+\='.'}⎕SE.Link.Version Version 3.x?
config.LINK.watch(1+P.HasDotNet)'ns' 'both'
config.LINK.watch(1+HasDotNet)'ns' 'both'
:EndIf
:If (name)'#⎕'
name{'.'}name
:EndIf
((~name⎕D,⎕A,'_∆⍙',⎕C ⎕A)/name)'_'
config.CIDER.projectSpacename
config P.##.Put_JSON5 filename
config Put_JSON5 filename
Done
21 changes: 21 additions & 0 deletions APLSource/Cider/CreateCreateProjectParms.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
parms{parms_}CreateCreateProjectParms folder;list;b;l
Creates a namespace with all parameters one might pass to `CreateProject`.\\
`folder` must point to the folder hosting the project to be created.
`parms_`, if specified, must be a namespace with some such parameters.
Parameters passed this way take precedence.
parms_{0<⎕NC : }'parms_'
parms(11⎕RSI,⎕THIS).⎕NS'' Create namespace where we got called from
parms.folderfolder
parms.acceptConfig0
parms.ignoreUserExec0
parms.namespace''
:If ~(parms_)''
'⍺ must not contain references'Assert 0=parms_.⎕NL 9
(b{0=+/b:'' 'Invalid parameter: ',{,',',}//}l)Assert 0=+/b~(l' '~¨parms_.⎕NL 2)' '~¨parms.⎕NL 2
:If 0<list' '~¨parms_.⎕NL 2
parms¨list{' '=10:,'''',,'''' :,'←⍬' ,'',}¨parms_.{}¨list
:EndIf
:EndIf
'Must not be empty: "folder"'Assert 0<parms.folder
('Is not a folder: ',parms.folder)Assert F.IsDir parms.folder
Done
21 changes: 21 additions & 0 deletions APLSource/Cider/CreateProject.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{r}CreateProject parms;filename;config;projectFolder;list
Create a project according to what's specified in parms.
Returns always ''. Throws errors in case the project cannot be created
parmsparms CreateCreateProjectParms
r''
filename(AddSlash parms.folder),'cider.config'
:If 0=parms.namespace
parms.namespace{{1+-/()'/\'}¯1}11 ⎕NPARTS filename
:EndIf
:If ~(,1 ⎕C parms.namespace),¨'#' '⎕SE'
('Not a valid APL name: <',parms.namespace,'>')Assert ¯1⎕NC parms.namespace
:EndIf
:If ~⎕NEXISTS parms.folder
'Invalid folder: parent must exist'Assert{0=:1 ⎕NEXISTS }1⎕NPARTS{-(¯1)'/\'}parms.folder Parent folder must exist
parms.folder1 ⎕NPARTS parms.folder
⎕MKDIR parms.folder
:EndIf
CreateConfigFile filename parms.namespace
config⎕JSON('Dialect' 'JSON5')⎕NGET filename
('Invalid config file: ',filename)Assert 0 PerformConfigChecks config
Done
3 changes: 2 additions & 1 deletion APLSource/Cider/History.apla
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(
'* 0.41.0 ⋄ 2024-06-20'
' * Cider now adds its own version number to a project config file whenever it is written to disk.'
' * API functions `CreateProject` and `CreateCreateProjectParms` added '
' * Cider now adds its own version number to a project config file whenever it is written to disk'
' * Cider''s "Make" now re-creates the UCMD cache'
'* 0.40.1 ⋄ 2024-06-18'
' * NuGet-related test cases are now executed in their own, independent process'
Expand Down
2 changes: 1 addition & 1 deletion APLSource/Cider/PolishProperties.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
f31
:EndIf
:If f1f2f3
config Put_JSON5(F.AddTrailingSep parms.folder),'cider.config'
config Put_JSON5(F.AddTrailingSep parms.folder),ConfigFilename
p'Modified file "cider.config" saved in ',parms.folder
:EndIf
:If errorFlag
Expand Down
4 changes: 2 additions & 2 deletions APLSource/Cider/ProjectConfig.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
pathGetFolderFromAlias path
('Alias "',path,'" not found')Assert 0<path
:EndIf
:If 'cider.config'{⎕C(-)}path
:AndIf (¯1(-'cider.config')path)'/\'
:If ConfigFilename{⎕C(-)}path
:AndIf (¯1(-ConfigFilename)path)'/\'
filenamepath
:Else
filenamepath,'/cider.config'
Expand Down
2 changes: 2 additions & 0 deletions APLSource/Cider/Public.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
r,'AddTatinDependencies'
r,'CloseProject'
r,'CreateOpenParms'
r,'CreateCreateProjectParms'
r,'CreateProject'
r,'DropAlias'
r,'GetCiderAliasFileContent'
r,'GetCiderAliasFilename'
Expand Down
2 changes: 1 addition & 1 deletion APLSource/Cider/ReadProjectConfigFile.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
`projectFolder` may or may not carry the filename as such.
Check the config file for some entries and adds them if they are missing. In such a
case the config file is also written back to file.
projectFolder2'cider.config'{(-): ({,'/'/~(¯1)'/\'}),}projectFolder
projectFolder2ConfigFilename{(-): ({,'/'/~(¯1)'/\'}),}projectFolder
configGet_JSON5 projectFolder2
saveFlag0
:If 0=config.CIDER.dependencies.⎕NC'tatin'
Expand Down
8 changes: 4 additions & 4 deletions APLSource/Cider/UC/CreateProject_.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
:Return
:EndIf
:EndIf
filename(AddSlash folder),configFilename
filename(AddSlash folder),##.ConfigFilename
:If 0=⎕NC'namespace'
:OrIf 0=namespace
namespace{{1+-/()'/\'}¯1}11 ⎕NPARTS filename
Expand All @@ -21,7 +21,7 @@
('Not a valid APL name: <',namespace,'>')Assert ¯1⎕NC namespace
:EndIf
:If acceptFlag
('The -acceptConfig flag was set but no file "',configFilename,'" was found')Assert ⎕NEXISTS filename
('The -acceptConfig flag was set but no file "',##.ConfigFilename,'" was found')Assert ⎕NEXISTS filename
:Else
:If ~⎕NEXISTS folder
'Invalid path: parent must exist'Assert{0=:1 ⎕NEXISTS }1⎕NPARTS{-(¯1)'/\'}folder Parent folder must exist
Expand All @@ -32,7 +32,7 @@
r'Cancelled by user' 0
:EndIf
:EndIf
CreateConfigFile filename namespace
P.##.CreateConfigFile filename namespace
:EndIf
:If ~noEditFlag
:If ¯1=P.ProjectConfig filename
Expand All @@ -59,7 +59,7 @@
:Else
:If 0<((config.CIDER.parent)config.CIDER.projectSpace).⎕NL 9~16
:If 1<listP.##.F.Dir projectFolder
:OrIf 'cider.config'{1:0 ,/1⎕NPARTS}list
:OrIf P.##.ConfigFilename{1:0 ,/1⎕NPARTS}list
:If batch
In batch mode there is nothing we can do but throw an error
'Both the target namespace and the source folder are not empty'Assert 0
Expand Down
22 changes: 10 additions & 12 deletions APLSource/Cider/UC/Help.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
:Case 1
:Select ⎕C Cmd
:Case ⎕C'OpenProject'
r,'Takes a path to a folder that must host a file "',configFilename,'" or a pre-defined alias.'
r,'Takes a path to a folder that must host a file "',##.ConfigFilename,'" or a pre-defined alias.'
r,'The config file must specify all variables required by Cider, including "source".'
r,'The contents of "source" is then linked to "parent.projectSpace" by default.'
r,'If no folder or alias is specified, Cider will present a list with all defined aliases.'
Expand Down Expand Up @@ -179,20 +179,19 @@
r,' into an edit window, and will add all remaining ones as aliase.'
:Case ⎕C'CreateProject'
r,'Requires a path to a folder ("source") that is about to become a project.'
r,''
r,'You might also specify a namespace. If no namespace is provided then the name of the namespace'
r,'is derived from the path. If the namespace does not yet exist it will be created.'
r,'The namespace will be LINKed to "source", and a namespace CiderConfig, holding the configuration'
r,'data, will be injected into the namespace.'
r,'For a root project (the whole of #, NOT recommended) you must specify # as 2nd argument.'
r,''
r,' * Creates a file "',configFilename,'" in that folder'
r,' * Creates a file "',##.ConfigFilename,'" in that folder'
r,' * Lets the user edit that file and makes sure that all mandatory settings are specified correctly'
r,' * In case an alias is specified the alias is saved'
r,' * In case an alias is specified, the alias is saved'
r,' * Finally it attempts to open the new project'
r,''
r,'If no path is specified it acts on the current directory, but in that case the user'
r,'is prompted for confirmation to avoid mishaps.'
r,'If no path is specified it acts on the current directory, but in that case the user is prompted'
r,'for confirmation to avoid mishaps.'
r,''
r,'-acceptConfig: By default a file cider.config is created, and an error is thrown in'
r,' case it already exists. You can use -acceptConfig to force CreateProject'
Expand All @@ -201,12 +200,11 @@
r,'-alias: In case you are going to work on the new project frequently you may specify'
r,' -alias=name; from then on you can use the [alias] rather than the path.'
r,' Note that aliases are not case sensitive.'
r,'-batch After a project has been created successfully, the user will be asked whether'
r,' she wants to open the project as well. You can enforce that without the user'
r,' being interrogated by setting the -batch flag. Mainly useful for test cases and'
r,' and possibly an automated build process.'
r,'-ignoreUserExec Suppress execution of a user function defined in Cider''s config file on this occasion'
r,' You don''t want to run a general user function in test suite, for example.'
r,'-batch After a project has been created successfully, the user will be asked whether she'
r,' wants to open the project as well. You can enforce that without the user being'
r,' questioned by setting the -batch flag. Mainly useful for test cases and possibly'
r,' an automated build process.'
r,'-ignoreUserExec Suppress execution of a user function defined in Cider''s config file on this occasion.'
:Case ⎕C'CloseProject'
r,'Breaks the Link between one or more projects and their associated files on disk.'
r,''
Expand Down
2 changes: 1 addition & 1 deletion APLSource/Cider/UC/OpenFileDialogBox.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ref⎕NEW'FileBox'
ref.Captioncaption
ref.(onFileBoxOK onFileBoxCancel)1
ref.File'cider.config'
ref.File##.ConfigFilename
resref.Wait
:If 'FileBoxOK'2res
opCode1
Expand Down
2 changes: 1 addition & 1 deletion APLSource/Cider/Version.aplf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rVersion
See also `History`
r'0.41.0-beta-3+671'
r'0.41.0-beta-4+671'
2 changes: 1 addition & 1 deletion APLSource/Cider/WriteProjectConfigFile.aplf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{r}config WriteProjectConfigFile path;path2
Writes project configuration "config" to file.\\
`path` may or may not carry the filename as such.
path2'cider.config'{(-): ({,'/'/~(¯1)'/\'}),}path
path2ConfigFilename{(-): ({,'/'/~(¯1)'/\'}),}path
rconfig Put_JSON5 path2
Done
29 changes: 29 additions & 0 deletions APLSource/TestCases/Test_Create_500.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
RTest_Create_500(stopFlag batchFlag);⎕TRAP;tempDir;parms;rc;parms2;res
Create a new project via the API
⎕TRAP(999 'C' '∘∘∘ ⍝ Deliberate error')(0 'N')
RT._Failed

tempDir∆GetFolderInTempDir⎕SI
3 ⎕MKDIR tempDir,'/APLSource'
('r←TheAnswerIs' 'r←42')⎕NPUT(tempDir,'/APLSource/TheAnswerIs.aplf')1

parms##.Cider.CreateCreateProjectParms tempDir
##.Cider.CreateProject parms

#.⎕EX'Foo' #.⎕SHADOW'Foo'
parms2##.Cider.CreateOpenParms
parms2.folderparms.folder
parms2.batch1
parms2.ignoreUserExec1
parms2.parent'#'
parms2.projectSpace'Foo'
res##.Cider.OpenProject parms2
T.GoToTidyUp~/'Project successfully opened and established in "#.Foo"'res

RT._OK

∆TidyUp:
Assert 0 ##.Cider.CloseProject'#.Foo'
rcFilesAndDirs.RmDir tempDir,'/..'
Assert rc.=0
Done
5 changes: 3 additions & 2 deletions APLSource/TestCases/Test_Misc_016.aplf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rTest_Misc_016(stopFlag batchFlag);⎕TRAP;b;folder;parms;log;success;msg;rc;res;en;cfg;body;pkgCfg;name;ref
rTest_Misc_016(stopFlag batchFlag);⎕TRAP;b;folder;parms;log;success;msg;rc;res;en;cfg;body;pkgCfg;name;ref;stop
Test the "tatinVars" property
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')

Expand All @@ -12,7 +12,8 @@
:Else
⎕SE.Cider.##.CommTools.YesOrNo_Answers1 2'OpenAsWell@' 'n'
:EndIf
(rc msg res)∆UCMD'CreateProject ',folder,' -noEdit -ignoreUserExec'
stop0
(rc msg res)stop ∆UCMD'CreateProject ',folder,' -noEdit -ignoreUserExec'
msg Assert rc=0
cfg∆GetJSON5 folder,'/cider.config'
body'r←Hello' 'r←42'
Expand Down
4 changes: 2 additions & 2 deletions APLSource/TestCases/Test_OpenAndClose_001.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{}⎕SE.Link.Add'#.Foo.Hello'
listFilesAndDirs.ListFiles projectFolder1
T.GoToTidyUp 1list
T.GoToTidyUp'cider.config',/1⎕NPARTS 1list
T.GoToTidyUp ##.Cider.ConfigFilename,/1⎕NPARTS 1list
aliase##.Cider.GetCiderAliasFileContent
T.GoToTidyUp~(⎕C'test-case-alias-Foo')aliase[;1]

Expand All @@ -31,7 +31,7 @@
Assert rc=0
listFilesAndDirs.ListFiles projectFolder2
T.GoToTidyUp 1list
T.GoToTidyUp'cider.config',/1⎕NPARTS 1list
T.GoToTidyUp ##.Cider.ConfigFilename,/1⎕NPARTS 1list
aliase##.Cider.GetCiderAliasFileContent
T.GoToTidyUp~/(⎕C'test-case-alias-Foo' 'test-case-alias-Goo')aliase[;1]

Expand Down
2 changes: 1 addition & 1 deletion APLSource/TestCases/Test_OpenAndClose_002.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
msg Assert 0=rc
listFilesAndDirs.ListFiles tempDir
T.GoToTidyUp 1list
T.GoToTidyUp'cider.config',/1⎕NPARTS 1list
T.GoToTidyUp ##.Cider.ConfigFilename,/1⎕NPARTS 1list

RT._OK

Expand Down
6 changes: 3 additions & 3 deletions APLSource/TestCases/Test_OpenAndClose_004.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{}⎕SE.Link.Add'#.Foo.Hello'
listFilesAndDirs.ListFiles projectFolder1
T.GoToTidyUp 1list
T.GoToTidyUp'cider.config',/1⎕NPARTS 1list
T.GoToTidyUp ##.Cider.ConfigFilename,/1⎕NPARTS 1list
aliase##.Cider.GetCiderAliasFileContent
T.GoToTidyUp~(⎕C'test-case-alias-Foo')aliase[;1]

Expand All @@ -31,7 +31,7 @@
Assert rc=0
listFilesAndDirs.ListFiles projectFolder2
T.GoToTidyUp 1list
T.GoToTidyUp'cider.config',/1⎕NPARTS 1list
T.GoToTidyUp ##.Cider.ConfigFilename,/1⎕NPARTS 1list
aliase##.Cider.GetCiderAliasFileContent
T.GoToTidyUp~/(⎕C'test-case-alias-Foo' 'test-case-alias-Goo')aliase[;1]

Expand All @@ -45,7 +45,7 @@
Assert rc=0
listFilesAndDirs.ListFiles projectFolder3
T.GoToTidyUp 1list
T.GoToTidyUp'cider.config',/1⎕NPARTS 1list
T.GoToTidyUp ##.Cider.ConfigFilename,/1⎕NPARTS 1list

T.GoToTidyUp 30 ##.Cider.CloseProject'#.Foo' '[test-case-alias-Goo]' '[Does not exist]'projectFolder3

Expand Down
2 changes: 1 addition & 1 deletion APLSource/TestCases/Test_OpenAndClose_010.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Assert'Project successfully opened and established in '{()}res
listFilesAndDirs.ListFiles tempDir
T.GoToTidyUp 1list
T.GoToTidyUp'cider.config',/1⎕NPARTS 1list
T.GoToTidyUp ##.Cider.ConfigFilename,/1⎕NPARTS 1list
T.GoToTidyUp 1#.Foo.∆INIT
res∆LINK'Break' '#.Foo'
Assert res ∆StartsWith'Unlinked:'
Expand Down
2 changes: 1 addition & 1 deletion APLSource/TestCases/Test_UC_040.aplf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

listFilesAndDirs.ListFiles tempDir
T.GoToTidyUp 1list
T.GoToTidyUp'cider.config',/1⎕NPARTS 1list
T.GoToTidyUp ##.Cider.ConfigFilename,/1⎕NPARTS 1list
config##.Cider.ReadProjectConfigFile tempDir
T.GoToTidyUp'config.CIDER.projectSpace'config.CIDER.projectSpace

Expand Down
2 changes: 1 addition & 1 deletion apl-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
tags: "project-management",
tatin_version: "0.103.0",
userCommandScript: "APLSource/Cider_UC.dyalog",
version: "0.41.0+739",
version: "0.41.0+743",
}
Loading

0 comments on commit b12f811

Please sign in to comment.