SonarQubeCommunity / sonar-pdf-report

80 stars 81 forks source link

SonarQube 5.1 compatibility issue #8

Open amuniz opened 9 years ago

amuniz commented 9 years ago

As explained here there is a compatibility issue with SonarQube 5.1.

st-f commented 8 years ago

Seconding.

dnyaneshwarsonawane commented 8 years ago

+1

kudlatyamroth commented 8 years ago
ERROR: Error during Sonar runner execution
org.sonar.runner.impl.RunnerException: Unable to execute Sonar
    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
    at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
    at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
    at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
    at org.sonar.runner.api.Runner.execute(Runner.java:100)
    at org.sonar.runner.Main.executeTask(Main.java:70)
    at org.sonar.runner.Main.execute(Main.java:59)
    at org.sonar.runner.Main.main(Main.java:53)
Caused by: java.lang.NoSuchMethodError: org.sonar.api.resources.Project.getConfiguration()Lorg/apache/commons/configuration/Configuration;
    at org.sonar.report.pdf.batch.PDFPostJob.shouldExecuteOnProject(PDFPostJob.java:57)
    at org.sonar.batch.bootstrap.BatchExtensionDictionnary.shouldKeep(BatchExtensionDictionnary.java:260)
    at org.sonar.batch.bootstrap.BatchExtensionDictionnary.getFilteredExtensions(BatchExtensionDictionnary.java:101)
    at org.sonar.batch.bootstrap.BatchExtensionDictionnary.select(BatchExtensionDictionnary.java:74)
    at org.sonar.batch.phases.PostJobsExecutor.execute(PostJobsExecutor.java:52)
    at org.sonar.batch.phases.PhaseExecutor.execute(PhaseExecutor.java:107)
    at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:185)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:132)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
    at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:243)
    at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:238)
    at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:228)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:132)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
    at org.sonar.batch.task.ScanTask.execute(ScanTask.java:55)
    at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:132)
    at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:117)
    at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:122)
    at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:119)
    at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:79)
    at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
    ... 9 more
rddesmit commented 8 years ago

+1

dnyaneshwarsonawane commented 8 years ago

+1

amedee commented 8 years ago

People. Please. Don't +1. Use the voting icons at the top. Do not spam other people with your +1 comments.

designerferro commented 8 years ago

I don't know about you, but my PDF Report is working. This was originally a credentials for access problem. My sonar.runner java call has 2 -D options for this:

-Dsonar.pdf.username="USERNAME" -Dsonar.pdf.password="PASSWORD"

Then, in june 2015, 3 patch went in to solve the issue in this URL https://github.com/sonar-pdf-report/network. Today the url gets a 404 HTTP ERROR.

diff --git a/src/main/java/org/sonar/report/pdf/builder/RuleBuilder.java b/src/main/java/org/sonar/report/pdf/builder/RuleBuilder.java

