FS#56433 - [texstudio] languagetool not usable

Attached to Project: Community Packages
Opened by xsmile (xsmile) - Friday, 24 November 2017, 15:07 GMT
Last edited by Sven-Hendrik Haase (Svenstaro) - Friday, 01 December 2017, 21:30 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Andrzej Giniewicz (Giniu)
Sven-Hendrik Haase (Svenstaro)
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Summary:

Languagetool's directory structure in Arch Linux differs from upstream and causes an issue with TeXstudio integration.
While languagetool can be started manually when needed, TeXstudio will not automatically start and end the process as intended.

- texstudio 2.12.6-3
- languagetool 3.9-1

Details:

According to the official documentation [1] following configuration for "Options > Configure TeXstudio > Language Checking" is fine:
- Java: java
- LT Path: /usr/share/java/languagetool/languagetool-server.jar
- LG Arguments: org.languagetool.server.HTTPServer -p 8081

However this doesn't work and trying to run the server manually causes this error:
java -cp /usr/share/java/languagetool/languagetool-server.jar org.languagetool.server.HTTPServer -p 8081
WARNING: running in HTTP mode, consider using org.languagetool.server.HTTPSServer for encrypted connections
Exception in thread "main" java.lang.NoClassDefFoundError: org/languagetool/language/LanguageIdentifier
at org.languagetool.server.TextChecker.<init>(TextChecker.java:77)
at org.languagetool.server.V2TextChecker.<init>(V2TextChecker.java:42)
at org.languagetool.server.LanguageToolHttpHandler.<init>(LanguageToolHttpHandler.java:59)
at org.languagetool.server.HTTPServer.<init>(HTTPServer.java:99)
at org.languagetool.server.HTTPServer.main(HTTPServer.java:138)
Caused by: java.lang.ClassNotFoundException: org.languagetool.language.LanguageIdentifier
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more

Languagetool in Arch Linux uses a wrapper (/usr/bin/languagetool) [2] to collect classpath information and only then runs the jar like this. TeXstudio recognizes the server afterwards.
/bin/java -cp /usr/share/languagetool:/usr/share/java/languagetool/annotations.jar:/usr/share/java/languagetool/bcprov-jdk15on.jar:[...]:/usr/share/java/languagetool/slf4j-nop.jar org.languagetool.server.HTTPServer -p 8081

The issue now is that TeXstudio assumes that the setting "LT Path" is a file and checks its existence [3]. If no file is found, languagetool is not automatically started and thus not usable.

The workaround proposed in a languagetool bug report [4] works only partially. While TeXstudio automatically starts languagetool, the process is not terminated when TeXstudio is closed and the option "Help > Check LanguageTool" causes various kinds of errors.

It is possible to disable the file check for the classpath and fill the "LT Path" setting with the classpath information provided by the wrapper. This works but requires patching the source and is probably not very future-proof.
--- a/grammarcheck.cpp
+++ b/grammarcheck.cpp
@@ -898,7 +898,7 @@ void GrammarCheckLanguageToolJSON::tryTo
}
triedToStart = true;
startTime = 0;
- if (ltPath == "" || !QFileInfo(ltPath).exists()) return;
+ if (ltPath == "") return;
javaProcess = new QProcess();
connect(javaProcess, SIGNAL(finished(int)), javaProcess, SLOT(deleteLater()));
connect(this, SIGNAL(destroyed()), javaProcess, SLOT(deleteLater()));

1: http://wiki.languagetool.org/checking-la-tex-with-languagetool#toc4
2: https://git.archlinux.org/svntogit/community.git/tree/trunk/languagetool.sh?h=packages/languagetool
3: https://sourceforge.net/p/texstudio/hg/ci/default/tree/grammarcheck.cpp, line 625
4: https://bugs.archlinux.org/task/44072#comment159470
This task depends upon

