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

allow to specify absolute paths for reports. to support msbuild runner #683

Conversation

jmecosta
Copy link
Member

support absolute path of report paths

@@ -187,6 +196,10 @@ protected String getStringProperty(String name, String def) {
}

for (String relPath : relPaths) {
CxxUtils.LOG.debug("Report '{}'", relPath);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jmecosta it's iterating twice over the paths now? Is there a reason for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

will take this, left for debugging. forgot to remove

Copy link
Member Author

Choose a reason for hiding this comment

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

@guwirth would you be ok to test this?

@jmecosta jmecosta force-pushed the feature/allow-to-specify-absolute-paths-in-report branch from 53daaa4 to 82097da Compare November 21, 2015 12:09
@jmecosta
Copy link
Member Author

comments done

@guwirth
Copy link
Collaborator

guwirth commented Nov 24, 2015

@jmecosta will try to test it this week

@guwirth guwirth added this to the M 0.9.5 milestone Nov 24, 2015
@guwirth
Copy link
Collaborator

guwirth commented Nov 24, 2015

Related to #425

@guwirth
Copy link
Collaborator

guwirth commented Nov 28, 2015

@jmecosta not sure if I understand the feature in the right way? Following it's not working;

sonar-project.properties at D:\Sonar\Test

sonar.cxx.other.reportPath=D:/xxx/reports/externalrules-*.xml

log:

23:31:54.840 INFO  - Base dir: D:\Sonar\Test
23:31:54.840 INFO  - Working dir: D:\Sonar\Test\.sonar
...
23:31:55.830 INFO  - Sensor CxxExternalRulesSensor
23:31:55.830 DEBUG - Using pattern 'D:\xxx\reports\externalrules-*.xml' to find reports
23:31:55.830 DEBUG - Search string transformed from 'D:\xxx\reports\externalrules-*.xml'
23:31:55.830 DEBUG - To ':\xxx\reports\externalrules-*.xml' to find reports, using base Path 'D:\Sonar\Test'
23:31:55.830 WARN  - Cannot find a report for 'sonar.cxx.other.reportPath=:\xxx\reports\externalrules-*.xml'
...

@jmecosta
Copy link
Member Author

I will change it, don't think there any reasons not to use reports outside
project root. In this change you can only specify absolute paths that are
inside project root

On Sun, Nov 29, 2015, 00:43 Günter Wirth [email protected] wrote:

@jmecosta https://github.com/jmecosta not sure if I understand the
feature in the right way? Following it's not working;

sonar-project.properties at D:\Sonar\Test

sonar.cxx.other.reportPath=D:/xxx/reports/externalrules-*.xml

log:

23:31:54.840 INFO - Base dir: D:\Sonar\Test
23:31:54.840 INFO - Working dir: D:\Sonar\Test.sonar
...
23:31:55.830 INFO - Sensor CxxExternalRulesSensor
23:31:55.830 DEBUG - Using pattern 'D:\xxx\reports\externalrules-.xml' to find reports
23:31:55.830 DEBUG - Search string transformed from 'D:\xxx\reports\externalrules-
.xml'
23:31:55.830 DEBUG - To ':\xxx\reports\externalrules-.xml' to find reports, using base Path 'D:\Sonar\Test'
23:31:55.830 WARN - Cannot find a report for 'sonar.cxx.other.reportPath=:\xxx\reports\externalrules-
.xml'
...


Reply to this email directly or view it on GitHub
#683 (comment)
.

@guwirth
Copy link
Collaborator

guwirth commented Nov 29, 2015

Still a problem:

09:54:01.296 INFO  - Sensor CxxExternalRulesSensor
09:54:01.296 DEBUG - Using pattern 'D:\xxx\reports\externalrules-*.xml' to find reports
09:54:01.296 DEBUG - Search string transformed from 'D:\xxx\reports\externalrules-*.xml'
09:54:01.296 DEBUG - To 'D:\xxx\reports\externalrules-*.xml' to find reports, using base Path 'D:\Sonar\Test'
09:54:01.296 WARN  - Cannot find a report for 'sonar.cxx.other.reportPath=D:\xxx\reports\externalrules-*.xml'

@guwirth
Copy link
Collaborator

guwirth commented Nov 29, 2015

@jmecosta Think would be better you write some unit tests. In my example above this should work:

 Base dir: D:\Sonar\Test

inside root absolute and relative inside root

sonar.cxx.other.reportPath=reports/externalrules-*.xml
sonar.cxx.other.reportPath=D:/Sonar/Test/reports/externalrules-*.xml

outside root absolute and relative outside root

sonar.cxx.other.reportPath=../../xxx/reports/externalrules-*.xml
sonar.cxx.other.reportPath=D:/xxx/reports/externalrules-*.xml

outside root on other drive

sonar.cxx.other.reportPath=C:/xxx/reports/externalrules-*.xml

DirectoryScanner scanner = new DirectoryScanner();
String[] includes = new String[1];
includes[0] = reportPath;
scanner.setIncludes(includes);
String baseDirPath = baseDirPath1;
scanner.setBasedir(new File(baseDirPath));
Copy link
Collaborator

Choose a reason for hiding this comment

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

is old baseDirPath

@jmecosta
Copy link
Member Author

@guwirth i will write a integration test, i think its a better solution than unit test for this case. anyway this is still incomplete. thanks for the initial test, i will update and create the it and let you know its ready

@jmecosta
Copy link
Member Author

@guwirth do you know why we have 2 basedir paths in the getReports function in CxxReportSensor?

can get the use for 2 paths from the tests..

edit: ok, so one is the root of the project and the other is the root of the module

@jmecosta jmecosta force-pushed the feature/allow-to-specify-absolute-paths-in-report branch from 2275078 to 6b2fd4c Compare November 29, 2015 19:25
@guwirth
Copy link
Collaborator

guwirth commented Dec 1, 2015

@jmecosta will test and if positive merge it this evening.

@guwirth
Copy link
Collaborator

guwirth commented Dec 1, 2015

@jmecosta I'm sorry but my example is still not working 👎

22:00:17.399 INFO  - Sensor CxxExternalRulesSensor
22:00:17.399 DEBUG - Using pattern 'D:\xxx\reports\externalrules-*.xml' to find reports
22:00:17.399 DEBUG - Unprocessed root directory 'D:\Sonar\Test'
22:00:17.399 DEBUG - Unprocessed report file 'D:\xxx\reports\externalrules-*.xml'
22:00:17.399 DEBUG - Processed root directory '\'
22:00:17.399 DEBUG - Processed report file 'D:\xxx\reports\externalrules-*.xml'
22:00:17.399 DEBUG - Unprocessed root directory 'D:\Sonar\Test'
22:00:17.399 DEBUG - Unprocessed report file 'D:\xxx\reports\externalrules-*.xml'
22:00:17.399 DEBUG - Processed root directory '\'
22:00:17.399 DEBUG - Processed report file 'D:\xxx\reports\externalrules-*.xml'
22:00:17.400 WARN  - Cannot find a report for 'sonar.cxx.other.reportPath=D:\xxx\reports\externalrules-*.xml'
22:00:17.400 INFO  - Sensor CxxExternalRulesSensor (done) | time=1ms

@jmecosta
Copy link
Member Author

jmecosta commented Dec 2, 2015

Ok suppose we need the it after all.

On Tue, Dec 1, 2015, 23:06 Günter Wirth [email protected] wrote:

@jmecosta https://github.com/jmecosta I'm sorry but my example is still
not working [image: 👎]

22:00:17.399 INFO - Sensor CxxExternalRulesSensor
22:00:17.399 DEBUG - Using pattern 'D:\xxx\reports\externalrules-.xml' to find reports
22:00:17.399 DEBUG - Unprocessed root directory 'D:\Sonar\Test'
22:00:17.399 DEBUG - Unprocessed report file 'D:\xxx\reports\externalrules-
.xml'
22:00:17.399 DEBUG - Processed root directory ''
22:00:17.399 DEBUG - Processed report file 'D:\xxx\reports\externalrules-.xml'
22:00:17.399 DEBUG - Unprocessed root directory 'D:\Sonar\Test'
22:00:17.399 DEBUG - Unprocessed report file 'D:\xxx\reports\externalrules-
.xml'
22:00:17.399 DEBUG - Processed root directory ''
22:00:17.399 DEBUG - Processed report file 'D:\xxx\reports\externalrules-.xml'
22:00:17.400 WARN - Cannot find a report for 'sonar.cxx.other.reportPath=D:\xxx\reports\externalrules-
.xml'
22:00:17.400 INFO - Sensor CxxExternalRulesSensor (done) | time=1ms


Reply to this email directly or view it on GitHub
#683 (comment)
.

@guwirth guwirth mentioned this pull request Dec 5, 2015
@jmecosta
Copy link
Member Author

jmecosta commented Dec 5, 2015

@guwirth actually it almost works.

DEBUG: Processed report file 'e:\reports\reports-xunit*.xml'
INFO: Cannot find a report for 'sonar.cxx.xunit.reportPath=e:\reports\reports-xunit*.xml'
DEBUG: No reports found, nothing to process
INFO: Sensor CxxXunitSensor (done) | time=1ms
INFO: Sensor CxxCoverageSensor
DEBUG: Parsing coverage reports
INFO: Processing report 'e:\reports\bullseye-coverage-results\bullseyecoverage-result-0.xml'
INFO: Parsing 'Cobertura' format
INFO: Parsing 'Bullseye' format
INFO: Added report 'e:\reports\bullseye-coverage-results\bullseyecoverage-result-0.xml' (parsed by: BullseyeParser) to the coverage data

if path is real file then is able to read it. need to figure out how that directory scanner works with these cases.

@jmecosta
Copy link
Member Author

jmecosta commented Dec 5, 2015

@guwirth i am really surprised with the behaviour of this directory scanner... i wrote a test to check for existing paths... the log shows this:

18:58:10.808 [main] DEBUG CxxPlugin - Unprocessed root directory 'E:\src\data'
18:58:10.810 [main] DEBUG CxxPlugin - Unprocessed report file 'E:\reports\reports-rats*.xml'
18:58:10.812 [main] DEBUG CxxPlugin - Processed root directory 'E:'
18:58:10.812 [main] DEBUG CxxPlugin - Processed report file 'reports\reports-rats*.xml'

In test it asserts that
assertThat(relPaths.length).isEqualTo(1615);

When i run the analysis i get:

DEBUG: Using pattern 'E:\reports\reports-rats*.xml' to find reports
DEBUG: Unprocessed root directory 'E:\src\data'
DEBUG: Unprocessed report file 'E:\reports\reports-rats*.xml'
DEBUG: Processed root directory 'E:'
DEBUG: Processed report file 'reports\reports-rats*.xml'
DEBUG: Number of Report Files Found '0'

Exactly the same output, one detects 1615 reports the other one 0.

What i am missing here? Can you cofirm this behaviour in your side? the test is this testWithRealDataInTest

this solution should work, as per test. i am ensure why its not working

@jmecosta
Copy link
Member Author

jmecosta commented Dec 5, 2015

drop directory scanner and use

http://wilddiary.com/list-files-matching-a-naming-pattern-java/

@guwirth
Copy link
Collaborator

guwirth commented Dec 5, 2015

@jmecosta did some tests removing reactor. Maybe you can take this into account => #695

@jmecosta
Copy link
Member Author

jmecosta commented Dec 6, 2015

are you suggesting to remove the reactor. for absolute paths the reactor does not apply, the base dir should be basepath or the padron is defined.

@jmecosta
Copy link
Member Author

jmecosta commented Dec 6, 2015

@guwirth i have something that works now for your case, hopefully it works also for other cases but the implementation is now totally different and tests need to be adjusted a lot.

also in my opinion we should isolate the tests for path lookup, reports parsing and metrics saving (there should not be any unit tests really but integration tests), having unit tests that do all requires loads of maintenance if we need to refactor some parts as we are doing it now

wdyt?

@jmecosta
Copy link
Member Author

jmecosta commented Dec 6, 2015

the implementation is like this:

absolute Path: x:\abc\dfe\abc.xml
. baseroot -> x:\abc\dfe
. search pattern -> abc.xml
. recursive -> false

absolute Path: c:\abc\dfe*.xml (or anytype of https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob)
. baseroot -> x:\abc\dfe
. search pattern -> *.xml or anytype of glob
. recursive -> false

relative Paths: abc.xml
. baseroot -> Reactor base Path, or Module Base Path if not found in reactor
. search pattern -> abc.xml
. recursive -> false

relative Paths: *.xml (or anytype of https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob)
. baseroot -> Reactor base Path, or Module Base Path if not found in reactor
. search pattern -> *.xml (or anytype of https://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob)
. recursive -> false

relative Paths: **/abc.xml
. baseroot -> Reactor base Path only because in fact all abc,xml in all folders will be found
. search pattern -> abc.xml
. recursive -> true

the code is much simpler now. also a notice the normalizepath function is really slow and we need to find some alternative also during this refactoring

@guwirth
Copy link
Collaborator

guwirth commented Dec 11, 2015

@jmecosta Travis build is working again. You can squash and rebase to get new results.

@jmecosta jmecosta force-pushed the feature/allow-to-specify-absolute-paths-in-report branch from e4f717b to 3e4f489 Compare December 11, 2015 15:49
@jmecosta
Copy link
Member Author

@guwirth its done, but this is not expected to pass for now. ive disable many unit tests. if we agree on a way to go then i will refactor the tests also

however i think you can test this to see if it supports your use case

@jmecosta
Copy link
Member Author

@guwirth appveyour down?

@guwirth
Copy link
Collaborator

guwirth commented Dec 11, 2015

@jmecosta Travis & AppVeyor failing, problem in multi-module IT.

@jmecosta jmecosta force-pushed the feature/allow-to-specify-absolute-paths-in-report branch from 1f3afb3 to 2e2012e Compare December 11, 2015 18:38
@SonarOpenCommunityAdmin
Copy link
Collaborator

appveyour should now pass. i need to check that it once it runs again.

@jmecosta jmecosta force-pushed the feature/allow-to-specify-absolute-paths-in-report branch from 6c89e46 to 4eae78e Compare December 12, 2015 07:45
@jmecosta
Copy link
Member Author

@guwirth i added a new it test, its a complex multimodule project. it can be used to test the process of reports relative to module. its currently testing reports outside project folder, however you might need to create a python function to change the contents of the reports if we are in windows or linux

@jmecosta jmecosta force-pushed the feature/allow-to-specify-absolute-paths-in-report branch from 5f09764 to a663b63 Compare December 12, 2015 11:24
@jmecosta
Copy link
Member Author

@guwirth tests are now passing in windows, and ITs are also passing in all configurations. there is 1 test failing in unix only that i am ensure whats the issue. not sure why it fails. ive push a commit to improve the logging of the test.

i supose review is ready, and please try also running with with your test data that was failing earlier

@jmecosta
Copy link
Member Author

All green now

@guwirth
Copy link
Collaborator

guwirth commented Dec 12, 2015

@jmecosta it's working now 👍
@Bertk: do you also wanna test it?

  • test with Windows 7 x64, SQ 5.1.2, this PR
  • reports absolute outside of baseDir
  • path in reports: absolute
sonar.cxx.other.reportPath=D:/xxx/reports/externalrules-*.xml
sonar.cxx.coverage.reportPath=D:/xxx/reports/coverage-*.xml
<?xml version="1.0"?>
<results>
<error file="D:\Sonar\Test\error_recovery\pi\Pi.cpp" line="11" ... />
<error file="d:\sonar\test\error_recovery\pi\pi.cpp" line="12" ... />
</results>

@@ -0,0 +1,2 @@
sonar.projectName=2
sonar.sources=./
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is sources this ./ and not only . ?

@guwirth
Copy link
Collaborator

guwirth commented Dec 13, 2015

@jmecosta could you squash and rebase that please that we can merge it.
@Bertk any comments from your side?

@jmecosta jmecosta force-pushed the feature/allow-to-specify-absolute-paths-in-report branch from 89262b0 to d2038d6 Compare December 13, 2015 08:34
@jmecosta
Copy link
Member Author

done

@Bertk
Copy link
Contributor

Bertk commented Dec 13, 2015

@jmecosta I started an analysis with the PR this morning and results are OK. By the way I also used PR #695 😉

@guwirth
Copy link
Collaborator

guwirth commented Dec 13, 2015

@Bertk what is your main use case:

  • path to reports in config file relative or absolute?
  • reports inside or outside baseDir?
  • file items in report files relative or absolute?

guwirth added a commit that referenced this pull request Dec 13, 2015
…te-paths-in-report

allow to specify absolute paths for reports. to support msbuild runner
@guwirth guwirth merged commit 0ecf39e into SonarOpenCommunity:master Dec 13, 2015
@Bertk
Copy link
Contributor

Bertk commented Dec 13, 2015

@guwirth

  • I use relative and absolute paths for the reports
  • additional I use multiple test reports for one component ( comma separate) . The ant pattern is useless because the files located in different folders and I use absolute paths for the test results
  • the reports for pc-lint, cppcheck, Vera++, RATS are located in basedir. I use post-build events to create this reports within CI builds
  • I use a mixture of relative or absolute paths for the files within the reports (vc compiler and pc-lint with absolute paths, Vera++ and CppCheck or RATS with relative paths)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants