Search in sources :

Example 1 with ResourceChangeType

use of org.uberfire.workbench.events.ResourceChangeType in project kie-wb-common by kiegroup.

the class Builder method applyBatchResourceChanges.

public IncrementalBuildResults applyBatchResourceChanges(final Map<org.uberfire.backend.vfs.Path, Collection<ResourceChange>> changes) {
    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>();
    final IncrementalBuildResults results = new IncrementalBuildResults(projectGAV);
    synchronized (kieFileSystem) {
        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("Builder.resourceĀ§", resource);
                final String destinationPath = destinationPath(resource);
                changedFilesKieBuilderPaths.add(destinationPath);
                switch(type) {
                    case ADD:
                    case UPDATE:
                        // Only files can be processed
                        if (!Files.isRegularFile(resource)) {
                            continue;
                        }
                        update(nonKieResourceValidatorAddedMessages, nonKieResourceValidatorRemovedMessages, resource);
                        break;
                    case DELETE:
                        delete(nonKieResourceValidatorRemovedMessages, resource);
                }
            }
        }
        // Perform the Incremental build and get messages from incremental build
        buildIncrementally(results, toArray(changedFilesKieBuilderPaths));
    }
    // Copy in BuildMessages for non-KIE resources
    results.addAllAddedMessages(convertValidationMessages(nonKieResourceValidatorAddedMessages));
    results.addAllRemovedMessages(convertValidationMessages(nonKieResourceValidatorRemovedMessages));
    return results;
}
Also used : Path(org.uberfire.java.nio.file.Path) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) ArrayList(java.util.ArrayList) ResourceChangeType(org.uberfire.workbench.events.ResourceChangeType) Collection(java.util.Collection) ResourceChange(org.uberfire.workbench.events.ResourceChange) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IncrementalBuildResults (org.guvnor.common.services.project.builder.model.IncrementalBuildResults)1 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)1 Path (org.uberfire.java.nio.file.Path)1 ResourceChange (org.uberfire.workbench.events.ResourceChange)1 ResourceChangeType (org.uberfire.workbench.events.ResourceChangeType)1