dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
134 stars 41 forks source link

Summarizer should take input through stdin #655

Closed mahesh-hegde closed 4 months ago

mahesh-hegde commented 1 year ago

This is a summarizer command invocation on in_app_java sample after adding some gradle sources support.

(jnigen) INFO: execute java -jar .dart_tool/jnigen/ApiSummarizer.jar -s android\app\src\main\java;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.6.10\ccdfdab71f0f3ba104191d8f673d0620e7ed2e46\kotlin-stdlib-jdk7-1.6.10-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.loader\loader\1.0.0\b9ef587f3e46c7fe5b00264989764e43ff45cada\loader-1.0.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.lifecycle\lifecycle-livedata\2.0.0\740ce61935bd789380c01178bd8ce402402ebd2f\lifecycle-livedata-2.0.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\5991ca87ef1fb5544943d9abc5a9a37583fabe03\annotations-13.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.annotation\annotation\1.2.0\8945212022e5276658ab7864714ced3553ea724a\annotation-1.2.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-coroutines-core\1.5.2\eec85c0ad7175c570935d37cfe8a749c57991a53\kotlinx-coroutines-core-1.5.2-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-coroutines-android\1.5.2\363aa80c0a981d7bcb39bb904145de5b40b862f0\kotlinx-coroutines-android-1.5.2-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.activity\activity\1.0.0\28eb83e6a29ac3fbb87aa632cfa0e644a313f491\activity-1.0.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.window\window\1.0.0-beta04\c05d535f15eafda40ef406aaa4cb9df2d7f5377\window-1.0.0-beta04-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.lifecycle\lifecycle-livedata-core\2.0.0\c158207594782b42f3a2e08a5a029eb3319e4404\lifecycle-livedata-core-2.0.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.arch.core\core-runtime\2.1.0\f19886651c9946b39f83d8c184fd0e2ce9f43c16\core-runtime-2.1.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\io.flutter\flutter_embedding_release\1.0.0-ec975089acb540fc60752606a3d3ba809dd1528b\87eb8311c7c3d4b4716b30c2185b44b99608bbd1\flutter_embedding_release-1.0.0-ec975089acb540fc60752606a3d3ba809dd1528b-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.lifecycle\lifecycle-viewmodel\2.1.0\bfd86b9887c2343516f82bed91acbab34a45841d\lifecycle-viewmodel-2.1.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.savedstate\savedstate\1.0.0\e6daf87ed227a6f80bb8accb466755a5ee01a652\savedstate-1.0.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.tracing\tracing\1.0.0\aa6dafdce323d80a993c5427cf81d5072f023c8c\tracing-1.0.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.core\core\1.6.0\7e14a47159a1cd7e5744d0fe465fbc97843d984a\core-1.6.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.6.10\884efb386c94b1ee8e2ca37335264a0ffb155250\kotlin-stdlib-common-1.6.10-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk8\1.5.30\171265ccd1f7a4307c3cb8eedd9115e662013190\kotlin-stdlib-jdk8-1.5.30-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.emoji2\emoji2\1.3.0\788179fcab96cd6ec9a3e284e2a509545dc0fb8d\emoji2-1.3.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.6.10\a6284476c56bd752eb0020e062c78c930abdc168\kotlin-stdlib-1.6.10-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.arch.core\core-common\2.1.0\80ac2d7c8e6400ce2fbc663cd1a7e1cbef38c4b8\core-common-2.1.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.versionedparcelable\versionedparcelable\1.1.1\d9085927216387af679d18b6f472bc0fc5c7cc81\versionedparcelable-1.1.1-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.startup\startup-runtime\1.1.1\714974d4ab4858eab9395d3b048002108b62cf0a\startup-runtime-1.1.1-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.lifecycle\lifecycle-runtime\2.4.1\ae7040cf314de81d20ac69f28f5ab6c9a2c0d1ab\lifecycle-runtime-2.4.1-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.customview\customview\1.0.0\61f6a717d144dff3a6bda413d9abeeb2bca71581\customview-1.0.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.lifecycle\lifecycle-common\2.4.1\29609e3d01eaafd06c688c5366154174cf686c12\lifecycle-common-2.4.1-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.annotation\annotation-experimental\1.1.0\238eb640abf1ca6c952c7cd2e9423fe7f715713f\annotation-experimental-1.1.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.collection\collection\1.1.0\bae67b0019fbb38498198fcc2d0282a340b71c5b\collection-1.1.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.window\window-java\1.0.0-beta04\aebe0d5dd92117437900757652f05fd10dc45382\window-java-1.0.0-beta04-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.fragment\fragment\1.1.0\b9ebb04df2cb0cad4419af3c658690bc82aa5706\fragment-1.1.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.viewpager\viewpager\1.0.0\db045f92188b9d247d5f556866f8861ab68528f0\viewpager-1.0.0-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.lifecycle\lifecycle-common-java8\2.4.1\5b8f86fea035328fc9e8c660773037a3401ce25f\lifecycle-common-java8-2.4.1-sources.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-coroutines-core-jvm\1.5.2\d4724dfd0c4e340e15bd681a47e786bac9fd77a3\kotlinx-coroutines-core-jvm-1.5.2-sources.jar -c C:\Users\Concurrent\AppData\Local\Android\Sdk\platforms\android-33\android.jar;C:\Users\Concurrent\Code\Flutter\jnigen\jnigen\example\in_app_java\build\app\intermediates\compile_and_runtime_not_namespaced_r_class_jar\release\R.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\010799bb733d735e6bc7eb55a004ce51\transformed\jetified-libs.jar;C:\Users\Concurrent\Code\Flutter\jnigen\jnigen\example\in_app_java\build\jni\intermediates\compile_library_classes_jar\release\classes.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\f5329812119b63e8d80e90f8e279fb64\transformed\jetified-flutter_embedding_release-1.0.0-ec975089acb540fc60752606a3d3ba809dd1528b.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\4b6714e8764d36fc5f2963ce7e32668c\transformed\jetified-window-java-1.0.0-beta04-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\2ed1856e8509c3559e509d57d5163600\transformed\jetified-window-1.0.0-beta04-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\598adb5e9149720d13f0bd0a0dcb6ee8\transformed\jetified-kotlinx-coroutines-android-1.5.2.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\efb248efc67e5b15184e44f46099cae3\transformed\jetified-kotlinx-coroutines-core-jvm-1.5.2.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\bf1c1216bd6ae07994ad3865cc233715\transformed\jetified-kotlin-stdlib-jdk8-1.5.30.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\c1ad1417f1a0d960d63d2b4e99f2c3ab\transformed\jetified-kotlin-stdlib-jdk7-1.6.10.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\8c0c5e352fdc1a448b53f679be4ca527\transformed\jetified-emoji2-1.3.0-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\e419da159160990b7feff3b389d2b5a8\transformed\jetified-armeabi_v7a_release-1.0.0-ec975089acb540fc60752606a3d3ba809dd1528b.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\70e7a4805f13d7f3aa7cfd7c635bc7d7\transformed\jetified-arm64_v8a_release-1.0.0-ec975089acb540fc60752606a3d3ba809dd1528b.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\0eaf6f4c95e9479426bbbd2f560f3453\transformed\jetified-x86_64_release-1.0.0-ec975089acb540fc60752606a3d3ba809dd1528b.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.lifecycle\lifecycle-common-java8\2.4.1\5b8f86fea035328fc9e8c660773037a3401ce25f\lifecycle-common-java8-2.4.1.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\cdf88c5cc537aaddfc2c2050fa347e9c\transformed\fragment-1.1.0-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\ea9559528b708c2ddbd8ffc8f6a391bc\transformed\viewpager-1.0.0-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\44759425f3db5f137147e512ecde1a3c\transformed\loader-1.0.0-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\b446ae01cc4feea870f9d4cdd76bbbed\transformed\jetified-activity-1.0.0-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\58d181116539456738cbc5eec385f703\transformed\customview-1.0.0-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\a5d1d8f25f8005438aa6f0c30d5c502a\transformed\core-1.6.0-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\2af0f27b0b84a53922472a0e6210c91a\transformed\lifecycle-runtime-2.4.1-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\1f9c0389144dc98c98c15c79358ad23f\transformed\jetified-savedstate-1.0.0-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\65c8ce426ffc7583bdb81c3188d22ba8\transformed\lifecycle-livedata-2.0.0-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\61fa0487a7e406de4f3e264e210faff8\transformed\lifecycle-livedata-core-2.0.0-api.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.lifecycle\lifecycle-common\2.4.1\1fdb7349701e9cf2f0a69fc10642b6fef6bb3e12\lifecycle-common-2.4.1.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\d8a303489ba2ae0a75ce057af4ce0e35\transformed\versionedparcelable-1.1.1-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\08d13d8d279ac4ef123bdae018db4637\transformed\core-runtime-2.1.0-api.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.arch.core\core-common\2.1.0\b3152fc64428c9354344bd89848ecddc09b6f07e\core-common-2.1.0.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.collection\collection\1.1.0\1f27220b47669781457de0d600849a5de0e89909\collection-1.1.0.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\ddf2acae941e89634e9d6193d68f4a65\transformed\lifecycle-viewmodel-2.1.0-api.jar;C:\Users\Concurrent\.gradle\caches\modules-2\files-2.1\androidx.annotation\annotation\1.2.0\57136ff68ee784c6e19db34ed4a175338fadfde1\annotation-1.2.0.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\16b2a3659d3f66cfb4dac6a52d79820d\transformed\jetified-annotation-experimental-1.1.0-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\58cbff39727146a52203300842706cfd\transformed\jetified-tracing-1.0.0-api.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\c0314e47cfdb88c484579924d748772c\transformed\jetified-kotlin-stdlib-1.6.10.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\d742cecfb9af51effcb2f82c5fa547fe\transformed\jetified-annotations-13.0.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\775bbb9baefa867ead960bb63dccd35f\transformed\jetified-kotlin-stdlib-common-1.6.10.jar;C:\Users\Concurrent\.gradle\caches\transforms-3\a5ecb3037b45778399ab52e6a8362c01\transformed\jetified-startup-runtime-1.1.1-api.jar;C:\Users\Concurrent\Code\Flutter\jnigen\jnigen\example\in_app_java\build\app\tmp\kotlin-classes\release com.example.in_app_java.AndroidUtils androidx.emoji2.text.EmojiCompat androidx.emoji2.text.DefaultEmojiCompatConfig android.os.Build java.util.HashMap

