mirror of
https://github.com/flutter/packages.git
synced 2025-07-02 08:34:31 +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
|
## 0.1.22
|
||||||
|
|
||||||
* Java code generator enhancements:
|
* 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\tdetails: null,
|
||||||
\t);
|
\t);
|
||||||
} else if (replyMap['error'] != null) {
|
} 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(
|
\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\tmessage: error['${Keys.errorMessage}'] as String$nullTag,
|
||||||
\t\tdetails: error['${Keys.errorDetails}'],
|
\t\tdetails: error['${Keys.errorDetails}'],
|
||||||
\t);
|
\t);
|
||||||
@ -161,10 +161,10 @@ void _writeFlutterApi(
|
|||||||
} else {
|
} else {
|
||||||
indent.writeln('final $returnType output = $call;');
|
indent.writeln('final $returnType output = $call;');
|
||||||
}
|
}
|
||||||
const String returnExpresion = 'output.encode()';
|
const String returnExpression = 'output.encode()';
|
||||||
final String returnStatement = isMockHandler
|
final String returnStatement = isMockHandler
|
||||||
? 'return <Object$nullTag, Object$nullTag>{\'${Keys.result}\': $returnExpresion};'
|
? 'return <Object$nullTag, Object$nullTag>{\'${Keys.result}\': $returnExpression};'
|
||||||
: 'return $returnExpresion;';
|
: 'return $returnExpression;';
|
||||||
indent.writeln(returnStatement);
|
indent.writeln(returnStatement);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -197,7 +197,7 @@ void generateDart(DartOptions opt, Root root, StringSink sink) {
|
|||||||
indent.writeln('// $generatedCodeWarning');
|
indent.writeln('// $generatedCodeWarning');
|
||||||
indent.writeln('// $seeAlsoWarning');
|
indent.writeln('// $seeAlsoWarning');
|
||||||
indent.writeln(
|
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('// @dart = ${opt.isNullSafe ? '2.12' : '2.8'}');
|
||||||
indent.writeln('import \'dart:async\';');
|
indent.writeln('import \'dart:async\';');
|
||||||
|
@ -8,7 +8,7 @@ import 'dart:mirrors';
|
|||||||
import 'ast.dart';
|
import 'ast.dart';
|
||||||
|
|
||||||
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
/// 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.
|
/// Read all the content from [stdin] to a String.
|
||||||
String readStdin() {
|
String readStdin() {
|
||||||
|
@ -56,7 +56,7 @@ void _writeHostApi(Indent indent, Api api) {
|
|||||||
}
|
}
|
||||||
indent.addln('');
|
indent.addln('');
|
||||||
indent.writeln(
|
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(
|
indent.write(
|
||||||
'static void setup(BinaryMessenger binaryMessenger, ${api.name} api) ');
|
'static void setup(BinaryMessenger binaryMessenger, ${api.name} api) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.scoped('{', '}', () {
|
||||||
@ -108,7 +108,7 @@ void _writeHostApi(Indent indent, Api api) {
|
|||||||
'wrapped.put("${Keys.result}", output.toMap());');
|
'wrapped.put("${Keys.result}", output.toMap());');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
indent.write('catch (Exception exception) ');
|
indent.write('catch (Error | RuntimeException exception) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.scoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'wrapped.put("${Keys.error}", wrapError(exception));');
|
'wrapped.put("${Keys.error}", wrapError(exception));');
|
||||||
@ -298,7 +298,7 @@ void generateJava(JavaOptions options, Root root, StringSink sink) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
indent.format('''
|
indent.format('''
|
||||||
private static Map<String, Object> wrapError(Exception exception) {
|
private static Map<String, Object> wrapError(Throwable exception) {
|
||||||
\tMap<String, Object> errorMap = new HashMap<>();
|
\tMap<String, Object> errorMap = new HashMap<>();
|
||||||
\terrorMap.put("${Keys.errorMessage}", exception.toString());
|
\terrorMap.put("${Keys.errorMessage}", exception.toString());
|
||||||
\terrorMap.put("${Keys.errorCode}", exception.getClass().getSimpleName());
|
\terrorMap.put("${Keys.errorCode}", exception.getClass().getSimpleName());
|
||||||
|
@ -305,7 +305,7 @@ options:
|
|||||||
..addOption('objc_prefix',
|
..addOption('objc_prefix',
|
||||||
help: 'Prefix for generated Objective-C classes and protocols.');
|
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) {
|
static PigeonOptions parseArgs(List<String> args) {
|
||||||
final ArgResults results = _argParser.parse(args);
|
final ArgResults results = _argParser.parse(args);
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: pigeon
|
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.
|
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
|
homepage: https://github.com/flutter/packages/tree/master/packages/pigeon
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -11,6 +11,16 @@ set -ex
|
|||||||
JAVA_LINTER=checkstyle-8.41-all.jar
|
JAVA_LINTER=checkstyle-8.41-all.jar
|
||||||
JAVA_FORMATTER=google-java-format-1.3-all-deps.jar
|
JAVA_FORMATTER=google-java-format-1.3-all-deps.jar
|
||||||
GOOGLE_CHECKS=google_checks.xml
|
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.
|
# TODO(blasten): Enable on stable when possible.
|
||||||
# https://github.com/flutter/flutter/issues/75187
|
# https://github.com/flutter/flutter/issues/75187
|
||||||
@ -72,17 +82,21 @@ test_pigeon_android() {
|
|||||||
--input $1 \
|
--input $1 \
|
||||||
--dart_out $temp_dir/pigeon.dart \
|
--dart_out $temp_dir/pigeon.dart \
|
||||||
--java_out $temp_dir/Pigeon.java \
|
--java_out $temp_dir/Pigeon.java \
|
||||||
|
--java_package foo
|
||||||
|
|
||||||
if ! javac $temp_dir/Pigeon.java \
|
java -jar ci/$JAVA_FORMATTER --replace "$temp_dir/Pigeon.java"
|
||||||
-Xlint:unchecked \
|
java -jar ci/$JAVA_LINTER -c "ci/$GOOGLE_CHECKS" "$temp_dir/Pigeon.java"
|
||||||
-classpath "$flutter_bin/cache/artifacts/engine/android-x64/flutter.jar"; then
|
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"
|
echo "javac $temp_dir/Pigeon.java failed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
dartfmt -w $temp_dir/pigeon.dart
|
||||||
dartanalyzer $temp_dir/pigeon.dart --fatal-infos --fatal-warnings --packages ./e2e_tests/test_objc/.packages
|
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
|
# Get java linter / formatter
|
||||||
###############################################################################
|
###############################################################################
|
||||||
if [ ! -f "$JAVA_LINTER" ]; then
|
if [ ! -f "ci/$JAVA_LINTER" ]; then
|
||||||
curl -L https://github.com/checkstyle/checkstyle/releases/download/checkstyle-8.41/$JAVA_LINTER > $JAVA_LINTER
|
curl -L https://github.com/checkstyle/checkstyle/releases/download/checkstyle-8.41/$JAVA_LINTER > "ci/$JAVA_LINTER"
|
||||||
fi
|
fi
|
||||||
if [ ! -f "$JAVA_FORMATTER" ]; then
|
if [ ! -f "ci/$JAVA_FORMATTER" ]; then
|
||||||
curl -L https://github.com/google/google-java-format/releases/download/google-java-format-1.3/$JAVA_FORMATTER > $JAVA_FORMATTER
|
curl -L https://github.com/google/google-java-format/releases/download/google-java-format-1.3/$JAVA_FORMATTER > "ci/$JAVA_FORMATTER"
|
||||||
fi
|
fi
|
||||||
if [ ! -f "$GOOGLE_CHECKS" ]; then
|
if [ ! -f "ci/$GOOGLE_CHECKS" ]; then
|
||||||
curl -L https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/$GOOGLE_CHECKS > $GOOGLE_CHECKS
|
curl -L https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/$GOOGLE_CHECKS > "ci/$GOOGLE_CHECKS"
|
||||||
fi
|
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
|
# Dart analysis and unit tests
|
||||||
|
@ -238,7 +238,7 @@ void main() {
|
|||||||
expect(results.errors.length, 1);
|
expect(results.errors.length, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('null saftey flag', () {
|
test('null safety flag', () {
|
||||||
final PigeonOptions results =
|
final PigeonOptions results =
|
||||||
Pigeon.parseArgs(<String>['--dart_null_safety']);
|
Pigeon.parseArgs(<String>['--dart_null_safety']);
|
||||||
expect(results.dartOptions.isNullSafe, true);
|
expect(results.dartOptions.isNullSafe, true);
|
||||||
|
Reference in New Issue
Block a user