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

Improved path handling, reported filenames are converted to src dir relative paths #22

Merged

Conversation

MichaelZinsmaier
Copy link
Contributor

Hi,

thats the 1st in a series of 3 pull request I tried to separate functionality a bit.

This one changes the treatment of the "filename" attributes in the scoverage report files. The report
files seem to vary regarding the filename format, I encountered 3 different formats

  • absolute path
  • relative to the base dir
  • relative to the source directory

The PR adds a path cleanup step, that aligns the filenames to a source file tree and converts them all to paths relative to the source directory. This allows to adapt the code in the sensor such that files are not longer searched with **/filepath.

Additionally the test cases are not longer dependent on Unix, but run equally well on Windows.

Some Remarks:

  • I'm not entire sure about the licensing text for the new classes, I copied yours is that ok?
  • I did tests mainly with Windows, partially also with Unix but if you have more real Scala projects
    more tests might be a good idea
  • this PR is a precondition for the 2nd one. In order to support directory coverage you have to get
    an InputDir and to get that you need a resolvable filename, which sadly does not work over
    FilePredicates (or I could at least not figure out how)

ok hope you find time to look through it

Best Michael

The stub parser is not used anymore, removed it
Justification: relying on getParentFile gets the path splitting working  under windows and unix

- adapted the tests to the new behavior
- added a windows / unix switch in the tests to get them working on both systems

PathUtils now converts:
- the empty path to an empty List
- an absolute path to a list folders (not including the drive name under windows)
- a relative path to a list of folders
Justification:

- sanitizing the reported file pathes to a common format makes the sensor simpler
- it is a precondition for implementing proper directory coverage
- tests run now under unix and windows, easier to develop

The sonar.sources property can be read from the settings. By mapping all
reported pathes (absolute / base dir relative / source dir relative) against
the actual file tree it is possible to converte all of them to the same
source dir relative format.

For instance

    /home/src/main/scala/folder/test0.scala  => folder/test0.scala
                         folder/test1.scala  => folder/test1.scala
         /src/main/scala/test2.scala         =>        test2.scala
   ...
- testing absolute report file paths
- testing base dir relative report file paths
- testing source dir relative report file paths
RadoBuransky added a commit that referenced this pull request Oct 25, 2015
Improved path handling, reported filenames are converted to src dir relative paths
@RadoBuransky RadoBuransky merged commit 3ed8ee8 into RadoBuransky:master Oct 25, 2015
@RadoBuransky
Copy link
Owner

Looks great. I will merge all PRs and will release a new version. Let's see if you broke something. Thanks!

@RadoBuransky
Copy link
Owner

@MichaelZinsmaier: Your changes have been included in the 5.1.2 release. Thanks. https://github.com/RadoBuransky/sonar-scoverage-plugin/releases/tag/v5.1.2

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.

2 participants