Changeset 217

Show
Ignore:
Timestamp:
02/20/07 23:24:39 (2 years ago)
Author:
rentzsch
Message:

[NEW] mogenerator 1.1.1: Now yaps about its activity. This should help counter the "why aren't source files being generated for my model and/or entities?!?" mysteries (hint: it's usually that you aren't using a custom entity class in your model). Credit to Michael McCracken? for the patch.

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 
    18#import <Foundation/Foundation.h> 
    29#import <CoreData/CoreData.h> 
     
    143150 
    144151int main (int argc, const char * argv[]) { 
    145     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
     152       NSAutoreleasePool      *pool = [[NSAutoreleasePool alloc] init]; 
    146153         
    147154        NSManagedObjectModel *model = nil; 
     
    164171                                assert(!model); // Currently we only can load one model. 
    165172                                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                                         
    166179                                if ([[path pathExtension] isEqualToString:@"xcdatamodel"]) { 
    167180                                        //      We've been handed a .xcdatamodel data model, transparently compile it into a .mom managed object model. 
     
    184197                                break; 
    185198                        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"); 
    187200                                break; 
    188201                        case opt_help: 
     
    196209         
    197210        NSFileManager *fm = [NSFileManager defaultManager]; 
     211 
     212        int machineFilesGenerated = 0;         
     213        int humanFilesGenerated = 0; 
    198214         
    199215        if (model) { 
     
    204220                 
    205221                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); 
    207225                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                } 
    209236                 
    210237                nsenumerate ([model entities], NSEntityDescription, entity) { 
    211238                        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]; 
    255292                } 
    256293        } 
     
    259296                [fm removeFileAtPath:tempMOMPath handler:nil]; 
    260297        } 
    261         if (mfilePath) { 
     298        bool mfileGenerated = NO; 
     299        if (mfilePath && ![mfileContent isEqualToString:@""]) { 
    262300                [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  
    140140                79D2C0570ACFBCB500F3F141 /* FoundationAdditions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FoundationAdditions.h; sourceTree = "<group>"; }; 
    141141                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; }; 
    143143/* End PBXFileReference section */ 
    144144 
  • trunk/cocoa/mogenerator/mogenerator.xcodeproj/wolf.mode1

    r178 r217  
    205205                                                <integer>0</integer> 
    206206                                                <key>bookmark</key> 
    207                                                 <string>798B56100B3F9A3E0017012B</string> 
     207                                                <string>7968E44B0B8C0D83007B6ABC</string> 
    208208                                                <key>history</key> 
    209209                                                <array> 
    210                                                         <string>798B560F0B3F9A3E0017012B</string> 
     210                                                        <string>798B56100B3F9A3E0017012B</string> 
    211211                                                </array> 
    212212                                        </dict> 
     
    224224                                <false/> 
    225225                                <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> 
    227227                        </dict> 
    228228                </dict> 
     
    305305                                                        <array> 
    306306                                                                <array> 
    307                                                                         <integer>2</integer> 
    308                                                                         <integer>1</integer> 
     307                                                                        <integer>10</integer> 
     308                                                                        <integer>9</integer> 
    309309                                                                        <integer>0</integer> 
    310310                                                                </array> 
     
    330330                                                </array> 
    331331                                                <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> 
    333333                                        </dict> 
    334334                                        <key>Module</key> 
     
    367367                                                                <string>{{0, 0}, {376, 0}}</string> 
    368368                                                                <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> 
    370370                                                        </dict> 
    371371                                                        <key>Module</key> 
     
    387387                                                                <string>{{0, 5}, {376, 351}}</string> 
    388388                                                                <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> 
    390390                                                        </dict> 
    391391                                                        <key>Module</key> 
     
    411411                        <key>TableOfContents</key> 
    412412                        <array> 
    413                                 <string>798B560D0B3F9A3E0017012B</string> 
     413                                <string>7968E42F0B8C0C54007B6ABC</string> 
    414414                                <string>1CE0B1FE06471DED0097A5F4</string> 
    415                                 <string>798B560E0B3F9A3E0017012B</string> 
     415                                <string>7968E4300B8C0C54007B6ABC</string> 
    416416                                <string>1CE0B20306471E060097A5F4</string> 
    417417                                <string>1CE0B20506471E060097A5F4</string> 
     
    552552        </array> 
    553553        <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> 
    555555        <key>WindowTools</key> 
    556556        <array> 
     
    582582                                                                <string>{{0, 0}, {500, 218}}</string> 
    583583                                                                <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> 
    585585                                                        </dict> 
    586586                                                        <key>Module</key> 
     
    590590                                                </dict> 
    591591                                                <dict> 
     592                                                        <key>BecomeActive</key> 
     593                                                        <true/> 
    592594                                                        <key>ContentConfiguration</key> 
    593595                                                        <dict> 
    594596                                                                <key>PBXBuildLogShowsTranscriptDefaultKey</key> 
    595                                                                 <string>{{0, 5}, {500, 231}}</string> 
     597                                                                <string>{{0, 236}, {500, 0}}</string> 
    596598                                                                <key>PBXProjectModuleGUID</key> 
    597599                                                                <string>XCMainBuildResultsModuleGUID</string> 
     
    608610                                                                <string>{{0, 223}, {500, 236}}</string> 
    609611                                                                <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> 
    611613                                                        </dict> 
    612614                                                        <key>Module</key> 
     
    631633                        <array> 
    632634                                <string>79D2BF1B0ACFAF4A00F3F141</string> 
    633                                 <string>798B56110B3F9A3E0017012B</string> 
     635                                <string>7968E42D0B8C0C4F007B6ABC</string> 
    634636                                <string>1CD0528F0623707200166675</string> 
    635637                                <string>XCMainBuildResultsModuleGUID</string> 
     
    638640                        <string>xcode.toolbar.config.build</string> 
    639641                        <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> 
    641643                        <key>WindowToolGUID</key> 
    642644                        <string>79D2BF1B0ACFAF4A00F3F141</string> 
  • trunk/cocoa/mogenerator/mogenerator.xcodeproj/wolf.pbxuser

    r178 r217  
    7373                                ); 
    7474                        }; 
    75                         PBXPerProjectTemplateStateSaveDate = 188717308
    76                         PBXWorkspaceStateSaveDate = 188717308
     75                        PBXPerProjectTemplateStateSaveDate = 193727532
     76                        PBXWorkspaceStateSaveDate = 193727532
    7777                }; 
    7878                perUserProjectItems = { 
    79                         790C56700B06A11E00BF93B7 = 790C56700B06A11E00BF93B7 /* PBXBookmark */; 
    80                         790C56760B06A8FA00BF93B7 = 790C56760B06A8FA00BF93B7 /* PBXTextBookmark */; 
    81                         798B560F0B3F9A3E0017012B /* PBXTextBookmark */ = 798B560F0B3F9A3E0017012B /* PBXTextBookmark */; 
     79                        7968E44B0B8C0D83007B6ABC /* PBXTextBookmark */ = 7968E44B0B8C0D83007B6ABC /* PBXTextBookmark */; 
    8280                        798B56100B3F9A3E0017012B /* PBXTextBookmark */ = 798B56100B3F9A3E0017012B /* PBXTextBookmark */; 
    8381                }; 
     
    8886        08FB7796FE84155DC02AAC07 /* mogenerator.m */ = { 
    8987                uiCtxt = { 
    90                         sepNavIntBoundsRect = "{{0, 0}, {1057, 3780}}"; 
     88                        sepNavIntBoundsRect = "{{0, 0}, {1057, 4368}}"; 
    9189                        sepNavSelRange = "{0, 0}"; 
    9290                        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 */ = { 
    10195                isa = PBXTextBookmark; 
    10296                fRef = 08FB7796FE84155DC02AAC07 /* mogenerator.m */; 
    103                 name = noninheritedRelationships
    104                 rLen = 25
    105                 rLoc = 1332
     97                name = "mogenerator.m: 1"
     98                rLen = 0
     99                rLoc = 0
    106100                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; 
    119103        }; 
    120104        798B56100B3F9A3E0017012B /* PBXTextBookmark */ = { 
     
    123107                name = "mogenerator.m: 1"; 
    124108                rLen = 0; 
    125                 rLoc = 0
     109                rLoc = 323
    126110                rType = 0; 
    127111                vrLen = 1689; 
     
    234218        79D2C0570ACFBCB500F3F141 /* FoundationAdditions.h */ = { 
    235219                uiCtxt = { 
    236                         sepNavIntBoundsRect = "{{0, 0}, {740, 630}}"; 
     220                        sepNavIntBoundsRect = "{{0, 0}, {689, 652}}"; 
    237221                        sepNavSelRange = "{1074, 20}"; 
    238                         sepNavVisRect = "{{0, 330}, {740, 195}}"; 
     222                        sepNavVisRect = "{{0, 0}, {689, 652}}"; 
    239223                        sepNavWindowFrame = "{{661, 54}, {728, 710}}"; 
    240224                };