Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Sonar's web service java client to persist properties
    text
    copied!<p>How can I persist a Sonar Property <a href="http://docs.codehaus.org/display/SONAR/Using+the+Web+Service+Java+client" rel="nofollow">using Sonar's web service java client</a>?</p> <p>[EDIT: I realize now that the Web Service Client is not applicable for developing a plugin; rather other classes should be used from Sonar's API. See the answer I accepted.]<br/><br/> I'm planing to make a plugin for Sonar. In the meantime, I am familiarizing myself with Sonar's API, and in particular Sonar's web service java client. I am trying to figure out how to persist a Sonar Property. I wrote the following code:</p> <pre><code> package testers; import org.sonar.wsclient.Sonar; import org.sonar.wsclient.services.Property; import org.sonar.wsclient.services.PropertyCreateQuery; import org.sonar.wsclient.services.PropertyQuery; public class PropertyPersister { public static Sonar localSonar; public static Property sonarStartTime; public static PropertyQuery findStartTime; public static Property testProperty; public static PropertyQuery findTestProperty; public static String testKey = "testKey"; public static String testValue = "testValue"; /** * @param args */ public static void main(String[] args) { //localSonar = Sonar.create("http://localhost:9000");//pointed to my instance of Sonar //EDIT: using this line instead, but it still gives the same stack trace. localSonar = Sonar.create("http://localhost:9000", "admin", "admin");//pointed to my instance of Sonar findStartTime = PropertyQuery.createForKey("sonar.core.startTime");//creating query for a key I know exists sonarStartTime = localSonar.find(findStartTime);//retrieve property object from my Sonar's database System.out.println(sonarStartTime);//print out this object PropertyCreateQuery testCreateQuery = new PropertyCreateQuery(testKey, testValue);//Query to create test property localSonar.create(testCreateQuery);//With this line, I'm trying to persist my test property findTestProperty = PropertyQuery.createForKey(testKey);//creating query for retrieving test property testProperty = localSonar.find(findTestProperty);//line 36: retrieve property object from my Sonar's database System.out.println(testProperty);//print test property } } </code></pre> <p>This code prints out the already existing sonarStartTime property:</p> <pre><code>[sonar.core.startTime:2013-03-14T08:05:42-0700] </code></pre> <p>It is then followed by a null pointer exception thrown by the second-to-last line. The exception message included:</p> <pre><code> org.sonar.wsclient.unmarshallers.UnmarshalException: Can not parse the response of query /api/properties/testKey?: {"err_code":404,"err_msg":"Property not found: testKey"} </code></pre> <p>Using MySQL workbench, I confirmed that indeed, my test property was never persisted. Obviously, I am going about this the wrong way. So, to reiterate my question, how can I persist a property in Sonar <a href="http://docs.codehaus.org/display/SONAR/Using+the+Web+Service+Java+client" rel="nofollow">using Sonar's web service java client</a>?</p> <p>[EDIT] Here is the full console output with stack trace:</p> <pre><code>[sonar.core.startTime:2013-03-14T08:05:42-0700] Exception in thread "main" org.sonar.wsclient.unmarshallers.UnmarshalException: Can not parse the response of query /api/properties/testKey?: {"err_code":404,"err_msg":"Property not found: testKey"} at org.sonar.wsclient.Sonar.find(Sonar.java:56) at testers.PropertyPersister.main(PropertyPersister.java:36) Caused by: java.lang.ClassCastException: org.json.simple.JSONObject cannot be cast to java.util.ArrayList at org.sonar.wsclient.JdkUtils.getArraySize(JdkUtils.java:87) at org.sonar.wsclient.unmarshallers.AbstractUnmarshaller.toModel(AbstractUnmarshaller.java:34) at org.sonar.wsclient.Sonar.find(Sonar.java:54) ... 1 more </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload