LibreOffice / loeclipse

LibreOffice Eclipse plugin for extension development
https://libreoffice.github.io/loeclipse/
31 stars 25 forks source link

Error in walking libs subfolder on uno package creation #85

Closed jragan-work closed 1 year ago

jragan-work commented 3 years ago

After updating LoEclipse i found out, that my extension no longer builds. I get Error launching configuration with following exception:

!MESSAGE Error launching configuration.
!STACK 0
java.lang.IllegalArgumentException: pFile [C:\Users\jragan\eclipse-workspace-LOswing\Harmonogram\libs\commons-net-3.6.jar] is not a file
    at org.libreoffice.plugin.core.model.UnoPackage.addOtherFile(UnoPackage.java:587)
    at org.libreoffice.ide.eclipse.java.JavaBuilder.fillUnoPackage(JavaBuilder.java:289)
    at org.libreoffice.ide.eclipse.core.internal.helpers.UnoidlProjectHelper.createMinimalUnoPackage(UnoidlProjectHelper.java:513)
    at org.libreoffice.ide.eclipse.core.gui.PackageContentSelector.createPackage(PackageContentSelector.java:185)
    at org.libreoffice.ide.eclipse.core.launch.office.OfficeLaunchDelegate.exportComponent(OfficeLaunchDelegate.java:177)
    at org.libreoffice.ide.eclipse.core.launch.office.OfficeLaunchDelegate.launch(OfficeLaunchDelegate.java:109)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:807)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:718)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1021)
    at org.eclipse.debug.internal.ui.DebugUIPlugin$2.run(DebugUIPlugin.java:1224)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

I have narrowed down the problem to JavaBuilder.java modification from commit 074eab804c5d83d3058bba3fee51b66125bf247a. The problem happens because the new version of getLibs(...) method calls new method getLibsFromLibsDir(...) and it cuts out subdirectories somehow. The correct path to the above mentioned file is: C:\Users\jragan\eclipse-workspace-LOswing\Harmonogram\libs\commons-net-3.6\commons-net-3.6.jar I have also checked in debugger data for other files with subdirectories, and their directories were also cut out.

I think it is in this part, but since I don't use collections much, I just can't wrap my head around the code (starting from line 357):

            try (Stream<java.nio.file.Path> walk = Files.walk(Paths.get(libFolderOsString))) {
                libs = walk.map(jarFile -> {
                    return libFolder.getFile(jarFile.getFileName().toString());
                }).filter(f -> f.getFileExtension() != null && f.getFileExtension().equalsIgnoreCase("jar"))
                    .collect(Collectors.toList());
            } catch (IOException e) {
                PluginLogger.error(
                    Messages.getString("JavaBuilder.GetExternalLibsFailed"), e);
            }

Temporary fix for this is to move all jars to main libs folder.

smehrbrodt commented 3 years ago

@michaelmassee Any chance to look at this issue?

michaelmassee commented 3 years ago

okay, i see the issue, i use gradle to resolve the dependencies, the Jars are put in the libs folder without any subdir. the libFolder.getFile(jarFile.getFileName().toString()) cuts of the subdirectory(ies)

jragan-work commented 3 years ago

I have also noticed another issue. I have created the libs folder on my own in 2019 when I started my project. Now I have discovered, that currently I have no control with package.properties over which jars get included and which not. So if I put complete library with sources and docs in separate jars into a subfolder of libs folder, those jars would also be unnecessarily included in the oxt package.

I don't know if any other existing extensions use libs folder as I did, but this behavior change is unexpected.