public IncrementalBuildResults applyBatchResourceChanges(
      final Map<org.uberfire.backend.vfs.Path, Collection<ResourceChange>> changes) {
    synchronized (kieFileSystem) {
      checkNotNull("changes", changes);

      checkAFullBuildHasBeenPerformed();

      // Add all changes to KieFileSystem before executing the build
      final List<String> changedFilesKieBuilderPaths = new ArrayList<String>();
      final List<ValidationMessage> nonKieResourceValidatorAddedMessages =
          new ArrayList<ValidationMessage>();
      final List<ValidationMessage> nonKieResourceValidatorRemovedMessages =
          new ArrayList<ValidationMessage>();

      for (final Map.Entry<org.uberfire.backend.vfs.Path, Collection<ResourceChange>>
          pathCollectionEntry : changes.entrySet()) {
        for (final ResourceChange change : pathCollectionEntry.getValue()) {
          final ResourceChangeType type = change.getType();
          final Path resource = Paths.convert(pathCollectionEntry.getKey());

          checkNotNull("type", type);
          checkNotNull("resource", resource);

          final String destinationPath =
              resource.toUri().toString().substring(projectPrefix.length() + 1);
          changedFilesKieBuilderPaths.add(destinationPath);
          switch (type) {
            case ADD:
            case UPDATE:
              // Only files can be processed
              if (!Files.isRegularFile(resource)) {
                continue;
              }

              update(
                  nonKieResourceValidatorAddedMessages,
                  nonKieResourceValidatorRemovedMessages,
                  resource,
                  destinationPath);

              break;
            case DELETE:
              delete(nonKieResourceValidatorRemovedMessages, resource, destinationPath);
          }
        }
      }

      // Perform the Incremental build and get messages from incremental build
      final IncrementalBuildResults results = new IncrementalBuildResults(projectGAV);
      buildIncrementally(results, toArray(changedFilesKieBuilderPaths));

      // Copy in BuildMessages for non-KIE resources
      results.addAllAddedMessages(convertValidationMessages(nonKieResourceValidatorAddedMessages));
      results.addAllRemovedMessages(
          convertValidationMessages(nonKieResourceValidatorRemovedMessages));

      return results;
    }
  }
Esempio n. 2
0
 void onResourceBatchEvent(@Observes final ResourceBatchChangesEvent batchEvent) {
   if (path != null && batchEvent.containPath(path)) {
     if (sessionInfo.getId().equals(batchEvent.getSessionInfo().getId())) {
       for (final ResourceChange change : batchEvent.getChanges(path)) {
         switch (change.getType()) {
           case COPY:
             executeCopyCommands();
             break;
           case DELETE:
             executeDeleteCommands();
             break;
           case RENAME:
             path = ((ResourceRenamed) change).getDestinationPath();
             executeRenameCommands();
             break;
           case UPDATE:
             executeUpdateCommands();
             break;
         }
       }
     } else {
       for (final ResourceChange change : batchEvent.getChanges(path)) {
         switch (change.getType()) {
           case COPY:
             executeConcurrentCopyCommand(
                 path,
                 ((ResourceCopied) change).getDestinationPath(),
                 batchEvent.getSessionInfo().getId(),
                 batchEvent.getSessionInfo().getIdentity());
             break;
           case DELETE:
             executeConcurrentDeleteCommand(
                 path,
                 batchEvent.getSessionInfo().getId(),
                 batchEvent.getSessionInfo().getIdentity());
             break;
           case RENAME:
             path = ((ResourceRenamed) change).getDestinationPath();
             executeConcurrentRenameCommand(
                 path,
                 ((ResourceRenamed) change).getDestinationPath(),
                 batchEvent.getSessionInfo().getId(),
                 batchEvent.getSessionInfo().getIdentity());
             break;
           case UPDATE:
             executeConcurrentUpdateCommand(
                 path,
                 batchEvent.getSessionInfo().getId(),
                 batchEvent.getSessionInfo().getIdentity());
             break;
         }
       }
     }
   }
 }