Decorator plugin in SonarQube - plugins

We have implemented a SonarQube-plugin with an extension that implements Decorator and deployed it to extensions/plugins.
Unfortunately, when triggering the sonar-analysis, the extension implementation is not called. Is there anything more that needs to be configured?
The implementation looks as simple as this:
public class MyPlugin extends SonarPlugin {
#Override
public List getExtensions() {
return Arrays.asList(MyExt.class);
}
}
#DependsUpon(DecoratorBarriers.ISSUES_TRACKED)
public class MyExt implements Decorator, BatchComponent {
#Override
public void decorate(Resource resource, DecoratorContext decoratorContext) {
Project project = decoratorContext.getProject();
Measure measure = new Measure();
measure.setData("abc");
decoratorContext.saveMeasure(measure);
}
#Override
public boolean shouldExecuteOnProject(Project project) {
return true;
}
}

If you're using SQ 5.2, Decorator does not work anymore. You have to move to the MeasureComputer interface instead.
The API is really unclear about this, and the #Deprecated annotation is misused IMHO (usually you first deprecate code, keep it working until it does not work anymore, then you just delete it... you don't deprecate code in order to inform people that it's not usable anymore...)
I guess that somebody at SonarSource forgot what code deprecation is about...
While a deprecated software feature remains in the software, its use may raise warning messages recommending alternative practices; deprecated status may also indicate the feature will be removed in the future. Features are deprecated rather than immediately removed, to provide backward compatibility and give programmers time to bring affected code into compliance with the new standard.

Related

Eclipse missing warning if variable used before assigned

We found a bug in old code which could be easily found if there would be a warning,
The issue was that inner class member was used but not assigned or initialized. Sample code minimized. Problem is that url is always null.
public class Main {
public class Sender {
private String url;
public Sender() {
}
public void send() {
OtherClass.send(url);
}
}
}
In intellij it warns about variable never assigned. In eclipse I didn't find such warning.
The code is more complex and adding a warning at any level will reduce time to find similar bugs.
Is it possible in eclipse to warn in some way if variable is used before assigned/initialized ?
You can use SpotBugs(successor of findbugs) eclipse plugin. Right click on project Spotbugs->find bugs this will find these types of bugs.
I suggest also installing sonarlint plugin which has good static analysis capabilities.
https://marketplace.eclipse.org/content/spotbugs-eclipse-plugin
https://marketplace.eclipse.org/content/sonarlint

GWTP REST-Dispatch - What is the new usage for rest dispach, since the removal of the RestService interface in 1.5 release

Hi everybody,
I encounter implementation issues with the rest-dispatch module of the gwtp framework.
If i follow the current documentation, the resource interface defining what a service provide should be as follow:
#Path(FOO)
#Produces(MediaType.APPLICATION_JSON)
public interface FooResource {
#GET
RestAction<FooDTO> getFoo();
}
On the client side (without delegate extension):
#Inject RestDispatch dispatcher;
#Inject FooResource fooResource;
...
dispatcher.execute(fooResource.getFoo(), new AsyncCallback<FooDTO>() {
#Override
public void onFailure(Throwable throwable) {
}
#Override
public void onSuccess(FooDTO fooDto) {
}
});
...
Question
The RestDispatch is waiting for method that return RestAction, but since the RestService interface has been remove from 1.5 release:
How can i implements the FooResource ?
Moreover
In the carstore sample project, the only resource that uses RestAction is:
https://github.com/ArcBees/GWTP-Samples/blob/master/carstore/src/main/java/com/gwtplatform/carstore/shared/api/StatisticsResource.java
But it's implementation, is in fact not an implementation in that case:
https://github.com/ArcBees/GWTP-Samples/blob/master/carstore/src/main/java/com/gwtplatform/carstore/server/api/StatisticsResourceImpl.java
Should i follow this example, and what is the purpose of an non-implemented Interface ?
I assume that my question is very specific and it is maybe principally directed to the authors of gwtp.
And i thank in advance those who will respond.
The rest-dispatch is a client-library, and the interface that describes the services are not to use on the server side.
I was attempting to do something not intended by the authors of GWTP.
Yet, the DelegateResource extension is a solution, if you want to use the interface on the server side too. It comes with a drawback: the anability to have type safe callback on the client side.
To go further, here the exchange i had with the team on github:
https://github.com/ArcBees/GWTP-Samples/issues/92

