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
4a730509
Unverified
Commit
4a730509
authored
Apr 09, 2021
by
Jenn Magder
Committed by
GitHub
Apr 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate persistent_tool_state to null safety (#80085)
parent
4cf0465b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
51 deletions
+54
-51
bot_detector.dart
packages/flutter_tools/lib/src/base/bot_detector.dart
+2
-2
devtools_launcher.dart
packages/flutter_tools/lib/src/devtools_launcher.dart
+1
-1
persistent_tool_state.dart
packages/flutter_tools/lib/src/persistent_tool_state.dart
+39
-36
first_run.dart
packages/flutter_tools/lib/src/reporting/first_run.dart
+2
-2
devtools_launcher_test.dart
...tter_tools/test/general.shard/devtools_launcher_test.dart
+1
-1
persistent_tool_state_test.dart
..._tools/test/general.shard/persistent_tool_state_test.dart
+5
-7
first_run_test.dart
...er_tools/test/general.shard/reporting/first_run_test.dart
+4
-2
No files found.
packages/flutter_tools/lib/src/base/bot_detector.dart
View file @
4a730509
...
...
@@ -42,10 +42,10 @@ class BotDetector {
// When set, GA logs to a local file (normally for tests) so we don't need to filter.
||
_platform
.
environment
.
containsKey
(
'FLUTTER_ANALYTICS_LOG_FILE'
)
)
{
return
_persistentToolState
.
isR
unningOnBot
=
false
;
return
_persistentToolState
.
r
unningOnBot
=
false
;
}
return
_persistentToolState
.
isR
unningOnBot
=
_platform
.
environment
[
'BOT'
]
==
'true'
return
_persistentToolState
.
r
unningOnBot
=
_platform
.
environment
[
'BOT'
]
==
'true'
// https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
||
_platform
.
environment
[
'TRAVIS'
]
==
'true'
...
...
packages/flutter_tools/lib/src/devtools_launcher.dart
View file @
4a730509
...
...
@@ -178,7 +178,7 @@ class DevtoolsServerLauncher extends DevtoolsLauncher {
'devtools`:
\n
${_devToolsActivateProcess.stderr}
'
);
return
false
;
}
_persistentToolState
.
lastDevToolsActivation
Time
=
DateTime
.
now
();
_persistentToolState
.
lastDevToolsActivation
=
DateTime
.
now
();
return
true
;
}
on
Exception
catch
(
e
,
_
)
{
_logger
.
printError
(
'Error running `pub global activate devtools`:
$e
'
);
...
...
packages/flutter_tools/lib/src/persistent_tool_state.dart
View file @
4a730509
...
...
@@ -2,8 +2,6 @@
// 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:meta/meta.dart'
;
import
'base/config.dart'
;
...
...
@@ -17,9 +15,9 @@ import 'version.dart';
/// must persist across tool invocations.
abstract
class
PersistentToolState
{
factory
PersistentToolState
({
@
required
FileSystem
fileSystem
,
@
required
Logger
logger
,
@
required
Platform
platform
,
required
FileSystem
fileSystem
,
required
Logger
logger
,
required
Platform
platform
,
})
=>
_DefaultPersistentToolState
(
fileSystem:
fileSystem
,
logger:
logger
,
...
...
@@ -27,43 +25,47 @@ abstract class PersistentToolState {
);
factory
PersistentToolState
.
test
({
@
required
Directory
directory
,
@
required
Logger
logger
,
required
Directory
directory
,
required
Logger
logger
,
})
=>
_DefaultPersistentToolState
.
test
(
directory:
directory
,
logger:
logger
,
);
static
PersistentToolState
get
instance
=>
context
.
get
<
PersistentToolState
>();
static
PersistentToolState
?
get
instance
=>
context
.
get
<
PersistentToolState
>();
/// Whether the welcome message should be redisplayed.
///
/// May give null if the value has not been set.
bool
redisplayWelcomeMessage
;
bool
?
get
shouldRedisplayWelcomeMessage
;
set
redisplayWelcomeMessage
(
bool
value
);
// Enforced nonnull setter.
/// Returns the last active version for a given [channel].
///
/// If there was no active prior version, returns `null` instead.
String
lastActiveVersion
(
Channel
channel
);
String
?
lastActiveVersion
(
Channel
channel
);
/// Update the last active version for a given [channel].
void
updateLastActiveVersion
(
String
fullGitHash
,
Channel
channel
);
/// Return the hash of the last active license terms.
String
lastActiveLicenseTerms
;
String
?
get
lastActiveLicenseTermsHash
;
set
lastActiveLicenseTerms
(
String
value
);
// Enforced nonnull setter.
/// Whether this client was already determined to be or not be a bot.
bool
isRunningOnBot
;
bool
?
get
isRunningOnBot
;
set
runningOnBot
(
bool
value
);
// Enforced nonnull setter.
/// The last time the DevTools package was activated from pub.
DateTime
lastDevToolsActivationTime
;
DateTime
?
get
lastDevToolsActivationTime
;
set
lastDevToolsActivation
(
DateTime
value
);
// Enforced nonnull setter.
}
class
_DefaultPersistentToolState
implements
PersistentToolState
{
_DefaultPersistentToolState
({
@
required
FileSystem
fileSystem
,
@
required
Logger
logger
,
@
required
Platform
platform
,
required
FileSystem
fileSystem
,
required
Logger
logger
,
required
Platform
platform
,
})
:
_config
=
Config
(
_kFileName
,
fileSystem:
fileSystem
,
...
...
@@ -73,8 +75,8 @@ class _DefaultPersistentToolState implements PersistentToolState {
@visibleForTesting
_DefaultPersistentToolState
.
test
({
@
required
Directory
directory
,
@
required
Logger
logger
,
required
Directory
directory
,
required
Logger
logger
,
})
:
_config
=
Config
.
test
(
name:
_kFileName
,
directory:
directory
,
...
...
@@ -96,55 +98,56 @@ class _DefaultPersistentToolState implements PersistentToolState {
final
Config
_config
;
@override
bool
get
r
edisplayWelcomeMessage
{
return
_config
.
getValue
(
_kRedisplayWelcomeMessage
)
as
bool
;
bool
?
get
shouldR
edisplayWelcomeMessage
{
return
_config
.
getValue
(
_kRedisplayWelcomeMessage
)
as
bool
?
;
}
@override
String
lastActiveVersion
(
Channel
channel
)
{
final
String
versionKey
=
_versionKeyFor
(
channel
);
assert
(
versionKey
!=
null
);
return
_config
.
getValue
(
versionKey
)
as
String
;
set
redisplayWelcomeMessage
(
bool
value
)
{
_config
.
setValue
(
_kRedisplayWelcomeMessage
,
value
);
}
@override
set
redisplayWelcomeMessage
(
bool
value
)
{
_config
.
setValue
(
_kRedisplayWelcomeMessage
,
value
);
String
?
lastActiveVersion
(
Channel
channel
)
{
final
String
?
versionKey
=
_versionKeyFor
(
channel
);
assert
(
versionKey
!=
null
);
return
_config
.
getValue
(
versionKey
!)
as
String
?;
}
@override
void
updateLastActiveVersion
(
String
fullGitHash
,
Channel
channel
)
{
final
String
versionKey
=
_versionKeyFor
(
channel
);
final
String
?
versionKey
=
_versionKeyFor
(
channel
);
assert
(
versionKey
!=
null
);
_config
.
setValue
(
versionKey
,
fullGitHash
);
_config
.
setValue
(
versionKey
!
,
fullGitHash
);
}
@override
String
get
lastActiveLicenseTerms
=>
_config
.
getValue
(
_kLicenseHash
)
as
String
;
String
?
get
lastActiveLicenseTermsHash
=>
_config
.
getValue
(
_kLicenseHash
)
as
String
?
;
@override
set
lastActiveLicenseTerms
(
String
value
)
{
assert
(
value
!=
null
);
_config
.
setValue
(
_kLicenseHash
,
value
);
}
String
_versionKeyFor
(
Channel
channel
)
{
String
?
_versionKeyFor
(
Channel
channel
)
{
return
_lastActiveVersionKeys
[
channel
];
}
@override
bool
get
isRunningOnBot
=>
_config
.
getValue
(
_kBotKey
)
as
bool
;
bool
?
get
isRunningOnBot
=>
_config
.
getValue
(
_kBotKey
)
as
bool
?
;
@override
set
isRunningOnBot
(
bool
value
)
=>
_config
.
setValue
(
_kBotKey
,
value
);
set
runningOnBot
(
bool
value
)
{
_config
.
setValue
(
_kBotKey
,
value
);
}
@override
DateTime
get
lastDevToolsActivationTime
{
final
String
value
=
_config
.
getValue
(
_kLastDevToolsActivationTimeKey
)
as
String
;
DateTime
?
get
lastDevToolsActivationTime
{
final
String
?
value
=
_config
.
getValue
(
_kLastDevToolsActivationTimeKey
)
as
String
?
;
return
value
!=
null
?
DateTime
.
parse
(
value
)
:
null
;
}
@override
set
lastDevToolsActivation
Time
(
DateTime
time
)
=>
set
lastDevToolsActivation
(
DateTime
time
)
=>
_config
.
setValue
(
_kLastDevToolsActivationTimeKey
,
time
.
toString
());
}
packages/flutter_tools/lib/src/reporting/first_run.dart
View file @
4a730509
...
...
@@ -61,10 +61,10 @@ class FirstRunMessenger {
/// that the license terms are not printed during a `flutter upgrade`, until the
/// user manually runs the tool.
bool shouldDisplayLicenseTerms() {
if (_persistentToolState.
r
edisplayWelcomeMessage == false) {
if (_persistentToolState.
shouldR
edisplayWelcomeMessage == false) {
return false;
}
final String oldHash = _persistentToolState.lastActiveLicenseTerms;
final String oldHash = _persistentToolState.lastActiveLicenseTerms
Hash
;
return oldHash != _currentHash;
}
...
...
packages/flutter_tools/test/general.shard/devtools_launcher_test.dart
View file @
4a730509
...
...
@@ -235,7 +235,7 @@ void main() {
});
testWithoutContext
(
'DevtoolsLauncher does not activate DevTools if it was recently activated'
,
()
async
{
persistentToolState
.
lastDevToolsActivation
Time
=
DateTime
.
now
();
persistentToolState
.
lastDevToolsActivation
=
DateTime
.
now
();
final
DevtoolsLauncher
launcher
=
DevtoolsServerLauncher
(
pubExecutable:
'pub'
,
logger:
logger
,
...
...
packages/flutter_tools/test/general.shard/persistent_tool_state_test.dart
View file @
4a730509
...
...
@@ -2,8 +2,6 @@
// 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:file/memory.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
...
...
@@ -22,18 +20,18 @@ void main() {
directory:
directory
,
logger:
BufferLogger
.
test
(),
);
expect
(
state1
.
r
edisplayWelcomeMessage
,
null
);
expect
(
state1
.
shouldR
edisplayWelcomeMessage
,
null
);
state1
.
redisplayWelcomeMessage
=
true
;
expect
(
stateFile
.
existsSync
(),
true
);
expect
(
state1
.
r
edisplayWelcomeMessage
,
true
);
expect
(
state1
.
shouldR
edisplayWelcomeMessage
,
true
);
state1
.
redisplayWelcomeMessage
=
false
;
expect
(
state1
.
r
edisplayWelcomeMessage
,
false
);
expect
(
state1
.
shouldR
edisplayWelcomeMessage
,
false
);
final
PersistentToolState
state2
=
PersistentToolState
.
test
(
directory:
directory
,
logger:
BufferLogger
.
test
(),
);
expect
(
state2
.
r
edisplayWelcomeMessage
,
false
);
expect
(
state2
.
shouldR
edisplayWelcomeMessage
,
false
);
});
testWithoutContext
(
'channel versions can be cached and stored'
,
()
{
...
...
@@ -69,7 +67,7 @@ void main() {
);
final
DateTime
time
=
DateTime
.
now
();
state1
.
lastDevToolsActivation
Time
=
time
;
state1
.
lastDevToolsActivation
=
time
;
final
PersistentToolState
state2
=
PersistentToolState
.
test
(
directory:
directory
,
...
...
packages/flutter_tools/test/general.shard/reporting/first_run_test.dart
View file @
4a730509
...
...
@@ -50,8 +50,10 @@ void main() {
FirstRunMessenger
setUpFirstRunMessenger
(
{
bool
redisplayWelcomeMessage
,
bool
test
=
false
})
{
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
PersistentToolState
state
=
PersistentToolState
.
test
(
directory:
fileSystem
.
currentDirectory
,
logger:
BufferLogger
.
test
())
..
redisplayWelcomeMessage
=
redisplayWelcomeMessage
;
final
PersistentToolState
state
=
PersistentToolState
.
test
(
directory:
fileSystem
.
currentDirectory
,
logger:
BufferLogger
.
test
());
if
(
redisplayWelcomeMessage
!=
null
)
{
state
.
redisplayWelcomeMessage
=
redisplayWelcomeMessage
;
}
if
(
test
)
{
return
TestFirstRunMessenger
(
state
);
}
...
...
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