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

Custom rules no longer working with v0.9.8 #1308

Closed
ghost opened this issue Nov 16, 2017 · 12 comments · Fixed by #1343, #1346 or #1347
Closed

Custom rules no longer working with v0.9.8 #1308

ghost opened this issue Nov 16, 2017 · 12 comments · Fixed by #1343, #1346 or #1347
Assignees
Labels
Milestone

Comments

@ghost
Copy link

ghost commented Nov 16, 2017

I had previously made my own custom rules plugin, which worked perfectly with the cxx plugin v0.9.7. I updated the cxx plugin to v0.9.8 and my plugin is no longer working.

My plugin was made according to Extending-the-code-analysis, Writing your own rules using SSLR, aka custom cxx-rules and cxx-custom-checks-example-plugin.

Since there was compile errors with v0.9.8, I had to make minor changes in my plugin (new package for CustomCxxRulesDefinition, and CppLanguage handling).

Now, when I analyze a C++ project, I see in the logs that my custom rules plugin starts correctly (i.e. the define() method of my plugin is called). This method is as follow:

    @Override
    public void define(Context context) {
        context.addExtension(MyCxxCustomRulesDefinition.class);
        LOGGER.info("MyCxxCustomRulesPlugin plugin started with {} rules",
                    MyCxxCustomRulesDefinition.CLASSES.length);
    }

However, it seems that the context.addExtension() call is ignored, since none of the methods of the MyCxxCustomRulesDefinition class are called. This worked previously.

Do I have missed something to make my plugin working?

@guwirth
Copy link
Collaborator

guwirth commented Nov 17, 2017

@phcouton I'm sorry that this is no more working. Starting with SQ 6.2 there were a lot of API changes, maybe one of them is the reason for this. I recommend you to have a look in Java or JavaScript source code how they are doing it and adapt your code accordingly.

To avoid this in future you should add some unit test to our code to ensure the interface is functional.

@ghost
Copy link
Author

ghost commented Nov 20, 2017

@guwirth I don't think that is related to the API changes introduced with of SQ 6.2:

  • SQ 6.2 + Cxx 0.9.7 + custom rules plugin: OK
  • SQ 6.2 + Cxx 0.9.8 + custom rules plugin: KO

If this can help to spot the problem, I found this:

  • CustomCxxRulesDefinition is only used in CxxChecks.addCustomChecks(CustomCxxRulesDefinition[])
  • CxxChecks.addCustomChecks(CustomCxxRulesDefinition[]) is only called from CxxSquidSensor.CxxSquidSensor(CxxLanguage, FileLinesContextFactory, CheckFactory, CustomCxxRulesDefinition[], CxxCoverageCache)
  • This one is only called from CxxSquidSensor.CxxSquidSensor(CxxLanguage, FileLinesContextFactory, CheckFactory, CxxCoverageCache), forcing the CustomCxxRulesDefinition[] to null!

So, the CustomCxxRulesDefinition[] is never used.

@ghost ghost closed this as completed Nov 20, 2017
@ghost
Copy link
Author

ghost commented Nov 20, 2017

Oops, closed by error!

@ghost ghost reopened this Nov 20, 2017
@guwirth
Copy link
Collaborator

guwirth commented Nov 20, 2017

@phcouton maybe you can compare with the 0.9.7 source code to see how it has been called there. Select in our repository the tag for 0.9.7 to see the old code.

grafik

@guwirth guwirth changed the title Custom rules no longer working with v0.9.8 ? Custom rules no longer working with v0.9.8 Nov 25, 2017
@guwirth guwirth added bug and removed question labels Nov 25, 2017
@guwirth guwirth added this to the 0.9.9 milestone Nov 25, 2017
@guwirth guwirth self-assigned this Nov 25, 2017
@guwirth
Copy link
Collaborator

guwirth commented Nov 25, 2017

@phcouton after splitting the plugin into c and cxx plugin there was only one ctor exported. Just a guess: but exporting both again custom rules should work again. Maybe you can try with #1343.

@guwirth
Copy link
Collaborator

guwirth commented Nov 26, 2017

@phcouton please try again with latest snapshot. Please keep in mind that 0.9.9 is working with SQ 6.7 only.

@ghost
Copy link
Author

ghost commented Nov 27, 2017

The latest 0.9.9-SNAPSHOT does not work for me (SQ 6.7, SonarScanner 3.0.3, Java 1.8, Linux):

