예제 #1
0
  @Test
  public void favourites_web_service() {
    Sonar adminWsClient = orchestrator.getServer().getAdminWsClient();

    // GET (nothing)
    List<Favourite> favourites = adminWsClient.findAll(new FavouriteQuery());
    assertThat(favourites).isEmpty();

    // POST (create favourites)
    Favourite favourite = adminWsClient.create(new FavouriteCreateQuery("sample"));
    assertThat(favourite).isNotNull();
    assertThat(favourite.getKey()).isEqualTo("sample");
    adminWsClient.create(new FavouriteCreateQuery("sample:src/main/xoo/sample/Sample.xoo"));

    // GET (created favourites)
    favourites = adminWsClient.findAll(new FavouriteQuery());
    assertThat(favourites).hasSize(2);
    List<String> keys =
        newArrayList(
            Iterables.transform(
                favourites,
                new Function<Favourite, String>() {
                  @Override
                  public String apply(Favourite input) {
                    return input.getKey();
                  }
                }));
    assertThat(keys).containsOnly("sample", "sample:src/main/xoo/sample/Sample.xoo");

    // DELETE (a favourite)
    adminWsClient.delete(new FavouriteDeleteQuery("sample"));
    favourites = adminWsClient.findAll(new FavouriteQuery());
    assertThat(favourites).hasSize(1);
    assertThat(favourites.get(0).getKey()).isEqualTo("sample:src/main/xoo/sample/Sample.xoo");
  }
예제 #2
0
  public MeasureFinder(String sonarUrl, String login, String password)
      throws SonarMetricsNotFoundException {
    this.sonarUrl = sonarUrl;

    if (isBlank(sonarUrl)) {
      throw new IllegalStateException("sonarUrl can't be null.");
    }
    if (isNotBlank(login) && isNotBlank(password)) {
      sonar = Sonar.create(sonarUrl, login, password);
    } else {
      sonar = Sonar.create(sonarUrl);
    }
  }
  /**
   * Obtains the list of all classes of a project (or module) with their metrics per class.
   *
   * @param resourceKey the project or module to analyse.
   * @return the list of classes of such project or module with their metrics, -1 if metric value
   *     not found.
   */
  public static ArrayList<ClassInfo> getStatisticsPerClass(
      String host, String resourceKey, String[] metricNames) {
    ArrayList<ClassInfo> list = new ArrayList<ClassInfo>();
    Sonar sonar = Sonar.create(host);
    ResourceQuery query = new ResourceQuery(resourceKey);
    query.setMetrics(metricNames);
    query.setScopes("FIL");
    query.setDepth(-1);
    // **************************************************put above and control!
    for (Resource resource : sonar.findAll(query)) {
      ClassInfo classInfo = new ClassInfo();
      classInfo.setClassName(resource.getName());

      for (String metricName : metricNames) {
        Measure measure = resource.getMeasure(metricName);
        //                System.err.println(measure);
        if (measure != null) {
          classInfo.setMetric(metricName, measure.getValue());
        } else {
          System.err.print(
              "Warning[getClassInfos]: "
                  + metricName
                  + " of "
                  + resource.getName()
                  + " is empty. ");
          classInfo.setMetric(metricName, new Double(-1.0));
        }
      }
      list.add(classInfo);
    }
    System.err.println();
    return list;
  }