Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all-modules-page: Validate cross-module links during resolution #2901

Conversation

EddieRingle
Copy link
Contributor

I scanned the list of open issues but didn't spot one that matched my experience directly, but the closest might be #2037 or #2272. I'm not sure if this is necessarily the correct or ideal fix, and the underlying wider issue of supporting split packages probably requires further changes, but I did want to at least share this as it makes Dokka usable for our use-cases.

From commit message:

The existing behavior was just taking the first module that includes the package name of a given reference, so this resulted in broken links when a package is split across multiple modules.

This change checks to ensure the resolved file exists before choosing it as the target for the resolved link.

The existing behavior was just taking the first module that includes the
package name of a given reference, so this resulted in broken links when
a package is split across multiple modules.

This change checks to ensure the resolved file exists before choosing it
as the target for the resolved link.

Signed-off-by: Eddie Ringle <eddie@ringle.io>
@EddieRingle EddieRingle marked this pull request as ready for review March 2, 2023 22:04
@IgnatBeresnev IgnatBeresnev self-requested a review March 7, 2023 23:32
val modulePath = context.configuration.outputDir.absolutePath
val validLink = resolvedLinks.firstOrNull {
val absolutePath = File(modulePath + it)
absolutePath.isFile
Copy link

@pbajurko pbajurko Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks assumes that dependee submodules have been already processed but that is upto process order
in all-modules-page plugin. For our project it lead to situation where same DRI was sometimes resolved and sometimes not.
I workaround it by checking paths against Dokka's output in submodules since partial tasks will be done before multimodule starts but that is not clean solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Thank you for noticing it. The workaround is correct, but it should not depend on particular paths like build/dokka/htmlMultiModule or build/dokka/htmlPartial/. It would be great to use module.sourceOutputDirectory

Copy link
Member

@vmishenev vmishenev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for your contribution and sorry for the delay. The issue is very painful for Dokka.

I left the comments in the review.
Could you rebase on master? I'm afraid some files have been moved.

val validLink = resolvedLinks.firstOrNull {
val absolutePath = File(modulePath + it)
absolutePath.isFile
} ?: return null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it not work for the non-local external package-list at all? See the example with the serialization library from External documentation links configuration. Can you fix it, please?

It is nice to fix the issue at least for cross-module links.
A check of existing external URLs online can be excessive and Dokka can be run without access to the Internet.

Also, I think the fix should check links only if resolvedLinks has more than one link. What do you think? It can help avoid unexpected behaviour with resolving cross-module links.
This fix is local and temporary. We have a long-term plan #3368.

@@ -56,7 +56,7 @@ class ResolveLinkCommandResolutionTest : MultiModuleAbstractTest() {
}
}

val contentFile = setup(link)
val contentFile = setup(link, testedDri)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test case for the case from #2272?

@vmishenev
Copy link
Member

Thank you again for your contribution. It fixes painful #2272.
I used your solution in #3425 to fix the notes above. You will be included as an author of this.
So I will close it in favor of #3425.

@vmishenev vmishenev closed this Jan 11, 2024
vmishenev added a commit that referenced this pull request Jan 11, 2024
Fixes #2272. There is a situation where 2 (or more) gradle modules have the same package and dokka doesn’t know where to link.
E.g.
The class com.example.classA is in moduleA
and com.example.classB is in moduleB
moduleC depends on moduleA and moduleB.
In moduleC: there is a link [com.example.classB]. Having only package-list, dokka doesn’t know where to link, since the package com.example is in both modules.

This is short-term and temporary solution of #3368 to cover a case of links between only local modules in a project.
It is based on #2901 from @EddieRingle. It generates an external link depending on a check if the local link exists. The check works only when the number of possible resolved links are more than one.



* all-modules-page: Validate cross-module links during resolution

The existing behavior was just taking the first module that includes the
package name of a given reference, so this resulted in broken links when
a package is split across multiple modules.

This change checks to ensure the resolved file exists before choosing it
as the target for the resolved link.

Signed-off-by: Eddie Ringle <eddie@ringle.io>

* Check links only if resolved links has more than one link

* Add integration test

* Refactor

* Add comment

---------

Signed-off-by: Eddie Ringle <eddie@ringle.io>
Co-authored-by: Eddie Ringle <eddie@ringle.io>
IgnatBeresnev pushed a commit that referenced this pull request Jan 11, 2024
Fixes #2272. There is a situation where 2 (or more) gradle modules have the same package and dokka doesn’t know where to link.
E.g.
The class com.example.classA is in moduleA
and com.example.classB is in moduleB
moduleC depends on moduleA and moduleB.
In moduleC: there is a link [com.example.classB]. Having only package-list, dokka doesn’t know where to link, since the package com.example is in both modules.

This is short-term and temporary solution of #3368 to cover a case of links between only local modules in a project.
It is based on #2901 from @EddieRingle. It generates an external link depending on a check if the local link exists. The check works only when the number of possible resolved links are more than one.

* all-modules-page: Validate cross-module links during resolution

The existing behavior was just taking the first module that includes the
package name of a given reference, so this resulted in broken links when
a package is split across multiple modules.

This change checks to ensure the resolved file exists before choosing it
as the target for the resolved link.

Signed-off-by: Eddie Ringle <eddie@ringle.io>

* Check links only if resolved links has more than one link

* Add integration test

* Refactor

* Add comment

---------

Signed-off-by: Eddie Ringle <eddie@ringle.io>
Co-authored-by: Eddie Ringle <eddie@ringle.io>
(cherry picked from commit 6904571)
vmishenev added a commit that referenced this pull request Mar 20, 2024
Fixes #2272. There is a situation where 2 (or more) gradle modules have the same package and dokka doesn’t know where to link.
E.g.
The class com.example.classA is in moduleA
and com.example.classB is in moduleB
moduleC depends on moduleA and moduleB.
In moduleC: there is a link [com.example.classB]. Having only package-list, dokka doesn’t know where to link, since the package com.example is in both modules.

This is short-term and temporary solution of #3368 to cover a case of links between only local modules in a project.
It is based on #2901 from @EddieRingle. It generates an external link depending on a check if the local link exists. The check works only when the number of possible resolved links are more than one.



* all-modules-page: Validate cross-module links during resolution

The existing behavior was just taking the first module that includes the
package name of a given reference, so this resulted in broken links when
a package is split across multiple modules.

This change checks to ensure the resolved file exists before choosing it
as the target for the resolved link.

Signed-off-by: Eddie Ringle <eddie@ringle.io>

* Check links only if resolved links has more than one link

* Add integration test

* Refactor

* Add comment

---------

Signed-off-by: Eddie Ringle <eddie@ringle.io>
Co-authored-by: Eddie Ringle <eddie@ringle.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants