Skip to content

Commit ab0e7cb

Browse files
committed
Merge pull request onevcat#144 from wentaozone/master
增强@SInCE@author
2 parents 5295e8c + 33adfdb commit ab0e7cb

4 files changed

Lines changed: 130 additions & 9 deletions

File tree

VVDocumenter-Xcode.xcodeproj/xcshareddata/xcschemes/VVDocumenter-Xcode.xcscheme

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@
2020
ReferencedContainer = "container:VVDocumenter-Xcode.xcodeproj">
2121
</BuildableReference>
2222
</BuildActionEntry>
23+
<BuildActionEntry
24+
buildForTesting = "YES"
25+
buildForRunning = "NO"
26+
buildForProfiling = "NO"
27+
buildForArchiving = "NO"
28+
buildForAnalyzing = "NO">
29+
<BuildableReference
30+
BuildableIdentifier = "primary"
31+
BlueprintIdentifier = "D1C462D917999C2000EB7B23"
32+
BuildableName = "VVDocumenterTests.xctest"
33+
BlueprintName = "VVDocumenterTests"
34+
ReferencedContainer = "container:VVDocumenter-Xcode.xcodeproj">
35+
</BuildableReference>
36+
</BuildActionEntry>
2337
</BuildActionEntries>
2438
</BuildAction>
2539
<TestAction
@@ -39,6 +53,15 @@
3953
</BuildableReference>
4054
</TestableReference>
4155
</Testables>
56+
<MacroExpansion>
57+
<BuildableReference
58+
BuildableIdentifier = "primary"
59+
BlueprintIdentifier = "D14380F2179551B900C829CE"
60+
BuildableName = "VVDocumenter-Xcode.xcplugin"
61+
BlueprintName = "VVDocumenter-Xcode"
62+
ReferencedContainer = "container:VVDocumenter-Xcode.xcodeproj">
63+
</BuildableReference>
64+
</MacroExpansion>
4265
</TestAction>
4366
<LaunchAction
4467
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
@@ -49,6 +72,15 @@
4972
ignoresPersistentStateOnLaunch = "NO"
5073
debugDocumentVersioning = "YES"
5174
allowLocationSimulation = "YES">
75+
<MacroExpansion>
76+
<BuildableReference
77+
BuildableIdentifier = "primary"
78+
BlueprintIdentifier = "D14380F2179551B900C829CE"
79+
BuildableName = "VVDocumenter-Xcode.xcplugin"
80+
BlueprintName = "VVDocumenter-Xcode"
81+
ReferencedContainer = "container:VVDocumenter-Xcode.xcodeproj">
82+
</BuildableReference>
83+
</MacroExpansion>
5284
<AdditionalOptions>
5385
</AdditionalOptions>
5486
</LaunchAction>
@@ -58,6 +90,15 @@
5890
useCustomWorkingDirectory = "NO"
5991
buildConfiguration = "Release"
6092
debugDocumentVersioning = "YES">
93+
<MacroExpansion>
94+
<BuildableReference
95+
BuildableIdentifier = "primary"
96+
BlueprintIdentifier = "D14380F2179551B900C829CE"
97+
BuildableName = "VVDocumenter-Xcode.xcplugin"
98+
BlueprintName = "VVDocumenter-Xcode"
99+
ReferencedContainer = "container:VVDocumenter-Xcode.xcodeproj">
100+
</BuildableReference>
101+
</MacroExpansion>
61102
</ProfileAction>
62103
<AnalyzeAction
63104
buildConfiguration = "Debug">

VVDocumenter-Xcode/ProjectHelper/VVProject.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@
1010

1111
@interface VVProject : NSObject
1212

13-
@property (nonatomic, strong) NSString *directoryPath;
13+
@property (nonatomic, copy) NSString *directoryPath;
1414

15-
@property (nonatomic, readonly) NSString *workspacePath;
15+
@property (nonatomic,copy,readonly) NSString *workspacePath;
1616

17-
@property (nonatomic, strong) NSString *projectName;
17+
@property (nonatomic, copy) NSString *projectName;
1818

19-
@property (nonatomic, strong) NSDictionary *infoDictionary;
19+
@property (nonatomic, copy) NSDictionary *infoDictionary;
20+
21+
@property (nonatomic, copy) NSString *projectVersion;
22+
23+
@property (nonatomic,copy) NSDictionary *pbxprojDictionary;
24+
25+
@property (nonatomic,copy) NSString *organizeationName;
2026

21-
@property (nonatomic, strong) NSString *projectVersion;
2227

2328
+ (instancetype)projectForKeyWindow;
2429

VVDocumenter-Xcode/ProjectHelper/VVProject.m

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ + (instancetype)projectForKeyWindow
1616
id workspace = [VVWorkspaceManager workspaceForKeyWindow];
1717

