Skip to content

Conversation

Spezialissimo
Copy link
Contributor

PROBLEM

Ivy does not replace property references in xml files. That means that when they are present, we might get a report that looks like this:

unrecognized,${properties.license.name} (https://example.org/${project.artifactId}),com.example # fake-lib # 1.0.0

I noticed that in some (rare) cases the original xml file only contains the url as info about the license. For this reason, I thought it would have been great if we were able to replace such references before creating the report.

SOLUTION

The current implementation uses a best effort approach.
If it finds any ${} it will try to find the xml file that ivy is retrieving information from. If it's able to find the file, it will try to find the replacement and update the UpdateReport object. If any of this fails, nothing happens and the references don't get replaced.

I'm not an expert of how the information gets originally retrieved, for this reason it will check, in order:

  1. .pom file with same path and name than the .jar file.
  2. any .xml.original file present two directories up from the .jar file.
  3. any .xml file present two directories up from the .jar file.

As these are the cases I found in my experience. If you know of way to improve this search please let me know.

Also, I added a test to check that the replacement is working. I want to reiterate that i'm not an expert of the various edge cases so let me know if you think the tests can be improved.

Additionally, other cases of failures in creating the URI object for the homepage field are now handled, taking in consideration that the ".toUri" function seems to not disclose every kind of exception it can throw.

@Spezialissimo
Copy link
Contributor Author

Since the recent release tests are no longer running, I'll fix this so that i can be reviewed.

@Spezialissimo Spezialissimo changed the title fix: property reference in dependencies' xml files now get replaced in the report fix: resolving property references in xml files Sep 11, 2025
@Spezialissimo
Copy link
Contributor Author

Errors have been fixed

@Spezialissimo Spezialissimo reopened this Sep 11, 2025
@mdedetrich
Copy link
Contributor

@Spezialissimo Need to also run a scalafmt

@mdedetrich
Copy link
Contributor

mdedetrich commented Sep 11, 2025

So far the PR looks good, the only thing I am concerned about is the fallback logic for detecting the ivy properties. I am somewhat sure that sbt also has logic for doing the same just that its private and not accessible from sbt plugins, would it be possible to do some research here? @raboof maybe you want to look into this as well?

@eed3si9n @dwijnand If its not too much work maybe you can provide input here (regarding how xml property substitution works with ivy). I think you two know more about ivy than anyone else in the Scala space

Copy link
Contributor

@raboof raboof left a comment

Choose a reason for hiding this comment

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

I'm not aware of such logic living anywhere else as well

case (Some(node), label) => (node \ label).headOption
case _ => None
}
finalNode.map(_.text.trim).getOrElse("")
Copy link
Contributor

Choose a reason for hiding this comment

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

This default might make it harder to figure out 'downstream' that there is something missing/redacted here. I'm OK with it, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good to add a logger warning here, @Spezialissimo read https://www.scala-sbt.org/1.x/docs/Howto-Logging.html#Log+messages+in+a+task on how to log in sbt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdedetrich Thanks! I'll take a look

Copy link
Contributor

Choose a reason for hiding this comment

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

Also its possible for trim itself to return an empty string "" so you need to handle that case as well. In other words if at any point an empty string is resolved (either because Optional value is empty and it goes to the .getOrElse("") part or there is an empty String value after .trim) we should log that as a warn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdedetrich @raboof
I've pushed the changes addressing your suggestions, thanks a lot!

Let me know if there is anything else

@mdedetrich
Copy link
Contributor

mdedetrich commented Sep 11, 2025

I'm not aware of such logic living anywhere else as well

iirc sbt resolves these property substitutions (even when Ivy is being used) so it must be done somewhere???

@Spezialissimo
Copy link
Contributor Author

@mdedetrich Let me know if there is something else I should look into for this PR, otherwise it would be great if it could be merged and released

@mdedetrich
Copy link
Contributor

@mdedetrich Let me know if there is something else I should look into for this PR, otherwise it would be great if it could be merged and released

One minor nit and then ill approve/merge

@mdedetrich mdedetrich merged commit 8fe4e06 into sbt:main Sep 24, 2025
13 checks passed
@mdedetrich
Copy link
Contributor

mdedetrich commented Sep 24, 2025

@Spezialissimo This is now being published as 1.9.0 to maven https://github.com/sbt/sbt-license-report/actions/runs/17974075180/

@Spezialissimo
Copy link
Contributor Author

Thank you @mdedetrich and @raboof for taking a look into this!

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.

3 participants