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