Skip to content

Commit cf7562f

Browse files
author
苼茹夏花
committed
修复infoplist 文件名问题.
增加获取组织名称
1 parent a6eb438 commit cf7562f

3 files changed

Lines changed: 116 additions & 2 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
@property (nonatomic, strong) NSString *projectVersion;
2222

23+
@property (nonatomic,strong) NSDictionary *pbxprojDictionary;
24+
25+
@property (nonatomic,strong) NSString *organizeationName;
26+
27+
2328
+ (instancetype)projectForKeyWindow;
2429

2530
@end

VVDocumenter-Xcode/ProjectHelper/VVProject.m

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

1818
id contextManager = [workspace valueForKey:@"_runContextManager"];
19+
// id activeScheme = [contextManager valueForKey:@"_activeRunContext"];
20+
// NSString *activeSchemeName = [activeScheme valueForKey:@"name"];
21+
// id activeSchemeIdentifier = [activeScheme valueForKey:@"schemeIdentifier"];
22+
1923
for (id scheme in[contextManager valueForKey:@"runContexts"]) {
2024
NSString *schemeName = [scheme valueForKey:@"name"];
2125
if (![schemeName hasPrefix:@"Pods-"]) {
@@ -34,8 +38,18 @@ - (id)initWithName:(NSString *)name
3438
_projectName = name;
3539
_directoryPath = path;
3640

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

4054
_infoDictionary = [NSDictionary dictionaryWithContentsOfFile:infoPath];
4155

@@ -45,4 +59,58 @@ - (id)initWithName:(NSString *)name
4559
return self;
4660
}
4761

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

0 commit comments

Comments
 (0)