With an app which has more dependencies, we might cross OS-imposed limits of command length and it's not great for debugging either.

We should take this class paths etc information as structured JSON in summarizer, reading from System.in.

mahesh-hegde commented 1 year ago

Since this is marked good first issue, here are the steps to solve this

Steps

Decisions

Karan741187 commented 1 year ago

Sir I wish to contribute on this one

Karan741187 commented 1 year ago

Can you elaborate this point "This class is being parsed from command line using Apache commons CLI, add factory (static) methods to obtain an instance of this class by parsing JSON, and another instance method to dump it back to JSON (for debugging purposes)"

Karan741187 commented 1 year ago

Do we have to parse "exampleClassSummary.json" return a object. And what is "dump it back to JSON", is it encoding new json file?

mahesh-hegde commented 1 year ago

Can you elaborate this point

"This class is being parsed from command line using Apache commons CLI, add factory (static) methods to obtain an instance of this class by parsing JSON, and another instance method to dump it back to JSON (for debugging purposes)"

We have a Java part and a Dart part in this codebase. Java part (It's a maven project in jnigen/java folder) parses the Java code we give to jnigen, and gives us a summary in JSON format. This part is called the summarizer.

For this, we need to pass the various options. Like class-path (where to find required java JARs), source-path (where to find java files to parse) etc..

All of that is stored in SummarizerOptions class.

So what we are doing now is, we invoke this summarizer as separate command, java -jar ApiSummarizer.jar etc.. You can see this command in the logs of executing jnigen.

What this issue is about: the command gets very long and cluttered if we pass everything as command option. So we want to read that from standard input System.in.

For that, we need some structure. You might have done scanner.next() etc.. when you're learning java. But here the input is complicated. So we have to read those options in JSON format.

If we read JSON, we can read all values it into SummarizerOptions class directly, using Jackson-databind library. We already using that library.

The task is to modify the APISummarizer java code, and the dart code which calls it, so that instead of command options, we pass options in JSON format through System.in (stdin of process on dart side).

Do we have to parse "exampleClassSummary.json" return a object. And what is "dump it back to JSON", is it encoding new json file?

You're probably looking at test file. If you're not familiar with pipes, json, serialization etc.. this might be hard (I know these aren't taught at universities properly). feel free to ask any question you get.

Karan741187 commented 1 year ago

I had some doubts 1.Are we passing the options through the terminal or they are getting read from any dart file.Because you mentioned stdin of process on dart side

2.Which dart code is calling the Java code. I went through the setup.dart and jni.dart but couldn't find anything of Java.

I ran Main.java and saw all the commons.cli implementation with SummerizerOptions.java.

Karan741187 commented 1 year ago

The term Standard input is being used very often.So far i know it means taking input from user through keyboard right?

mahesh-hegde commented 1 year ago

Sure. That's a good start.

Are we passing the options through the terminal Standard input is being used very often

In any OS, Standard input is an abstraction your program sees, input doesn't necessarily come from the terminal.

If you do echo "HI" | cat in Linux Bash, there are 2 processes, (echo & cat), the output of first one will be passed to input of second. Like that, we can programmatically give input to any command.

And the inverse, we can programmatically invoke and read output of the command.

How is this possible? conceptually, input & output are just streams just like any other file. If you create a process from your program (eg run a command), you can write to its input and read from its output. So we don't have to do that manually from terminal.

Which dart code is calling the Java code.

It's jnigen that calls the JAR command.

https://github.com/dart-lang/jnigen/blob/f7e6de15735f21678f899bf9f5c98fdbdaea793b/jnigen/lib/src/summary/summary.dart#L89

Karan741187 commented 1 year ago

Sir today I was trying to make a process object with start function and wanted to give stdin but i got file not found exception Although the file was in current working directory

when gave cat as exec and A file path through stdin it gave the error file not found

mahesh-hegde commented 1 year ago

I don't quite understand what you're trying to do. Can you paste the code?

Karan741187 commented 1 year ago

`import 'dart:io'; import 'dart:convert';

Future main() async { Process.start('cat', []).then((Process ps) { ps.stdout.transform(utf8.decoder).listen((event) { print('$event'); }); ps.stdin.write('C:\Users\Dell\IdeaProjects\Processpractice\myfile.txt');

Process.killPid(ps.pid); }); }`

Karan741187 commented 1 year ago

when i cat command in powershell it asks for path[0] then i enter the path and it keeps on asking till i press enter two times i was trying to pass the file path through stdin but throws this exception

`Unhandled exception: ProcessException: The system cannot find the file specified.

Command: cat

0 _ProcessImpl._start (dart:io-patch/process_patch.dart:401:33)

dart-lang/jnigen#1 Process.start (dart:io-patch/process_patch.dart:38:20) dart-lang/jnigen#2 main (file:///C:/Users/Dell/IdeaProjects/Processpractice/progprac.dart:5:11) dart-lang/native#802 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:297:19) dart-lang/jnigen#4 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)

Process finished with exit code 255 `

Karan741187 commented 1 year ago

And with run also I'm getting this code: var result = await Process.run('ls', ['c:\\Users\Dell']);

Exception: `Unhandled exception: ProcessException: The system cannot find the file specified.

Command: ls c:\UsersDell

0 _ProcessImpl._start (dart:io-patch/process_patch.dart:401:33)

dart-lang/jnigen#1 Process.start (dart:io-patch/process_patch.dart:38:20) dart-lang/jnigen#2 _runNonInteractiveProcess (dart:io-patch/process_patch.dart:578:18) dart-lang/native#802 Process.run (dart:io-patch/process_patch.dart:49:12) dart-lang/jnigen#4 main (file:///C:/Users/Dell/IdeaProjects/Processpractice/progprac.dart:16:30) dart-lang/native#803 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:297:19) dart-lang/jnigen#6 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)

Process finished with exit code 255 `

mahesh-hegde commented 1 year ago

You shouldn't need stream listeners and all, in this particular case. It appears you're writing file name as the content, not the contents of file itself. So what you wrote doesn't include end of file delimiter or close the stdin, which means cat doesn't terminate.

For second one, it may be that you're escaping the path improperly, because '\D' should show you a warning anyway, or maybe because ls doesn't exist as executable on your specific windows machine.

If you don't understand the concept itself, I'd recommend you to go through following topics:

Karan741187 commented 1 year ago

ok sir

Karan741187 commented 1 year ago

Sir I did those topics and rectified those errors as well. I also wrote a java code and gave its input through dart programme using process.

Dart code:

`import 'dart:io'; import 'dart:convert';

Future main()async { var p=await Process.start("java", ["Doingitfromdart.java"]); p.stdout.transform(utf8.decoder).forEach((element) {print(element);}); p.stdin.write("Karan "); p.stdin.write(19); p.stdin.write(" Gujarat India Earth!"); p.stdin.close(); } `

Java code: `import java.util.Scanner;

public class Doingitfromdart { public static void main(String[] Karan) { System.out.println("Programme started!");

    //Biodata programme

// int age; String name,address,age; Scanner s=new Scanner(System.in); name=s.next(); age=s.next();

    address=s.nextLine();
    System.out.println(name+" is "+age+" years old and resident of "+address);
}

} `

Output: `C:/Dell/flutter/bin/cache/dart-sdk/bin/dart.exe --enable-asserts C:\Users\Dell\IdeaProjects\Processpractice\progprac2.dart Programme started!

Karan is 19 years old and resident of Gujarat India Earth!

Process finished with exit code 0`

Karan741187 commented 1 year ago

It seems like a pipe mechanism since we are directly giving the input to java programme without any intermediate file. So ,now the commandline invocation of APISummarizer.jar gives us a very long output in the terminal which i should read through stdin of Process object and take it into a json file to have a clear picture of output. Right?

mahesh-hegde commented 1 year ago

which i should read through stdin of Process object and take it into a json file to have a clear picture of output.

I don't get whether you understood the JSON part very well.

Currently we pass cli options. You know about command line options right? -optionname argument format.

(If you don't, I encourage you to read about those command line option conventions.)

All this information has some structure.

For example, class path and source path are arrays of strings.

List of classes is also array of strings.

Some are simpler strings eg --backend=doclet.

This structure (class SummarizerOptions) is already there which has all these fields. You just have to read it from JSON by creating a factory method which uses Jackson ObjectMapper class. If you don't understand this part, read up on POJO types and Jackson databind library.

To create JSON, you need an equivalent type on dart side. You have to create a dart SummarizerOptions class which mirrors the same java class. You can use json_serializable library or write a manual function. Both are fine.

Keep this class in separate file in lib/src/summary/

This allows us to provide larger options without long command line, also it's a bit cleaner.

You still have to log the JSON in one-line. (Because logs have to be one line).

Also, dump the same JSON to .dart_tool/jnigen/summarizer_last_invocation.json.

So that when debugging we can do

cat .dart_tool/jnigen/summarizer_last_invocation.json | java -jar .dart_tool/jnigen/ApiSummarizer.jar.

Despite having this, you don't want to remove current command line mechanism, that's very useful for debugging.

So you may want to add a new option --read-params-from-stdin, and in fromCommandLine factory method, you first check for this argument and if present, return an object created from JSON. If you have an alternative idea here, you're welcome to discuss it, too.


Also you don't have to address us as "sir". It's not your college 🙂.

Karan741187 commented 1 year ago

For writing the dart class that mirrors the Java class(SummarizerOptions) how will I get the values for those class variables to write in Json. I was looking through Config class but could find only source path,class path,and backend but there are more left

mahesh-hegde commented 1 year ago

Good progress.

There is at least one more: summarizer.extraArgs which can be passed to summarizer.

You should check the getSummary function, and work backwards from Process call to understand what what is passed to summarizer. (I could check myself and tell, but it would be beneficial for you to learn these patterns).

As for supporting extra options, you have 2 choices:

  1. You may want to change it to summarizer.extraConfig which may be a Map type we give in YAML. You will also have to change the corresponding parts where config is read from YAML.

  2. Alternatively, you can take a simpler approach, by still supporting those extra flags, while taking main input from stdin.

So this is your choice as implementer. For me at the end code should be neat 🙂.

Karan741187 commented 1 year ago

The Java part is getting it's cli options argument list from dart side if somehow that list is known i could get those remaining options But i couldn't find it

Karan741187 commented 1 year ago

get summary function is returning a classes future and that is used in generating bindings should i study about bindings part or is there any other way

mahesh-hegde commented 1 year ago

Read my comment again.

The CLI arguments list is passed through a process call.

You can look how each of these argument is constructed. That will tell you which parameters are passed. Rest of them are passed as extra args (needed only in rare cases).

Karan741187 commented 1 year ago

How should I run my code for checking ? I'm trying to extract the options and arguments from Listargs(after splitting from index 1) and trying to traverse it after using it in main of setup.dart, but it says args has not been initialized

Karan741187 commented 1 year ago

Maybe it was because I had made args a static late List but when I removed late the code runs fine but doesn't display the part of my added code.I cannot see the list being iterated. Code: `// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file.

import 'dart:io';

import 'package:jnigen/src/logging/logging.dart'; import 'package:jnigen/src/summary/SummarizerOpts.dart'; import 'package:jnigen/src/tools/tools.dart'; import 'package:logging/logging.dart';

void main(List args) async { bool force = false; setLoggingLevel(Level.INFO); if (args.isNotEmpty) { if (args.length != 1 || args[0] != '-f') { stderr.writeln('usage: dart run jnigen:setup [-f]'); stderr.writeln('* -f\trebuild ApiSummarizer jar even if it already ' 'exists.'); } else { force = true; } } print("Hi"); final SummarizerOpts s=SummarizerOpts(); for(int i=0;i<s.optarg.length;i++) { print(s.optarg[i]); } await buildSummarizerIfNotExists(force: force);

} `

Karan741187 commented 1 year ago

The Hi is visible but not the list.

Output: `C:/Dell/flutter/bin/cache/dart-sdk/bin/dart.exe --enable-asserts C:\Users\Dell\Desktop\jnigen\jnigen\bin\setup.dart Hi (jnigen) INFO: Building ApiSummarizer component. This might take some time. The build will be cached for subsequent runs

(jnigen) INFO: execute mvn --batch-mode --update-snapshots -f C:\Users\Dell\Desktop\jnigen\jnigen\java\pom.xml assembly:assembly

Process finished with exit code 0 `

And a Jar file is generated in jnigen/.dartool/jnigen/ApiSummarizer.jar

Karan741187 commented 1 year ago

I tracked back the getSummary function to bin/jnigen.dart and did the same thing here.

it gave this error on running: `C:/Dell/flutter/bin/cache/dart-sdk/bin/dart.exe --enable-asserts C:\Users\Dell\Desktop\jnigen\jnigen\bin\jnigen.dart Fatal: Error parsing configuration: C output config must be provided!

Process finished with exit code 1 `

mahesh-hegde commented 1 year ago

Why are you looking at setup.dart? The code which spawns summarizer process is in summary.dart.

Also didn't understand what your trying with print(Hi) etc..

--

Side note: from the next time use GitHub markdown code blocks for pasting dart code.

```dart
// Dart code here
Karan741187 commented 1 year ago

Actually I wanted to just run and check the changes I'm making

mahesh-hegde commented 1 year ago

dart run jni:setup builds ApiSummarizer in .dart_tool/jnigen/ApiSummarizer.jar. (needs internet when running for the first time. That might be your first error).

You have run at least one of the examples right? If you don't have Android SDK setup, run jnigen in pdfbox example. You will see logs detailing what's happening.

If you didn't change options to JSON input yet, you can copy paste one of java -jar .dart_tool/jnigen/ApiSummarizer.jar ..... commands in logs and check JSON output is coming. (Output is already JSON, it will tell you which classes and methods are there in java file).

Otherwise you have to modify the command appropriately, to take new options or input you added. Once you add JSON input, you can prepare a JSON file and pipe it to command.

Once you add JSON input on dart side also, you can just run dart run jnigen --config jnigen.yaml as usual.

When you're trying these, print the JSON etc.. you generate. But after you're done remove those prints.

Karan741187 commented 1 year ago

which pdf box ?

mahesh-hegde commented 1 year ago

!

jnigen/example/pdfbox_plugin

You understand what this project does, right? I assumed you have gone through README and examples.

Karan741187 commented 1 year ago

Sir does this issue has any time bound. Actually I've got my mid semester exams this month so I'll try to do as much as I can for this month.

mahesh-hegde commented 1 year ago

Take time. This doesn't have any milestones attached with it.

mahesh-hegde commented 1 year ago

@Karan741187

It appears you posted a message in the thread and deleted it.

If that's the case, don't do it. Because people will receive email notifications about the issues anyway.

Regarding the issue - yeah it's perfectly fine to take time. You appear to be in 1st year from the bio that GitHub shows. You have ample time to learn things.

I will probably take up this issue if time permits. Else someone will. Not a problem.

HosseinYousefi commented 4 months ago

Planning to rewrite APISummarizer in Dart. Closing this.