Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored the code and prepared layout for the main runtime phases.

  • Loading branch information...
commit 3ec9e8f87bcd95a72bea707f88ca432ca474ac3f 1 parent 69a0152
@tomaz authored
View
18 Application/GBAppledocApplication.h
@@ -8,12 +8,26 @@
#import <Foundation/Foundation.h>
#import "DDCliApplication.h"
+#import "GBApplicationSettingsProvider.h"
/** The appledoc application handler.
This is the principal tool class. It represents the entry point for the application. The main promises of the class
- are parsing and validating of command line arguments and initiating document extraction.
+ are parsing and validating of command line arguments and initiating documentation generation. Generation is divided
+ into several distinct phases:
+
+ 1. Parsing data from source files: This is the initial phase where input directories and files are parsed into a
+ memory representation (i.e. objects) suitable for subsequent handling. This is where the source code files are
+ parsed and validated for possible file or object-level incosistencies. This step is driven by `GBParser` class.
+
+ 2. Post-processing of the data parsed in the previous step: At this phase, we already have in-memory representation
+ of all source code objects, so we can post-process and validate things such as links to other objects etc. We can
+ also update the in-memory representation with this data and therefore prepare everything for the final phase. This
+ step is driven by `GBProcessor` class.
+
+ 3. Generating output: This is the final phase where we use the in-memory data to generate output. This step is driven
+ by `GBGenerator` class.
*/
-@interface GBAppledocApplication : NSObject <DDCliApplicationDelegate>
+@interface GBAppledocApplication : NSObject <GBApplicationSettingsProvider, DDCliApplicationDelegate>
@end
View
29 Application/GBAppledocApplication.m
@@ -61,14 +61,26 @@ - (int)application:(DDCliApplication *)app runWithArguments:(NSArray *)arguments
return EXIT_SUCCESS;
}
if (self.version) {
- [self printHelp];
+ [self printVersion];
return EXIT_SUCCESS;
}
@try {
[self validateArguments:arguments];
[self initializeLoggingSystem];
- GBLogNormal(@"Starting...");
+
+// GBLogNormal(@"Parsing source files...");
+// GBParser *parser = [[GBParser alloc] initWithSettingsProvider:self];
+// [parser parseObjectsFromPaths:arguments];
+//
+// GBLogNormal(@"Processing parsed data...");
+// GBProcessor *processor = [[GBProcessor alloc] init];
+// [processor processObjectsFromParser:parser];
+//
+// GBLogNormal(@"Generating output...");
+// GBGenerator *generator = [[GBGenerator alloc] init];
+// [generator generateOutputFromProcessor:processor];
+
GBLogNormal(@"Finished.");
}
@catch (NSException *e) {
@@ -102,6 +114,17 @@ - (void)initializeLoggingSystem {
- (void)validateArguments:(NSArray *)arguments {
if ([arguments count] == 0) [NSException raise:@"At least one argument is required"];
+ for (NSString *path in arguments) {
+ if (![self.fileManager fileExistsAtPath:path]) {
+ [NSException raise:@"Path or file '%@' doesn't exist!", path];
+ }
+ }
+}
+
+#pragma mark Overriden methods
+
+- (NSString *)description {
+ return [self className];
}
#pragma mark Properties
@@ -123,7 +146,7 @@ - (void)printVersion {
- (void)printHelp {
#define PRINT_USAGE(short,long,arg,desc) [self printHelpForShortOption:short longOption:long argument:arg description:desc]
- ddprintf(@"Usage: %@ [OPTIONS] <path to source dirs or files>\n", DDCliApp);
+ ddprintf(@"Usage: %@ [OPTIONS] <paths to source dirs or files>\n", DDCliApp);
ddprintf(@"\n");
PRINT_USAGE(@"-f,", kGBArgLogFormat, @"<format>", @"Log format [0-4]");
PRINT_USAGE(@"-v,", kGBArgVerbose, @"<level>", @"Log verbosity level [0-6]");
View
17 Application/GBApplicationSettingsProvider.h
@@ -0,0 +1,17 @@
+//
+// GBApplicationSettingsProvider.h
+// appledoc
+//
+// Created by Tomaz Kragelj on 23.7.10.
+// Copyright 2010 Gentle Bytes. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+/** Defines the requirements for application-level settings providers.
+
+ Application-level settings providers provide application-wide settings and properties that affect application handling.
+ */
+@protocol GBApplicationSettingsProvider
+
+@end
View
16 Common/NSException+GBException.h
@@ -6,7 +6,7 @@
// Copyright (C) 2010, Gentle Bytes. All rights reserved.
//
-#import <Cocoa/Cocoa.h>
+#import <Foundation/Foundation.h>
/** Adds helper methods to `NSException` for more organized code.
*/
@@ -23,4 +23,18 @@
*/
+ (void)raise:(NSString *)format, ...;
+/** Raises the exception with the given `NSError` object.
+
+ This is useful for converting `NSError`s into `NSException`s. The method allows the client to pass in additional
+ context information which further aids diagnosting the exact reason for the exception. If no context information
+ is desired, pass `nil` and only error information is used for formatting. As exception message can become quite
+ verbose, it is split into several lines to make the output more readable.
+
+ @param error The error that describes the reason.
+ @param format A human readable message string explaining the context of the error.
+ @param ... Variable information to be inserted into the formatted reason.
+ @exception NSException Always thrown ;)
+ */
++ (void)raise:(NSError *)error format:(NSString *)format, ...;
+
@end
View
22 Common/NSException+GBException.m
@@ -17,4 +17,26 @@ + (void)raise:(NSString *)format, ... {
va_end(args);
}
++ (void)raise:(NSError *)error format:(NSString *)format, ... {
+ NSString *message = nil;
+ if (format) {
+ va_list args;
+ va_start(args, format);
+ message = [[[NSString alloc] initWithFormat:format arguments:args] autorelease];
+ va_end(args);
+ }
+
+ NSInteger code = [error code];
+ NSString *domain = [error domain];
+ NSString *description = [error localizedDescription];
+ NSString *reason = [error localizedFailureReason];
+
+ NSMutableString *output = [NSMutableString string];
+ if (message) [output appendFormat:@"%@\n", message];
+ [output appendFormat:@"Error: %@, code %i: %@\n", domain, code, description];
+ if (reason) [output appendFormat:@"Reason: %@", reason];
+
+ [self raise:output];
+}
+
@end
View
25 Common/NSFileManager+GBFileManager.h
@@ -0,0 +1,25 @@
+//
+// NSFileManager+GBFileManager.h
+// appledoc
+//
+// Created by Tomaz Kragelj on 23.7.10.
+// Copyright (C) 2010, Gentle Bytes. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+/** Extensions to `NSFileManager`.
+ */
+@interface NSFileManager (GBFileManager)
+
+/** Determines if the given path is a directory.
+
+ The method returns `YES` if the given path exists and is a directory, `NO` otherwise. This makes directory checking
+ one-line of code, however does not give information on whether the path exists or not! Use `
+
+ @param path The path to test.
+ @return Returns `YES` if the given path is a directory, `NO` otherwise.
+ */
+- (BOOL)isPathDirectory:(NSString *)path;
+
+@end
View
19 Common/NSFileManager+GBFileManager.m
@@ -0,0 +1,19 @@
+//
+// NSFileManager+GBFileManager.m
+// appledoc
+//
+// Created by Tomaz Kragelj on 23.7.10.
+// Copyright (C) 2010, Gentle Bytes. All rights reserved.
+//
+
+#import "NSFileManager+GBFileManager.h"
+
+@implementation NSFileManager (GBFileManager)
+
+- (BOOL)isPathDirectory:(NSString *)path {
+ BOOL result = NO;
+ if ([self fileExistsAtPath:path isDirectory:&result]) return result;
+ return NO;
+}
+
+@end
View
19 Common/NSObject+GBObject.h
@@ -0,0 +1,19 @@
+//
+// NSObject+GBObject.h
+// appledoc
+//
+// Created by Tomaz Kragelj on 23.7.10.
+// Copyright (C) 2010, Gentle Bytes. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+/** Implementes common application-wide functionality.
+ */
+@interface NSObject (GBObject)
+
+/** Returns the `NSFileManager` instance to use for dealing with OS.
+ */
+@property (readonly) NSFileManager *fileManager;
+
+@end
View
17 Common/NSObject+GBObject.m
@@ -0,0 +1,17 @@
+//
+// NSObject+GBObject.m
+// appledoc
+//
+// Created by Tomaz Kragelj on 23.7.10.
+// Copyright (C) 2010, Gentle Bytes. All rights reserved.
+//
+
+#import "NSObject+GBObject.h"
+
+@implementation NSObject (GBObject)
+
+- (NSFileManager *)fileManager {
+ return [NSFileManager defaultManager];
+}
+
+@end
View
19 appledoc.xcodeproj/project.pbxproj
@@ -8,6 +8,8 @@
/* Begin PBXBuildFile section */
731E7CE811F9962D00AAF15D /* NSException+GBException.m in Sources */ = {isa = PBXBuildFile; fileRef = 731E7CE711F9962D00AAF15D /* NSException+GBException.m */; };
+ 7340F02811FCC63100E712A4 /* NSFileManager+GBFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7340F02511FCC63100E712A4 /* NSFileManager+GBFileManager.m */; };
+ 7340F02911FCC63100E712A4 /* NSObject+GBObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 7340F02711FCC63100E712A4 /* NSObject+GBObject.m */; };
73D54C6211F8CE6D00CCDDB0 /* appledoc.m in Sources */ = {isa = PBXBuildFile; fileRef = 73D54C6111F8CE6D00CCDDB0 /* appledoc.m */; };
73D54C9E11F8D22B00CCDDB0 /* DDConsoleLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 73D54C9911F8D22B00CCDDB0 /* DDConsoleLogger.m */; };
73D54C9F11F8D22B00CCDDB0 /* DDFileLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 73D54C9B11F8D22B00CCDDB0 /* DDFileLogger.m */; };
@@ -25,6 +27,10 @@
08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
731E7CE611F9962D00AAF15D /* NSException+GBException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSException+GBException.h"; sourceTree = "<group>"; };
731E7CE711F9962D00AAF15D /* NSException+GBException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSException+GBException.m"; sourceTree = "<group>"; };
+ 7340F02411FCC63100E712A4 /* NSFileManager+GBFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+GBFileManager.h"; sourceTree = "<group>"; };
+ 7340F02511FCC63100E712A4 /* NSFileManager+GBFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+GBFileManager.m"; sourceTree = "<group>"; };
+ 7340F02611FCC63100E712A4 /* NSObject+GBObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+GBObject.h"; sourceTree = "<group>"; };
+ 7340F02711FCC63100E712A4 /* NSObject+GBObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+GBObject.m"; sourceTree = "<group>"; };
73D54C6111F8CE6D00CCDDB0 /* appledoc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = appledoc.m; sourceTree = "<group>"; };
73D54C6911F8CEEF00CCDDB0 /* appledoc_prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = appledoc_prefix.pch; sourceTree = "<group>"; };
73D54C9811F8D22B00CCDDB0 /* DDConsoleLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDConsoleLogger.h; sourceTree = "<group>"; };
@@ -66,18 +72,19 @@
children = (
73D54C9011F8D18300CCDDB0 /* Classes */,
73D54BDF11F8CE2300CCDDB0 /* Startup */,
- 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */,
+ 08FB779DFE84155DC02AAC07 /* Libraries & Frameworks */,
1AB674ADFE9D54B511CA2CBB /* Products */,
);
name = appledoc;
sourceTree = "<group>";
};
- 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = {
+ 08FB779DFE84155DC02AAC07 /* Libraries & Frameworks */ = {
isa = PBXGroup;
children = (
08FB779EFE84155DC02AAC07 /* Foundation.framework */,
);
- name = "External Frameworks and Libraries";
+ name = "Libraries & Frameworks";
+ path = Libraries;
sourceTree = "<group>";
};
1AB674ADFE9D54B511CA2CBB /* Products */ = {
@@ -111,6 +118,10 @@
children = (
73D54CA711F8D27F00CCDDB0 /* GBLog.h */,
73D54CA811F8D27F00CCDDB0 /* GBLog.m */,
+ 7340F02611FCC63100E712A4 /* NSObject+GBObject.h */,
+ 7340F02711FCC63100E712A4 /* NSObject+GBObject.m */,
+ 7340F02411FCC63100E712A4 /* NSFileManager+GBFileManager.h */,
+ 7340F02511FCC63100E712A4 /* NSFileManager+GBFileManager.m */,
731E7CE611F9962D00AAF15D /* NSException+GBException.h */,
731E7CE711F9962D00AAF15D /* NSException+GBException.m */,
73D54C9511F8D1F500CCDDB0 /* ThirdParty */,
@@ -221,6 +232,8 @@
73D54D2111F8D53E00CCDDB0 /* DDGetoptLongParser.m in Sources */,
73D54D2911F8D59200CCDDB0 /* GBAppledocApplication.m in Sources */,
731E7CE811F9962D00AAF15D /* NSException+GBException.m in Sources */,
+ 7340F02811FCC63100E712A4 /* NSFileManager+GBFileManager.m in Sources */,
+ 7340F02911FCC63100E712A4 /* NSObject+GBObject.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
2  appledoc_Prefix.pch
@@ -8,6 +8,8 @@
#ifdef __OBJC__
#import <Foundation/Foundation.h>
+ #import "NSObject+GBObject.h"
#import "NSException+GBException.h"
+ #import "NSFileManager+GBFileManager.h"
#import "GBLog.h"
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.