Search in sources :

Example 16 with IncrementalBuildResults

use of org.guvnor.common.services.project.builder.model.IncrementalBuildResults in project kie-wb-common by kiegroup.

the class BuildServiceImplTest method testApplyBatchResourceChanges.

@Test
public void testApplyBatchResourceChanges() {
    when(buildServiceHelper.localBuild(module, resourceChanges)).thenReturn(incrementalBuildResults);
    IncrementalBuildResults result = buildService.applyBatchResourceChanges(module, resourceChanges);
    assertEquals(incrementalBuildResults, result);
    verify(buildServiceHelper, times(1)).localBuild(module, resourceChanges);
}
Also used : IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) Test(org.junit.Test)

Example 17 with IncrementalBuildResults

use of org.guvnor.common.services.project.builder.model.IncrementalBuildResults in project kie-wb-common by kiegroup.

the class BuildHelper method deletePackageResource.

public IncrementalBuildResults deletePackageResource(final Path resource) {
    try {
        IncrementalBuildResults results = new IncrementalBuildResults();
        final KieModule module = moduleService.resolveModule(resource);
        if (module == null) {
            return results;
        }
        final Builder builder = cache.assertBuilder(module);
        if (!builder.isBuilt()) {
            throw new IllegalStateException("Incremental Build requires a full build be completed first.");
        } else {
            results = builder.deleteResource(Paths.convert(resource));
        }
        return results;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw ExceptionUtilities.handleException(e);
    }
}
Also used : IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.workbench.common.services.shared.project.KieModule) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException)

Example 18 with IncrementalBuildResults

use of org.guvnor.common.services.project.builder.model.IncrementalBuildResults 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)

Example 19 with IncrementalBuildResults

use of org.guvnor.common.services.project.builder.model.IncrementalBuildResults in project kie-wb-common by kiegroup.

the class Builder method deleteResource.

public IncrementalBuildResults deleteResource(final Path resource) {
    checkNotNull("resource", resource);
    checkAFullBuildHasBeenPerformed();
    // Resource Type might have been validated "externally" (i.e. it's not covered by Kie). Clear any errors.
    final IncrementalBuildResults results = new IncrementalBuildResults(projectGAV);
    final BuildValidationHelper validator = getBuildValidationHelper(resource);
    if (validator != null) {
        nonKieResourceValidationHelpers.remove(resource);
        results.addAllRemovedMessages(convertValidationMessages(nonKieResourceValidationHelperMessages.remove(resource)));
    }
    synchronized (kieFileSystem) {
        removeResource(resource);
        buildIncrementally(results, destinationPath(resource));
    }
    return results;
}
Also used : BuildValidationHelper(org.guvnor.common.services.project.builder.service.BuildValidationHelper) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults)

Example 20 with IncrementalBuildResults

use of org.guvnor.common.services.project.builder.model.IncrementalBuildResults in project kie-wb-common by kiegroup.

the class Builder method addResource.

private IncrementalBuildResults addResource(final Path resource, final InputStream inputStream) {
    checkNotNull("resource", resource);
    // Only files can be processed
    if (!Files.isRegularFile(resource)) {
        return new IncrementalBuildResults(projectGAV);
    }
    checkAFullBuildHasBeenPerformed();
    // Resource Type might require "external" validation (i.e. it's not covered by Kie)
    final IncrementalBuildResults results = new IncrementalBuildResults(projectGAV);
    final BuildValidationHelper validator = getBuildValidationHelper(resource);
    if (validator != null) {
        final List<ValidationMessage> addedValidationMessages = validator.validate(Paths.convert(resource));
        results.addAllAddedMessages(convertValidationMessages(addedValidationMessages));
        results.addAllRemovedMessages(convertValidationMessages(nonKieResourceValidationHelperMessages.remove(resource)));
        nonKieResourceValidationHelpers.put(resource, validator);
        nonKieResourceValidationHelperMessages.put(resource, addedValidationMessages);
    }
    synchronized (kieFileSystem) {
        addNewResource(resource, inputStream);
        buildIncrementally(results, destinationPath(resource));
    }
    return results;
}
Also used : BuildValidationHelper(org.guvnor.common.services.project.builder.service.BuildValidationHelper) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage)

Aggregations

IncrementalBuildResults (org.guvnor.common.services.project.builder.model.IncrementalBuildResults)27 Test (org.junit.Test)19 BuildResults (org.guvnor.common.services.project.builder.model.BuildResults)14 Path (org.uberfire.backend.vfs.Path)14 URL (java.net.URL)12 KieModule (org.kie.workbench.common.services.shared.project.KieModule)11 CreationalContext (javax.enterprise.context.spi.CreationalContext)6 Bean (javax.enterprise.inject.spi.Bean)6 Collection (java.util.Collection)5 ResourceChange (org.uberfire.workbench.events.ResourceChange)5 Consumer (java.util.function.Consumer)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)3 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)3 Builder (org.kie.workbench.common.services.backend.builder.core.Builder)3 List (java.util.List)2 ConfigExecutor (org.guvnor.ala.pipeline.ConfigExecutor)2 Input (org.guvnor.ala.pipeline.Input)2