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