This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Use Android linter from cmdline-tools #28153
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ const LocalProcessManager processManager = LocalProcessManager(); | |
/// Java 1.8. | ||
Future<void> main(List<String> args) async { | ||
final ArgParser argParser = setupOptions(); | ||
await checkJava1_8(); | ||
final int exitCode = await runLint(argParser, argParser.parse(args)); | ||
exit(exitCode); | ||
} | ||
|
@@ -74,7 +73,7 @@ Future<int> runLint(ArgParser argParser, ArgResults argResults) async { | |
<!-- WILL AUTOMATICALLY FIND ALL .java FILES AND INCLUDE THEM HERE --> | ||
<project> | ||
<sdk dir="${androidSdkDir.path}" /> | ||
<module name="FlutterEngine" android="true" library="true" compile-sdk-version="android-P"> | ||
<module name="FlutterEngine" android="true" library="true" compile-sdk-version="android-S"> | ||
<manifest file="${path.join(androidDir.path, 'AndroidManifest.xml')}" /> | ||
'''); | ||
for (final FileSystemEntity entity in androidDir.listSync(recursive: true)) { | ||
|
@@ -89,12 +88,11 @@ Future<int> runLint(ArgParser argParser, ArgResults argResults) async { | |
</project> | ||
'''); | ||
await projectXml.close(); | ||
|
||
print('Wrote project.xml, starting lint...'); | ||
final List<String> lintArgs = <String>[ | ||
path.join(androidSdkDir.path, 'tools', 'bin', 'lint'), | ||
'--project', | ||
projectXmlPath, | ||
path.join(androidSdkDir.path, 'cmdline-tools', 'bin', 'lint'), | ||
'--project', projectXmlPath, | ||
'--compile-sdk-version', '31', | ||
'--showall', | ||
'--exitcode', // Set non-zero exit code on errors | ||
'-Wall', | ||
|
@@ -106,14 +104,13 @@ Future<int> runLint(ArgParser argParser, ArgResults argResults) async { | |
if (html) { | ||
lintArgs.addAll(<String>['--html', argResults['out'] as String]); | ||
} | ||
final String? javaHome = await getJavaHome(); | ||
final String javahome = getJavaHome(inArgument); | ||
print('Using JAVA_HOME=$javahome'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Is this print meant to be here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's intended. It helps inform the user of this script that this ENV variable is set. Particularly, relevant in CI. |
||
final Process lintProcess = await processManager.start( | ||
lintArgs, | ||
environment: javaHome != null | ||
? <String, String>{ | ||
'JAVA_HOME': javaHome, | ||
} | ||
: null, | ||
environment: <String, String>{ | ||
'JAVA_HOME': javahome, | ||
}, | ||
); | ||
lintProcess.stdout.pipe(stdout); | ||
lintProcess.stderr.pipe(stderr); | ||
|
@@ -166,50 +163,11 @@ ArgParser setupOptions() { | |
return argParser; | ||
} | ||
|
||
/// On macOS, we can try to find Java 1.8. | ||
/// | ||
/// Otherwise, default to whatever JAVA_HOME is already. | ||
Future<String?> getJavaHome() async { | ||
String getJavaHome(String src) { | ||
if (Platform.isMacOS) { | ||
final ProcessResult result = await processManager.run( | ||
<String>['/usr/libexec/java_home', '-v', '1.8', '-F'], | ||
); | ||
if (result.exitCode == 0) { | ||
return (result.stdout as String).trim(); | ||
} | ||
} | ||
return Platform.environment['JAVA_HOME']; | ||
} | ||
|
||
/// Checks that `java` points to Java 1.8. | ||
/// | ||
/// The SDK lint tool may not work with Java > 1.8. | ||
Future<void> checkJava1_8() async { | ||
print('Checking Java version...'); | ||
|
||
if (Platform.isMacOS) { | ||
final ProcessResult result = await processManager.run( | ||
<String>['/usr/libexec/java_home', '-v', '1.8', '-F'], | ||
); | ||
if (result.exitCode != 0) { | ||
print('Java 1.8 not available - the linter may not work properly.'); | ||
} | ||
return; | ||
} | ||
final ProcessResult javaResult = await processManager.run( | ||
<String>['java', '-version'], | ||
); | ||
if (javaResult.exitCode != 0) { | ||
print('Could not run "java -version". ' | ||
'Ensure Java is installed and available on your path.'); | ||
print(javaResult.stderr); | ||
} | ||
// `java -version` writes to stderr. | ||
final String javaVersionStdout = javaResult.stderr as String; | ||
if (!javaVersionStdout.contains('"1.8')) { | ||
print('The Android SDK tools may not work properly with your Java version. ' | ||
'If this process fails, please retry using Java 1.8.'); | ||
return path.normalize('$src/third_party/java/openjdk/Contents/Home/'); | ||
} | ||
return path.normalize('$src/third_party/java/openjdk/'); | ||
} | ||
|
||
/// The root directory of this project. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why the closing
was removed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The closing tag
</p>
isn't required. See this thread google/google-java-format#61