Last active
October 15, 2017 10:27
-
-
Save kemsakurai/8bbd24d15b833aeb5c656cc6dd1034d0 to your computer and use it in GitHub Desktop.
SonarQube 6.5 sonar-ws example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This build file was generated by the Gradle 'init' task. | |
* | |
* This generated file contains a sample Java Library project to get you started. | |
* For more details take a look at the Java Libraries chapter in the Gradle | |
* user guide available at https://docs.gradle.org/4.1/userguide/java_library_plugin.html | |
*/ | |
// Apply the java-library plugin to add support for Java Library | |
apply plugin: 'java-library' | |
// In this section you declare where to find the dependencies of your project | |
repositories { | |
// Use jcenter for resolving your dependencies. | |
// You can declare any Maven/Ivy/file repository here. | |
jcenter() | |
} | |
dependencies { | |
// This dependency is exported to consumers, that is to say found on their compile classpath. | |
api 'org.apache.commons:commons-math3:3.6.1' | |
// This dependency is used internally, and not exposed to consumers on their own compile classpath. | |
implementation 'com.google.guava:guava:22.0' | |
// https://mvnrepository.com/artifact/org.sonarsource.sonarqube/sonar-ws | |
implementation 'org.sonarsource.sonarqube:sonar-ws:6.5' | |
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 | |
implementation 'org.apache.commons:commons-lang3:3.6' | |
testImplementation 'junit:junit:4.12' | |
} | |
test { | |
testLogging { | |
events "passed", "skipped", "failed", "standardOut", "standardError" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.lang3.builder.ToStringBuilder; | |
import org.apache.commons.lang3.builder.ToStringStyle; | |
import org.sonarqube.ws.Common; | |
import org.sonarqube.ws.Issues; | |
import org.sonarqube.ws.client.HttpConnector; | |
import org.sonarqube.ws.client.WsClient; | |
import org.sonarqube.ws.client.WsClientFactories; | |
import org.sonarqube.ws.client.issue.SearchWsRequest; | |
import java.util.List; | |
/* | |
* This Java source file was generated by the Gradle 'init' task. | |
*/ | |
public class SearchIssues { | |
/** | |
* Main method.. | |
* | |
* @param args | |
*/ | |
public static void main(String... args) { | |
// execute search Issues | |
HttpConnector httpConnector = HttpConnector.newBuilder().url("http://localhost:9000").credentials("admin", "admin").token("your_token").build(); | |
WsClient wsClient = WsClientFactories.getDefault().newClient(httpConnector); | |
SearchWsRequest searchWsRequest = new SearchWsRequest(); | |
Issues.SearchWsResponse response = wsClient.issues().search(searchWsRequest); | |
// STD Out Paging Object | |
Common.Paging paging = response.getPaging(); | |
System.out.println("------------------------------------------------------------"); | |
System.out.println(ToStringBuilder.reflectionToString(paging, ToStringStyle.JSON_STYLE)); | |
System.out.println("------------------------------------------------------------"); | |
// STD Out issue | |
List<Issues.Issue> issuesList = response.getIssuesList(); | |
for (Issues.Issue issue : issuesList) { | |
System.out.println("------------------------------------------------------------"); | |
System.out.println(ToStringBuilder.reflectionToString(issue, ToStringStyle.JSON_STYLE)); | |
System.out.println("------------------------------------------------------------"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
public class SearchIssuesTest { | |
@Test | |
public void main() throws Exception { | |
String arg = null; | |
SearchIssues.main(arg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
の、
credentials
、token
の指定はどちらか片方の指定で動作します。