13:34:33.808 INFO: ------------------------------------------------------------------------
13:34:33.808 INFO: EXECUTION FAILURE
13:34:33.808 INFO: ------------------------------------------------------------------------
13:34:33.808 INFO: Total time: 3.467s
13:34:33.844 INFO: Final Memory: 43M/205M
13:34:33.844 INFO: ------------------------------------------------------------------------
13:34:33.844 ERROR: Error during SonarQube Scanner execution
org.picocontainer.PicoCompositionException: 2 satisfiable constructors is too many for 'class org.sonar.plugins.cxx.CxxPlugin$CxxSquidSensorImpl'. Constructor List:[<init>(org.sonar.cxx.CxxLanguage,org.sonar.api.measures.FileLinesContextFactory,org.sonar.api.batch.rule.CheckFactory,org.sonar.cxx.sensors.squid.CustomCxxRulesDefinition[]), <init>(org.sonar.api.config.Configuration,org.sonar.api.measures.FileLinesContextFactory,org.sonar.api.batch.rule.CheckFactory,org.sonar.plugins.cxx.CxxPlugin$CxxCoverageAggregator)]
	at org.picocontainer.injectors.ConstructorInjector.getGreediestSatisfiableConstructor(ConstructorInjector.java:189)
	at org.picocontainer.injectors.ConstructorInjector.getGreediestSatisfiableConstructor(ConstructorInjector.java:110)
	at org.picocontainer.injectors.ConstructorInjector.access$100(ConstructorInjector.java:51)
	at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:331)
	at org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
	at org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
	at org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
	at org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
	at org.picocontainer.DefaultPicoContainer.getLocalInstance(DefaultPicoContainer.java:606)
	at org.picocontainer.DefaultPicoContainer.getComponents(DefaultPicoContainer.java:587)
	at org.sonar.core.platform.ComponentContainer.getComponentsByType(ComponentContainer.java:274)
	at org.sonar.scanner.bootstrap.ScannerExtensionDictionnary.completeBatchExtensions(ScannerExtensionDictionnary.java:148)
	at org.sonar.scanner.bootstrap.ScannerExtensionDictionnary.getExtensions(ScannerExtensionDictionnary.java:143)
	at org.sonar.scanner.bootstrap.ScannerExtensionDictionnary.getFilteredExtensions(ScannerExtensionDictionnary.java:121)
	at org.sonar.scanner.bootstrap.ScannerExtensionDictionnary.selectSensors(ScannerExtensionDictionnary.java:82)
	at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:53)
	at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:88)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:180)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:288)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:283)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:261)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
	at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:84)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:121)
	at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:121)
	at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
	at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:111)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:63)
	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:123)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:77)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)

@guwirth
Copy link
Collaborator

guwirth commented Nov 27, 2017

@phcouton thanks for th feedback. Will have a look again.

org.picocontainer.PicoCompositionException:
2 satisfiable constructors is too many for 'class org.sonar.plugins.cxx.CxxPlugin$CxxSquidSensorImpl'.
Constructor List:
[
<init>(org.sonar.cxx.CxxLanguage,org.sonar.api.measures.FileLinesContextFactory,org.sonar.api.batch.rule.CheckFactory,org.sonar.cxx.sensors.squid.CustomCxxRulesDefinition[]),
<init>(org.sonar.api.config.Configuration,org.sonar.api.measures.FileLinesContextFactory,org.sonar.api.batch.rule.CheckFactory,org.sonar.plugins.cxx.CxxPlugin$CxxCoverageAggregator)
]

http://picocontainer.com/faq.html

@guwirth
Copy link
Collaborator

guwirth commented Nov 27, 2017

@phcouton please try again with #1346 (latest snapshot). Sorry is try and error...

@ghost
Copy link
Author

ghost commented Nov 28, 2017

@guwirth Same exception with the latest snapshot.

However, I made a small change in the source of CxxPlugin and there is no longer exception, the custom rules work :

  public static class CxxSquidSensorImpl extends CxxSquidSensor {

    public CxxSquidSensorImpl(Configuration settings,
      FileLinesContextFactory fileLinesContextFactory,
      CheckFactory checkFactory,
      CxxCoverageAggregator coverageCache) {
      super(new CppLanguage(settings), fileLinesContextFactory, checkFactory);
    }

    public CxxSquidSensorImpl(Configuration settings,
      FileLinesContextFactory fileLinesContextFactory,
      CheckFactory checkFactory,
      CxxCoverageAggregator coverageCache, // <-- added this one
      @Nullable CustomCxxRulesDefinition[] customRulesDefinition) {
      super(new CppLanguage(settings), fileLinesContextFactory, checkFactory, customRulesDefinition);
    }
  }

@guwirth
Copy link
Collaborator

guwirth commented Nov 28, 2017

@phcouton I tried it again in #1347 bur the other way around: removing coverageCache because it is not used. Hope this is working now.

@ghost
Copy link
Author

ghost commented Nov 28, 2017

@guwirth No problem on my side. Thanks for your help :)

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

Successfully merging a pull request may close this issue.

1 participant