|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the SVN-Buddy library. |
|
4
|
|
|
* For the full copyright and license information, please view |
|
5
|
|
|
* the LICENSE file that was distributed with this source code. |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
|
8
|
|
|
* @link https://github.com/console-helpers/svn-buddy |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\SVNBuddy; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
use ConsoleHelpers\ConsoleKit\Config\ConfigEditor; |
|
15
|
|
|
use ConsoleHelpers\DatabaseMigration\MigrationManager; |
|
16
|
|
|
use ConsoleHelpers\DatabaseMigration\PhpMigrationRunner; |
|
17
|
|
|
use ConsoleHelpers\DatabaseMigration\SqlMigrationRunner; |
|
18
|
|
|
use ConsoleHelpers\SVNBuddy\Cache\CacheManager; |
|
19
|
|
|
use ConsoleHelpers\SVNBuddy\Command\ChangelogCommand; |
|
20
|
|
|
use ConsoleHelpers\SVNBuddy\Command\CleanupCommand; |
|
21
|
|
|
use ConsoleHelpers\SVNBuddy\Command\CommitCommand; |
|
22
|
|
|
use ConsoleHelpers\SVNBuddy\Command\CompletionCommand; |
|
23
|
|
|
use ConsoleHelpers\SVNBuddy\Command\ConfigCommand; |
|
24
|
|
|
use ConsoleHelpers\SVNBuddy\Command\ConflictsCommand; |
|
25
|
|
|
use ConsoleHelpers\SVNBuddy\Command\DeployCommand; |
|
26
|
|
|
use ConsoleHelpers\SVNBuddy\Command\Dev\MigrationCreateCommand; |
|
27
|
|
|
use ConsoleHelpers\SVNBuddy\Command\Dev\PharCreateCommand; |
|
28
|
|
|
use ConsoleHelpers\SVNBuddy\Command\LogCommand; |
|
29
|
|
|
use ConsoleHelpers\SVNBuddy\Command\MergeCommand; |
|
30
|
|
|
use ConsoleHelpers\SVNBuddy\Command\ProjectCommand; |
|
31
|
|
|
use ConsoleHelpers\SVNBuddy\Command\ReparseCommand; |
|
32
|
|
|
use ConsoleHelpers\SVNBuddy\Command\RevertCommand; |
|
33
|
|
|
use ConsoleHelpers\SVNBuddy\Command\SearchCommand; |
|
34
|
|
|
use ConsoleHelpers\SVNBuddy\Command\SelfUpdateCommand; |
|
35
|
|
|
use ConsoleHelpers\SVNBuddy\Command\UpdateCommand; |
|
36
|
|
|
use ConsoleHelpers\SVNBuddy\Config\CommandConfig; |
|
37
|
|
|
use ConsoleHelpers\SVNBuddy\Database\StatementProfiler; |
|
38
|
|
|
use ConsoleHelpers\SVNBuddy\Helper\DateHelper; |
|
39
|
|
|
use ConsoleHelpers\SVNBuddy\Helper\OutputHelper; |
|
40
|
|
|
use ConsoleHelpers\SVNBuddy\Helper\SizeHelper; |
|
41
|
|
|
use ConsoleHelpers\SVNBuddy\MergeSourceDetector\ClassicMergeSourceDetector; |
|
42
|
|
|
use ConsoleHelpers\SVNBuddy\MergeSourceDetector\InPortalMergeSourceDetector; |
|
43
|
|
|
use ConsoleHelpers\SVNBuddy\MergeSourceDetector\MergeSourceDetectorAggregator; |
|
44
|
|
|
use ConsoleHelpers\SVNBuddy\Process\ProcessFactory; |
|
45
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\CommitMessageBuilder; |
|
46
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\EmptyMergeTemplate; |
|
47
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\GroupByBugMergeTemplate; |
|
48
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\GroupByRevisionMergeTemplate; |
|
49
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\MergeTemplateFactory; |
|
50
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\SummaryMergeTemplate; |
|
51
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Connector\CommandFactory; |
|
52
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; |
|
53
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Connector\UrlResolver; |
|
54
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Parser\LogMessageParserFactory; |
|
55
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Parser\RevisionListParser; |
|
56
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\DatabaseManager; |
|
57
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLogFactory; |
|
58
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionPrinter; |
|
59
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\WorkingCopyConflictTracker; |
|
60
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\WorkingCopyResolver; |
|
61
|
|
|
use ConsoleHelpers\SVNBuddy\Updater\UpdateManager; |
|
62
|
|
|
use ConsoleHelpers\SVNBuddy\Updater\Updater; |
|
63
|
|
|
use ConsoleHelpers\SVNBuddy\Updater\VersionUpdateStrategy; |
|
64
|
|
|
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface; |
|
65
|
|
|
use Symfony\Component\Console\Exception\CommandNotFoundException; |
|
66
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
|
67
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
68
|
|
|
|
|
69
|
|
|
class Container extends \ConsoleHelpers\ConsoleKit\Container implements CommandLoaderInterface |
|
70
|
|
|
{ |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Command factories. |
|
74
|
|
|
* |
|
75
|
|
|
* @var callable[] |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $commandFactories = array(); |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritdoc} |
|
81
|
|
|
*/ |
|
82
|
195 |
|
public function __construct(array $values = array()) |
|
83
|
|
|
{ |
|
84
|
195 |
|
parent::__construct($values); |
|
85
|
|
|
|
|
86
|
195 |
|
$this['app_name'] = 'SVN-Buddy'; |
|
87
|
195 |
|
$this['app_version'] = '@git-version@'; |
|
88
|
|
|
|
|
89
|
195 |
|
$this['working_directory_sub_folder'] = '.svn-buddy'; |
|
90
|
|
|
|
|
91
|
195 |
|
$this['config_defaults'] = array( |
|
92
|
195 |
|
'repository-connector.username' => '', |
|
93
|
195 |
|
'repository-connector.password' => '', |
|
94
|
195 |
|
'repository-connector.last-revision-cache-duration' => '10 minutes', |
|
95
|
195 |
|
'update-channel' => 'stable', |
|
96
|
195 |
|
'theme' => 'dark', |
|
97
|
195 |
|
); |
|
98
|
|
|
|
|
99
|
195 |
|
$this['dark_theme'] = function ($c) { |
|
100
|
|
|
/** @var ConfigEditor $config_editor */ |
|
101
|
1 |
|
$config_editor = $c['config_editor']; |
|
102
|
|
|
|
|
103
|
1 |
|
return $config_editor->get('theme', $c['config_defaults']['theme']) === 'dark'; |
|
104
|
195 |
|
}; |
|
105
|
|
|
|
|
106
|
195 |
|
$this->extend('output', function ($output) { |
|
107
|
|
|
/** @var OutputInterface $output */ |
|
108
|
12 |
|
$output->getFormatter()->setStyle('debug', new OutputFormatterStyle('white', 'magenta')); |
|
109
|
|
|
|
|
110
|
12 |
|
return $output; |
|
111
|
195 |
|
}); |
|
112
|
|
|
|
|
113
|
195 |
|
$this['process_factory'] = function () { |
|
114
|
10 |
|
return new ProcessFactory(); |
|
115
|
195 |
|
}; |
|
116
|
|
|
|
|
117
|
195 |
|
$this['merge_source_detector'] = function () { |
|
118
|
1 |
|
$merge_source_detector = new MergeSourceDetectorAggregator(0); |
|
119
|
1 |
|
$merge_source_detector->add(new ClassicMergeSourceDetector(0)); |
|
120
|
1 |
|
$merge_source_detector->add(new InPortalMergeSourceDetector(50)); |
|
121
|
|
|
|
|
122
|
1 |
|
return $merge_source_detector; |
|
123
|
195 |
|
}; |
|
124
|
|
|
|
|
125
|
195 |
|
$this['repository_url_resolver'] = function ($c) { |
|
126
|
1 |
|
return new UrlResolver($c['repository_connector']); |
|
127
|
195 |
|
}; |
|
128
|
|
|
|
|
129
|
195 |
|
$this['cache_manager'] = function ($c) { |
|
130
|
10 |
|
return new CacheManager($c['working_directory'], $c['size_helper'], $c['io']); |
|
131
|
195 |
|
}; |
|
132
|
|
|
|
|
133
|
195 |
|
$this['statement_profiler'] = function () { |
|
134
|
20 |
|
$statement_profiler = new StatementProfiler(); |
|
135
|
|
|
|
|
136
|
|
|
// The "AbstractPlugin::getLastRevision" method. |
|
137
|
20 |
|
$statement_profiler->ignoreDuplicateStatement('SELECT LastRevision FROM PluginData WHERE Name = :name'); |
|
138
|
|
|
|
|
139
|
|
|
// The "AbstractPlugin::getProject" method. |
|
140
|
20 |
|
$statement_profiler->ignoreDuplicateStatement('SELECT Id FROM Projects WHERE Path = :path'); |
|
141
|
|
|
|
|
142
|
|
|
// The "AbstractDatabaseCollectorPlugin::getProjects" method. |
|
143
|
20 |
|
$statement_profiler->ignoreDuplicateStatement( |
|
144
|
20 |
|
'SELECT Path, Id AS PathId, RevisionAdded, RevisionDeleted, RevisionLastSeen |
|
145
|
|
|
FROM Paths |
|
146
|
20 |
|
WHERE PathHash IN (:path_hashes)' |
|
147
|
20 |
|
); |
|
148
|
|
|
|
|
149
|
|
|
// The "ProjectsPlugin::createRepositoryWideProject" method. |
|
150
|
20 |
|
$statement_profiler->ignoreDuplicateStatement( |
|
151
|
20 |
|
'SELECT Id FROM Paths WHERE ProjectPath = :project_path LIMIT 100' |
|
152
|
20 |
|
); |
|
153
|
|
|
|
|
154
|
20 |
|
$statement_profiler->setActive(true); |
|
155
|
20 |
|
$statement_profiler->trackDuplicates(false); |
|
156
|
|
|
|
|
157
|
20 |
|
return $statement_profiler; |
|
158
|
195 |
|
}; |
|
159
|
|
|
|
|
160
|
195 |
|
$this['project_root_folder'] = function () { |
|
161
|
165 |
|
return dirname(dirname(__DIR__)); |
|
162
|
195 |
|
}; |
|
163
|
|
|
|
|
164
|
195 |
|
$this['migration_manager'] = function ($c) { |
|
165
|
165 |
|
$migrations_directory = $c['project_root_folder'] . '/migrations'; |
|
166
|
165 |
|
$migration_manager = new MigrationManager($migrations_directory, $c); |
|
167
|
165 |
|
$migration_manager->registerMigrationRunner(new SqlMigrationRunner()); |
|
168
|
165 |
|
$migration_manager->registerMigrationRunner(new PhpMigrationRunner()); |
|
169
|
|
|
|
|
170
|
165 |
|
return $migration_manager; |
|
171
|
195 |
|
}; |
|
172
|
|
|
|
|
173
|
195 |
|
$this['db_manager'] = function ($c) { |
|
174
|
2 |
|
return new DatabaseManager($c['working_directory'], $c['migration_manager'], $c['statement_profiler']); |
|
175
|
195 |
|
}; |
|
176
|
|
|
|
|
177
|
195 |
|
$this['revision_log_factory'] = function ($c) { |
|
178
|
2 |
|
return new RevisionLogFactory( |
|
179
|
2 |
|
$c['repository_connector'], |
|
180
|
2 |
|
$c['db_manager'], |
|
181
|
2 |
|
$c['log_message_parser_factory'], |
|
182
|
2 |
|
$c['working_directory'] |
|
183
|
2 |
|
); |
|
184
|
195 |
|
}; |
|
185
|
|
|
|
|
186
|
195 |
|
$this['log_message_parser_factory'] = function () { |
|
187
|
3 |
|
return new LogMessageParserFactory(); |
|
188
|
195 |
|
}; |
|
189
|
|
|
|
|
190
|
195 |
|
$this['revision_list_parser'] = function () { |
|
191
|
9 |
|
return new RevisionListParser(); |
|
192
|
195 |
|
}; |
|
193
|
|
|
|
|
194
|
195 |
|
$this['revision_printer'] = function ($c) { |
|
195
|
1 |
|
return new RevisionPrinter($c['date_helper'], $c['output_helper'], $c['dark_theme']); |
|
196
|
195 |
|
}; |
|
197
|
|
|
|
|
198
|
195 |
|
$this['command_factory'] = function ($c) { |
|
199
|
9 |
|
return new CommandFactory($c['config_editor'], $c['process_factory'], $c['io'], $c['cache_manager']); |
|
200
|
195 |
|
}; |
|
201
|
|
|
|
|
202
|
195 |
|
$this['repository_connector'] = function ($c) { |
|
203
|
8 |
|
return new Connector( |
|
204
|
8 |
|
$c['config_editor'], |
|
205
|
8 |
|
$c['command_factory'], |
|
206
|
8 |
|
$c['io'], |
|
207
|
8 |
|
$c['revision_list_parser'] |
|
208
|
8 |
|
); |
|
209
|
195 |
|
}; |
|
210
|
|
|
|
|
211
|
195 |
|
$this['commit_message_builder'] = function ($c) { |
|
212
|
1 |
|
return new CommitMessageBuilder($c['working_copy_conflict_tracker']); |
|
213
|
195 |
|
}; |
|
214
|
|
|
|
|
215
|
195 |
|
$this['working_copy_resolver'] = function ($c) { |
|
216
|
4 |
|
return new WorkingCopyResolver($c['repository_connector']); |
|
217
|
195 |
|
}; |
|
218
|
|
|
|
|
219
|
195 |
|
$this['working_copy_conflict_tracker'] = function ($c) { |
|
220
|
2 |
|
return new WorkingCopyConflictTracker($c['repository_connector'], $c['command_config']); |
|
221
|
195 |
|
}; |
|
222
|
|
|
|
|
223
|
195 |
|
$this['merge_template_factory'] = function ($c) { |
|
224
|
1 |
|
$factory = new MergeTemplateFactory(); |
|
225
|
1 |
|
$repository_connector = $c['repository_connector']; |
|
226
|
1 |
|
$revision_log_factory = $c['revision_log_factory']; |
|
227
|
|
|
|
|
228
|
1 |
|
$factory->add(new GroupByBugMergeTemplate($repository_connector, $revision_log_factory)); |
|
229
|
1 |
|
$factory->add(new GroupByRevisionMergeTemplate($repository_connector, $revision_log_factory)); |
|
230
|
1 |
|
$factory->add(new SummaryMergeTemplate($repository_connector, $revision_log_factory)); |
|
231
|
1 |
|
$factory->add(new EmptyMergeTemplate($repository_connector, $revision_log_factory)); |
|
232
|
|
|
|
|
233
|
1 |
|
return $factory; |
|
234
|
195 |
|
}; |
|
235
|
|
|
|
|
236
|
195 |
|
$this['command_config'] = function ($c) { |
|
237
|
3 |
|
return new CommandConfig($c['config_editor'], $c['working_copy_resolver']); |
|
238
|
195 |
|
}; |
|
239
|
|
|
|
|
240
|
195 |
|
$this['date_helper'] = function () { |
|
241
|
2 |
|
return new DateHelper(); |
|
242
|
195 |
|
}; |
|
243
|
|
|
|
|
244
|
195 |
|
$this['size_helper'] = function () { |
|
245
|
11 |
|
return new SizeHelper(); |
|
246
|
195 |
|
}; |
|
247
|
|
|
|
|
248
|
195 |
|
$this['output_helper'] = function () { |
|
249
|
2 |
|
return new OutputHelper(); |
|
250
|
195 |
|
}; |
|
251
|
|
|
|
|
252
|
195 |
|
$this['editor'] = function () { |
|
253
|
1 |
|
return new InteractiveEditor(); |
|
254
|
195 |
|
}; |
|
255
|
|
|
|
|
256
|
195 |
|
$this['updater'] = function ($c) { |
|
257
|
|
|
/** @var ConfigEditor $config_editor */ |
|
258
|
1 |
|
$config_editor = $c['config_editor']; |
|
259
|
|
|
|
|
260
|
1 |
|
$update_strategy = new VersionUpdateStrategy(); |
|
261
|
1 |
|
$update_strategy->setStability($config_editor->get('update-channel')); |
|
|
|
|
|
|
262
|
1 |
|
$update_strategy->setCurrentLocalVersion($c['app_version']); |
|
263
|
|
|
|
|
264
|
1 |
|
$updater = new Updater(null, false); |
|
265
|
1 |
|
$updater->setStrategyObject($update_strategy); |
|
266
|
|
|
|
|
267
|
1 |
|
return $updater; |
|
268
|
195 |
|
}; |
|
269
|
|
|
|
|
270
|
195 |
|
$this['update_manager'] = function ($c) { |
|
271
|
|
|
return new UpdateManager( |
|
272
|
|
|
$c['updater'], |
|
273
|
|
|
$c['config_editor'], |
|
274
|
|
|
$c['process_factory'], |
|
275
|
|
|
$c['working_directory'] |
|
276
|
|
|
); |
|
277
|
195 |
|
}; |
|
278
|
|
|
|
|
279
|
195 |
|
$this->addCommandFactories(); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Adds command factories. |
|
284
|
|
|
* |
|
285
|
|
|
* @return void |
|
286
|
|
|
*/ |
|
287
|
195 |
|
protected function addCommandFactories() |
|
288
|
|
|
{ |
|
289
|
195 |
|
$this->commandFactories['merge'] = function () { |
|
290
|
|
|
return new MergeCommand(); |
|
291
|
195 |
|
}; |
|
292
|
195 |
|
$this->commandFactories['cleanup'] = function () { |
|
293
|
|
|
return new CleanupCommand(); |
|
294
|
195 |
|
}; |
|
295
|
195 |
|
$this->commandFactories['revert'] = function () { |
|
296
|
|
|
return new RevertCommand(); |
|
297
|
195 |
|
}; |
|
298
|
195 |
|
$this->commandFactories['reparse'] = function () { |
|
299
|
|
|
return new ReparseCommand(); |
|
300
|
195 |
|
}; |
|
301
|
195 |
|
$this->commandFactories['log'] = function () { |
|
302
|
|
|
return new LogCommand(); |
|
303
|
195 |
|
}; |
|
304
|
195 |
|
$this->commandFactories['update'] = function () { |
|
305
|
|
|
return new UpdateCommand(); |
|
306
|
195 |
|
}; |
|
307
|
195 |
|
$this->commandFactories['up'] = function () { |
|
308
|
|
|
return new UpdateCommand(); |
|
309
|
195 |
|
}; |
|
310
|
195 |
|
$this->commandFactories['commit'] = function () { |
|
311
|
|
|
return new CommitCommand(); |
|
312
|
195 |
|
}; |
|
313
|
195 |
|
$this->commandFactories['ci'] = function () { |
|
314
|
|
|
return new CommitCommand(); |
|
315
|
195 |
|
}; |
|
316
|
195 |
|
$this->commandFactories['conflicts'] = function () { |
|
317
|
|
|
return new ConflictsCommand(); |
|
318
|
195 |
|
}; |
|
319
|
195 |
|
$this->commandFactories['cf'] = function () { |
|
320
|
|
|
return new ConflictsCommand(); |
|
321
|
195 |
|
}; |
|
322
|
195 |
|
$this->commandFactories['config'] = function () { |
|
323
|
|
|
return new ConfigCommand(); |
|
324
|
195 |
|
}; |
|
325
|
195 |
|
$this->commandFactories['cfg'] = function () { |
|
326
|
|
|
return new ConfigCommand(); |
|
327
|
195 |
|
}; |
|
328
|
195 |
|
$this->commandFactories['project'] = function () { |
|
329
|
|
|
return new ProjectCommand(); |
|
330
|
195 |
|
}; |
|
331
|
195 |
|
$this->commandFactories['_completion'] = function () { |
|
332
|
|
|
return new CompletionCommand(); |
|
333
|
195 |
|
}; |
|
334
|
195 |
|
$this->commandFactories['search'] = function () { |
|
335
|
|
|
return new SearchCommand(); |
|
336
|
195 |
|
}; |
|
337
|
195 |
|
$this->commandFactories['self-update'] = function () { |
|
338
|
|
|
return new SelfUpdateCommand(); |
|
339
|
195 |
|
}; |
|
340
|
195 |
|
$this->commandFactories['changelog'] = function () { |
|
341
|
|
|
return new ChangelogCommand(); |
|
342
|
195 |
|
}; |
|
343
|
195 |
|
$this->commandFactories['deploy'] = function () { |
|
344
|
|
|
return new DeployCommand(); |
|
345
|
195 |
|
}; |
|
346
|
|
|
|
|
347
|
195 |
|
if ( strpos(__DIR__, 'phar://') === false ) { |
|
348
|
195 |
|
$this->commandFactories['dev:migration-create'] = function () { |
|
349
|
|
|
return new MigrationCreateCommand(); |
|
350
|
195 |
|
}; |
|
351
|
195 |
|
$this->commandFactories['dev:phar-create'] = function () { |
|
352
|
|
|
return new PharCreateCommand(); |
|
353
|
195 |
|
}; |
|
354
|
|
|
} |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* {@inheritdoc} |
|
359
|
|
|
*/ |
|
360
|
|
|
public function has($name) |
|
361
|
|
|
{ |
|
362
|
|
|
return isset($this->commandFactories[$name]); |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* {@inheritdoc} |
|
367
|
|
|
* |
|
368
|
|
|
* @throws CommandNotFoundException When command wasn't found. |
|
369
|
|
|
*/ |
|
370
|
|
|
public function get($name) |
|
371
|
|
|
{ |
|
372
|
|
|
if ( !isset($this->commandFactories[$name]) ) { |
|
373
|
|
|
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
$factory = $this->commandFactories[$name]; |
|
377
|
|
|
|
|
378
|
|
|
return $factory(); |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
/** |
|
382
|
|
|
* {@inheritdoc} |
|
383
|
|
|
*/ |
|
384
|
|
|
public function getNames() |
|
385
|
|
|
{ |
|
386
|
|
|
return array_keys($this->commandFactories); |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
} |
|
390
|
|
|
|