Remote API should use paths for affected files relative to specified source directory#3214
Conversation
…ve to specified source directory
…e method to IssueApi for relative file name retrieval
|
@uhafner Please review the changes. There is one PMD warning in IssuesPublisher.java file at L306 regarding coupling within the class. I think this is not related my changes. Can you please help me how to fix this? |
uhafner
left a comment
There was a problem hiding this comment.
Why do you check the "tests provided" task, when you do not test your code?
This is really essential: before changing code you must create a test case that exposes the problem!
… directory configuration
|
I added test cases for this change. Please review the changes. @uhafner |
| /** | ||
| * Verifies that the Remote API returns file paths relative to the configured source directory. | ||
| * This test addresses JENKINS-68856 where file paths should be relative to the sourceDirectory | ||
| * when specified, rather than showing the full workspace path. | ||
| */ |
There was a problem hiding this comment.
This test actually does not test anything 🤔
When I remove your production code, the test already passes. This is a fundamental concept in software engineering: first write a test that fails. Then implement the changes.
|
Can you please also have a look at |
…; update related classes to ensure file paths are relative to source directories in the model, addressing JENKINS-68856.
…es parameter; update logic to ensure file paths are relative to source directories, addressing JENKINS-68856. Add tests for relative path functionality in PathRelativeTest.
…warnings and remove unused imports.
The |
…le paths relative to source directories, addressing JENKINS-68856.
| if (!filteredSourceDirectories.isEmpty()) { | ||
| return makePathsRelativeToSourceDirectories(report, filteredSourceDirectories); |
There was a problem hiding this comment.
Can you check, why the FileNameResolver does not already find the correct paths in the code above? Your code seems to do the things that the FileNameResolver already should do 🤔
There was a problem hiding this comment.
Yes, the FileNameResolver.java has a makeRelative method that calls PATH_UTIL.getRelativePath(sourceDirectoryPrefix, fileName) which already makes path relative to source directory. So basically makePathsRelativeToSourceDirectories method is duplicating what already FileNameResolver.java does. But the issue is that FileNameResolver only makes path relative if the file exists in that directory by the filter PATH_UTIL.exists(entry.getValue(), sourceDirectoryPrefix), which won't work for archive/historical build data. Here it is work even for archive data as here is no such filter.
So:
Input: X:/Archive/old-build/tasks/src/main/java/Foo.java
Source: X:/Archive/old-build/tasks/src
Output: main/java/Foo.java
What should I do now?
There was a problem hiding this comment.
But for historical build data the report is not changed at all, these reports are final.
So either the bug is not present anymore or we do oversee something. For me it does not make sense to create a duplicate of the method (where the only change is that the file might not exist anymore).
So if we cannot reproduce the issue in a real integration test (*ITest), I think I would probably close the issue as cannot reproduce.
I'm not sure if you want to spend some more time for an integration test that actually fails when we
- create a job in Jenkins
- create a source file within a sub folder
- create a fake warning for this source file
- run a build with the source prefix option
- check that the path is correctly mapped to the relative path
- call the remote API and see if the path is correctly mapped to the relative path
What do you think?
There was a problem hiding this comment.
I also suspect that the same because the issue was raised back in 2022 and I myself updated FileNameResolver.java file in analysis-model via PR jenkinsci/analysis-model#1279 to fix issue https://issues.jenkins.io/browse/JENKINS-75009. By which I think the issue is already resolved. So it will be better to add a dedicated integration test as well as unit test for the issue to show it is already resolved and close the issue. Other wise keep the PR open, I will reinvestigate it one more time.
… relative to the configured source directory
… relative to the configured source directory
… relative to the configured source directory
… relative to the configured source directory
… relative to the configured source directory
|
I have added an integration test in |
|
Thank you! |
Remote API should use paths for affected files relative to specified source directory
Fixes #3092
Testing done
Submitter checklist