Can you use NW Cloud to run … Sonar?
It may sound easy, but, actually, Sonar is not a pure Java application. It makes extensive use of Ruby. To be able to run sonar under Neo, it needs be converted to run under Java / JRuby on Tomcat and be able to connect to the Neo database => increasing the complexity.
How to deploy Sonar?
Sonar comes with a script to transform it into a WAR file, enabling a deploy to a Java application server:
Running the script produces a WAR that you can deploy.
The problem is that because of how sonar is configured, the application won’t start. The log shows why:
java.lang.IllegalStateException: SONAR_HOME is not valid: C:/sonar-3.3.1. Please fix the environment variable/system property SONAR_HOME or the file WEB-INF/classes/sonar-war.properties at org.sonar.server.platform.SonarHome.locate(SonarHome.java:77)
Sonar expects a specific folder structure under the SONAR_HOME location. By default, SONAR_HOME is expected to be the same location at the time the WAR file was created. This is a directory local to your computer and on Neo you cannot create the same directory. Now, you cannot simply define a location and expect Neo’s Tomcat to do the rest. The workaround is to simply point SONAR_HOME to a folder included in the WAR before creating the war build script. I gave it the name home:
Now point SONAR_HOME to that location. Change the file sonar-war.properties
# Path to Sonar installation directory, if the environment variable/system property SONAR_HOME is not defined
Sonar stores it information into a database, so the database also needs to be configured. There is not direct DB access, you have to use the configured data source. Not sure where exactly to put the reference to the data source, so I inserted it in two locations.
1st, the location where sonar WAR builder is putting it is META-INF/context.xml
<Context antiJARLocking="true" antiResourceLocking="true"> <ResourceLink name="jdbc/DefaultDB" global="jdbc/sonar" type="javax.sql.DataSource" /> </Context>
2nd, location is web.xml:
Now everything is ready to deploy the WAR.
This takes some time as the WAR is 50MB, but it works. After a successful deploy and start, Neo shows in the log that sonar is up and running:
Deploying file with path [/usr/sap/ljs/./pickup/sonar.war]| #sonar#web#null#null#JRuby limited openssl loaded. http://jruby.org/openssl| #sonar#web#null#null#gem install jruby-openssl for full support.| #sonar#web#null#null#Deployment of file with path [/usr/sap/ljs/./pickup/sonar.war] is successful.|
Sonar works, the configured NW Cloud DB is working without a problem too. You can create users and configure Sonar:
To see more information about the JVM sonar runs, just go the system information page.
Surprisingly, the only issue creator here is how Sonar is expecting to be configured: by using a directory on the server. All the rest someone may expect to cause troubles caused nothing at all: database and JRuby.
This is truely fascinating ... we heavily use Sonar in our development process and it's great to know that it runs on NW Cloud. It's very powerful and i think it makes sense to provide some context to Non-Java developers. Not sure whether it makes sense in the context of ABAP apps, though.
There is a Sonar plugin for ABAP available ($$). There is even a blog here on SCN about that plugin by Tom Van Doorslaer: http://scn.sap.com/community/abap/blog/2012/02/24/sonarsource-visualizing-technical-debt
Great post, thanks a lot!
What happens with the configuration directory when you redeploy the application?
Would be cool if Neo would provide some sort of access to a filesystem which could be used by applications that work like that (e.g. Sonar, Jenkins)
The conf directory should get deleted as I have put it into the WAR file. But this shouldn't be a problem as long as the conf dir is there (aka: redeployed).
For accessing data NWCloud comes with CMIS, but don't ask me how to store and retrieve data with this as I didn't look into it (yet)
Happy to hear you got it running Tobias and many thanks for sharing!
What puzzles me a bit is that in the last screenshot you provide it states H2 as the JDBC driver used. So, it may not be using the NW Cloud DB but a local in-memory instance ... (The context.xml config in META-INF should not be needed no more either.)
Anyway, it's sure good to know it's working in general and I'm looking forward to your next blogs 🙂
Someone has an eye for the detail. Yes, sonar is not using the NW Cloud DB. As stated in the blog, I do not know 100% how to configure the Sonar DB. Normally the DB is configured in a py file and then the tables and data is created. I guess that Sonar is using the DB configuration from there instead using the defined data source .
But I do not have the time to find this out and even so: Sonar runner needs direct DB access, something not possible without having a user and password