Dagger and Object Graph Scoping with Flow/Mortar

So I've been spending a lot of time with Mortar and Flow this weekend, and I think I've finally worked most of it out. I've found that it's a little bit more complex than I originally thought, mostly because I haven't quite gotten my mind around Dagger's ObjectGraph Scoping, which Mortar relies on heavily. I've read as much as I could find on this on Dagger's site, but I find information on this subject lacking when it relates specifically to Dagger.
So I have a few questions:
1. I see examples of them scoping #Singleton's:
#Layout(R.layout.screen_friend)
public class FriendScreen implements Blueprint {
#Override public String getMortarScopeName() {
return getClass().getName();
}
#Override public Object getDaggerModule() {
return new Module();
}
#dagger.Module(
injects = FriendView.class
)
static class Module {
}
#Singleton
public static class Presenter extends ViewPresenter<TestView> {
#Inject
public Presenter() {
Log.d("FriendScreen", "Friend Presenter Created");
}
#Override protected void onLoad(Bundle savedInstanceState) {
super.onLoad(savedInstanceState);
}
}
Is Presenter in this case scoped to this Module specifically because it's an inner class?
2. How can I make sure that an instance of it is only created in this Object Graph but not the global application object graph?
2. What if the Presenter was too big, and I wanted to move it to it's own separate class? How would I scope it just to this module?
3. I noticed that some of the Module classes in their examples are static, and others aren't. Does this have any effect on scoping?
4. Where can I read more to better understand Dagger's Object Graph. I need to get a better understanding of includes, injects, addsTo and how those are used in ObjectGraph creation
etc:
#dagger.Module( //
includes = ActionBarModule.class,
injects = MainView.class,
addsTo = ApplicationModule.class, //
library = true //
)
I don't believe presenters are scoped to a module since on a rotation they are preserved. the #Singleton annotation also leads me to believe that a presenter is on a global graph and just binds to a view when an activity recreates itself.
Here's a good scoping source.
Effective Java has a fantastic explanation about static inner vs non static inner vs anonymous classes if you want to learn more about those.

Implementing FluentSecurity over Ninject (aka porting StructureMap to Ninject)

I'm a beginner on IoC and dependency injection. I'm reading about it, but I just can't get it.
While I figure out how stuff works, I'm trying to implement some of these patterns on my project (and maybe learn by trial and error).
I'm implementing security control by using FluentSecurity package (from NuGet, btw). I need to implement a Policy Violation Handler, as described on this wiki. The problem is that the example is written for StructureMap IoC-container, and I'm using (or trying to) Ninject 2.2 (it seemed more simple for a beginner).
On their code, they suggest (a):
configuration.ResolveServicesUsing(type => ObjectFactory.GetAllInstances(type).Cast<object>());
And then (b):
public class WebRegistry : Registry
{
public WebRegistry()
{
Scan(scan =>
{
scan.TheCallingAssembly();
scan.AddAllTypesOf<IPolicyViolationHandler>();
});
}
}
My concerns:
I know that code (a) will be included on Global.asax. But what is Ninject's alternative to ObjectFactory.GetAllInstances()?
I have no idea neither where this code should be inserted nor what are the equivalents for WebRegistry, Scan, and the internal functions TheCallingAssembly and AddAllTypesOf.
I know this is a bit extensive question, but I appreciate any help! Thanks in advance.
Marius Schulz has written an excellent article that should help anyone wanting to use Ninject together with FluentSecurity.
Setting Up FluentSecurity to Use Ninject for Dependency Resolution
I think this would be roughly equivelent
//add an instance of IKernel to your MvcApplication
[Inject]
public IKernel Kernel { get; set; }
...
configuration.ResolveServicesUsing(type => Kernel.GetAll(type));
To get the ability to scan an assembly for dependencies you would need an extension for ninject called Ninject.Extensions.Conventions, which was modeled after the one from SM.
public class WebModule : NinjectModule
{
public WebModule()
{
Kernel.Scan(a => {
a.FromAssemblyContaining<YourType>();
a.BindWithDefaultConventions();
a.InTransientScope();
});
}
}
The assembly scanning business obviously isn't strictly necassary for what you're doing, this would work just as well. Personally I'm not a fan of assembly scanning because it seems a little too "magic", and when it doesn't work, it's not fun to debug.
Kernel.Bind<YourType>().ToSelf();
I had same problem like you had with Ninject. After hours of googling I downloaded the source code from github. I understood the code and debugged few methods to figured out how to resolve the services. All I have to do is provide a service locator to find the PolicyViolationException handlers.
Ninject equivalent seems to be like this.
configuration.ResolveServicesUsing(type => System.Web.Mvc.DependencyResolver.Current.GetServices(type));
I used Ninject MVC3 and I used below code to load the modules from my current MVC web project plus other assemblies.
private static void RegisterServices(IKernel kernel)
{
kernel.Load("*.dll");
//kernel.Load(Assembly.GetExecutingAssembly());
}
I configured PolicyViolationException handlers in my module:
public class MainWebNinjectModule : NinjectModule
{
public override void Load()
{
// other bindings here
Bind<IPolicyViolationHandler>().To<DenyAnonymousAccessPolicyViolationHandler>();
}
}
Other required dependencies like ISecurityHandler, ISecurityContext etc are resolved by the internal IoC used in FluentSecurity.

