Jump to content

Development/Java

From The Document Foundation Wiki

LibreOffice contains various pieces of code written in Java. Some of these pieces are currently being replaced/rewritten, but it is likely that LibreOffice will contain Java code for quite some time.

What pieces of LibreOffice are written in Java?

Some basic GNU/Linux tools can be run over the source code to report on various aspects relating to Java usage. Each example command below has been run against an extracted copy of the v4.2.6.3 archived (tar/7z) source tree.

Which directories contain *.java files?

You can count the number of *.java files this way:

git ls-files *.java|awk -F/ {'print $1'}|uniq -c|sort -bg

This is the preliminary result, counting each and every folder of LibreOffice core source code:

1 chart2
      1 cli_ure
      1 comphelper
      1 cppuhelper
      1 jurt
      1 jvmaccess
      1 jvmfwk
      1 sw
      1 unoxml
      1 xmlsecurity
      2 bridges
      2 linguistic
      3 smoketest
      3 stoc
      4 filter
      4 sot
      5 sc
      5 testtools
      6 ure
      7 embeddedobj
      8 extensions
      8 svl
      9 desktop
     10 unotest
     12 javaunohelper
     12 sfx2
     12 swext
     16 dbaccess
     16 ucb
     24 bean
     31 framework
     33 connectivity
     35 forms
     38 nlpsolver
     48 package
     57 scripting
     63 toolkit
     96 android
    116 wizards
    129 ridljar
    159 reportbuilder
    230 odk
   1223 qadevOOo

Note that very little of this Java code is actually part of the shipped product. Most of these lines of code are actually only test code from the $MODULE/qa and $MODULE/test subdirectories. A more relevant analysis would exclude those subdirectories as they are never shipped with the product.

git ls-files *.java|grep -Ev '\/qa\/|\/test\/'|awk -F/ {'print $1'}|uniq -c|sort -bg

The list then becomes:

1 jurt
      1 jvmaccess
      1 jvmfwk
      1 xmlsecurity
      2 bridges         # modules that provide the bridge to Java itself -- little to no LO core functionality by itself
      3 smoketest
      3 testtools
      6 ure
      9 connectivity    # remaining core functionality -- mostly hsqldb 1.8 driver for LO Base default database (~3 KLOC)
     12 swext
     19 bean            # extensions and scripting -- little to no LO core functionality by itself
     38 nlpsolver
     57 scripting
     96 android         # android port -- not part of the core product
    102 ridljar
    116 wizards         # seems to be dead code only really by now
    159 reportbuilder
    228 odk
   1222 qadevOOo        # various forms of integration tests -- little to no LO core functionality by itself

For a comprehensive list of directories:

git ls-files *.java|sed 's/[^/]*.java$//'|uniq -c|sort -bg

Output (last 10 lines) from the above sed/sort commands, using tail, which shows the top 10 directories with the most .java files is:

35 android/source/src/java/org/mozilla/gecko/gfx/
     37 package/qa/storages/
     41 qadevOOo/tests/java/mod/_forms/
     43 qadevOOo/tests/java/mod/_sc/
     45 toolkit/test/accessibility/
     49 qadevOOo/tests/java/ifc/drawing/
     58 qadevOOo/tests/java/ifc/awt/
     68 qadevOOo/tests/java/ifc/text/
     71 qadevOOo/tests/java/mod/_toolkit/
     73 qadevOOo/tests/java/mod/_sw/

For the complete list, please see Development/Java/Directories containing .java files

How many lines of java source code in each main directory?

It is worth using cloc to count the lines of code easily:

for i in $(git ls-files *.java|awk -F/ {'print $1'}|uniq);
do
    cloc --quiet --include-lang=Java $i|grep Java|awk -v i=$i '{print $5"\t"i}';
done | sort -bg

Output from the above script:

28      jvmfwk
45      jurt
50      jvmaccess
59      cli_ure
71      sw
98      stoc
120     smoketest
137     xmlsecurity
143     ure
175     sot
201     bridges
239     cppuhelper
275     linguistic
370     comphelper
390     embeddedobj
430     svl
519     unotest
622     desktop
684     filter
719     chart2
769     extensions
963     sc
1104    ucb
1399    testtools
1817    unoxml
2133    sfx2
2373    nlpsolver
2839    dbaccess
2924    javaunohelper
3035    bean
3071    connectivity
3233    swext
4282    forms
5207    framework
7878    scripting
8519    toolkit
9158    package
12129   android
14649   reportbuilder
15082   ridljar
27344   wizards
33636   odk
86227   qadevOOo

Total number of lines is reported with this command, which outputs ~255K LOC at the moment.

cloc --quiet --include-lang=Java `git ls-files *.java|awk -F/ {'print $1'}|uniq`

Java use (as a percentage) in each LibreOffice end-of-train release, is also available in the Ask thread Is there any plan to ditch Java in the future and use only C/C++ code?. Note though that very little of this Java code is actually part of the shipped product. Most of these lines of code are actually only testcode from the $MODULE/qa subdirectory. A more relevant analysis would exclude that subdirectories as they are never shipped with the product.

Which directories contain *.jar files?

find -type f -name "*.jar"

Output from above find/sort commands contains > 170 files at the moment. These are files from all over the code base, generated files in instdir/ and also external/.

These are the *.jar files, only from the source tree itself:

git ls-files *.jar

The output contains only 3 files:

android/source/gradle/wrapper/gradle-wrapper.jar
qadevOOo/testdocs/qadevlibs/JobExecutor.jar
qadevOOo/testdocs/qadevlibs/MyPersistObjectImpl.jar

Building LibreOffice without Java

Compile LibreOffice with the flag --without-java

Suggestion to Remove Java Components

Per Development/Crazy Ideas,

Some think java is a slow memory hog, others think it is a legal swamp that invites lawsuits. Neither might be true, but some developers have nevertheless expressed their desire to remove Java usage in LO over time.

Resources