Beispiel #1
0
  @Test(expected = SonarException.class)
  public void shouldFailIfIndexingAndLocked() {
    lock.setFailWhenLocked(true);
    lock.lock();

    Directory dir = new Directory("org/foo");
    index.index(dir);
  }
Beispiel #2
0
  /** Only a warning is logged when index is locked. */
  @Test
  public void shouldIndexEvenIfLocked() {
    lock.lock();

    Directory dir = new Directory("org/foo");
    assertThat(index.index(dir), is(true));
    assertThat(index.isIndexed(dir, true), is(true));
  }
Beispiel #3
0
 private Bucket checkIndexed(Resource resource) {
   Bucket bucket = getBucket(resource, true);
   if (bucket == null) {
     if (lock.isLocked()) {
       if (lock.isFailWhenLocked()) {
         throw new ResourceNotIndexedException(resource);
       }
       LOG.warn("Resource will be ignored in next Sonar versions, index is locked: " + resource);
     }
     if (Scopes.isDirectory(resource) || Scopes.isFile(resource)) {
       bucket = doIndex(resource);
     } else if (!lock.isLocked()) {
       LOG.warn(
           "Resource will be ignored in next Sonar versions, it must be indexed before adding data: "
               + resource);
     }
   }
   return bucket;
 }
Beispiel #4
0
  /** Keep only project stuff */
  public void clear() {
    Iterator<Map.Entry<Resource, Bucket>> it = buckets.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry<Resource, Bucket> entry = it.next();
      Resource resource = entry.getKey();
      if (!ResourceUtils.isSet(resource)) {
        entry.getValue().clear();
        it.remove();
      }
    }

    Set<Dependency> projectDependencies = getDependenciesBetweenProjects();
    dependencies.clear();
    incomingDependenciesByResource.clear();
    outgoingDependenciesByResource.clear();
    for (Dependency projectDependency : projectDependencies) {
      projectDependency.setId(null);
      registerDependency(projectDependency);
    }

    lock.unlock();
  }
Beispiel #5
0
 private void checkLock(Resource resource) {
   if (lock.isLocked() && !ResourceUtils.isLibrary(resource) && lock.isFailWhenLocked()) {
     throw new SonarException("Index is locked, resource can not be indexed: " + resource);
   }
 }