Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/jnigen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 1.0.1-wip

- Report an empty entry under `classes` in the config file as a config error
instead of failing with a type error.
- Generate links to method-specific Javadocs for Maven dependencies when
source Javadocs are unavailable.

Expand Down
10 changes: 9 additions & 1 deletion pkgs/jnigen/lib/src/config/config_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ bool _isCapitalized(String s) {
}

void _validateClassName(String className) {
if (className.isEmpty) {
throw ConfigException('Class names cannot be empty.');
}
final parts = className.split('.');
assert(parts.isNotEmpty);
const nestedClassesInfo =
Expand Down Expand Up @@ -471,7 +474,12 @@ final class JniGenerator {
input: Input(
sourcePath: prov.getPathList(_Props.sourcePath) ?? const [],
classPath: prov.getPathList(_Props.classPath) ?? const [],
classes: must(prov.getStringList, [], _Props.classes),
classes: must(prov.getStringList, <String>[], _Props.classes)
// An empty YAML entry reads as null. Turn it into an empty name so
// that _validateClassName reports it instead of a cast error.
.cast<Object?>()
.map((className) => className as String? ?? '')
.toList(),
extraArgs: prov.getStringList(_Props.summarizerArgs) ?? const [],
backend: getSummarizerBackend(prov.getString(_Props.backend), null),
workingDirectory: prov.getPath(_Props.summarizerWorkingDir),
Expand Down
22 changes: 22 additions & 0 deletions pkgs/jnigen/test/config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,27 @@ void main() async {
name: 'Nested class specified',
overrides: ['-Dclasses=com.android.Clock\$Clock'],
);

test('Empty classes entry from YAML', () {
final dir = Directory.systemTemp.createTempSync('jnigen_config_test');
addTearDown(() => dir.deleteSync(recursive: true));
final yaml = File(join(dir.path, 'jnigen.yaml'))..writeAsStringSync('''
output:
dart:
path: lib/gen.dart
structure: single_file
classes:
- "com.example.Foo"
-
''');
expect(
() => JniGenerator.parseArgs(['--config', yaml.path]),
throwsA(isA<ConfigException>().having(
(error) => error.message,
'message',
'Class names cannot be empty.',
)),
);
});
});
}
Loading