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