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

Remove working directory substring from filename of pmd violation #25

Merged
merged 3 commits into from
Jul 16, 2018

Conversation

djydewang
Copy link
Member

When we generate the baseline which will be uploaded to somewhere, the file attribute of the violation element in the pmd report contains the local working path information. The baseline is used for sharing, so we should remove this part of the information.

Copy link
Member

@adangel adangel left a comment

Choose a reason for hiding this comment

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

Hm.... maybe I misunderstood what you wanted to do. I understood, that you want to remove the local working path information from the pmd report....

You're right and good catch for seeing this problem: If someone would run the tool from a different path than from which the baseline was created, the diff wouldn't work.

I've created now the baseline locally and the full local working path is still contained in the pmd_report.xml files. Is this, what you wanted?
Post-filtering the report might have the advantage, that the files become a bit smaller. But I think, this should really be an option of PMD itself (e.g. output relative filenames....would be a option for the renderer...).

By looking at the code, it should work, since we remove the code on-the-fly when reading the reports.
Note: I think, it won't work with PmdError, since the filename there is still with the local part (and used with the eql method).

@@ -28,11 +29,11 @@ def start_element(name, attrs = [])
case name
when 'file'
@current_violations = []
@current_filename = attrs['name']
@current_filename = attrs['name'].sub(/^#{@working_dir}/, '')
Copy link
Member

Choose a reason for hiding this comment

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

That's the hash key, that is used to collect the violations...

when 'violation'
@current_violation = PmdViolation.new(attrs, @branch_name)
when 'error'
@current_filename = attrs['filename']
@current_filename = attrs['filename'].sub(/^#{@working_dir}/, '')
Copy link
Member

Choose a reason for hiding this comment

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

That's again only the hash key. attrs['filename'] is not changed, so the full filename is later on still available in PmdError.

@@ -25,6 +27,7 @@ def load(report_info_path)
hash = JSON.parse(File.read(report_info_path))
@execution_time = hash['execution_time']
@timestamp = hash['timestamp']
@working_dir = hash['working_dir']
Copy link
Member

Choose a reason for hiding this comment

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

That would expose the working directory again.... which I though, you wanted to remove...

The baseline is used for sharing, so we should remove this part of the information.

Copy link
Member Author

@djydewang djydewang Jul 13, 2018

Choose a reason for hiding this comment

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

This is used to record the working directory when generating the pmd report. When we reading pmd report, we can remove the working dir from pmd report according to value of this 'working dir'.

@djydewang
Copy link
Member Author

I've created now the baseline locally and the full local working path is still contained in the pmd_report.xml files. Is this, what you wanted?

Yes, I agree with you that post-filtering the report should be a option of PMD itself.

Note: I think, it won't work with PmdError, since the filename there is still with the local part (and used with the eql method).

Good catch! I'll fix it.

@adangel adangel merged commit 44d9f9b into pmd:master Jul 16, 2018
adangel added a commit that referenced this pull request Jul 16, 2018
@djydewang djydewang deleted the branch_detail branch July 25, 2018 13:59
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