forked from tomaz/appledoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutputGenerator.m
188 lines (159 loc) · 6.25 KB
/
OutputGenerator.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//
// OutputGenerator.m
// appledoc
//
// Created by Tomaz Kragelj on 11.6.09.
// Copyright (C) 2009, Tomaz Kragelj. All rights reserved.
//
#import "OutputGenerator.h"
#import "CommandLineParser.h"
#import "Systemator.h"
#import "LoggingProvider.h"
@implementation OutputGenerator
//////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Initialization & disposal
//////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------
- (id) initWithDatabase:(NSMutableDictionary*) data
{
self = [super init];
if (self)
{
cmd = [CommandLineParser sharedInstance];
manager = [NSFileManager defaultManager];
database = [data retain];
dependentGenerators = [[NSMutableArray alloc] init];
}
return self;
}
//----------------------------------------------------------------------------------------
- (void) dealloc
{
cmd = nil;
manager = nil;
[database release], database = nil;
[dependentGenerators release], dependentGenerators = nil;
[super dealloc];
}
//////////////////////////////////////////////////////////////////////////////////////////
#pragma mark OutputInfoProvider protocol implementation
//////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------
- (NSString*) outputObjectFilenameForObject:(NSDictionary*) objectData
{
NSString* path = [objectData objectForKey:kTKDataObjectRelPathKey];
return [self pathByReplacingTemplatePlaceholdersInPath:path];
}
//----------------------------------------------------------------------------------------
- (NSString*) outputIndexFilename
{
return [NSString stringWithFormat:@"index%@", [self outputReferencesExtension]];
}
//----------------------------------------------------------------------------------------
- (NSString*) outputHierarchyFilename
{
return [NSString stringWithFormat:@"hierarchy%@", [self outputReferencesExtension]];
}
//----------------------------------------------------------------------------------------
- (NSString*) outputFilesExtension
{
return @"";
}
//----------------------------------------------------------------------------------------
- (NSString*) outputReferencesExtension
{
return [self outputFilesExtension];
}
//----------------------------------------------------------------------------------------
- (NSString*) outputBasePath
{
return @"";
}
//////////////////////////////////////////////////////////////////////////////////////////
#pragma mark OutputProcessing protocol implementation
//////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------
- (void) outputGenerationStarting
{
}
//----------------------------------------------------------------------------------------
- (void) outputGenerationFinished
{
}
//----------------------------------------------------------------------------------------
- (void) generateOutput
{
if (self.isOutputGenerationEnabled)
{
logNormal(@"Generating %@ output...", [[self outputBasePath] lastPathComponent]);
// Create required output directories.
[self createOutputDirectories];
// Generate the output for this class.
[self outputGenerationStarting];
[self generateSpecificOutput];
[self outputGenerationFinished];
// Process all dependent generators. Note that this recursively generates the
// output for all nested dependencies as well. Note that we only need to send
// generateOutput message, it will take care of creating directories and the rest.
BOOL outputWasGenerated = NO;
for (id<OutputProcessing> dependentGenerator in dependentGenerators)
{
if (dependentGenerator.isOutputGenerationEnabled)
{
[dependentGenerator generateOutput];
outputWasGenerated = YES;
}
}
// If temporary files should be removed after creating and at least one dependent
// generator output was created, we can remove our files.
if (cmd.cleanTempFilesAfterBuild && outputWasGenerated)
{
[self removeOutputDirectories];
}
}
}
//----------------------------------------------------------------------------------------
- (BOOL) isOutputGenerationEnabled
{
// By default we always return yes, so concrete subclasses which should always be
// enabled don't have to handle this. However subclasses which can optionally be
// disabled, should override and return proper value.
return YES;
}
//----------------------------------------------------------------------------------------
- (void) createOutputDirectories
{
NSString* basePath = self.outputBasePath;
[Systemator createDirectory:basePath];
[Systemator createDirectory:[basePath stringByAppendingPathComponent:kTKDirClasses]];
[Systemator createDirectory:[basePath stringByAppendingPathComponent:kTKDirCategories]];
[Systemator createDirectory:[basePath stringByAppendingPathComponent:kTKDirProtocols]];
}
//----------------------------------------------------------------------------------------
- (void) removeOutputDirectories
{
[Systemator removeItemAtPath:self.outputBasePath];
}
//////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Subclass handling
//////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------
- (void) generateSpecificOutput
{
}
//////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Helper methods
//////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------
- (void) registerDependentGenerator:(id<OutputProcessing>) generator
{
NSParameterAssert(generator != nil);
[dependentGenerators addObject:generator];
}
//----------------------------------------------------------------------------------------
- (NSString*) pathByReplacingTemplatePlaceholdersInPath:(NSString*) path
{
return [path stringByReplacingOccurrencesOfString:kTKPlaceholderExtension
withString:[self outputReferencesExtension]];
}
@end