Closed by  Sven-Hendrik Haase (Svenstaro)
Friday, 01 December 2017, 21:30 GMT
Reason for closing:  Fixed
Comment by Sven-Hendrik Haase (Svenstaro) - Sunday, 26 November 2017, 06:45 GMT
Andrzej, do you think we should fix this in languagetool or should I just patch texstudio?
Comment by Andrzej Giniewicz (Giniu) - Sunday, 26 November 2017, 07:34 GMT
The way we package languagetool is making it a little bit harder to integrate. I followed https://wiki.archlinux.org/index.php/Java_package_guidelines - but maybe we should diverge to upstream layout? I don't know.
Comment by Sven-Hendrik Haase (Svenstaro) - Friday, 01 December 2017, 14:28 GMT
I patched the package. Can you give it a try?
Comment by xsmile (xsmile) - Friday, 01 December 2017, 14:38 GMT
Languagetool works, thank you.

The only downside is that you have to manually find out and insert the complete classpath string for the "LT Path" setting instead of the default "/usr/share/java/languagetool/languagetool-server.jar". However I don't know a simpler solution.
Comment by Sven-Hendrik Haase (Svenstaro) - Friday, 01 December 2017, 15:27 GMT
Well I could path the default LT Path. Do you think that would work?
Comment by xsmile (xsmile) - Friday, 01 December 2017, 15:43 GMT
That should work and you can even use "/usr/share/languagetool:/usr/share/java/languagetool/*" for "LT Path" instead of listing all jars separately.
Comment by Sven-Hendrik Haase (Svenstaro) - Friday, 01 December 2017, 16:07 GMT
Could you make a patch? You seem to know what you're talking about and I don't.
Comment by xsmile (xsmile) - Friday, 01 December 2017, 18:56 GMT
Sorry, I should have written more. The "LT Path" setting theoretically requires the languagetool server path: "/usr/share/java/languagetool/languagetool-server.jar".

With Arch Linux it needs to contain the complete classpath information as provided by the languagetool wrapper: /usr/share/languagetool:/usr/share/java/languagetool/annotations.jar:[...]:/usr/share/java/languagetool/slf4j-nop.jar
However, future languagetool versions might contain different jar files and our patch would need to be adjusted each time.

The good thing is that this string can be shortened to "/usr/share/languagetool:/usr/share/java/languagetool/*" and java will automatically include all jar files.

Here is the patch:
--- a/configmanager.cpp
+++ b/configmanager.cpp
@@ -596,7 +596,7 @@
#else
registerOption("Grammar/Language Tool URL", &grammarCheckerConfig->languageToolURL, "http://localhost:8081/", &pseudoDialog->lineEditGrammarLTUrl);
#endif
- registerOption("Grammar/Language Tool Path", &grammarCheckerConfig->languageToolPath, "", &pseudoDialog->lineEditGrammarLTPath);
+ registerOption("Grammar/Language Tool Path", &grammarCheckerConfig->languageToolPath, "/usr/share/languagetool:/usr/share/java/languagetool/*", &pseudoDialog->lineEditGrammarLTPath);
registerOption("Grammar/Language Tool Arguments", &grammarCheckerConfig->languageToolArguments, "org.languagetool.server.HTTPServer -p 8081", &pseudoDialog->lineEditGrammarLTArguments);
registerOption("Grammar/Language Tool Java Path", &grammarCheckerConfig->languageToolJavaPath, "java", &pseudoDialog->lineEditGrammarLTJava);
registerOption("Grammar/Language Tool Autorun", &grammarCheckerConfig->languageToolAutorun, true, &pseudoDialog->checkBoxGrammarLTAutorun);

I verified it with a clean TeXstudio profile.
Comment by Sven-Hendrik Haase (Svenstaro) - Friday, 01 December 2017, 20:10 GMT
Thanks for the work. Please test the new package.
Comment by xsmile (xsmile) - Friday, 01 December 2017, 20:45 GMT
It works, thank you!

Loading...