[tool] Move Java functions to their own file (#126086)
This is the first step in unifying Java-finding logic across the tool. If curious, see #126029 for an example of what all the changes will probably entail. Moves java-related functionality like `AndroidSdk.findJavaHome` to a new class, `Java`. See tracking issue https://github.com/flutter/flutter/issues/126126 for more.
This commit is contained in:
@@ -7,6 +7,7 @@ import 'dart:io' as io show IOSink, ProcessSignal, Stdout, StdoutException;
|
||||
|
||||
import 'package:flutter_tools/src/android/android_sdk.dart';
|
||||
import 'package:flutter_tools/src/android/android_studio.dart';
|
||||
import 'package:flutter_tools/src/android/java.dart';
|
||||
import 'package:flutter_tools/src/base/bot_detector.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
@@ -588,6 +589,7 @@ class FakeFlutterProjectFactory implements FlutterProjectFactory {
|
||||
}
|
||||
|
||||
class FakeAndroidSdk extends Fake implements AndroidSdk {
|
||||
|
||||
@override
|
||||
late bool platformToolsAvailable;
|
||||
|
||||
@@ -602,3 +604,41 @@ class FakeAndroidStudio extends Fake implements AndroidStudio {
|
||||
@override
|
||||
String get javaPath => 'java';
|
||||
}
|
||||
|
||||
class FakeJava extends Fake implements Java {
|
||||
FakeJava({
|
||||
this.javaHome = '/android-studio/jbr',
|
||||
String binary = '/android-studio/jbr/bin/java',
|
||||
JavaVersion? version,
|
||||
bool canRun = true,
|
||||
}): binaryPath = binary,
|
||||
version = version ?? JavaVersion(
|
||||
longText: 'openjdk 19.0.2 2023-01-17',
|
||||
number: '19.0.2',
|
||||
),
|
||||
_environment = <String, String>{
|
||||
if (javaHome != null) 'JAVA_HOME': javaHome,
|
||||
'PATH': '/android-studio/jbr/bin',
|
||||
},
|
||||
_canRun = canRun;
|
||||
|
||||
@override
|
||||
String? javaHome;
|
||||
|
||||
@override
|
||||
String binaryPath;
|
||||
|
||||
final Map<String, String> _environment;
|
||||
final bool _canRun;
|
||||
|
||||
@override
|
||||
Map<String, String> get environment => _environment;
|
||||
|
||||
@override
|
||||
JavaVersion? version;
|
||||
|
||||
@override
|
||||
bool canRun() {
|
||||
return _canRun;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user