Changeset 217
- Timestamp:
- 02/20/07 23:24:39 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cocoa/mogenerator/mogenerator.m
r178 r217 1 /******************************************************************************* 2 mogenerator.m 3 Copyright (c) 2006-2007 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com> 4 Some rights reserved: <http://opensource.org/licenses/mit-license.php> 5 6 ***************************************************************************/ 7 1 8 #import <Foundation/Foundation.h> 2 9 #import <CoreData/CoreData.h> … … 143 150 144 151 int main (int argc, const char * argv[]) { 145 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];152 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 146 153 147 154 NSManagedObjectModel *model = nil; … … 164 171 assert(!model); // Currently we only can load one model. 165 172 NSString *path = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:optarg length:strlen(optarg)]; 173 174 if( ![[NSFileManager defaultManager] fileExistsAtPath:path]){ 175 fprintf(stderr, "mogenerator: error loading file at %s: no such file exists.\n", optarg); 176 return ENOENT; 177 } 178 166 179 if ([[path pathExtension] isEqualToString:@"xcdatamodel"]) { 167 180 // We've been handed a .xcdatamodel data model, transparently compile it into a .mom managed object model. … … 184 197 break; 185 198 case opt_version: 186 printf("mogenerator 1.1. By Jonathan 'Wolf' Rentzsch.\n");199 printf("mogenerator 1.1.1. By Jonathan 'Wolf' Rentzsch + friends.\n"); 187 200 break; 188 201 case opt_help: … … 196 209 197 210 NSFileManager *fm = [NSFileManager defaultManager]; 211 212 int machineFilesGenerated = 0; 213 int humanFilesGenerated = 0; 198 214 199 215 if (model) { … … 204 220 205 221 MiscMergeEngine *machineH = engineWithTemplatePath([mogeneratorAppSupportFolder stringByAppendingPathComponent:@"machine.h.motemplate"]); 206 MiscMergeEngine *machineM = engineWithTemplatePath([mogeneratorAppSupportFolder stringByAppendingPathComponent:@"machine.M.motemplate"]); 222 assert(machineH); 223 MiscMergeEngine *machineM = engineWithTemplatePath([mogeneratorAppSupportFolder stringByAppendingPathComponent:@"machine.m.motemplate"]); 224 assert(machineM); 207 225 MiscMergeEngine *humanH = engineWithTemplatePath([mogeneratorAppSupportFolder stringByAppendingPathComponent:@"human.h.motemplate"]); 208 MiscMergeEngine *humanM = engineWithTemplatePath([mogeneratorAppSupportFolder stringByAppendingPathComponent:@"human.M.motemplate"]); 226 assert(humanH); 227 MiscMergeEngine *humanM = engineWithTemplatePath([mogeneratorAppSupportFolder stringByAppendingPathComponent:@"human.m.motemplate"]); 228 assert(humanM); 229 230 int entityCount = [[model entities] count]; 231 232 if(entityCount == 0){ 233 printf("No entities found in model. No files will be generated.\n"); 234 NSLog(@"the model description is %@.", model); 235 } 209 236 210 237 nsenumerate ([model entities], NSEntityDescription, entity) { 211 238 NSString *entityClassName = [entity managedObjectClassName]; 212 if (![entityClassName isEqualToString:@"NSManagedObject"] && ![entityClassName isEqualToString:gCustomBaseClass]) { 213 NSString *generatedMachineH = [machineH executeWithObject:entity sender:nil]; 214 NSString *generatedMachineM = [machineM executeWithObject:entity sender:nil]; 215 NSString *generatedHumanH = [humanH executeWithObject:entity sender:nil]; 216 NSString *generatedHumanM = [humanM executeWithObject:entity sender:nil]; 217 218 BOOL machineDirtied = NO; 219 220 NSString *machineHFileName = [NSString stringWithFormat:@"_%@.h", entityClassName]; 221 if (![fm regularFileExistsAtPath:machineHFileName] || ![generatedMachineH isEqualToString:[NSString stringWithContentsOfFile:machineHFileName]]) { 222 // If the file doesn't exist or is different than what we just generated, write it out. 223 [generatedMachineH writeToFile:machineHFileName atomically:NO]; 224 machineDirtied = YES; 225 } 226 NSString *machineMFileName = [NSString stringWithFormat:@"_%@.m", entityClassName]; 227 if (![fm regularFileExistsAtPath:machineMFileName] || ![generatedMachineM isEqualToString:[NSString stringWithContentsOfFile:machineMFileName]]) { 228 // If the file doesn't exist or is different than what we just generated, write it out. 229 [generatedMachineM writeToFile:machineMFileName atomically:NO]; 230 machineDirtied = YES; 231 } 232 NSString *humanHFileName = [NSString stringWithFormat:@"%@.h", entityClassName]; 233 if ([fm regularFileExistsAtPath:humanHFileName]) { 234 if (machineDirtied) 235 [fm touchPath:humanHFileName]; 236 } else { 237 [generatedHumanH writeToFile:humanHFileName atomically:NO]; 238 } 239 NSString *humanMFileName = [NSString stringWithFormat:@"%@.m", entityClassName]; 240 NSString *humanMMFileName = [NSString stringWithFormat:@"%@.mm", entityClassName]; 241 if (![fm regularFileExistsAtPath:humanMFileName] && [fm regularFileExistsAtPath:humanMMFileName]) { 242 // Allow .mm human files as well as .m files. 243 humanMFileName = humanMMFileName; 244 } 245 246 if ([fm regularFileExistsAtPath:humanMFileName]) { 247 if (machineDirtied) 248 [fm touchPath:humanMFileName]; 249 } else { 250 [generatedHumanM writeToFile:humanMFileName atomically:NO]; 251 } 252 253 [mfileContent appendFormat:@"#include \"%@\"\n#include \"%@\"\n", humanMFileName, machineMFileName]; 254 } 239 240 if ([entityClassName isEqualToString:@"NSManagedObject"] || 241 [entityClassName isEqualToString:gCustomBaseClass]){ 242 printf("skipping entity %s because it doesn't use a custom subclass.\n", 243 [entityClassName cStringUsingEncoding:NSUTF8StringEncoding]); 244 continue; 245 } 246 247 NSString *generatedMachineH = [machineH executeWithObject:entity sender:nil]; 248 NSString *generatedMachineM = [machineM executeWithObject:entity sender:nil]; 249 NSString *generatedHumanH = [humanH executeWithObject:entity sender:nil]; 250 NSString *generatedHumanM = [humanM executeWithObject:entity sender:nil]; 251 252 BOOL machineDirtied = NO; 253 254 NSString *machineHFileName = [NSString stringWithFormat:@"_%@.h", entityClassName]; 255 if (![fm regularFileExistsAtPath:machineHFileName] || ![generatedMachineH isEqualToString:[NSString stringWithContentsOfFile:machineHFileName]]) { 256 // If the file doesn't exist or is different than what we just generated, write it out. 257 [generatedMachineH writeToFile:machineHFileName atomically:NO]; 258 machineDirtied = YES; 259 machineFilesGenerated++; 260 } 261 NSString *machineMFileName = [NSString stringWithFormat:@"_%@.m", entityClassName]; 262 if (![fm regularFileExistsAtPath:machineMFileName] || ![generatedMachineM isEqualToString:[NSString stringWithContentsOfFile:machineMFileName]]) { 263 // If the file doesn't exist or is different than what we just generated, write it out. 264 [generatedMachineM writeToFile:machineMFileName atomically:NO]; 265 machineDirtied = YES; 266 machineFilesGenerated++; 267 } 268 NSString *humanHFileName = [NSString stringWithFormat:@"%@.h", entityClassName]; 269 if ([fm regularFileExistsAtPath:humanHFileName]) { 270 if (machineDirtied) 271 [fm touchPath:humanHFileName]; 272 } else { 273 [generatedHumanH writeToFile:humanHFileName atomically:NO]; 274 humanFilesGenerated++; 275 } 276 NSString *humanMFileName = [NSString stringWithFormat:@"%@.m", entityClassName]; 277 NSString *humanMMFileName = [NSString stringWithFormat:@"%@.mm", entityClassName]; 278 if (![fm regularFileExistsAtPath:humanMFileName] && [fm regularFileExistsAtPath:humanMMFileName]) { 279 // Allow .mm human files as well as .m files. 280 humanMFileName = humanMMFileName; 281 } 282 283 if ([fm regularFileExistsAtPath:humanMFileName]) { 284 if (machineDirtied) 285 [fm touchPath:humanMFileName]; 286 } else { 287 [generatedHumanM writeToFile:humanMFileName atomically:NO]; 288 humanFilesGenerated++; 289 } 290 291 [mfileContent appendFormat:@"#include \"%@\"\n#include \"%@\"\n", humanMFileName, machineMFileName]; 255 292 } 256 293 } … … 259 296 [fm removeFileAtPath:tempMOMPath handler:nil]; 260 297 } 261 if (mfilePath) { 298 bool mfileGenerated = NO; 299 if (mfilePath && ![mfileContent isEqualToString:@""]) { 262 300 [mfileContent writeToFile:mfilePath atomically:NO]; 263 } 264 265 [pool release]; 266 return 0; 267 } 301 mfileGenerated = YES; 302 } 303 304 printf("%d machine files%s %d human files%s generated.\n", machineFilesGenerated, 305 (mfileGenerated ? "," : " and"), humanFilesGenerated, (mfileGenerated ? " and one include.m file" : "")); 306 307 [pool release]; 308 return 0; 309 } trunk/cocoa/mogenerator/mogenerator.xcodeproj/project.pbxproj
r178 r217 140 140 79D2C0570ACFBCB500F3F141 /* FoundationAdditions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FoundationAdditions.h; sourceTree = "<group>"; }; 141 141 79D2C0580ACFBCB500F3F141 /* FoundationAdditions.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = FoundationAdditions.m; sourceTree = "<group>"; }; 142 8DD76FA10486AA7600D96B5E /* mogenerator */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = mogenerator; sourceTree = BUILT_PRODUCTS_DIR; };142 8DD76FA10486AA7600D96B5E /* mogenerator */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = mogenerator; sourceTree = BUILT_PRODUCTS_DIR; }; 143 143 /* End PBXFileReference section */ 144 144 trunk/cocoa/mogenerator/mogenerator.xcodeproj/wolf.mode1
r178 r217 205 205 <integer>0</integer> 206 206 <key>bookmark</key> 207 <string>79 8B56100B3F9A3E0017012B</string>207 <string>7968E44B0B8C0D83007B6ABC</string> 208 208 <key>history</key> 209 209 <array> 210 <string>798B56 0F0B3F9A3E0017012B</string>210 <string>798B56100B3F9A3E0017012B</string> 211 211 </array> 212 212 </dict> … … 224 224 <false/> 225 225 <key>RubberWindowFrame</key> 226 <string> 576 193 1096 835 0 0 1680 1028 </string>226 <string>1444 743 1096 835 0 0 2560 1578 </string> 227 227 </dict> 228 228 </dict> … … 305 305 <array> 306 306 <array> 307 <integer> 2</integer>308 <integer> 1</integer>307 <integer>10</integer> 308 <integer>9</integer> 309 309 <integer>0</integer> 310 310 </array> … … 330 330 </array> 331 331 <key>RubberWindowFrame</key> 332 <string> 832 514 690 397 0 0 1680 1028 </string>332 <string>1572 956 690 397 0 0 2560 1578 </string> 333 333 </dict> 334 334 <key>Module</key> … … 367 367 <string>{{0, 0}, {376, 0}}</string> 368 368 <key>RubberWindowFrame</key> 369 <string> 832 514 690 397 0 0 1680 1028 </string>369 <string>1572 956 690 397 0 0 2560 1578 </string> 370 370 </dict> 371 371 <key>Module</key> … … 387 387 <string>{{0, 5}, {376, 351}}</string> 388 388 <key>RubberWindowFrame</key> 389 <string> 832 514 690 397 0 0 1680 1028 </string>389 <string>1572 956 690 397 0 0 2560 1578 </string> 390 390 </dict> 391 391 <key>Module</key> … … 411 411 <key>TableOfContents</key> 412 412 <array> 413 <string>79 8B560D0B3F9A3E0017012B</string>413 <string>7968E42F0B8C0C54007B6ABC</string> 414 414 <string>1CE0B1FE06471DED0097A5F4</string> 415 <string>79 8B560E0B3F9A3E0017012B</string>415 <string>7968E4300B8C0C54007B6ABC</string> 416 416 <string>1CE0B20306471E060097A5F4</string> 417 417 <string>1CE0B20506471E060097A5F4</string> … … 552 552 </array> 553 553 <key>WindowString</key> 554 <string> 832 514 690 397 0 0 1680 1028 </string>554 <string>1572 956 690 397 0 0 2560 1578 </string> 555 555 <key>WindowTools</key> 556 556 <array> … … 582 582 <string>{{0, 0}, {500, 218}}</string> 583 583 <key>RubberWindowFrame</key> 584 <string> 45 495 500 500 0 0 1680 1028 </string>584 <string>79 1008 500 500 0 0 2560 1578 </string> 585 585 </dict> 586 586 <key>Module</key> … … 590 590 </dict> 591 591 <dict> 592 <key>BecomeActive</key> 593 <true/> 592 594 <key>ContentConfiguration</key> 593 595 <dict> 594 596 <key>PBXBuildLogShowsTranscriptDefaultKey</key> 595 <string>{{0, 5}, {500, 231}}</string>597 <string>{{0, 236}, {500, 0}}</string> 596 598 <key>PBXProjectModuleGUID</key> 597 599 <string>XCMainBuildResultsModuleGUID</string> … … 608 610 <string>{{0, 223}, {500, 236}}</string> 609 611 <key>RubberWindowFrame</key> 610 <string> 45 495 500 500 0 0 1680 1028 </string>612 <string>79 1008 500 500 0 0 2560 1578 </string> 611 613 </dict> 612 614 <key>Module</key> … … 631 633 <array> 632 634 <string>79D2BF1B0ACFAF4A00F3F141</string> 633 <string>79 8B56110B3F9A3E0017012B</string>635 <string>7968E42D0B8C0C4F007B6ABC</string> 634 636 <string>1CD0528F0623707200166675</string> 635 637 <string>XCMainBuildResultsModuleGUID</string> … … 638 640 <string>xcode.toolbar.config.build</string> 639 641 <key>WindowString</key> 640 <string> 45 495 500 500 0 0 1680 1028 </string>642 <string>79 1008 500 500 0 0 2560 1578 </string> 641 643 <key>WindowToolGUID</key> 642 644 <string>79D2BF1B0ACFAF4A00F3F141</string> trunk/cocoa/mogenerator/mogenerator.xcodeproj/wolf.pbxuser
r178 r217 73 73 ); 74 74 }; 75 PBXPerProjectTemplateStateSaveDate = 1 88717308;76 PBXWorkspaceStateSaveDate = 1 88717308;75 PBXPerProjectTemplateStateSaveDate = 193727532; 76 PBXWorkspaceStateSaveDate = 193727532; 77 77 }; 78 78 perUserProjectItems = { 79 790C56700B06A11E00BF93B7 = 790C56700B06A11E00BF93B7 /* PBXBookmark */; 80 790C56760B06A8FA00BF93B7 = 790C56760B06A8FA00BF93B7 /* PBXTextBookmark */; 81 798B560F0B3F9A3E0017012B /* PBXTextBookmark */ = 798B560F0B3F9A3E0017012B /* PBXTextBookmark */; 79 7968E44B0B8C0D83007B6ABC /* PBXTextBookmark */ = 7968E44B0B8C0D83007B6ABC /* PBXTextBookmark */; 82 80 798B56100B3F9A3E0017012B /* PBXTextBookmark */ = 798B56100B3F9A3E0017012B /* PBXTextBookmark */; 83 81 }; … … 88 86 08FB7796FE84155DC02AAC07 /* mogenerator.m */ = { 89 87 uiCtxt = { 90 sepNavIntBoundsRect = "{{0, 0}, {1057, 3780}}";88 sepNavIntBoundsRect = "{{0, 0}, {1057, 4368}}"; 91 89 sepNavSelRange = "{0, 0}"; 92 90 sepNavVisRect = "{{0, 0}, {1057, 777}}"; 93 sepNavWindowFrame = "{{339, 43}, {1096, 835}}"; 94 }; 95 }; 96 790C56700B06A11E00BF93B7 /* PBXBookmark */ = { 97 isa = PBXBookmark; 98 fRef = 08FB7796FE84155DC02AAC07 /* mogenerator.m */; 99 }; 100 790C56760B06A8FA00BF93B7 /* PBXTextBookmark */ = { 91 sepNavWindowFrame = "{{1444, 743}, {1096, 835}}"; 92 }; 93 }; 94 7968E44B0B8C0D83007B6ABC /* PBXTextBookmark */ = { 101 95 isa = PBXTextBookmark; 102 96 fRef = 08FB7796FE84155DC02AAC07 /* mogenerator.m */; 103 name = noninheritedRelationships;104 rLen = 25;105 rLoc = 1332;97 name = "mogenerator.m: 1"; 98 rLen = 0; 99 rLoc = 0; 106 100 rType = 0; 107 vrLen = 1690; 108 vrLoc = 638; 109 }; 110 798B560F0B3F9A3E0017012B /* PBXTextBookmark */ = { 111 isa = PBXTextBookmark; 112 fRef = 08FB7796FE84155DC02AAC07 /* mogenerator.m */; 113 name = noninheritedRelationships; 114 rLen = 25; 115 rLoc = 1332; 116 rType = 0; 117 vrLen = 1690; 118 vrLoc = 638; 101 vrLen = 1739; 102 vrLoc = 0; 119 103 }; 120 104 798B56100B3F9A3E0017012B /* PBXTextBookmark */ = { … … 123 107 name = "mogenerator.m: 1"; 124 108 rLen = 0; 125 rLoc = 0;109 rLoc = 323; 126 110 rType = 0; 127 111 vrLen = 1689; … … 234 218 79D2C0570ACFBCB500F3F141 /* FoundationAdditions.h */ = { 235 219 uiCtxt = { 236 sepNavIntBoundsRect = "{{0, 0}, { 740, 630}}";220 sepNavIntBoundsRect = "{{0, 0}, {689, 652}}"; 237 221 sepNavSelRange = "{1074, 20}"; 238 sepNavVisRect = "{{0, 330}, {740, 195}}";222 sepNavVisRect = "{{0, 0}, {689, 652}}"; 239 223 sepNavWindowFrame = "{{661, 54}, {728, 710}}"; 240 224 };
