FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ObjectGraph-Xcode/ObjectGraph/ObjectGraph.m at master · vampirewalk/ObjectGraph-Xcode · GitHub
vampirewalk
/
ObjectGraph-Xcode
Public
Notifications
You must be signed in to change notification settings
Fork
52
Star
657
Code
Issues
5
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
ObjectGraph-Xcode
/
ObjectGraph
/
ObjectGraph.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
279 lines (236 loc) · 9.9 KB
Breadcrumbs
ObjectGraph-Xcode
/
ObjectGraph
/
ObjectGraph.m
Copy path
File metadata and controls
279 lines (236 loc) · 9.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//
//
ObjectGraph.m
//
ObjectGraph
//
//
Created by vampirewalk on 2015/1/13.
//
Copyright (c) 2015年 mocacube. All rights reserved.
//
//
Permission is hereby granted, free of charge, to any person obtaining a copy
//
of this software and associated documentation files (the "Software"), to
//
deal in the Software without restriction, including without limitation the
//
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
//
sell copies of the Software, and to permit persons to whom the Software is
//
furnished to do so, subject to the following conditions:
//
//
The above copyright notice and this permission notice shall be included in
//
all copies or substantial portions of the Software.
//
//
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
//
IN THE SOFTWARE.
#
import
"
ObjectGraph.h
"
#
import
"
VWKShellHandler.h
"
#
import
"
VWKWorkspaceManager.h
"
#
import
"
VWKProject.h
"
static
ObjectGraph *sharedPlugin;
static
NSString
*
BIN_PATH
=
@"
/bin
"
;
static
NSString
*
USER_BIN_PATH
=
@"
/usr/bin
"
;
static
NSString
*
USER_LOCAL_BIN_PATH
=
@"
/usr/local/bin
"
;
static
NSString
*
PYTHON_EXECUTABLE
=
@"
python
"
;
static
NSString
*
GRAPHVIZ_EXECUTABLE
=
@"
dot
"
;
static
NSString
*
MOVE_EXECUTABLE
=
@"
mv
"
;
static
NSString
*
OPEN_EXECUTABLE
=
@"
open
"
;
typedef
void
(^TaskBlock)(
NSTask
*t,
NSString
*standardOutputString,
NSString
*standardErrorString);
@interface
ObjectGraph
()
@property
(
nonatomic
,
strong
,
readwrite
)
NSBundle
*bundle;
@property
(
nonatomic
,
strong
)
NSMenuItem
*drawObjectGraphItem;
@property
(
nonatomic
,
strong
)
NSMenuItem
*pathItem;
@property
(
nonatomic
,
copy
)
NSString
*sourceCodePath;
@property
(
nonatomic
,
copy
) TaskBlock getGraphvizExecutablePathBlock;
@property
(
nonatomic
,
copy
) TaskBlock convertToPDFBlock;
@property
(
nonatomic
,
copy
) TaskBlock movePDFFileBlock;
@property
(
nonatomic
,
copy
) TaskBlock moveDOTFileBlock;
@property
(
nonatomic
,
copy
) TaskBlock openBlock;
@end
@implementation
ObjectGraph
+ (
void
)
pluginDidLoad
:
(
NSBundle
*)
plugin
{
static
dispatch_once_t
onceToken;
NSString
*currentApplicationName = [[
NSBundle
mainBundle
]
infoDictionary
][
@"
CFBundleName
"
];
if
([currentApplicationName
isEqual:
@"
Xcode
"
]) {
dispatch_once
(&onceToken, ^{
sharedPlugin = [[
self
alloc
]
initWithBundle:
plugin];
});
}
}
+ (
instancetype
)
sharedPlugin
{
return
sharedPlugin;
}
+ (
NSBundle
*)
pluginBundle
{
return
[
NSBundle
bundleForClass:
self
];
}
- (
id
)
initWithBundle
:
(
NSBundle
*)
plugin
{
if
(self = [
super
init
]) {
//
reference to plugin's bundle, for resource access
self.
bundle
= plugin;
[
self
setDefaultSourceCodePathPath
];
[
self
setupGetGraphvizExecutablePathBlock
];
[
self
setupConvertToPDFBlock
];
[
self
setupMovePDFFileBlock
];
[
self
setupMoveDOTFileBlock
];
[
self
setupOpenBlock
];
//
Create menu items, initialize UI, etc.
[[
NSOperationQueue
mainQueue
]
addOperationWithBlock:
^{
[
self
addMenuItems
];
}];
}
return
self;
}
- (
void
)
setDefaultSourceCodePathPath
{
VWKProject *project = [VWKProject
projectForKeyWindow
];
self.
sourceCodePath
= project.
directoryPath
;
}
#
pragma mark
- Menu
- (
void
)
addMenuItems
{
NSMenuItem
*topMenuItem = [[
NSApp
mainMenu
]
itemWithTitle:
@"
Product
"
];
if
(topMenuItem) {
NSMenuItem
*objectGraphMenu = [[
NSMenuItem
alloc
]
initWithTitle:
@"
ObjectGraph
"
action:
nil
keyEquivalent:
@"
"
];
objectGraphMenu.
submenu
= [[
NSMenu
alloc
]
initWithTitle:
@"
ObjectGraph
"
];
self.
drawObjectGraphItem
= [[
NSMenuItem
alloc
]
initWithTitle:
@"
Draw Object Graph
"
action:
@selector
(
drawObjectGraph
)
keyEquivalent:
@"
"
];
[
self
.drawObjectGraphItem
setTarget:
self
];
self.
pathItem
= [[
NSMenuItem
alloc
]
initWithTitle:
@"
Set Source Code PATH...
"
action:
@selector
(
selectPath
)
keyEquivalent:
@"
"
];
[
self
.pathItem
setTarget:
self
];
[[objectGraphMenu
submenu
]
addItem:
self
.drawObjectGraphItem];
[[objectGraphMenu
submenu
]
addItem:
self
.pathItem];
[[topMenuItem
submenu
]
insertItem:
objectGraphMenu
atIndex:
[topMenuItem.submenu
indexOfItemWithTitle:
@"
Build For
"
]];
}
}
#
pragma mark
- Menu Actions
//
Sample Action, for menu item:
- (
void
)
drawObjectGraph
{
if
([
self
isValidSourceCodePath
])
{
self.
sourceCodePath
= self.
projectPath
;
}
NSString
*dotFileScriptPath = [[ObjectGraph
pluginBundle
]
pathForResource:
@"
objc_dep
"
ofType:
@"
py
"
];
if
(dotFileScriptPath.
length
) {
[VWKShellHandler
runShellCommand:
[
USER_BIN_PATH
stringByAppendingPathComponent:
PYTHON_EXECUTABLE
]
withArgs:
@[dotFileScriptPath, _sourceCodePath,
@"
-o
"
,
self
.dotFileName]
directory:
_sourceCodePath
completion:
self
.getGraphvizExecutablePathBlock];
}
}
- (
void
)
selectPath
{
NSOpenPanel
*oPanel = [
NSOpenPanel
openPanel
];
[oPanel
setCanChooseDirectories:
YES
];
[oPanel
setCanChooseFiles:
NO
];
if
([oPanel
runModal
] ==
NSModalResponseOK
) {
NSString
*projPath = [[[oPanel
URLs
]
objectAtIndex:
0
]
path
];
self.
sourceCodePath
= projPath;
}
}
#
pragma mark
- Private Method
- (
NSString
*)
dotFileName
{
VWKProject *project = [VWKProject
projectForKeyWindow
];
NSString
*dotFileName = [project.projectName
stringByAppendingPathExtension:
@"
dot
"
];
return
dotFileName;
}
- (
NSString
*)
pdfFileName
{
VWKProject *project = [VWKProject
projectForKeyWindow
];
NSString
*pdfFileName = [project.projectName
stringByAppendingPathExtension:
@"
pdf
"
];
return
pdfFileName;
}
- (
NSString
*)
projectPath
{
VWKProject *project = [VWKProject
projectForKeyWindow
];
NSString
*projectPath = project.
directoryPath
;
return
projectPath;
}
- (
BOOL
)
isValidSourceCodePath
{
NSFileManager
*manager = [
NSFileManager
defaultManager
];
return
_sourceCodePath ==
nil
|| ![manager
fileExistsAtPath:
_sourceCodePath];
}
- (
void
)
setupGetGraphvizExecutablePathBlock
{
NSDictionary
*environmentDict = [[
NSProcessInfo
processInfo
]
environment
];
NSString
*shellString = [environmentDict
objectForKey:
@"
SHELL
"
];
NSArray
*args = @[
@"
-l
"
,
@"
-c
"
,
@"
which dot
"
,
//
Assuming git is the launch path you want to run
];
__weak
__typeof
(&*self)weakSelf = self;
self.
getGraphvizExecutablePathBlock
= ^(
NSTask
*t,
NSString
*standardOutputString,
NSString
*standardErrorString)
{
__strong
__typeof
(&*weakSelf)strongSelf = weakSelf;
[VWKShellHandler
runShellCommand:
shellString
withArgs:
args
directory:
strongSelf.sourceCodePath
completion:
strongSelf.convertToPDFBlock];
};
}
- (
void
)
setupConvertToPDFBlock
{
__weak
__typeof
(&*self)weakSelf = self;
self.
convertToPDFBlock
= ^(
NSTask
*t,
NSString
*standardOutputString,
NSString
*standardErrorString){
__strong
__typeof
(&*weakSelf)strongSelf = weakSelf;
if
(standardOutputString.
length
>
0
) {
NSString
*
GRAPHVIZ_EXECUTABLE_PATH
= [standardOutputString
stringByTrimmingCharactersInSet:
[
NSCharacterSet
whitespaceAndNewlineCharacterSet
]];
[VWKShellHandler
runShellCommand:
GRAPHVIZ_EXECUTABLE_PATH
withArgs:
@[
@"
-Tpdf
"
, strongSelf.dotFileName,
@"
-o
"
, strongSelf.pdfFileName]
directory:
strongSelf.sourceCodePath
completion:
strongSelf.movePDFFileBlock];
}
};
}
- (
void
)
setupMovePDFFileBlock
{
__weak
__typeof
(&*self)weakSelf = self;
self.
movePDFFileBlock
= ^(
NSTask
*t,
NSString
*standardOutputString,
NSString
*standardErrorString){
__strong
__typeof
(&*weakSelf)strongSelf = weakSelf;
[VWKShellHandler
runShellCommand:
[
BIN_PATH
stringByAppendingPathComponent:
MOVE_EXECUTABLE
]
withArgs:
@[strongSelf.pdfFileName, strongSelf.projectPath]
directory:
strongSelf.sourceCodePath
completion:
strongSelf.moveDOTFileBlock];
};
}
- (
void
)
setupMoveDOTFileBlock
{
__weak
__typeof
(&*self)weakSelf = self;
self.
moveDOTFileBlock
= ^(
NSTask
*t,
NSString
*standardOutputString,
NSString
*standardErrorString){
__strong
__typeof
(&*weakSelf)strongSelf = weakSelf;
[VWKShellHandler
runShellCommand:
[
BIN_PATH
stringByAppendingPathComponent:
MOVE_EXECUTABLE
]
withArgs:
@[strongSelf.dotFileName, strongSelf.projectPath]
directory:
strongSelf.sourceCodePath
completion:
strongSelf.openBlock];
};
}
- (
void
)
setupOpenBlock
{
__weak
__typeof
(&*self)weakSelf = self;
self.
openBlock
= ^(
NSTask
*t,
NSString
*standardOutputString,
NSString
*standardErrorString){
__strong
__typeof
(&*weakSelf)strongSelf = weakSelf;
[VWKShellHandler
runShellCommand:
[
USER_BIN_PATH
stringByAppendingPathComponent:
OPEN_EXECUTABLE
]
withArgs:
@[strongSelf.pdfFileName]
directory:
strongSelf.projectPath
completion:
nil
];
};
}
- (
void
)
dealloc
{
[[
NSNotificationCenter
defaultCenter
]
removeObserver:
self
];
}
@end
Back
|
FazBrowse Home
|
New Git URL