index 338fed1..5eb31cf 100644 --- a/src/main/java/org/sonar/report/pdf/builder/RuleBuilder.java +++ b/src/main/java/org/sonar/report/pdf/builder/RuleBuilder.java @@ -93,7 +93,10 @@ public void loadViolatedResources(final Rule rule, final String ruleKey, final S // ruleKey = URLEncoder.encode(ruleKey, "UTF8"); LOG.debug("Accessing Sonar: getting violated resurces by one given rule (" + ruleKey + ")");

- SonarClient client = SonarClient.create(credentials.getUrl());

  • SonarClient client = SonarClient.builder().url(credentials.getUrl())
  • .login(credentials.getUsername())
  • .password(credentials.getPassword())
  • .build(); IssueClient issueClient = client.issueClient(); IssueQuery issueQuery = IssueQuery.create();

Patch 11 contained the following:

src/main/java/org/sonar/report/pdf/batch/PDFGenerator.java | 9 +-------- src/main/java/org/sonar/report/pdf/batch/PDFPostJob.java | 6 +----- 2 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/sonar/report/pdf/batch/PDFGenerator.java b/src/main/java/org/sonar/report/pdf/batch/PDFGenerator.java index 533a370..3d1cf71 100644 --- a/src/main/java/org/sonar/report/pdf/batch/PDFGenerator.java +++ b/src/main/java/org/sonar/report/pdf/batch/PDFGenerator.java @@ -44,20 +44,18 @@ private String sonarHostUrl; private String username; private String password;

  • private String sonarBranch; private String reportType;

    private Project project; private FileSystem fs;

    public PDFGenerator(final Project project, final FileSystem fs, final String sonarHostUrl, final String username, final String password,

  • final String sonarBranch, final String reportType) {
  • final String reportType) { this.project = project; this.fs = fs; this.sonarHostUrl = sonarHostUrl; this.username = username; this.password = password;
  • this.sonarBranch = sonarBranch; this.reportType = reportType; }

@@ -82,11 +80,6 @@ public void execute() { String sonarProjectId = project.getEffectiveKey(); String path = fs.workDir().getAbsolutePath() + "/" + sonarProjectId.replace(':', '-') + ".pdf";

- if (sonarBranch != null) {

  • sonarProjectId += ":" + sonarBranch;
  • LOG.info("Branch " + sonarBranch + " selected");
  • }
  • PDFReporter reporter = null; if (reportType != null) { if (reportType.equals("executive")) { diff --git a/src/main/java/org/sonar/report/pdf/batch/PDFPostJob.java b/src/main/java/org/sonar/report/pdf/batch/PDFPostJob.java index df360a7..55f295e 100644 --- a/src/main/java/org/sonar/report/pdf/batch/PDFPostJob.java +++ b/src/main/java/org/sonar/report/pdf/batch/PDFPostJob.java @@ -51,9 +51,6 @@ public static final String SONAR_HOST_URL = "sonar.host.url"; public static final String SONAR_HOST_URL_DEFAULT_VALUE = "http://localhost:9000";

- public static final String SONAR_BRANCH = "sonar.branch";

  • public static final String SONAR_BRANCH_DEFAULT_VALUE = null;
  • private final Settings settings; private final FileSystem fs;

@@ -73,9 +70,8 @@ public void executeOn(final Project project, final SensorContext context) { String sonarHostUrl = settings.hasKey(SONAR_HOST_URL) ? settings.getString(SONAR_HOST_URL) : SONAR_HOST_URL_DEFAULT_VALUE; String username = settings.hasKey(USERNAME) ? settings.getString(USERNAME) : USERNAME_DEFAULT_VALUE; String password = settings.hasKey(PASSWORD) ? settings.getString(PASSWORD) : PASSWORD_DEFAULT_VALUE;

  • String branch = settings.hasKey(SONAR_BRANCH) ? settings.getString(SONAR_BRANCH) : SONAR_BRANCH_DEFAULT_VALUE; String reportType = settings.hasKey(REPORT_TYPE) ? settings.getString(REPORT_TYPE) : REPORT_TYPE_DEFAULT_VALUE;
  • PDFGenerator generator = new PDFGenerator(project, fs, sonarHostUrl, username, password, branch, reportType);
  • PDFGenerator generator = new PDFGenerator(project, fs, sonarHostUrl, username, password, reportType);

generator.execute();

Patch 12 contained the following:

src/main/java/org/sonar/report/pdf/batch/PDFPostJob.java | 2 +- src/main/java/org/sonar/report/pdf/util/FileUploader.java | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/sonar/report/pdf/batch/PDFPostJob.java b/src/main/java/org/sonar/report/pdf/batch/PDFPostJob.java index df360a7..fc10182 100644 --- a/src/main/java/org/sonar/report/pdf/batch/PDFPostJob.java +++ b/src/main/java/org/sonar/report/pdf/batch/PDFPostJob.java @@ -83,7 +83,7 @@ public void executeOn(final Project project, final SensorContext context) {

 File pdf = new File(path);
 if (pdf.exists()) {

- FileUploader.upload(pdf, sonarHostUrl + "/pdf_report/store");

  • FileUploader.upload(pdf, sonarHostUrl + "/pdf_report/store", username, password); } else { LOG.error("PDF file not found in local filesystem. Report could not be sent to server."); } diff --git a/src/main/java/org/sonar/report/pdf/util/FileUploader.java b/src/main/java/org/sonar/report/pdf/util/FileUploader.java index 27cd7c3..5b19cc6 100644 --- a/src/main/java/org/sonar/report/pdf/util/FileUploader.java +++ b/src/main/java/org/sonar/report/pdf/util/FileUploader.java @@ -22,8 +22,11 @@

    import java.io.File;

+import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.multipart.FilePart; import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; @@ -36,7 +39,7 @@

private static final Logger LOG = LoggerFactory.getLogger(PDFPostJob.class);

- public static void upload(final File file, final String url) {

  • public static void upload(final File file, final String url, String username, String password) { PostMethod filePost = new PostMethod(url);
 try {

@@ -47,6 +50,11 @@ public static void upload(final File file, final String url) { filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));

   HttpClient client = new HttpClient();

+ if (username != null && !username.isEmpty() && password != null && !password.isEmpty()) {

  • client.getParams().setAuthenticationPreemptive(true);
  • Credentials credentials = new UsernamePasswordCredentials(username, password);
  • client.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), credentials);
  • } client.getHttpConnectionManager().getParams().setConnectionTimeout(10000); int status = client.executeMethod(filePost); if (status == HttpStatus.SC_OK) {
LavrL commented 7 years ago

So now sonar-pdf-report plugin is compatible with SQ 5.1?

amedee commented 7 years ago

@MacXatu could you please edit your comment to make the code properly formatted? @LavrL it doesn't help if you send email to my work address, I'm a user waiting for a solution just like you.

designerferro commented 7 years ago

@amedee fixed it. Had to escape all the - and +.

designerferro commented 7 years ago

I just checked the URL I was getting a 404 http erro. This was moved to https://github.com/SonarQubeCommunity/sonar-pdf-report/network. If you go there you can get all the info directly.

LavrL commented 7 years ago

Compatibility with SQ 5.1 is fixed?

On Wed, Sep 7, 2016 at 12:55 PM, designerferro notifications@github.com wrote:

I just checked the URL I was getting a 404 http erro. This was moved to https://github.com/SonarQubeCommunity/sonar-pdf-report/network. If you go there you can get all the info directly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SonarQubeCommunity/sonar-pdf-report/issues/8#issuecomment-245232598, or mute the thread https://github.com/notifications/unsubscribe-auth/ATDQ8j8GRX9PO9MLpTqEMds0gWRv0-rdks5qnoovgaJpZM4EfEtK .

monaka commented 7 years ago

@LavrL Patches are required but basically code can be rebuilt with 5.1 libs. I'm facing 404 error but it will be fixed by applying patches @MacXatu suggested.

amit-srivastava-007 commented 7 years ago

Hi,

I am using SonarQube v6.2 getting same error with PDF report plugin

Exception in thread "main" java.lang.NoSuchMethodError: org.sonar.api.resources.Project.getConfiguration()Lorg/apache/commons/configuration/Configuration; at org.sonar.report.pdf.batch.PDFPostJob.shouldExecuteOnProject(PDFPostJob.java:57) at org.sonar.scanner.bootstrap.BatchExtensionDictionnary.shouldKeep(BatchExtensionDictionnary.java:261) at org.sonar.scanner.bootstrap.BatchExtensionDictionnary.getFilteredExtensions(BatchExtensionDictionnary.java:101) at org.sonar.scanner.bootstrap.BatchExtensionDictionnary.select(BatchExtensionDictionnary.java:74) at org.sonar.scanner.phases.PostJobsExecutor.execute(PostJobsExecutor.java:50) at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:82) at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:182) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:247) at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:242) at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:232) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:47) at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:86) at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142) at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127) at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:115) at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:116) at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:62) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60) at com.sun.proxy.$Proxy0.execute(Unknown Source) at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233) at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151) at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:110) at org.sonarsource.scanner.cli.Main.execute(Main.java:74) at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Can someone suggest what to be done?

designerferro commented 7 years ago

This is because the SonarQube API changed. Until someone recodes this, the plugin won't work.

Amuniz isn't answering calls to explain how to do this.