Permalink
Browse files

Merge pull request #51 from lksoft/mogenerator

---

Here are the changes to present error messages when the directories cannot be created and also it will now create the output directories automatically. Also fixed a logging bug.
  • Loading branch information...
2 parents 33f3dd1 + b080a24 commit 33fbde02c0d66af9f1cb7cfe7e1cc9d1887bc021 @rentzsch rentzsch committed Apr 7, 2011
Showing with 42 additions and 2 deletions.
  1. +41 −1 mogenerator.m
  2. +1 −1 mogeneratorTestMule/mogenerate.command
View
@@ -376,6 +376,8 @@ - (NSString*)currentXcodePath {
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput:pipe];
+ // Ensures that the current tasks output doesn't get hijacked
+ [task setStandardInput:[NSPipe pipe]];
NSFileHandle *file = [pipe fileHandleForReading];
@@ -432,6 +434,39 @@ - (void)setModel:(NSString*)path;
assert(model);
}
+- (void)validateOutputPath:(NSString *)path forType:(NSString *)type
+{
+ // Ignore nil ones
+ if (path == nil) {
+ return;
+ }
+
+ NSString *errorString = nil;
+ NSError *error = nil;
+ NSFileManager *fm = [NSFileManager defaultManager];
+ BOOL isDir = NO;
+
+ // Test to see if the path exists
+ if ([fm fileExistsAtPath:path isDirectory:&isDir]) {
+ if (!isDir) {
+ errorString = [NSString stringWithFormat:@"%@ Directory path (%@) exists as a file.", type, path];
+ }
+ }
+ // Try to create path
+ else {
+ if (![fm createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]) {
+ errorString = [NSString stringWithFormat:@"Couldn't create %@ Directory (%@):%@", type, path, [error localizedDescription]];
+ }
+ }
+
+ if (errorString != nil) {
+
+ // Print error message and exit with IO error
+ ddprintf(errorString);
+ exit(EX_IOERR);
+ }
+}
+
- (int) application: (DDCliApplication *) app
runWithArguments: (NSArray *) arguments;
{
@@ -444,10 +479,15 @@ - (int) application: (DDCliApplication *) app
printf("mogenerator 1.22. By Jonathan 'Wolf' Rentzsch + friends.\n");
return EXIT_SUCCESS;
}
-
+
gCustomBaseClass = [baseClass retain];
NSString * mfilePath = includem;
NSMutableString * mfileContent = [NSMutableString stringWithString:@""];
+
+ [self validateOutputPath:outputDir forType:@"Output"];
+ [self validateOutputPath:machineDir forType:@"Machine Output"];
+ [self validateOutputPath:humanDir forType:@"Human Output"];
+
if (outputDir == nil)
outputDir = @"";
if (machineDir == nil)
View
@@ -1,4 +1,4 @@
#!/bin/sh
cd "`dirname \"$0\"`"
cd MOs
-mogenerator -model ../mogeneratorTestMule_DataModel.xcdatamodel -baseClass MyBaseClass -includem include.m
+mogenerator --model ../mogeneratorTestMule_DataModel.xcdatamodel --baseClass MyBaseClass --includem include.m

0 comments on commit 33fbde0

Please sign in to comment.