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
e6e14b0d
Unverified
Commit
e6e14b0d
authored
4 years ago
by
Christopher Fujino
Committed by
GitHub
4 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Have android validator suggest ANDROID_SDK_ROOT instead of deprecated ANDROID_HOME (#49846)
parent
db901ce5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
197 additions
and
82 deletions
+197
-82
android_sdk.dart
packages/flutter_tools/lib/src/android/android_sdk.dart
+22
-10
android_workflow.dart
packages/flutter_tools/lib/src/android/android_workflow.dart
+88
-38
cache.dart
packages/flutter_tools/lib/src/cache.dart
+1
-1
context_runner.dart
packages/flutter_tools/lib/src/context_runner.dart
+9
-1
globals.dart
packages/flutter_tools/lib/src/globals.dart
+7
-1
android_workflow_test.dart
...ols/test/general.shard/android/android_workflow_test.dart
+70
-31
No files found.
packages/flutter_tools/lib/src/android/android_sdk.dart
View file @
e6e14b0d
...
...
@@ -3,15 +3,17 @@
// found in the LICENSE file.
import
'package:meta/meta.dart'
;
import
'package:platform/platform.dart'
;
import
'../base/common.dart'
;
import
'../base/context.dart'
;
import
'../base/file_system.dart'
;
import
'../base/os.dart'
;
import
'../base/process.dart'
;
import
'../base/version.dart'
;
import
'../convert.dart'
;
import
'../globals.dart'
as
globals
;
import
'android_studio.dart'
as
android_studio
;
import
'android_studio.dart'
;
AndroidSdk
get
androidSdk
=>
context
.
get
<
AndroidSdk
>();
...
...
@@ -549,20 +551,25 @@ class AndroidSdk {
}
/// First try Java bundled with Android Studio, then sniff JAVA_HOME, then fallback to PATH.
static
String
findJavaBinary
()
{
if
(
android_studio
.
javaPath
!=
null
)
{
return
globals
.
fs
.
path
.
join
(
android_studio
.
javaPath
,
'bin'
,
'java'
);
static
String
findJavaBinary
({
@required
AndroidStudio
androidStudio
,
@required
FileSystem
fileSystem
,
@required
OperatingSystemUtils
operatingSystemUtils
,
@required
Platform
platform
,
})
{
if
(
androidStudio
?.
javaPath
!=
null
)
{
return
fileSystem
.
path
.
join
(
androidStudio
.
javaPath
,
'bin'
,
'java'
);
}
final
String
javaHomeEnv
=
globals
.
platform
.
environment
[
_javaHomeEnvironmentVariable
];
final
String
javaHomeEnv
=
platform
.
environment
[
_javaHomeEnvironmentVariable
];
if
(
javaHomeEnv
!=
null
)
{
// Trust JAVA_HOME.
return
globals
.
fs
.
path
.
join
(
javaHomeEnv
,
'bin'
,
'java'
);
return
fileSystem
.
path
.
join
(
javaHomeEnv
,
'bin'
,
'java'
);
}
// MacOS specific logic to avoid popping up a dialog window.
// See: http://stackoverflow.com/questions/14292698/how-do-i-check-if-the-java-jdk-is-installed-on-mac.
if
(
globals
.
platform
.
isMacOS
)
{
if
(
platform
.
isMacOS
)
{
try
{
final
String
javaHomeOutput
=
processUtils
.
runSync
(
<
String
>[
'/usr/libexec/java_home'
],
...
...
@@ -573,14 +580,14 @@ class AndroidSdk {
final
List
<
String
>
javaHomeOutputSplit
=
javaHomeOutput
.
split
(
'
\n
'
);
if
((
javaHomeOutputSplit
!=
null
)
&&
(
javaHomeOutputSplit
.
isNotEmpty
))
{
final
String
javaHome
=
javaHomeOutputSplit
[
0
].
trim
();
return
globals
.
fs
.
path
.
join
(
javaHome
,
'bin'
,
'java'
);
return
fileSystem
.
path
.
join
(
javaHome
,
'bin'
,
'java'
);
}
}
}
catch
(
_
)
{
/* ignore */
}
}
// Fallback to PATH based lookup.
return
globals
.
o
s
.
which
(
_javaExecutable
)?.
path
;
return
operatingSystemUtil
s
.
which
(
_javaExecutable
)?.
path
;
}
Map
<
String
,
String
>
_sdkManagerEnv
;
...
...
@@ -590,7 +597,12 @@ class AndroidSdk {
if
(
_sdkManagerEnv
==
null
)
{
// If we can locate Java, then add it to the path used to run the Android SDK manager.
_sdkManagerEnv
=
<
String
,
String
>{};
final
String
javaBinary
=
findJavaBinary
();
final
String
javaBinary
=
findJavaBinary
(
androidStudio:
globals
.
androidStudio
,
fileSystem:
globals
.
fs
,
operatingSystemUtils:
globals
.
os
,
platform:
globals
.
platform
,
);
if
(
javaBinary
!=
null
)
{
_sdkManagerEnv
[
'PATH'
]
=
globals
.
fs
.
path
.
dirname
(
javaBinary
)
+
globals
.
os
.
pathVarSeparator
+
...
...
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/android/android_workflow.dart
View file @
e6e14b0d
...
...
@@ -4,9 +4,16 @@
import
'dart:async'
;
import
'package:meta/meta.dart'
;
import
'package:platform/platform.dart'
;
import
'package:process/process.dart'
;
import
'../base/common.dart'
;
import
'../base/context.dart'
;
import
'../base/file_system.dart'
;
import
'../base/io.dart'
;
import
'../base/logger.dart'
;
import
'../base/os.dart'
;
import
'../base/process.dart'
;
import
'../base/user_messages.dart'
;
import
'../base/utils.dart'
;
...
...
@@ -15,6 +22,7 @@ import '../convert.dart';
import
'../doctor.dart'
;
import
'../globals.dart'
as
globals
;
import
'android_sdk.dart'
;
import
'android_studio.dart'
;
const
int
kAndroidSdkMinVersion
=
28
;
final
Version
kAndroidJavaMinVersion
=
Version
(
1
,
8
,
0
);
...
...
@@ -50,7 +58,37 @@ class AndroidWorkflow implements Workflow {
}
class
AndroidValidator
extends
DoctorValidator
{
AndroidValidator
()
:
super
(
'Android toolchain - develop for Android devices'
,);
AndroidValidator
({
@required
AndroidSdk
androidSdk
,
@required
AndroidStudio
androidStudio
,
@required
FileSystem
fileSystem
,
@required
Logger
logger
,
@required
Platform
platform
,
@required
ProcessManager
processManager
,
@required
UserMessages
userMessages
,
})
:
_androidSdk
=
androidSdk
,
_androidStudio
=
androidStudio
,
_fileSystem
=
fileSystem
,
_logger
=
logger
,
_operatingSystemUtils
=
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
logger
,
platform:
platform
,
processManager:
processManager
,
),
_platform
=
platform
,
_processManager
=
processManager
,
_userMessages
=
userMessages
,
super
(
'Android toolchain - develop for Android devices'
);
final
AndroidSdk
_androidSdk
;
final
AndroidStudio
_androidStudio
;
final
FileSystem
_fileSystem
;
final
Logger
_logger
;
final
OperatingSystemUtils
_operatingSystemUtils
;
final
Platform
_platform
;
final
ProcessManager
_processManager
;
final
UserMessages
_userMessages
;
@override
String
get
slowWarning
=>
'
${_task ?? 'This'}
is taking a long time...'
;
...
...
@@ -72,32 +110,32 @@ class AndroidValidator extends DoctorValidator {
Future
<
bool
>
_checkJavaVersion
(
String
javaBinary
,
List
<
ValidationMessage
>
messages
)
async
{
_task
=
'Checking Java status'
;
try
{
if
(!
globals
.
processManager
.
canRun
(
javaBinary
))
{
messages
.
add
(
ValidationMessage
.
error
(
userMessages
.
androidCantRunJavaBinary
(
javaBinary
)));
if
(!
_
processManager
.
canRun
(
javaBinary
))
{
messages
.
add
(
ValidationMessage
.
error
(
_
userMessages
.
androidCantRunJavaBinary
(
javaBinary
)));
return
false
;
}
String
javaVersionText
;
try
{
globals
.
printTrace
(
'java -version'
);
final
ProcessResult
result
=
await
globals
.
processManager
.
run
(<
String
>[
javaBinary
,
'-version'
]);
_logger
.
printTrace
(
'java -version'
);
final
ProcessResult
result
=
await
_
processManager
.
run
(<
String
>[
javaBinary
,
'-version'
]);
if
(
result
.
exitCode
==
0
)
{
final
List
<
String
>
versionLines
=
(
result
.
stderr
as
String
).
split
(
'
\n
'
);
javaVersionText
=
versionLines
.
length
>=
2
?
versionLines
[
1
]
:
versionLines
[
0
];
}
}
catch
(
error
)
{
globals
.
printTrace
(
error
.
toString
());
_logger
.
printTrace
(
error
.
toString
());
}
if
(
javaVersionText
==
null
||
javaVersionText
.
isEmpty
)
{
// Could not determine the java version.
messages
.
add
(
ValidationMessage
.
error
(
userMessages
.
androidUnknownJavaVersion
));
messages
.
add
(
ValidationMessage
.
error
(
_
userMessages
.
androidUnknownJavaVersion
));
return
false
;
}
final
Version
javaVersion
=
Version
.
parse
(
_extractJavaVersion
(
javaVersionText
));
if
(
javaVersion
<
kAndroidJavaMinVersion
)
{
messages
.
add
(
ValidationMessage
.
error
(
userMessages
.
androidJavaMinimumVersion
(
javaVersionText
)));
messages
.
add
(
ValidationMessage
.
error
(
_
userMessages
.
androidJavaMinimumVersion
(
javaVersionText
)));
return
false
;
}
messages
.
add
(
ValidationMessage
(
userMessages
.
androidJavaVersion
(
javaVersionText
)));
messages
.
add
(
ValidationMessage
(
_
userMessages
.
androidJavaVersion
(
javaVersionText
)));
return
true
;
}
finally
{
_task
=
null
;
...
...
@@ -108,72 +146,79 @@ class AndroidValidator extends DoctorValidator {
Future
<
ValidationResult
>
validate
()
async
{
final
List
<
ValidationMessage
>
messages
=
<
ValidationMessage
>[];
if
(
androidSdk
==
null
)
{
if
(
_
androidSdk
==
null
)
{
// No Android SDK found.
if
(
globals
.
platform
.
environment
.
containsKey
(
kAndroidHome
))
{
final
String
androidHomeDir
=
globals
.
platform
.
environment
[
kAndroidHome
];
messages
.
add
(
ValidationMessage
.
error
(
userMessages
.
androidBadSdkDir
(
kAndroidHome
,
androidHomeDir
)));
if
(
_
platform
.
environment
.
containsKey
(
kAndroidHome
))
{
final
String
androidHomeDir
=
_
platform
.
environment
[
kAndroidHome
];
messages
.
add
(
ValidationMessage
.
error
(
_
userMessages
.
androidBadSdkDir
(
kAndroidHome
,
androidHomeDir
)));
}
else
{
messages
.
add
(
ValidationMessage
.
error
(
userMessages
.
androidMissingSdkInstructions
(
kAndroidHome
)));
// Instruct user to set [kAndroidSdkRoot] and not deprecated [kAndroidHome]
// See https://github.com/flutter/flutter/issues/39301
messages
.
add
(
ValidationMessage
.
error
(
_userMessages
.
androidMissingSdkInstructions
(
kAndroidSdkRoot
)));
}
return
ValidationResult
(
ValidationType
.
missing
,
messages
);
}
if
(
androidSdk
.
licensesAvailable
&&
!
androidSdk
.
platformToolsAvailable
)
{
messages
.
add
(
ValidationMessage
.
hint
(
userMessages
.
androidSdkLicenseOnly
(
kAndroidHome
)));
if
(
_androidSdk
.
licensesAvailable
&&
!
_
androidSdk
.
platformToolsAvailable
)
{
messages
.
add
(
ValidationMessage
.
hint
(
_
userMessages
.
androidSdkLicenseOnly
(
kAndroidHome
)));
return
ValidationResult
(
ValidationType
.
partial
,
messages
);
}
messages
.
add
(
ValidationMessage
(
userMessages
.
androidSdkLocation
(
androidSdk
.
directory
)));
messages
.
add
(
ValidationMessage
(
_userMessages
.
androidSdkLocation
(
_
androidSdk
.
directory
)));
messages
.
add
(
ValidationMessage
(
androidSdk
.
ndk
==
null
?
userMessages
.
androidMissingNdk
:
userMessages
.
androidNdkLocation
(
androidSdk
.
ndk
.
directory
)));
messages
.
add
(
ValidationMessage
(
_
androidSdk
.
ndk
==
null
?
_
userMessages
.
androidMissingNdk
:
_userMessages
.
androidNdkLocation
(
_
androidSdk
.
ndk
.
directory
)));
String
sdkVersionText
;
if
(
androidSdk
.
latestVersion
!=
null
)
{
if
(
androidSdk
.
latestVersion
.
sdkLevel
<
28
||
androidSdk
.
latestVersion
.
buildToolsVersion
<
kAndroidSdkBuildToolsMinVersion
)
{
if
(
_
androidSdk
.
latestVersion
!=
null
)
{
if
(
_androidSdk
.
latestVersion
.
sdkLevel
<
28
||
_
androidSdk
.
latestVersion
.
buildToolsVersion
<
kAndroidSdkBuildToolsMinVersion
)
{
messages
.
add
(
ValidationMessage
.
error
(
userMessages
.
androidSdkBuildToolsOutdated
(
androidSdk
.
sdkManagerPath
,
kAndroidSdkMinVersion
,
kAndroidSdkBuildToolsMinVersion
.
toString
())),
_userMessages
.
androidSdkBuildToolsOutdated
(
_
androidSdk
.
sdkManagerPath
,
kAndroidSdkMinVersion
,
kAndroidSdkBuildToolsMinVersion
.
toString
())),
);
return
ValidationResult
(
ValidationType
.
missing
,
messages
);
}
sdkVersionText
=
userMessages
.
androidStatusInfo
(
androidSdk
.
latestVersion
.
buildToolsVersionName
);
sdkVersionText
=
_userMessages
.
androidStatusInfo
(
_
androidSdk
.
latestVersion
.
buildToolsVersionName
);
messages
.
add
(
ValidationMessage
(
userMessages
.
androidSdkPlatformToolsVersion
(
androidSdk
.
latestVersion
.
platformName
,
androidSdk
.
latestVersion
.
buildToolsVersionName
)));
messages
.
add
(
ValidationMessage
(
_
userMessages
.
androidSdkPlatformToolsVersion
(
_
androidSdk
.
latestVersion
.
platformName
,
_
androidSdk
.
latestVersion
.
buildToolsVersionName
)));
}
else
{
messages
.
add
(
ValidationMessage
.
error
(
userMessages
.
androidMissingSdkInstructions
(
kAndroidHome
)));
messages
.
add
(
ValidationMessage
.
error
(
_
userMessages
.
androidMissingSdkInstructions
(
kAndroidHome
)));
}
if
(
globals
.
platform
.
environment
.
containsKey
(
kAndroidHome
))
{
final
String
androidHomeDir
=
globals
.
platform
.
environment
[
kAndroidHome
];
if
(
_
platform
.
environment
.
containsKey
(
kAndroidHome
))
{
final
String
androidHomeDir
=
_
platform
.
environment
[
kAndroidHome
];
messages
.
add
(
ValidationMessage
(
'
$kAndroidHome
=
$androidHomeDir
'
));
}
if
(
globals
.
platform
.
environment
.
containsKey
(
kAndroidSdkRoot
))
{
final
String
androidSdkRoot
=
globals
.
platform
.
environment
[
kAndroidSdkRoot
];
if
(
_
platform
.
environment
.
containsKey
(
kAndroidSdkRoot
))
{
final
String
androidSdkRoot
=
_
platform
.
environment
[
kAndroidSdkRoot
];
messages
.
add
(
ValidationMessage
(
'
$kAndroidSdkRoot
=
$androidSdkRoot
'
));
}
final
List
<
String
>
validationResult
=
androidSdk
.
validateSdkWellFormed
();
final
List
<
String
>
validationResult
=
_
androidSdk
.
validateSdkWellFormed
();
if
(
validationResult
.
isNotEmpty
)
{
// Android SDK is not functional.
messages
.
addAll
(
validationResult
.
map
<
ValidationMessage
>((
String
message
)
{
return
ValidationMessage
.
error
(
message
);
}));
messages
.
add
(
ValidationMessage
(
userMessages
.
androidSdkInstallHelp
));
messages
.
add
(
ValidationMessage
(
_
userMessages
.
androidSdkInstallHelp
));
return
ValidationResult
(
ValidationType
.
partial
,
messages
,
statusInfo:
sdkVersionText
);
}
// Now check for the JDK.
final
String
javaBinary
=
AndroidSdk
.
findJavaBinary
();
final
String
javaBinary
=
AndroidSdk
.
findJavaBinary
(
androidStudio:
_androidStudio
,
fileSystem:
_fileSystem
,
operatingSystemUtils:
_operatingSystemUtils
,
platform:
_platform
,
);
if
(
javaBinary
==
null
)
{
messages
.
add
(
ValidationMessage
.
error
(
userMessages
.
androidMissingJdk
));
messages
.
add
(
ValidationMessage
.
error
(
_
userMessages
.
androidMissingJdk
));
return
ValidationResult
(
ValidationType
.
partial
,
messages
,
statusInfo:
sdkVersionText
);
}
messages
.
add
(
ValidationMessage
(
userMessages
.
androidJdkLocation
(
javaBinary
)));
messages
.
add
(
ValidationMessage
(
_
userMessages
.
androidJdkLocation
(
javaBinary
)));
// Check JDK version.
if
(!
await
_checkJavaVersion
(
javaBinary
,
messages
))
{
...
...
@@ -223,7 +268,12 @@ class AndroidLicenseValidator extends DoctorValidator {
}
Future
<
bool
>
_checkJavaVersionNoOutput
()
async
{
final
String
javaBinary
=
AndroidSdk
.
findJavaBinary
();
final
String
javaBinary
=
AndroidSdk
.
findJavaBinary
(
androidStudio:
globals
.
androidStudio
,
fileSystem:
globals
.
fs
,
operatingSystemUtils:
globals
.
os
,
platform:
globals
.
platform
,
);
if
(
javaBinary
==
null
)
{
return
false
;
}
...
...
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/cache.dart
View file @
e6e14b0d
...
...
@@ -101,7 +101,7 @@ class Cache {
})
:
_rootOverride
=
rootOverride
,
_logger
=
logger
??
globals
.
logger
,
_fileSystem
=
fileSystem
??
globals
.
fs
,
_platform
=
platform
??
globals
.
platform
,
_platform
=
platform
??
globals
.
platform
,
_osUtils
=
osUtils
??
globals
.
os
{
// TODO(zra): Move to initializer list once logger and platform parameters
// are required.
...
...
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/context_runner.dart
View file @
e6e14b0d
...
...
@@ -69,7 +69,15 @@ Future<T> runInContext<T>(
AndroidLicenseValidator:
()
=>
AndroidLicenseValidator
(),
AndroidSdk:
AndroidSdk
.
locateAndroidSdk
,
AndroidStudio:
AndroidStudio
.
latestValid
,
AndroidValidator:
()
=>
AndroidValidator
(),
AndroidValidator:
()
=>
AndroidValidator
(
androidStudio:
globals
.
androidStudio
,
androidSdk:
globals
.
androidSdk
,
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
processManager:
globals
.
processManager
,
userMessages:
globals
.
userMessages
,
),
AndroidWorkflow:
()
=>
AndroidWorkflow
(),
ApplicationPackageFactory:
()
=>
ApplicationPackageFactory
(),
Artifacts:
()
=>
CachedArtifacts
(
...
...
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/globals.dart
View file @
e6e14b0d
...
...
@@ -5,6 +5,8 @@
import
'package:platform/platform.dart'
;
import
'package:process/process.dart'
;
import
'android/android_sdk.dart'
;
import
'android/android_studio.dart'
;
import
'artifacts.dart'
;
import
'base/config.dart'
;
import
'base/context.dart'
;
...
...
@@ -14,6 +16,7 @@ import 'base/io.dart';
import
'base/logger.dart'
;
import
'base/os.dart'
;
import
'base/terminal.dart'
;
import
'base/user_messages.dart'
;
import
'cache.dart'
;
import
'ios/mac.dart'
;
import
'macos/xcode.dart'
;
...
...
@@ -53,9 +56,12 @@ const Platform _kLocalPlatform = LocalPlatform();
Platform
get
platform
=>
context
.
get
<
Platform
>()
??
_kLocalPlatform
;
Xcode
get
xcode
=>
context
.
get
<
Xcode
>();
AndroidStudio
get
androidStudio
=>
context
.
get
<
AndroidStudio
>();
AndroidSdk
get
androidSdk
=>
context
.
get
<
AndroidSdk
>();
FlutterVersion
get
flutterVersion
=>
context
.
get
<
FlutterVersion
>();
IMobileDevice
get
iMobileDevice
=>
context
.
get
<
IMobileDevice
>();
UserMessages
get
userMessages
=>
context
.
get
<
UserMessages
>();
Xcode
get
xcode
=>
context
.
get
<
Xcode
>();
XCDevice
get
xcdevice
=>
context
.
get
<
XCDevice
>();
...
...
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/android/android_workflow_test.dart
View file @
e6e14b0d
...
...
@@ -7,12 +7,14 @@ import 'dart:async';
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/android/android_sdk.dart'
;
import
'package:flutter_tools/src/android/android_workflow.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
show
AnsiTerminal
,
OutputPreferences
;
import
'package:flutter_tools/src/base/user_messages.dart'
;
import
'package:flutter_tools/src/base/version.dart'
;
import
'package:flutter_tools/src/doctor.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'package:mockito/mockito.dart'
;
import
'package:platform/platform.dart'
;
...
...
@@ -23,19 +25,30 @@ import '../../src/context.dart';
import
'../../src/mocks.dart'
show
MockAndroidSdk
,
MockProcess
,
MockProcessManager
,
MockStdio
;
class
MockAndroidSdkVersion
extends
Mock
implements
AndroidSdkVersion
{}
class
MockOperatingSystemUtils
extends
Mock
implements
OperatingSystemUtils
{}
void
main
(
)
{
AndroidSdk
sdk
;
Logger
logger
;
MemoryFileSystem
fs
;
MockProcessManager
processManager
;
MockStdio
stdio
;
UserMessages
userMessages
;
setUp
(()
{
sdk
=
MockAndroidSdk
();
fs
=
MemoryFileSystem
();
fs
.
directory
(
'/home/me'
).
createSync
(
recursive:
true
);
logger
=
BufferLogger
(
terminal:
AnsiTerminal
(
stdio:
null
,
platform:
const
LocalPlatform
(),
),
outputPreferences:
OutputPreferences
.
test
(),
);
processManager
=
MockProcessManager
();
stdio
=
MockStdio
();
userMessages
=
UserMessages
();
});
MockProcess
Function
(
List
<
String
>)
processMetaFactory
(
List
<
String
>
stdout
)
{
...
...
@@ -208,24 +221,26 @@ void main() {
Stdio:
()
=>
stdio
,
}));
test
Using
Context
(
'detects license-only SDK installation'
,
()
async
{
test
Without
Context
(
'detects license-only SDK installation'
,
()
async
{
when
(
sdk
.
licensesAvailable
).
thenReturn
(
true
);
when
(
sdk
.
platformToolsAvailable
).
thenReturn
(
false
);
final
ValidationResult
validationResult
=
await
AndroidValidator
().
validate
();
final
ValidationResult
validationResult
=
await
AndroidValidator
(
androidStudio:
null
,
androidSdk:
sdk
,
fileSystem:
fs
,
logger:
logger
,
processManager:
processManager
,
platform:
FakePlatform
()..
environment
=
<
String
,
String
>{
'HOME'
:
'/home/me'
},
userMessages:
userMessages
,
).
validate
();
expect
(
validationResult
.
type
,
ValidationType
.
partial
);
expect
(
validationResult
.
messages
.
last
.
message
,
userMessages
.
androidSdkLicenseOnly
(
kAndroidHome
),
);
},
overrides:
Map
<
Type
,
Generator
>.
unmodifiable
(<
Type
,
Generator
>{
AndroidSdk:
()
=>
sdk
,
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
processManager
,
Platform:
()
=>
FakePlatform
()..
environment
=
<
String
,
String
>{
'HOME'
:
'/home/me'
},
Stdio:
()
=>
stdio
,
}));
});
test
UsingContext
(
'detects mini
um required SDK and buildtools'
,
()
async
{
test
WithoutContext
(
'detects minim
um required SDK and buildtools'
,
()
async
{
final
AndroidSdkVersion
mockSdkVersion
=
MockAndroidSdkVersion
();
when
(
sdk
.
licensesAvailable
).
thenReturn
(
true
);
when
(
sdk
.
platformToolsAvailable
).
thenReturn
(
true
);
...
...
@@ -236,13 +251,24 @@ void main() {
when
(
sdk
.
sdkManagerPath
).
thenReturn
(
'/foo/bar/sdkmanager'
);
when
(
sdk
.
latestVersion
).
thenReturn
(
mockSdkVersion
);
when
(
sdk
.
validateSdkWellFormed
()).
thenReturn
(<
String
>[]);
when
(
processManager
.
runSync
(<
String
>[
'which'
,
'java'
])).
thenReturn
(
ProcessResult
(
123
,
1
,
''
,
''
));
final
String
errorMessage
=
userMessages
.
androidSdkBuildToolsOutdated
(
sdk
.
sdkManagerPath
,
kAndroidSdkMinVersion
,
kAndroidSdkBuildToolsMinVersion
.
toString
(),
);
ValidationResult
validationResult
=
await
AndroidValidator
().
validate
();
final
AndroidValidator
androidValidator
=
AndroidValidator
(
androidStudio:
null
,
androidSdk:
sdk
,
fileSystem:
fs
,
logger:
logger
,
processManager:
processManager
,
platform:
FakePlatform
()..
environment
=
<
String
,
String
>{
'HOME'
:
'/home/me'
},
userMessages:
userMessages
,
);
ValidationResult
validationResult
=
await
androidValidator
.
validate
();
expect
(
validationResult
.
type
,
ValidationType
.
missing
);
expect
(
validationResult
.
messages
.
last
.
message
,
...
...
@@ -253,7 +279,7 @@ void main() {
when
(
mockSdkVersion
.
sdkLevel
).
thenReturn
(
28
);
when
(
mockSdkVersion
.
buildToolsVersion
).
thenReturn
(
Version
(
28
,
0
,
2
));
validationResult
=
await
AndroidValidator
()
.
validate
();
validationResult
=
await
androidValidator
.
validate
();
expect
(
validationResult
.
type
,
ValidationType
.
missing
);
expect
(
validationResult
.
messages
.
last
.
message
,
...
...
@@ -265,21 +291,15 @@ void main() {
when
(
mockSdkVersion
.
sdkLevel
).
thenReturn
(
kAndroidSdkMinVersion
);
when
(
mockSdkVersion
.
buildToolsVersion
).
thenReturn
(
kAndroidSdkBuildToolsMinVersion
);
validationResult
=
await
AndroidValidator
()
.
validate
();
validationResult
=
await
androidValidator
.
validate
();
expect
(
validationResult
.
type
,
ValidationType
.
partial
);
// No Java binary
expect
(
validationResult
.
messages
.
any
((
ValidationMessage
message
)
=>
message
.
message
==
errorMessage
),
isFalse
,
);
},
overrides:
Map
<
Type
,
Generator
>.
unmodifiable
(<
Type
,
Generator
>{
AndroidSdk:
()
=>
sdk
,
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
processManager
,
Platform:
()
=>
FakePlatform
()..
environment
=
<
String
,
String
>{
'HOME'
:
'/home/me'
},
Stdio:
()
=>
stdio
,
}));
});
test
Using
Context
(
'detects minimum required java version'
,
()
async
{
test
Without
Context
(
'detects minimum required java version'
,
()
async
{
final
AndroidSdkVersion
mockSdkVersion
=
MockAndroidSdkVersion
();
// Mock a pass through scenario to reach _checkJavaVersion()
...
...
@@ -293,22 +313,41 @@ void main() {
//Test with older version of JDK
const
String
javaVersionText
=
'openjdk version "1.7.0_212"'
;
when
(
globals
.
processManager
.
run
(
argThat
(
contains
(
'-version'
)))).
thenAnswer
((
_
)
=>
when
(
processManager
.
run
(
argThat
(
contains
(
'-version'
)))).
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
0
,
null
,
javaVersionText
)));
final
String
errorMessage
=
userMessages
.
androidJavaMinimumVersion
(
javaVersionText
);
final
ValidationResult
validationResult
=
await
AndroidValidator
().
validate
();
final
ValidationResult
validationResult
=
await
AndroidValidator
(
androidSdk:
sdk
,
androidStudio:
null
,
fileSystem:
fs
,
logger:
logger
,
platform:
FakePlatform
()..
environment
=
<
String
,
String
>{
'HOME'
:
'/home/me'
,
'JAVA_HOME'
:
'home/java'
},
processManager:
processManager
,
userMessages:
userMessages
,
).
validate
();
expect
(
validationResult
.
type
,
ValidationType
.
partial
);
expect
(
validationResult
.
messages
.
last
.
message
,
errorMessage
,
);
},
overrides:
Map
<
Type
,
Generator
>.
unmodifiable
(<
Type
,
Generator
>{
AndroidSdk:
()
=>
sdk
,
FileSystem:
()
=>
fs
,
Platform:
()
=>
FakePlatform
()..
environment
=
<
String
,
String
>{
'HOME'
:
'/home/me'
,
'JAVA_HOME'
:
'home/java'
},
ProcessManager:
()
=>
processManager
,
Stdio:
()
=>
stdio
,
}));
});
testWithoutContext
(
'Mentions `kAndroidSdkRoot if user has no AndroidSdk`'
,
()
async
{
final
ValidationResult
validationResult
=
await
AndroidValidator
(
androidSdk:
null
,
androidStudio:
null
,
fileSystem:
fs
,
logger:
logger
,
platform:
FakePlatform
()..
environment
=
<
String
,
String
>{
'HOME'
:
'/home/me'
,
'JAVA_HOME'
:
'home/java'
},
processManager:
processManager
,
userMessages:
userMessages
,
).
validate
();
expect
(
validationResult
.
messages
.
any
(
(
ValidationMessage
message
)
=>
message
.
message
.
contains
(
kAndroidSdkRoot
)
),
true
,
);
});
}
This diff is collapsed.
Click to expand it.
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