2 // a package is either a quark or a folder in SCClassLibrary or extensions folders
4 // a class is in a 'package' determined by where its Class file is
5 // all folders in class library :
10 // all folders in system extension
11 // all folders in user extension
13 // any loose files are placed in a packaged calle SCClassLibrary or Extensions
14 // possiblity for error: if you have loose files in user extensions and system extensions
15 // they will both be placed in the same package: Extensions
17 // [ name -> folderPath, name -> folderPath ... ]
20 var platform,scClassLibrary,looseFiles;
24 packages = Library.at(Quarks,\packages);
25 if(packages.notNil,{ ^packages });
27 platform = thisProcess.platform;
30 var folders,packages,paths,files;
31 dir = dir.withTrailingSlash;
32 paths = (dir++"*").pathMatch;
33 folders = paths.reject({ |p| p.last != $/ or: {p.basename == "quarks"} });
34 files = paths.select({ |p| p.last != $/ });
35 packages = folders.collect({ |p| p.basename.asSymbol -> p });
37 // if there are any loose files then create a package called dir
38 packages = packages.add( dir.basename.asSymbol -> dir )
44 (f.value(platform.classLibraryDir)
48 f.value(platform.systemExtensionDir)
52 Quarks.installed.collect({ |q|
53 q.name.asSymbol -> (Platform.userExtensionDir +/+ "quarks" +/+ q.path.withTrailingSlash)
55 .sort({ |a,b| a.value.size > b.value.size }) // sort longer paths first
59 f.value(platform.userExtensionDir);
60 Library.put(Quarks,\packages,packages);
68 path = this.filenameSymbol.asString;
69 Main.packages.do({ |namepath|
70 if(path.copyRange(0,namepath.value.size-1) == namepath.value,{
74 Error("Discrepancy: Package not found for class !").throw;
81 may not be the package that its class is in
86 path = this.filenameSymbol.asString;
87 Main.packages.do({ |namepath|
88 if(path.copyRange(0,namepath.value.size-1) == namepath.value,{
92 Error("Discrepancy: Package not found for method !").throw;
101 myPath = Platform.userExtensionDir +/+ "quarks" +/+ this.path;
103 ^Class.allClasses.reject(_.isMetaClass).select({ |class|
104 class.filenameSymbol.asString.copyRange(0,end) == myPath
107 definesExtensionMethods {
108 // all methods whose path is in this quark folder
109 // where the class is not in this quark
111 myPath = Platform.userExtensionDir +/+ "quarks" +/+ this.path;
113 ^Class.allClasses.collect({ |c| c.methods }).reject(_.isNil).flat
115 method.filenameSymbol.asString.copyRange(0,end) == myPath
117 method.ownerClass.filenameSymbol.asString.copyRange(0,end) != myPath
121 // of the classes you defined, what packages are the superclasses in ?
122 // of the extension methods you defined, what packages are the super classes in ?
123 /* checkDependencies {
129 // the equivalent to Quark-definesClasses
130 // but works for non-quarks like Quarks.classesInPackage("JITlib")
131 *classesInPackage { |packageName|
132 var myPath,end,package;
133 package = Main.packages.detect({ |pk| pk.key == packageName });
134 if(package.isNil,{ Error("Package not found:"+packageName).throw });
136 myPath = package.value;
138 ^Class.allClasses.select({ |class|
139 class.isMetaClass.not and: {
140 class.filenameSymbol.asString.copyRange(0,end) == myPath