1818
id contextManager = [workspace valueForKey:@"_runContextManager"];
19+
1920
for (id scheme in[contextManager valueForKey:@"runContexts"]) {
2021
NSString *schemeName = [scheme valueForKey:@"name"];
2122
if (![schemeName hasPrefix:@"Pods-"]) {
@@ -34,8 +35,17 @@ - (id)initWithName:(NSString *)name
3435
_projectName = name;
3536
_directoryPath = path;
3637

37-
//FIXME: 此处应从工程配置文件中,获取info.plist文件名称. 目前使用默认名称查找
38-
NSString *infoPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%@-Info.plist", _projectName, _projectName]];
38+
39+
NSString *pbxprojPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.xcodeproj/project.pbxproj",name]];
40+
_pbxprojDictionary = [NSDictionary dictionaryWithContentsOfFile:pbxprojPath];
41+
42+
43+
44+
_organizeationName = [self getOrganizeationName];
45+
NSString *infoplistName = [self infoplistNameWithAtScheme:name];
46+
47+
NSString *infoPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", infoplistName]];
48+
3949

4050
_infoDictionary = [NSDictionary dictionaryWithContentsOfFile:infoPath];
4151

@@ -45,4 +55,58 @@ - (id)initWithName:(NSString *)name
4555
return self;
4656
}
4757

58+
-(NSString *)getOrganizeationName{
59+
NSDictionary *objects = [_pbxprojDictionary objectForKey:@"objects"];
60+
NSString *rootObjectId = [_pbxprojDictionary objectForKey:@"rootObject"];
61+
62+
NSDictionary *pbxProjectDic = [objects objectForKey:rootObjectId];
63+
NSDictionary *attributes = [pbxProjectDic objectForKey:@"attributes"];
64+
NSString *organizeationName = [attributes objectForKey:@"ORGANIZATIONNAME"];
65+
return organizeationName;
66+
}
67+
68+
-(NSString *)infoplistNameWithAtScheme:(NSString *)currentSchemeName{
69+
NSDictionary *objects = [_pbxprojDictionary objectForKey:@"objects"];
70+
NSString *rootObjectId = [_pbxprojDictionary objectForKey:@"rootObject"];
71+
72+
NSDictionary *pbxProjectDic = [objects objectForKey:rootObjectId];
73+
NSArray *targetIds = [pbxProjectDic objectForKey:@"targets"];
74+
NSString *currentTargetId;
75+
for (NSString *targetId in targetIds) {
76+
NSDictionary *targetDic = [objects objectForKey:targetId];
77+
NSString *targetName = [targetDic objectForKey:@"name"];
78+
if ([targetName isEqualToString:currentSchemeName]) {
79+
currentTargetId = targetId;
80+
break;
81+
}
82+
}
83+
if (!currentTargetId) {
84+
currentTargetId = [targetIds firstObject];
85+
}
86+
87+
NSDictionary *targetDic = [objects objectForKey:currentTargetId];
88+
NSString *buildConfigurationListId = [targetDic objectForKey:@"buildConfigurationList"];
89+
90+
NSDictionary *buildConfigurationListDic = [objects objectForKey:buildConfigurationListId];
91+
NSArray *buildConfigurationIds = [buildConfigurationListDic objectForKey:@"buildConfigurations"];
92+
93+
NSString *debugBuildConfigurationId;
94+
for (NSString *buildConfigurationId in buildConfigurationIds) {
95+
NSDictionary *buildConfigurationDic = [objects objectForKey:buildConfigurationId];
96+
NSString *name = [buildConfigurationDic objectForKey:@"name"];
97+
if ([name isEqualToString:@"Debug"]) {
98+
debugBuildConfigurationId = buildConfigurationId;
99+
break;
100+
}
101+
}
102+
if (!debugBuildConfigurationId) {
103+
debugBuildConfigurationId = [buildConfigurationIds firstObject];
104+
}
105+
106+
NSDictionary *buildConfigurationDic = [objects objectForKey:debugBuildConfigurationId];
107+
NSDictionary *buildSettings = [buildConfigurationDic objectForKey:@"buildSettings"];
108+
NSString *infoplistName = [buildSettings objectForKey:@"INFOPLIST_FILE"];
109+
return infoplistName;
110+
}
111+
48112
@end

VVDocumenter-Xcode/Setting/VVDocumenterSetting.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "VVDocumenterSetting.h"
1010
#import <Carbon/Carbon.h>
11+
#import "VVProject.h"
1112

1213
NSString *const VVDDefaultTriggerString = @"///";
1314
NSString *const VVDDefaultAuthorString = @"";
@@ -205,8 +206,18 @@ -(void) setUseAuthorInformation:(BOOL)useAuthorInformation
205206

206207
-(NSString *)authorInformation {
207208
NSString *authorInformation = [[NSUserDefaults standardUserDefaults] objectForKey:kVVDAuthorInfomation];
208-
if (authorInformation == nil ) {
209-
authorInformation = VVDDefaultAuthorString;
209+
if (authorInformation.length <= 0 ) {
210+
NSString *name = [[VVProject projectForKeyWindow] organizeationName];
211+
if (name.length <= 0) {
212+
NSDictionary *environment = [[NSProcessInfo processInfo] environment];
213+
name = [environment objectForKey:@"LOGNAME"];
214+
}
215+
216+
if (name.length > 0) {
217+
authorInformation = name;
218+
}else{
219+
authorInformation = VVDDefaultAuthorString;
220+
}
210221
}
211222
return authorInformation;
212223
}

0 commit comments

Comments
 (0)