Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
e9a3cbf2
Unverified
Commit
e9a3cbf2
authored
Jun 06, 2022
by
Gary Qian
Committed by
GitHub
Jun 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate abandon (#102789)
parent
febc6a14
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
296 additions
and
4 deletions
+296
-4
migrate.dart
packages/flutter_tools/lib/src/commands/migrate.dart
+10
-3
migrate_abandon.dart
packages/flutter_tools/lib/src/commands/migrate_abandon.dart
+134
-0
migrate_abandon_test.dart
...s/test/commands.shard/permeable/migrate_abandon_test.dart
+148
-0
migrate_status_test.dart
...ls/test/commands.shard/permeable/migrate_status_test.dart
+4
-1
No files found.
packages/flutter_tools/lib/src/commands/migrate.dart
View file @
e9a3cbf2
...
...
@@ -10,19 +10,19 @@ import '../base/platform.dart';
import
'../base/terminal.dart'
;
import
'../migrate/migrate_utils.dart'
;
import
'../runner/flutter_command.dart'
;
import
'migrate_abandon.dart'
;
import
'migrate_status.dart'
;
/// Base command for the migration tool.
class
MigrateCommand
extends
FlutterCommand
{
MigrateCommand
({
bool
verbose
=
fal
se
,
required
bool
verbo
se
,
required
this
.
logger
,
// TODO(garyq): Add parameter in as they are needed for subcommands.
required
FileSystem
fileSystem
,
required
Terminal
terminal
,
required
Platform
platform
,
required
ProcessManager
processManager
,
})
{
// TODO(garyq): Add each subcommand back in as they land.
addSubcommand
(
MigrateStatusCommand
(
verbose:
verbose
,
logger:
logger
,
...
...
@@ -30,6 +30,13 @@ class MigrateCommand extends FlutterCommand {
platform:
platform
,
processManager:
processManager
));
addSubcommand
(
MigrateAbandonCommand
(
logger:
logger
,
fileSystem:
fileSystem
,
terminal:
terminal
,
platform:
platform
,
processManager:
processManager
));
}
final
Logger
logger
;
...
...
packages/flutter_tools/lib/src/commands/migrate_abandon.dart
0 → 100644
View file @
e9a3cbf2
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:process/process.dart'
;
import
'../base/file_system.dart'
;
import
'../base/logger.dart'
;
import
'../base/platform.dart'
;
import
'../base/terminal.dart'
;
import
'../migrate/migrate_utils.dart'
;
import
'../project.dart'
;
import
'../runner/flutter_command.dart'
;
import
'migrate.dart'
;
/// Abandons the existing migration by deleting the migrate working directory.
class
MigrateAbandonCommand
extends
FlutterCommand
{
MigrateAbandonCommand
({
required
this
.
logger
,
required
this
.
fileSystem
,
required
this
.
terminal
,
required
Platform
platform
,
required
ProcessManager
processManager
,
})
:
migrateUtils
=
MigrateUtils
(
logger:
logger
,
fileSystem:
fileSystem
,
platform:
platform
,
processManager:
processManager
,
)
{
requiresPubspecYaml
();
argParser
.
addOption
(
'staging-directory'
,
help:
'Specifies the custom migration working directory used to stage '
'and edit proposed changes. This path can be absolute or relative '
'to the flutter project root. This defaults to '
'`
$kDefaultMigrateStagingDirectoryName
`'
,
valueHelp:
'path'
,
);
argParser
.
addOption
(
'project-directory'
,
help:
'The root directory of the flutter project. This defaults to the '
'current working directory if omitted.'
,
valueHelp:
'path'
,
);
argParser
.
addFlag
(
'force'
,
abbr:
'f'
,
help:
'Delete the migrate working directory without asking for confirmation.'
,
);
}
final
Logger
logger
;
final
FileSystem
fileSystem
;
final
Terminal
terminal
;
final
MigrateUtils
migrateUtils
;
@override
final
String
name
=
'abandon'
;
@override
final
String
description
=
'Deletes the current active migration working directory.'
;
@override
String
get
category
=>
FlutterCommandCategory
.
project
;
@override
Future
<
Set
<
DevelopmentArtifact
>>
get
requiredArtifacts
async
=>
const
<
DevelopmentArtifact
>{};
@override
Future
<
FlutterCommandResult
>
runCommand
()
async
{
final
String
?
projectDirectory
=
stringArg
(
'project-directory'
);
final
FlutterProjectFactory
flutterProjectFactory
=
FlutterProjectFactory
(
logger:
logger
,
fileSystem:
fileSystem
);
final
FlutterProject
project
=
projectDirectory
==
null
?
FlutterProject
.
current
()
:
flutterProjectFactory
.
fromDirectory
(
fileSystem
.
directory
(
projectDirectory
));
Directory
stagingDirectory
=
project
.
directory
.
childDirectory
(
kDefaultMigrateStagingDirectoryName
);
final
String
?
customStagingDirectoryPath
=
stringArg
(
'staging-directory'
);
if
(
customStagingDirectoryPath
!=
null
)
{
if
(
fileSystem
.
path
.
isAbsolute
(
customStagingDirectoryPath
))
{
stagingDirectory
=
fileSystem
.
directory
(
customStagingDirectoryPath
);
}
else
{
stagingDirectory
=
project
.
directory
.
childDirectory
(
customStagingDirectoryPath
);
}
if
(!
stagingDirectory
.
existsSync
())
{
logger
.
printError
(
'Provided staging directory `
$customStagingDirectoryPath
` '
'does not exist or is not valid.'
);
return
const
FlutterCommandResult
(
ExitStatus
.
fail
);
}
}
if
(!
stagingDirectory
.
existsSync
())
{
logger
.
printStatus
(
'No migration in progress. Start a new migration with:'
);
printCommandText
(
'flutter migrate start'
,
logger
);
return
const
FlutterCommandResult
(
ExitStatus
.
fail
);
}
logger
.
printStatus
(
'
\n
Abandoning the existing migration will delete the '
'migration staging directory at
${stagingDirectory.path}
'
);
final
bool
force
=
boolArg
(
'force'
)
??
false
;
if
(!
force
)
{
String
selection
=
'y'
;
terminal
.
usesTerminalUi
=
true
;
try
{
selection
=
await
terminal
.
promptForCharInput
(
<
String
>[
'y'
,
'n'
],
logger:
logger
,
prompt:
'Are you sure you wish to continue with abandoning? (y)es, (N)o'
,
defaultChoiceIndex:
1
,
);
}
on
StateError
catch
(
e
)
{
logger
.
printError
(
e
.
message
,
indent:
0
,
);
}
if
(
selection
!=
'y'
)
{
return
const
FlutterCommandResult
(
ExitStatus
.
success
);
}
}
try
{
stagingDirectory
.
deleteSync
(
recursive:
true
);
}
on
FileSystemException
catch
(
e
)
{
logger
.
printError
(
'Deletion failed with:
$e
'
);
logger
.
printError
(
'Please manually delete the staging directory at `
${stagingDirectory.path}
`'
);
}
logger
.
printStatus
(
'
\n
Abandon complete. Start a new migration with:'
);
printCommandText
(
'flutter migrate start'
,
logger
);
return
const
FlutterCommandResult
(
ExitStatus
.
success
);
}
}
packages/flutter_tools/test/commands.shard/permeable/migrate_abandon_test.dart
0 → 100644
View file @
e9a3cbf2
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/migrate.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'package:flutter_tools/src/migrate/migrate_utils.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/test_flutter_command_runner.dart'
;
void
main
(
)
{
FileSystem
fileSystem
;
BufferLogger
logger
;
Platform
platform
;
Terminal
terminal
;
ProcessManager
processManager
;
Directory
appDir
;
setUp
(()
{
fileSystem
=
globals
.
localFileSystem
;
appDir
=
fileSystem
.
systemTempDirectory
.
createTempSync
(
'apptestdir'
);
logger
=
BufferLogger
.
test
();
platform
=
FakePlatform
();
terminal
=
Terminal
.
test
();
processManager
=
globals
.
processManager
;
});
setUpAll
(()
{
Cache
.
disableLocking
();
});
tearDown
(()
async
{
tryToDelete
(
appDir
);
});
testUsingContext
(
'abandon deletes staging directory'
,
()
async
{
final
MigrateCommand
command
=
MigrateCommand
(
verbose:
true
,
logger:
logger
,
fileSystem:
fileSystem
,
terminal:
terminal
,
platform:
platform
,
processManager:
processManager
,
);
final
Directory
stagingDir
=
appDir
.
childDirectory
(
kDefaultMigrateStagingDirectoryName
);
appDir
.
childFile
(
'lib/main.dart'
).
createSync
(
recursive:
true
);
final
File
pubspecOriginal
=
appDir
.
childFile
(
'pubspec.yaml'
);
pubspecOriginal
.
createSync
();
pubspecOriginal
.
writeAsStringSync
(
'''
name: originalname
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: '
>=
2.18
.
0
-
58.0
.
dev
<
3.0
.
0
'
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true'''
,
flush:
true
);
expect
(
stagingDir
.
existsSync
(),
false
);
await
createTestCommandRunner
(
command
).
run
(
<
String
>[
'migrate'
,
'abandon'
,
'--staging-directory=
${stagingDir.path}
'
,
'--project-directory=
${appDir.path}
'
,
]
);
expect
(
logger
.
errorText
,
contains
(
'Provided staging directory'
));
expect
(
logger
.
errorText
,
contains
(
'migrate_staging_dir` does not exist or is not valid.'
));
logger
.
clear
();
await
createTestCommandRunner
(
command
).
run
(
<
String
>[
'migrate'
,
'abandon'
,
'--project-directory=
${appDir.path}
'
,
]
);
expect
(
logger
.
statusText
,
contains
(
'No migration in progress. Start a new migration with:'
));
final
File
pubspecModified
=
stagingDir
.
childFile
(
'pubspec.yaml'
);
pubspecModified
.
createSync
(
recursive:
true
);
pubspecModified
.
writeAsStringSync
(
'''
name: newname
description: new description of the test project
version: 1.0.0+1
environment:
sdk: '
>=
2.18
.
0
-
58.0
.
dev
<
3.0
.
0
'
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: false
EXTRALINE'''
,
flush:
true
);
final
File
addedFile
=
stagingDir
.
childFile
(
'added.file'
);
addedFile
.
createSync
(
recursive:
true
);
addedFile
.
writeAsStringSync
(
'new file contents'
);
final
File
manifestFile
=
stagingDir
.
childFile
(
'.migrate_manifest'
);
manifestFile
.
createSync
(
recursive:
true
);
manifestFile
.
writeAsStringSync
(
'''
merged_files:
- pubspec.yaml
conflict_files:
added_files:
- added.file
deleted_files:
'''
);
expect
(
appDir
.
childFile
(
'lib/main.dart'
).
existsSync
(),
true
);
expect
(
stagingDir
.
existsSync
(),
true
);
logger
.
clear
();
await
createTestCommandRunner
(
command
).
run
(
<
String
>[
'migrate'
,
'abandon'
,
'--staging-directory=
${stagingDir.path}
'
,
'--project-directory=
${appDir.path}
'
,
'--force'
,
]
);
expect
(
logger
.
statusText
,
contains
(
'Abandon complete. Start a new migration with:'
));
expect
(
stagingDir
.
existsSync
(),
false
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
processManager
,
Platform:
()
=>
platform
,
});
}
packages/flutter_tools/test/commands.shard/permeable/migrate_status_test.dart
View file @
e9a3cbf2
...
...
@@ -7,6 +7,7 @@
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/migrate.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
...
...
@@ -20,7 +21,7 @@ void main() {
FileSystem
fileSystem
;
BufferLogger
logger
;
Platform
platform
;
// TODO(garyq): Add terminal back in when other subcommands land.
Terminal
terminal
;
ProcessManager
processManager
;
Directory
appDir
;
...
...
@@ -29,6 +30,7 @@ void main() {
appDir
=
fileSystem
.
systemTempDirectory
.
createTempSync
(
'apptestdir'
);
logger
=
BufferLogger
.
test
();
platform
=
FakePlatform
();
terminal
=
Terminal
.
test
();
processManager
=
globals
.
processManager
;
});
...
...
@@ -45,6 +47,7 @@ void main() {
verbose:
true
,
logger:
logger
,
fileSystem:
fileSystem
,
terminal:
terminal
,
platform:
platform
,
processManager:
processManager
,
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment