SonarQube
  1. SonarQube
  2. SONAR-3224

API: support Ruby on Rails applications

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0
    • Component/s: API, Web
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Extension points allow to define new web services (controllers) and widgets (ERB templates), but they do not allow to write a complete application with controllers, helpers and views.

      Resolving this issue is required to fully deprecate support of GWT.

        Activity

        Hide
        Simon Brandhof added a comment -

        This feature is experimental. Plugins can define their own Ruby on Rails applications by storing the directory app/ in org/sonar/ror/<plugin>. For example for the plugin with key "foo" :

        org/sonar/ror/foo/app/controllers/foo_controller.rb
        org/sonar/ror/foo/app/views/foo/index.html.rb
        
        Show
        Simon Brandhof added a comment - This feature is experimental. Plugins can define their own Ruby on Rails applications by storing the directory app/ in org/sonar/ror/<plugin>. For example for the plugin with key "foo" : org/sonar/ror/foo/app/controllers/foo_controller.rb org/sonar/ror/foo/app/views/foo/index.html.rb
        Hide
        Simon Brandhof added a comment -

        Integration tests added

        Show
        Simon Brandhof added a comment - Integration tests added
        Hide
        Khayrat Glende added a comment -

        Could you please give an example on how to use this feature. I would like to have a link in the sonar-sidebar refering to my plugin-controller to get full MVC-support. I've already done this by extending sonar 2.14 and with sonar 3.0 I would like to move my code to a sonar plugin. I've played a little with the sonar-reference-plugin of https://github.com/SonarSource/sonar-examples but didn't find the clue.

        Show
        Khayrat Glende added a comment - Could you please give an example on how to use this feature. I would like to have a link in the sonar-sidebar refering to my plugin-controller to get full MVC-support. I've already done this by extending sonar 2.14 and with sonar 3.0 I would like to move my code to a sonar plugin. I've played a little with the sonar-reference-plugin of https://github.com/SonarSource/sonar-examples but didn't find the clue.
        Hide
        Simon Brandhof added a comment -

        Documentation is coming, but in 2 words, just declare the ruby app as described in my first comment and add the following Java metadata :

        @NavigationSection(NavigationSection.CONFIGURATION)
        @UserRole(UserRole.ADMIN)
        public final class FooPage implements Page {
        
          public String getId() {
            // URL of the controller
            return "/foo";
          }
        
          public String getTitle() {
            return "Foo";
          }
        }
        
        Show
        Simon Brandhof added a comment - Documentation is coming, but in 2 words, just declare the ruby app as described in my first comment and add the following Java metadata : @NavigationSection(NavigationSection.CONFIGURATION) @UserRole(UserRole.ADMIN) public final class FooPage implements Page { public String getId() { // URL of the controller return "/foo"; } public String getTitle() { return "Foo"; } }
        Hide
        Khayrat Glende added a comment -

        Hi Simon, thanx for the snippet. I think I'm still missing some thing. Here is what I did:

        Added the metadata to my example-plugin

        package com.mycompany.sonar.reference.ui;
        
        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;
        import org.sonar.api.config.Settings;
        import org.sonar.api.web.NavigationSection;
        import org.sonar.api.web.UserRole;
        import org.sonar.api.web.Page;
        
        @NavigationSection(NavigationSection.HOME) 
        @UserRole(UserRole.ADMIN) 
        public class ExampleROR implements Page {
                Logger logger = LoggerFactory.getLogger(getClass());
                
                public ExampleROR(Settings settings) {
                        logger.info("my first log...");
                        logger.info("my key: {}", settings.getString("pluginKey"));
                }
                
                public String getId() {
                    // URL of the controller
                    return "/foo";
                }
        
                public String getTitle() {
                    return "Foo";
                }
                
        }
        
        

        I've also added the plugin key

        pom.xml:
        ...
          <build>
            <plugins>
              <plugin>
                <groupId>org.codehaus.sonar</groupId>
                <artifactId>sonar-packaging-maven-plugin</artifactId>
                <version>1.1</version>
                <extensions>true</extensions>
                <configuration>
                  <pluginKey>foo</pluginKey>
                  <pluginClass>com.mycompany.sonar.reference.ExamplePlugin</pluginClass>
                </configuration>
              </plugin>
        ...
        

        and the ruby-parts with simple controller impl:

        ./src/main/resources/org/sonar/ror/foo/app/controllers/foo_controller.rb
        ./src/main/resources/org/sonar/ror/foo/app/views/foo
        

        Now the link appears and points to

        localhost:9000/foo
        

        Which yield The page you were looking for doesn't exist.

        BTW: how can I access the pluginKey - settings.getString("pluginKey") yields null.

        Show
        Khayrat Glende added a comment - Hi Simon, thanx for the snippet. I think I'm still missing some thing. Here is what I did: Added the metadata to my example-plugin package com.mycompany.sonar.reference.ui; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.config.Settings; import org.sonar.api.web.NavigationSection; import org.sonar.api.web.UserRole; import org.sonar.api.web.Page; @NavigationSection(NavigationSection.HOME) @UserRole(UserRole.ADMIN) public class ExampleROR implements Page { Logger logger = LoggerFactory.getLogger(getClass()); public ExampleROR(Settings settings) { logger.info( "my first log..." ); logger.info( "my key: {}" , settings.getString( "pluginKey" )); } public String getId() { // URL of the controller return "/foo" ; } public String getTitle() { return "Foo" ; } } I've also added the plugin key pom.xml: ... <build> <plugins> <plugin> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-packaging-maven-plugin</artifactId> <version>1.1</version> <extensions> true </extensions> <configuration> <pluginKey>foo</pluginKey> <pluginClass>com.mycompany.sonar.reference.ExamplePlugin</pluginClass> </configuration> </plugin> ... and the ruby-parts with simple controller impl: ./src/main/resources/org/sonar/ror/foo/app/controllers/foo_controller.rb ./src/main/resources/org/sonar/ror/foo/app/views/foo Now the link appears and points to localhost:9000/foo Which yield The page you were looking for doesn't exist. BTW: how can I access the pluginKey - settings.getString("pluginKey") yields null .
        Hide
        Simon Brandhof added a comment -

        Sorry I forgot to mention that the directory /src/main/resources/org/sonar/ror/foo/ must contain the empty file init.rb.
        Server logs should contain :

        INFO  o.s.s.p.ApplicationDeployer  Deploy Ruby on Rails applications
        INFO  o.s.s.p.ApplicationDeployer  Deploy app: foo
        
        Show
        Simon Brandhof added a comment - Sorry I forgot to mention that the directory /src/main/resources/org/sonar/ror/foo/ must contain the empty file init.rb. Server logs should contain : INFO o.s.s.p.ApplicationDeployer Deploy Ruby on Rails applications INFO o.s.s.p.ApplicationDeployer Deploy app: foo
        Hide
        Simon Brandhof added a comment -

        Note that the plugin key can not be loaded dynamically from Settings.

        Show
        Simon Brandhof added a comment - Note that the plugin key can not be loaded dynamically from Settings.
        Hide
        Khayrat Glende added a comment -

        Thanx Simon, I finally got it this way. In my extensions I made in the sonar-server module I have java classes depending on spring/hibernate. I added these dependencies to the sonar-server pom and loaded the spring context in

        ./main/webapp/WEB-INF/config/initializers/neo_spring.rb
        

        this way

        SPRING_XML_CONFIG_FILES = %w(
            applicationContext
            persistenceContext).map { |c|
          "classpath:#{c}.xml" 
        }.to_java :string
        
        
        SPRING_CONTEXT = org.springframework.context.support.
          ClassPathXmlApplicationContext.new(SPRING_XML_CONFIG_FILES)
        
        

        Now in sonar 3.0 could I have spring support for my plugin without altering the sonar-server setup (pom/initalizers)? Adding the spring dependencies to the plugin pom and the initializer code to the plugin's init.rb
        leads to

        INFO   | jvm 1    | 2012/04/27 15:20:24 | 2012-04-27 15:20:24.727:WARN:/:unable to create shared application instance
        INFO   | jvm 1    | 2012/04/27 15:20:24 | org.jruby.rack.RackInitializationException: cannot load Java class org.springframework.context.support.ClassPathXmlApplicationContext|?from file:/daten/glende/opt/sonar-3.0/war/sonar-server/WEB-INF/lib/jruby-complete-1.6.1.jar!/builtin/javasupport/java.rb:51:in `method_missing'|?from /daten/glende/opt/sonar-3.0/temp/ror/foo/init.rb:167:....
        
        Show
        Khayrat Glende added a comment - Thanx Simon, I finally got it this way. In my extensions I made in the sonar-server module I have java classes depending on spring/hibernate. I added these dependencies to the sonar-server pom and loaded the spring context in ./main/webapp/WEB-INF/config/initializers/neo_spring.rb this way SPRING_XML_CONFIG_FILES = %w( applicationContext persistenceContext).map { |c| "classpath:#{c}.xml" }.to_java :string SPRING_CONTEXT = org.springframework.context.support. ClassPathXmlApplicationContext. new (SPRING_XML_CONFIG_FILES) Now in sonar 3.0 could I have spring support for my plugin without altering the sonar-server setup (pom/initalizers)? Adding the spring dependencies to the plugin pom and the initializer code to the plugin's init.rb leads to INFO | jvm 1 | 2012/04/27 15:20:24 | 2012-04-27 15:20:24.727:WARN:/:unable to create shared application instance INFO | jvm 1 | 2012/04/27 15:20:24 | org.jruby.rack.RackInitializationException: cannot load Java class org.springframework.context.support.ClassPathXmlApplicationContext|?from file:/daten/glende/opt/sonar-3.0/war/sonar-server/WEB-INF/lib/jruby-complete-1.6.1.jar!/builtin/javasupport/java.rb:51:in `method_missing'|?from /daten/glende/opt/sonar-3.0/temp/ror/foo/init.rb:167:....

          People

          • Assignee:
            Simon Brandhof
            Reporter:
            Simon Brandhof
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: