mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 23:51:55 +08:00
[pigeon] Added error-prone to CI and fixed its issue. (#312)
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
## 0.1.23
|
||||
|
||||
* More Java linter and linter fixes.
|
||||
|
||||
## 0.1.22
|
||||
|
||||
* Java code generator enhancements:
|
||||
|
1
packages/pigeon/ci/.gitignore
vendored
Normal file
1
packages/pigeon/ci/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*
|
@ -65,9 +65,9 @@ if (replyMap == null) {
|
||||
\t\tdetails: null,
|
||||
\t);
|
||||
} else if (replyMap['error'] != null) {
|
||||
\tfinal Map<Object$nullTag, Object$nullTag> error = replyMap['${Keys.error}'] as Map<Object$nullTag, Object$nullTag>;
|
||||
\tfinal Map<Object$nullTag, Object$nullTag> error = (replyMap['${Keys.error}'] as Map<Object$nullTag, Object$nullTag>$nullTag)$unwrapOperator;
|
||||
\tthrow PlatformException(
|
||||
\t\tcode: error['${Keys.errorCode}'] as String,
|
||||
\t\tcode: (error['${Keys.errorCode}'] as String$nullTag)$unwrapOperator,
|
||||
\t\tmessage: error['${Keys.errorMessage}'] as String$nullTag,
|
||||
\t\tdetails: error['${Keys.errorDetails}'],
|
||||
\t);
|
||||
@ -161,10 +161,10 @@ void _writeFlutterApi(
|
||||
} else {
|
||||
indent.writeln('final $returnType output = $call;');
|
||||
}
|
||||
const String returnExpresion = 'output.encode()';
|
||||
const String returnExpression = 'output.encode()';
|
||||
final String returnStatement = isMockHandler
|
||||
? 'return <Object$nullTag, Object$nullTag>{\'${Keys.result}\': $returnExpresion};'
|
||||
: 'return $returnExpresion;';
|
||||
? 'return <Object$nullTag, Object$nullTag>{\'${Keys.result}\': $returnExpression};'
|
||||
: 'return $returnExpression;';
|
||||
indent.writeln(returnStatement);
|
||||
}
|
||||
});
|
||||
@ -197,7 +197,7 @@ void generateDart(DartOptions opt, Root root, StringSink sink) {
|
||||
indent.writeln('// $generatedCodeWarning');
|
||||
indent.writeln('// $seeAlsoWarning');
|
||||
indent.writeln(
|
||||
'// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import',
|
||||
'// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators',
|
||||
);
|
||||
indent.writeln('// @dart = ${opt.isNullSafe ? '2.12' : '2.8'}');
|
||||
indent.writeln('import \'dart:async\';');
|
||||
|
@ -8,7 +8,7 @@ import 'dart:mirrors';
|
||||
import 'ast.dart';
|
||||
|
||||
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
||||
const String pigeonVersion = '0.1.22';
|
||||
const String pigeonVersion = '0.1.23';
|
||||
|
||||
/// Read all the content from [stdin] to a String.
|
||||
String readStdin() {
|
||||
|
@ -56,7 +56,7 @@ void _writeHostApi(Indent indent, Api api) {
|
||||
}
|
||||
indent.addln('');
|
||||
indent.writeln(
|
||||
'/** Sets up an instance of `${api.name}` to handle messages through the `binaryMessenger` */');
|
||||
'/** Sets up an instance of `${api.name}` to handle messages through the `binaryMessenger`. */');
|
||||
indent.write(
|
||||
'static void setup(BinaryMessenger binaryMessenger, ${api.name} api) ');
|
||||
indent.scoped('{', '}', () {
|
||||
@ -108,7 +108,7 @@ void _writeHostApi(Indent indent, Api api) {
|
||||
'wrapped.put("${Keys.result}", output.toMap());');
|
||||
}
|
||||
});
|
||||
indent.write('catch (Exception exception) ');
|
||||
indent.write('catch (Error | RuntimeException exception) ');
|
||||
indent.scoped('{', '}', () {
|
||||
indent.writeln(
|
||||
'wrapped.put("${Keys.error}", wrapError(exception));');
|
||||
@ -298,7 +298,7 @@ void generateJava(JavaOptions options, Root root, StringSink sink) {
|
||||
}
|
||||
|
||||
indent.format('''
|
||||
private static Map<String, Object> wrapError(Exception exception) {
|
||||
private static Map<String, Object> wrapError(Throwable exception) {
|
||||
\tMap<String, Object> errorMap = new HashMap<>();
|
||||
\terrorMap.put("${Keys.errorMessage}", exception.toString());
|
||||
\terrorMap.put("${Keys.errorCode}", exception.getClass().getSimpleName());
|
||||
|
@ -305,7 +305,7 @@ options:
|
||||
..addOption('objc_prefix',
|
||||
help: 'Prefix for generated Objective-C classes and protocols.');
|
||||
|
||||
/// Convert command-line arugments to [PigeonOptions].
|
||||
/// Convert command-line arguments to [PigeonOptions].
|
||||
static PigeonOptions parseArgs(List<String> args) {
|
||||
final ArgResults results = _argParser.parse(args);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: pigeon
|
||||
version: 0.1.22 # This must match the version in lib/generator_tools.dart
|
||||
version: 0.1.23 # This must match the version in lib/generator_tools.dart
|
||||
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
||||
homepage: https://github.com/flutter/packages/tree/master/packages/pigeon
|
||||
dependencies:
|
||||
|
@ -11,6 +11,16 @@ set -ex
|
||||
JAVA_LINTER=checkstyle-8.41-all.jar
|
||||
JAVA_FORMATTER=google-java-format-1.3-all-deps.jar
|
||||
GOOGLE_CHECKS=google_checks.xml
|
||||
JAVA_ERROR_PRONE=error_prone_core-2.5.1-with-dependencies.jar
|
||||
DATAFLOW_SHADED=dataflow-shaded-3.7.1.jar
|
||||
JFORMAT_STRING=jFormatString-3.0.0.jar
|
||||
JAVA_VERSION=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
|
||||
JAVAC_JAR=javac-9+181-r4173-1.jar
|
||||
if [ $JAVA_VERSION == "8" ]; then
|
||||
JAVAC_BOOTCLASSPATH="-J-Xbootclasspath/p:ci/$JAVAC_JAR"
|
||||
else
|
||||
JAVAC_BOOTCLASSPATH=
|
||||
fi
|
||||
|
||||
# TODO(blasten): Enable on stable when possible.
|
||||
# https://github.com/flutter/flutter/issues/75187
|
||||
@ -72,17 +82,21 @@ test_pigeon_android() {
|
||||
--input $1 \
|
||||
--dart_out $temp_dir/pigeon.dart \
|
||||
--java_out $temp_dir/Pigeon.java \
|
||||
--java_package foo
|
||||
|
||||
if ! javac $temp_dir/Pigeon.java \
|
||||
-Xlint:unchecked \
|
||||
-classpath "$flutter_bin/cache/artifacts/engine/android-x64/flutter.jar"; then
|
||||
java -jar ci/$JAVA_FORMATTER --replace "$temp_dir/Pigeon.java"
|
||||
java -jar ci/$JAVA_LINTER -c "ci/$GOOGLE_CHECKS" "$temp_dir/Pigeon.java"
|
||||
if ! javac \
|
||||
$JAVAC_BOOTCLASSPATH \
|
||||
-XDcompilePolicy=simple \
|
||||
-processorpath "ci/$JAVA_ERROR_PRONE:ci/$DATAFLOW_SHADED:ci/$JFORMAT_STRING" \
|
||||
'-Xplugin:ErrorProne -Xep:CatchingUnchecked:ERROR' \
|
||||
-classpath "$flutter_bin/cache/artifacts/engine/android-x64/flutter.jar" \
|
||||
$temp_dir/Pigeon.java; then
|
||||
echo "javac $temp_dir/Pigeon.java failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
java -jar $JAVA_FORMATTER $temp_dir/Pigeon.java > $temp_dir/Pigeon.java
|
||||
java -jar $JAVA_LINTER -c $GOOGLE_CHECKS $temp_dir/Pigeon.java
|
||||
|
||||
dartfmt -w $temp_dir/pigeon.dart
|
||||
dartanalyzer $temp_dir/pigeon.dart --fatal-infos --fatal-warnings --packages ./e2e_tests/test_objc/.packages
|
||||
|
||||
@ -108,15 +122,28 @@ test_null_safe_dart() {
|
||||
###############################################################################
|
||||
# Get java linter / formatter
|
||||
###############################################################################
|
||||
if [ ! -f "$JAVA_LINTER" ]; then
|
||||
curl -L https://github.com/checkstyle/checkstyle/releases/download/checkstyle-8.41/$JAVA_LINTER > $JAVA_LINTER
|
||||
if [ ! -f "ci/$JAVA_LINTER" ]; then
|
||||
curl -L https://github.com/checkstyle/checkstyle/releases/download/checkstyle-8.41/$JAVA_LINTER > "ci/$JAVA_LINTER"
|
||||
fi
|
||||
if [ ! -f "$JAVA_FORMATTER" ]; then
|
||||
curl -L https://github.com/google/google-java-format/releases/download/google-java-format-1.3/$JAVA_FORMATTER > $JAVA_FORMATTER
|
||||
if [ ! -f "ci/$JAVA_FORMATTER" ]; then
|
||||
curl -L https://github.com/google/google-java-format/releases/download/google-java-format-1.3/$JAVA_FORMATTER > "ci/$JAVA_FORMATTER"
|
||||
fi
|
||||
if [ ! -f "$GOOGLE_CHECKS" ]; then
|
||||
curl -L https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/$GOOGLE_CHECKS > $GOOGLE_CHECKS
|
||||
if [ ! -f "ci/$GOOGLE_CHECKS" ]; then
|
||||
curl -L https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/$GOOGLE_CHECKS > "ci/$GOOGLE_CHECKS"
|
||||
fi
|
||||
if [ ! -f "ci/$JAVA_ERROR_PRONE" ]; then
|
||||
curl https://repo1.maven.org/maven2/com/google/errorprone/error_prone_core/2.5.1/$JAVA_ERROR_PRONE > "ci/$JAVA_ERROR_PRONE"
|
||||
fi
|
||||
if [ ! -f "ci/$DATAFLOW_SHADED" ]; then
|
||||
curl https://repo1.maven.org/maven2/org/checkerframework/dataflow-shaded/3.7.1/$DATAFLOW_SHADED > "ci/$DATAFLOW_SHADED"
|
||||
fi
|
||||
if [ ! -f "ci/$JFORMAT_STRING" ]; then
|
||||
curl https://repo1.maven.org/maven2/com/google/code/findbugs/jFormatString/3.0.0/$JFORMAT_STRING > "ci/$JFORMAT_STRING"
|
||||
fi
|
||||
if [ ! -f "ci/$JAVAC_JAR" ]; then
|
||||
curl https://repo1.maven.org/maven2/com/google/errorprone/javac/9+181-r4173-1/$JAVAC_JAR > "ci/$JAVAC_JAR"
|
||||
fi
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Dart analysis and unit tests
|
||||
|
@ -238,7 +238,7 @@ void main() {
|
||||
expect(results.errors.length, 1);
|
||||
});
|
||||
|
||||
test('null saftey flag', () {
|
||||
test('null safety flag', () {
|
||||
final PigeonOptions results =
|
||||
Pigeon.parseArgs(<String>['--dart_null_safety']);
|
||||
expect(results.dartOptions.isNullSafe, true);
|
||||
|
Reference in New Issue
Block a user