예제 #1
0
  public static boolean processElementsByRelativePath(
      @NotNull final CompositePackagingElement<?> parent,
      @NotNull String relativePath,
      @NotNull final PackagingElementResolvingContext context,
      @NotNull final ArtifactType artifactType,
      @NotNull PackagingElementPath parentPath,
      @NotNull final PackagingElementProcessor<PackagingElement<?>> processor) {
    relativePath = StringUtil.trimStart(relativePath, "/");
    if (relativePath.length() == 0) {
      return true;
    }

    int i = relativePath.indexOf('/');
    final String firstName = i != -1 ? relativePath.substring(0, i) : relativePath;
    final String tail = i != -1 ? relativePath.substring(i + 1) : "";

    return processElementsWithSubstitutions(
        parent.getChildren(),
        context,
        artifactType,
        parentPath.appendComposite(parent),
        new PackagingElementProcessor<PackagingElement<?>>() {
          @Override
          public boolean process(
              @NotNull PackagingElement<?> element, @NotNull PackagingElementPath path) {
            boolean process = false;
            if (element instanceof CompositePackagingElement
                && firstName.equals(((CompositePackagingElement<?>) element).getName())) {
              process = true;
            } else if (element instanceof FileCopyPackagingElement) {
              final FileCopyPackagingElement fileCopy = (FileCopyPackagingElement) element;
              if (firstName.equals(fileCopy.getOutputFileName())) {
                process = true;
              }
            }

            if (process) {
              if (tail.length() == 0) {
                if (!processor.process(element, path)) return false;
              } else if (element instanceof CompositePackagingElement<?>) {
                return processElementsByRelativePath(
                    (CompositePackagingElement) element,
                    tail,
                    context,
                    artifactType,
                    path,
                    processor);
              }
            }
            return true;
          }
        });
  }
예제 #2
0
 private static <E extends PackagingElement<?>> boolean processElementRecursively(
     @NotNull PackagingElement<?> element,
     @Nullable PackagingElementType<E> type,
     @NotNull PackagingElementProcessor<? super E> processor,
     @NotNull PackagingElementResolvingContext resolvingContext,
     final boolean processSubstitutions,
     ArtifactType artifactType,
     @NotNull PackagingElementPath path,
     Set<PackagingElement<?>> processed) {
   if (!processor.shouldProcess(element) || !processed.add(element)) {
     return true;
   }
   if (type == null || element.getType().equals(type)) {
     if (!processor.process((E) element, path)) {
       return false;
     }
   }
   if (element instanceof CompositePackagingElement<?>) {
     final CompositePackagingElement<?> composite = (CompositePackagingElement<?>) element;
     return processElementsRecursively(
         composite.getChildren(),
         type,
         processor,
         resolvingContext,
         processSubstitutions,
         artifactType,
         path.appendComposite(composite),
         processed);
   } else if (element instanceof ComplexPackagingElement<?> && processSubstitutions) {
     final ComplexPackagingElement<?> complexElement = (ComplexPackagingElement<?>) element;
     if (processor.shouldProcessSubstitution(complexElement)) {
       final List<? extends PackagingElement<?>> substitution =
           complexElement.getSubstitution(resolvingContext, artifactType);
       if (substitution != null) {
         return processElementsRecursively(
             substitution,
             type,
             processor,
             resolvingContext,
             processSubstitutions,
             artifactType,
             path.appendComplex(complexElement),
             processed);
       }
     }
   }
   return true;
 }