How to make your GWT application plug-able?

I am writing (with my team) an GWT application, which parses and represent some domain specific language - for example, plays media presentation with text, video and UI controls. So the application has a set of components: ones - for holding model, ones - for control routines (controllers), and of course we have classes for View.
Now we have a problem - make it all plug-able, in the sense of:
should be one core plugin, which make all common stuff. This coer block must be an JavaScript file (one for every permutation)
should be ability to extend core classes, write custom ones - and compile it to separate JS file (one for every permutation)
Every plugin must registers (export it's classes etc) itself to the core platform, so it could be used.
Problems:
How to compile the custom stuff
separately ?
How to load plugins ?
For the second one problem i've found http://code.google.com/p/gwt-exporter/, that exports GWT classes to outer world, so they could be invoked from pure JS.
Also I have an idea to create new module for new plugin, so it will be compiled to separate file (first problem).
Have you an experience of building such architecture, have you some best practices in this case ?
I have experimented with this same question since GWT 1.5 and every time I come up with a more elegant solution they change the linker and break it. The only way that I have come up with that would work independent of linker design is to do exactly what you are talking about and create a new module for ever plug-in. Then use GWT exporter to create an abstract class that plugins must extend that would have an abstract method that would take the root element of the plugin passed to it by the core and populate it. The issue with this method is all plug-in modules must be added to the DOM on the initial load of the page because since 2.0 the iFrame linker relies on a page load event so dynamically added modules wont fully load. So because of this you will want to have the exported population method wrapped in runAsync so that you aren't downloading modules till you use them.
Edit:
Here is a rough example of what I am talking about. Please be aware that I haven't done any GWT in a couple years and there may be a better way of doing this by now.
public final class PluginManager
{
public static final PluginManager INSTANCE = new PluginManager();
private PluginManager()
{
}
private static native void loadPlugin( AbstractPlugin plugin )
/*-{
if (!$wnd.Plugins) {
$wnd.Plugins = {};
}
var name = plugin.#com.example.PluginManager.AbstractPlugin::getName()();
$wnd.Plugins[name] = $entry(plugin.#com.example.PluginManager.AbstractPlugin::load(Ljava/lang/String;));
}-*/;
private static native void unloadPlugin( AbstractPlugin plugin )
/*-{
if ($wnd.Plugins) {
var name = plugin.#com.example.PluginManager.AbstractPlugin::getName()();
delete $wnd.Plugins[name];
}
}-*/;
private static native JsArrayString getPlugins()
/*-{
if ($wnd.Plugins) {
return Object.keys($wnd.Plugins);
}
return undefined;
}-*/;
public static abstract class AbstractPlugin implements EntryPoint
{
#Override
public final void onModuleLoad()
{
PluginManager.INSTANCE.loadPlugin( this );
}
protected final void unload()
{
PluginManager.INSTANCE.unloadPlugin( this );
}
protected abstract String getName();
protected abstract void load( String rootPanelId );
}
}