Question

I'm relative new to Sonar - especially to writing my own Sonar Plugin. After some successful trials, I got stuck now. I have written a simple Plugin which only should transfer source files (*.abap -Files) to the sonar server.

and in my plugin I have an AbapLangauge (extended from AbstractLangauge)

package sonarplugin;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.resources.AbstractLanguage;

public class AbapLanguage extends AbstractLanguage {
  public static final String DEFAULT_SOURCE_SUFFIXES = "abap";
  public static final String KEY = "sap";

  private String[] fileSuffixes;
  private static final Logger LOG = LoggerFactory.getLogger(AbapLanguage.class);

  public AbapLanguage() {   
    super(KEY, "sap");
    LOG.info("SETTING LANGUAGE TO SAP: " + KEY);
    fileSuffixes = createStringArray(null, DEFAULT_SOURCE_SUFFIXES);
  }

  public String[] getFileSuffixes() {
      return fileSuffixes;
  }

  private String[] createStringArray(String[] values, String defaultValues) {
    if (values == null || values.length == 0) {
      return StringUtils.split(defaultValues, ",");
    }
    return values;
  }

}

And I also have an SourceImporter

package sonarplugin;

import org.sonar.api.batch.AbstractSourceImporter;

public final class AbapSourceImporter extends AbstractSourceImporter {

public AbapSourceImporter(AbapLanguage language) {
    super(language);
}
}

I registered these two classes as extension points. In my testproject which I want to analyse with the sonar-runner I have set in the sonar-project.properties

sonar.language=sap

But when I start the sonar runner I get the follwing error:

15:11:36.148 INFO  - -------------  Executing Project Scan
15:11:36.386 INFO  - ABAPIMPORTGERPLUGIN has just started.
15:11:36.924 INFO  - Install JDBC driver
15:11:36.929 INFO  - Apply project exclusions
15:11:36.937 WARN  - H2 database should be used for evaluation purpose only
15:11:36.937 INFO  - Create JDBC datasource for jdbc:h2:tcp://localhost:9092/sonar
15:11:37.051 INFO  - Initializing Hibernate
15:11:42.669 INFO  - -------------  Inspecting MeinTestprojekt
15:11:42.683 INFO  - Load module settings
15:11:43.062 INFO  - ABAPIMPORTGERPLUGIN has just started.
15:11:43.244 INFO  - SETTING LANGUAGE TO SAP: sap
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 15.544s
INFO: Final Memory: 10M/158M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: You must install a plugin that supports the language 'sap'

Can somebody help me? Why sonar-runner says that there is no plugin that supports the language 'sap'? Isn't my plugin configured right?

thank in advanced bernhard

Was it helpful?

Solution

In your specific case, the problem comes from the fact that you do not have defined any rule repository (even an empty one) for your new language, so Sonar thinks that your new language is not supported.

More generally, the best option for you is to take a look at some open-source language plugins that we develop for Sonar. For instance, you can go and see the Javascript plugin.

OTHER TIPS

Some more reasons why this error might occur:

  1. You did not define your language class in the getExtensions() method of your Plugin class
  2. In your SonarQube web site, no profile for your language has been created. Click on Quality-Profiles --> choose the create button next to your language --> click on create. Then, click on "Set as default". (Note: Your language will only appear if getExtensions() has been implemented correctly as described in 1.)

Having just been through this same process, the rough set of things that seem to be needed (and advertised by your plugin's getExtensions() method) are:

  • A subclass of org.sonar.api.resources.AbstractLanguage - your constructor's call to super supplies the language code and its name as two parameters
  • An implementation of org.sonar.api.server.rule.RulesDefinition
  • A subclass of org.sonar.api.profiles..ProfileDefinition that returns a RulesProfile object with your languaged code referenced
  • Plus whatever implementations of other extension points your plugin needs to actually do any useful work - probably a org.sonar.api.batch.Sensor implementation at least
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top