gitリポジトリのurlを貼り付けるだけでアプリケーションのビルドを実行するアプリ。 macOS用
Revisión | 401881ee109078d94650a8f7cbe5d53b66d8f1aa (tree) |
---|---|
Tiempo | 2017-08-16 22:06:59 |
Autor | masakih <masakih@user...> |
Commiter | masakih |
コマンドのログを残すようにした
@@ -17,6 +17,7 @@ | ||
17 | 17 | F41A45081F3D98180066F83D /* ProjectBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41A45071F3D98180066F83D /* ProjectBuilder.swift */; }; |
18 | 18 | F41A45141F3E9DFA0066F83D /* BuildInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41A45131F3E9DFA0066F83D /* BuildInfo.swift */; }; |
19 | 19 | F41A45161F3EC0950066F83D /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41A45151F3EC0950066F83D /* WindowController.swift */; }; |
20 | + F41A45181F401D4B0066F83D /* LogStocker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41A45171F401D4B0066F83D /* LogStocker.swift */; }; | |
20 | 21 | /* End PBXBuildFile section */ |
21 | 22 | |
22 | 23 | /* Begin PBXFileReference section */ |
@@ -32,6 +33,7 @@ | ||
32 | 33 | F41A45071F3D98180066F83D /* ProjectBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProjectBuilder.swift; sourceTree = "<group>"; }; |
33 | 34 | F41A45131F3E9DFA0066F83D /* BuildInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BuildInfo.swift; sourceTree = "<group>"; }; |
34 | 35 | F41A45151F3EC0950066F83D /* WindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = "<group>"; }; |
36 | + F41A45171F401D4B0066F83D /* LogStocker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogStocker.swift; sourceTree = "<group>"; }; | |
35 | 37 | /* End PBXFileReference section */ |
36 | 38 | |
37 | 39 | /* Begin PBXFrameworksBuildPhase section */ |
@@ -71,6 +73,7 @@ | ||
71 | 73 | F41A45031F3D782A0066F83D /* Git.swift */, |
72 | 74 | F41A45051F3D83AE0066F83D /* ProjectFinder.swift */, |
73 | 75 | F41A45071F3D98180066F83D /* ProjectBuilder.swift */, |
76 | + F41A45171F401D4B0066F83D /* LogStocker.swift */, | |
74 | 77 | F41A45131F3E9DFA0066F83D /* BuildInfo.swift */, |
75 | 78 | F41A44F21F3D6B1B0066F83D /* Assets.xcassets */, |
76 | 79 | F41A44F41F3D6B1B0066F83D /* Main.storyboard */, |
@@ -150,6 +153,7 @@ | ||
150 | 153 | isa = PBXSourcesBuildPhase; |
151 | 154 | buildActionMask = 2147483647; |
152 | 155 | files = ( |
156 | + F41A45181F401D4B0066F83D /* LogStocker.swift in Sources */, | |
153 | 157 | F41A45021F3D77020066F83D /* ApplicationDirecrories.swift in Sources */, |
154 | 158 | F41A45081F3D98180066F83D /* ProjectBuilder.swift in Sources */, |
155 | 159 | F41A45041F3D782A0066F83D /* Git.swift in Sources */, |
@@ -70,6 +70,11 @@ final class Git { | ||
70 | 70 | |
71 | 71 | private func excuteGit(workingURL: URL, args: [String]) throws { |
72 | 72 | |
73 | + guard !args.isEmpty else { | |
74 | + | |
75 | + throw GitError.other("Iligal arguments") | |
76 | + } | |
77 | + | |
73 | 78 | let xcodeURL = NSApplication.appDelegate.xcodeURL |
74 | 79 | guard let gitURL = xcodeURL?.appendingPathComponent("/Contents/Developer/usr/bin/git") else { |
75 | 80 |
@@ -91,6 +96,12 @@ final class Git { | ||
91 | 96 | let pipe = Pipe() |
92 | 97 | git.standardError = pipe |
93 | 98 | |
99 | + let logPipe = Pipe() | |
100 | + git.standardOutput = logPipe | |
101 | + git.standardError = logPipe | |
102 | + let log = LogStocker("git-" + args[0] + ".log") | |
103 | + log?.read(logPipe.fileHandleForReading) | |
104 | + | |
94 | 105 | git.launch() |
95 | 106 | git.waitUntilExit() |
96 | 107 |
@@ -0,0 +1,66 @@ | ||
1 | +// | |
2 | +// LogStocker.swift | |
3 | +// AppBuilderWithGit | |
4 | +// | |
5 | +// Created by Hori,Masaki on 2017/08/13. | |
6 | +// Copyright © 2017年 Hori,Masaki. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +import Foundation | |
10 | + | |
11 | +private func fileURL(for name: String) -> URL? { | |
12 | + | |
13 | + let base = ApplicationDirecrories.support.appendingPathComponent("Logs") | |
14 | + guard checkDirectory(base) else { | |
15 | + | |
16 | + return base.appendingPathComponent(name) | |
17 | + } | |
18 | + | |
19 | + return base.appendingPathComponent(name) | |
20 | +} | |
21 | + | |
22 | +private func nameWithDate(_ name: String) -> String { | |
23 | + | |
24 | + let formatter = DateFormatter() | |
25 | + formatter.dateFormat = "yyyy-MM-dd-HH-mm-ss-A" | |
26 | + | |
27 | + return formatter.string(from: Date()) + "-" + name | |
28 | + | |
29 | +} | |
30 | + | |
31 | +final class LogStocker { | |
32 | + | |
33 | + private let output: FileHandle | |
34 | + | |
35 | + init?(_ name: String) { | |
36 | + | |
37 | + do { | |
38 | + | |
39 | + let datename = nameWithDate(name) | |
40 | + guard let url = fileURL(for: datename) else { return nil } | |
41 | + | |
42 | + try Data().write(to: url) | |
43 | + | |
44 | + output = try FileHandle(forWritingTo: url) | |
45 | + | |
46 | + } catch { | |
47 | + | |
48 | + print("can not open file for log writing.\n\(error)") | |
49 | + | |
50 | + return nil | |
51 | + } | |
52 | + | |
53 | + } | |
54 | + | |
55 | + deinit { output.closeFile() } | |
56 | + | |
57 | + func read(_ fileHandle: FileHandle) { | |
58 | + | |
59 | + DispatchQueue.global().async { | |
60 | + | |
61 | + self.output.write(fileHandle.readDataToEndOfFile()) | |
62 | + } | |
63 | + | |
64 | + } | |
65 | + | |
66 | +} |
@@ -56,34 +56,9 @@ final class ProjectBuilder { | ||
56 | 56 | |
57 | 57 | let pipe = Pipe() |
58 | 58 | xcodebuild.standardOutput = pipe |
59 | - | |
60 | - weak var token: NSObjectProtocol? | |
61 | - token = NotificationCenter.default | |
62 | - .addObserver(forName: FileHandle.readCompletionNotification, | |
63 | - object: pipe.fileHandleForReading, | |
64 | - queue: nil) { [weak xcodebuild] notifiction in | |
65 | - | |
66 | - if let data = notifiction.userInfo?[NSFileHandleNotificationDataItem] as? Data, | |
67 | - let string = String(data: data, encoding: .utf8) { | |
68 | - | |
69 | - print(string) | |
70 | - | |
71 | - } | |
72 | - | |
73 | - if let task = xcodebuild, | |
74 | - task.isRunning, | |
75 | - let handle = notifiction.object as? FileHandle { | |
76 | - | |
77 | - handle.readInBackgroundAndNotify() | |
78 | - | |
79 | - } else { | |
80 | - | |
81 | - token.map(NotificationCenter.default.removeObserver) | |
82 | - } | |
83 | - | |
84 | - } | |
85 | - | |
86 | - pipe.fileHandleForReading.readInBackgroundAndNotify() | |
59 | + xcodebuild.standardError = pipe | |
60 | + let log = LogStocker("xcodebuild.log") | |
61 | + log?.read(pipe.fileHandleForReading) | |
87 | 62 | |
88 | 63 | xcodebuild.launch() |
89 | 64 | xcodebuild.waitUntilExit() |