Permalink
Browse files

Implemented proper docset packaging handling. Relates to #45.

Instead of relying on hardcoded docset filenames, the can now be supplied through command line switches. Additionally, all docset names can be used as placeholders, so specifying stuff like --docset-feed-url is simpler.
  • Loading branch information...
1 parent a28b2ff commit afef3b23ea9cc5bcc6cb4e0071ae69ff4f84884a @tomaz committed Jan 12, 2011
@@ -41,6 +41,12 @@
/** Company unique identifier, ussualy in the form of reverse domain like _com.company_. */
@property (copy) NSString *companyIdentifier;
+/** Project identifier which is derived by normalizing `projectName`. */
+@property (readonly) NSString *projectIdentifier;
+
+/** Version identifier which is derived by normalizing `projectVersion`. */
+@property (readonly) NSString *versionIdentifier;
+
///---------------------------------------------------------------------------------------
/// @name Documentation set handling
///---------------------------------------------------------------------------------------
@@ -84,6 +90,15 @@
/** Documentation set human readble copyright message. */
@property (copy) NSString *docsetCopyrightMessage;
+/** The name of the documentation set installed bundle. The folder is generated in `docsetInstallPath`. */
+@property (copy) NSString *docsetBundleFilename;
+
+/** The name of the documentation set atom file when generating publishing files. The file is generated in `outputPath`. */
+@property (copy) NSString *docsetAtomFilename;
+
+/** The name of the documentation set compressed package file when generating publishing files. The file is generated in `outputPath`. */
+@property (copy) NSString *docsetPackageFilename;
+
///---------------------------------------------------------------------------------------
/// @name Paths handling
///---------------------------------------------------------------------------------------
@@ -7,6 +7,7 @@
//
#import <objc/runtime.h>
+#import "RegexKitLite.h"
#import "GBDataObjects.h"
#import "GBApplicationSettingsProvider.h"
@@ -18,6 +19,7 @@ - (NSString *)relativePathPrefixFromObject:(GBModelBase *)source toObject:(GBMod
- (NSString *)htmlReferenceForObjectFromIndex:(GBModelBase *)object;
- (NSString *)htmlReferenceForTopLevelObject:(GBModelBase *)object fromTopLevelObject:(GBModelBase *)source;
- (NSString *)htmlReferenceForMember:(GBModelBase *)member prefixedWith:(NSString *)prefix;
+- (NSString *)stringByNormalizingString:(NSString *)string;
@property (readonly) NSDateFormatter *yearDateFormatter;
@property (readonly) NSDateFormatter *yearToDayDateFormatter;
@@ -71,19 +73,23 @@ - (id)init {
self.warnOnInvalidCrossReference = YES;
self.warnOnMissingMethodArgument = YES;
- self.docsetBundleIdentifier = @"$COMPANYID.$PROJECT";
+ self.docsetBundleIdentifier = @"$COMPANYID.$PROJECTID";
self.docsetBundleName = @"$PROJECT Documentation";
self.docsetCertificateIssuer = @"";
self.docsetCertificateSigner = @"";
self.docsetDescription = @"";
self.docsetFallbackURL = @"";
- self.docsetFeedName = @"";
+ self.docsetFeedName = self.docsetBundleName;
self.docsetFeedURL = @"";
self.docsetMinimumXcodeVersion = @"3.0";
self.docsetPlatformFamily = @"";
self.docsetPublisherIdentifier = @"$COMPANYID.documentation";
self.docsetPublisherName = @"$COMPANY";
- self.docsetCopyrightMessage = @"© $YEAR $COMPANY. All rights reserved.";
+ self.docsetCopyrightMessage = @"Copyright © $YEAR $COMPANY. All rights reserved.";
+
+ self.docsetBundleFilename = @"$COMPANYID.$PROJECTID.docset";
+ self.docsetAtomFilename = @"$COMPANYID.$PROJECTID.atom";
+ self.docsetPackageFilename = @"$COMPANYID.$PROJECTID-$VERSIONID.xar";
self.commentComponents = [GBCommentComponentsProvider provider];
self.stringTemplates = [GBApplicationStringsProvider provider];
@@ -107,6 +113,9 @@ - (void)replaceAllOccurencesOfPlaceholderStringsInSettingsValues {
self.docsetPublisherIdentifier = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetPublisherIdentifier];
self.docsetPublisherName = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetPublisherName];
self.docsetCopyrightMessage = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetCopyrightMessage];
+ self.docsetBundleFilename = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetBundleFilename];
+ self.docsetAtomFilename = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetAtomFilename];
+ self.docsetPackageFilename = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetPackageFilename];
}
#pragma mark HTML references handling
@@ -254,14 +263,23 @@ - (BOOL)isTopLevelStoreObject:(id)object {
- (NSString *)stringByReplacingOccurencesOfPlaceholdersInString:(NSString *)string {
string = [string stringByReplacingOccurrencesOfString:@"$COMPANYID" withString:self.companyIdentifier];
+ string = [string stringByReplacingOccurrencesOfString:@"$PROJECTID" withString:self.projectIdentifier];
+ string = [string stringByReplacingOccurrencesOfString:@"$VERSIONID" withString:self.versionIdentifier];
string = [string stringByReplacingOccurrencesOfString:@"$PROJECT" withString:self.projectName];
string = [string stringByReplacingOccurrencesOfString:@"$COMPANY" withString:self.projectCompany];
string = [string stringByReplacingOccurrencesOfString:@"$VERSION" withString:self.projectVersion];
+ string = [string stringByReplacingOccurrencesOfString:@"$DOCSETBUNDLEFILENAME" withString:self.docsetBundleFilename];
+ string = [string stringByReplacingOccurrencesOfString:@"$DOCSETATOMFILENAME" withString:self.docsetAtomFilename];
+ string = [string stringByReplacingOccurrencesOfString:@"$DOCSETPACKAGEFILENAME" withString:self.docsetPackageFilename];
string = [string stringByReplacingOccurrencesOfString:@"$YEAR" withString:[self yearStringFromDate:[NSDate date]]];
string = [string stringByReplacingOccurrencesOfString:@"$UPDATEDATE" withString:[self yearToDayStringFromDate:[NSDate date]]];
return string;
}
+- (NSString *)stringByNormalizingString:(NSString *)string {
+ return [string stringByReplacingOccurrencesOfRegex:@"[ \t]+" withString:@"-"];
+}
+
#pragma mark Overriden methods
- (NSString *)description {
@@ -270,6 +288,14 @@ - (NSString *)description {
#pragma mark Properties
+- (NSString *)projectIdentifier {
+ return [self stringByNormalizingString:self.projectName];
+}
+
+- (NSString *)versionIdentifier {
+ return [self stringByNormalizingString:self.projectVersion];
+}
+
@synthesize projectName;
@synthesize projectCompany;
@synthesize projectVersion;
@@ -294,6 +320,9 @@ - (NSString *)description {
@synthesize docsetPublisherIdentifier;
@synthesize docsetPublisherName;
@synthesize docsetCopyrightMessage;
+@synthesize docsetBundleFilename;
+@synthesize docsetAtomFilename;
+@synthesize docsetPackageFilename;
@synthesize repeatFirstParagraphForMemberDescription;
@synthesize keepUndocumentedObjects;
@@ -257,13 +257,12 @@ - (BOOL)publishDocSet:(NSError **)error {
// Get the path to the installed documentation set and extract the name. Then replace the name's extension with .xar.
NSString *installedDocSetPath = self.docsetInstallationPath;
- NSString *docsetBaseName = [[installedDocSetPath lastPathComponent] stringByDeletingPathExtension];
- NSString *docsetName = [docsetBaseName stringByAppendingPathExtension:@"xar"];
- NSString *atomName = [docsetBaseName stringByAppendingPathExtension:@"atom"];
+ NSString *packageName = self.settings.docsetPackageFilename;
+ NSString *atomName = self.settings.docsetAtomFilename;
// Prepare command line arguments for packaging.
NSString *outputDir = [self.settings.outputPath stringByAppendingPathComponent:@"publish"];
- NSString *outputDocSetPath = [outputDir stringByAppendingPathComponent:docsetName];
+ NSString *outputDocSetPath = [outputDir stringByAppendingPathComponent:packageName];
NSString *outputAtomPath = [outputDir stringByAppendingPathComponent:atomName];
NSString *signer = self.settings.docsetCertificateSigner;
NSString *url = self.settings.docsetFeedURL;
@@ -448,8 +447,7 @@ - (NSString *)outputSubpath {
#pragma mark Properties
- (NSString *)docsetInstallationPath {
- NSString *bundleSubDir = [self.settings.docsetBundleIdentifier stringByAppendingPathExtension:@"docset"];
- return [self.settings.docsetInstallPath stringByAppendingPathComponent:bundleSubDir];
+ return [self.settings.docsetInstallPath stringByAppendingPathComponent:self.settings.docsetBundleFilename];
}
- (NSMutableSet *)temporaryFiles {
@@ -23,11 +23,11 @@ @implementation GBApplicationSettingsProviderTesting
- (void)testPlaceholderReplacements_shouldReplacePlaceholderStringsInAllSupportedValues {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
- settings.projectName = @"<PN>";
- settings.projectCompany = @"<PC>";
- settings.projectVersion = @"<PV>";
- settings.companyIdentifier = @"<CI>";
- NSString *template = @"$PROJECT/$COMPANY/$VERSION/$COMPANYID/$YEAR/$UPDATEDATE";
+ settings.projectName = @"<P N>";
+ settings.projectCompany = @"<P C>";
+ settings.projectVersion = @"<P V>";
+ settings.companyIdentifier = @"<C I>";
+ NSString *template = @"$PROJECT/$COMPANY/$VERSION/$PROJECTID/$COMPANYID/$VERSIONID/$YEAR/$UPDATEDATE";
settings.docsetBundleIdentifier = template;
settings.docsetBundleName = template;
settings.docsetCertificateIssuer = template;
@@ -41,11 +41,14 @@ - (void)testPlaceholderReplacements_shouldReplacePlaceholderStringsInAllSupporte
settings.docsetPublisherIdentifier = template;
settings.docsetPublisherName = template;
settings.docsetCopyrightMessage = template;
+ settings.docsetBundleFilename = template;
+ settings.docsetAtomFilename = template;
+ settings.docsetPackageFilename = template;
// setup expected values; this might break sometimes as it's based on time...
NSDate *date = [NSDate date];
NSString *year = [[self yearFormatterFromSettings:settings] stringFromDate:date];
NSString *day = [[self yearToDayFormatterFromSettings:settings] stringFromDate:date];
- NSString *expected = [NSString stringWithFormat:@"<PN>/<PC>/<PV>/<CI>/%@/%@", year, day];
+ NSString *expected = [NSString stringWithFormat:@"<P N>/<P C>/<P V>/<P-N>/<C I>/<P-V>/%@/%@", year, day];
// execute
[settings replaceAllOccurencesOfPlaceholderStringsInSettingsValues];
// verify
@@ -62,6 +65,68 @@ - (void)testPlaceholderReplacements_shouldReplacePlaceholderStringsInAllSupporte
assertThat(settings.docsetPublisherIdentifier, is(expected));
assertThat(settings.docsetPublisherName, is(expected));
assertThat(settings.docsetCopyrightMessage, is(expected));
+ assertThat(settings.docsetBundleFilename, is(expected));
+ assertThat(settings.docsetAtomFilename, is(expected));
+ assertThat(settings.docsetPackageFilename, is(expected));
+}
+
+- (void)testPlaceholderReplacements_shouldReplaceDocSetFilenames {
+ // setup
+ GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
+ settings.projectName = @"<PN>";
+ settings.projectCompany = @"<PC>";
+ settings.projectVersion = @"<PV>";
+ settings.companyIdentifier = @"<CI>";
+ settings.docsetBundleFilename = @"<DSB>";
+ settings.docsetAtomFilename = @"<DSA>";
+ settings.docsetPackageFilename = @"<DSP>";
+ NSString *template = @"$DOCSETBUNDLEFILENAME/$DOCSETATOMFILENAME/$DOCSETPACKAGEFILENAME";
+ settings.docsetBundleIdentifier = template;
+ settings.docsetBundleName = template;
+ settings.docsetCertificateIssuer = template;
+ settings.docsetCertificateSigner = template;
+ settings.docsetDescription = template;
+ settings.docsetFallbackURL = template;
+ settings.docsetFeedName = template;
+ settings.docsetFeedURL = template;
+ settings.docsetMinimumXcodeVersion = template;
+ settings.docsetPlatformFamily = template;
+ settings.docsetPublisherIdentifier = template;
+ settings.docsetPublisherName = template;
+ settings.docsetCopyrightMessage = template;
+ NSString *expected = @"<DSB>/<DSA>/<DSP>";
+ // execute
+ [settings replaceAllOccurencesOfPlaceholderStringsInSettingsValues];
+ // verify
+ assertThat(settings.docsetBundleIdentifier, is(expected));
+ assertThat(settings.docsetBundleName, is(expected));
+ assertThat(settings.docsetCertificateIssuer, is(expected));
+ assertThat(settings.docsetCertificateSigner, is(expected));
+ assertThat(settings.docsetDescription, is(expected));
+ assertThat(settings.docsetFallbackURL, is(expected));
+ assertThat(settings.docsetFeedName, is(expected));
+ assertThat(settings.docsetFeedURL, is(expected));
+ assertThat(settings.docsetMinimumXcodeVersion, is(expected));
+ assertThat(settings.docsetPlatformFamily, is(expected));
+ assertThat(settings.docsetPublisherIdentifier, is(expected));
+ assertThat(settings.docsetPublisherName, is(expected));
+ assertThat(settings.docsetCopyrightMessage, is(expected));
+}
+
+- (void)testProjectIdentifier_shouldNormalizeProjectName {
+ // setup
+ GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
+ settings.projectName = @"My Great \t Project";
+ // execute & verify
+ assertThat(settings.projectIdentifier, is(@"My-Great-Project"));
+}
+
+- (void)testVersionIdentifier_shouldNormalizeProjectVersion {
+ // setup
+ GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
+ settings.projectVersion = @"1.0 beta3 \t something";
+ // execute & verify
+ assertThat(settings.versionIdentifier, is(@"1.0-beta3-something"));
}
#pragma mark HTML href names handling

0 comments on commit afef3b2

Please sign in to comment.