Ejemplo n.º 1
0
 static String createUID(Project project, Resource resource) {
   String uid = resource.getKey();
   if (!StringUtils.equals(Scopes.PROJECT, resource.getScope())) {
     // not a project nor a library
     uid =
         new StringBuilder(ResourceModel.KEY_SIZE)
             .append(project.getKey())
             .append(':')
             .append(resource.getKey())
             .toString();
   }
   return uid;
 }
Ejemplo n.º 2
0
  private Bucket doIndex(Resource resource, @Nullable Resource parentReference) {
    Bucket bucket = getBucket(resource);
    if (bucket != null) {
      return bucket;
    }

    if (StringUtils.isBlank(resource.getKey())) {
      LOG.warn("Unable to index a resource without key " + resource);
      return null;
    }

    Resource parent = null;
    if (!ResourceUtils.isLibrary(resource)) {
      // a library has no parent
      parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject);
    }

    Bucket parentBucket = getBucket(parent);
    if (parentBucket == null && parent != null) {
      LOG.warn("Resource ignored, parent is not indexed: " + resource);
      return null;
    }

    if (ResourceUtils.isProject(resource)
        || /* For technical projects */ ResourceUtils.isRootProject(resource)) {
      resource.setEffectiveKey(resource.getKey());
    } else {
      resource.setEffectiveKey(ComponentKeys.createEffectiveKey(currentProject, resource));
    }
    bucket = new Bucket(resource).setParent(parentBucket);
    addBucket(resource, bucket);

    Resource parentResource = parentBucket != null ? parentBucket.getResource() : null;
    resourceCache.add(resource, parentResource);

    return bucket;
  }
Ejemplo n.º 3
0
 private Bucket getBucket(@Nullable Resource reference) {
   if (reference == null) {
     return null;
   }
   if (StringUtils.isNotBlank(reference.getKey())) {
     return buckets.get(reference);
   }
   String relativePathFromSourceDir = null;
   boolean isTest = false;
   boolean isDir = false;
   if (reference instanceof File) {
     File referenceFile = (File) reference;
     isTest = Qualifiers.UNIT_TEST_FILE.equals(referenceFile.getQualifier());
     relativePathFromSourceDir = referenceFile.relativePathFromSourceDir();
   } else if (reference instanceof Directory) {
     isDir = true;
     Directory referenceDir = (Directory) reference;
     relativePathFromSourceDir = referenceDir.relativePathFromSourceDir();
     if (Directory.ROOT.equals(relativePathFromSourceDir)) {
       relativePathFromSourceDir = "";
     }
   }
   if (relativePathFromSourceDir != null) {
     // Resolve using deprecated key
     List<java.io.File> dirs;
     if (isTest) {
       dirs = getProject().getFileSystem().getTestDirs();
     } else {
       dirs = getProject().getFileSystem().getSourceDirs();
     }
     for (java.io.File src : dirs) {
       java.io.File abs = new java.io.File(src, relativePathFromSourceDir);
       Bucket b =
           getBucket(
               isDir
                   ? Directory.fromIOFile(abs, getProject())
                   : File.fromIOFile(abs, getProject()));
       if (b != null) {
         return b;
       }
     }
   }
   return null;
 }