Search in sources :

Example 1 with IncrementalBuildResults

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

the class BuildHelper method addPackageResource.

public IncrementalBuildResults addPackageResource(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.addResource(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 2 with IncrementalBuildResults

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

the class BuildHelper method updatePackageResource.

public IncrementalBuildResults updatePackageResource(final Path resource) {
    try {
        final Module module = moduleService.resolveModule(resource);
        if (module == null) {
            return new IncrementalBuildResults();
        }
        final Builder builder = cache.assertBuilder(module);
        if (!builder.isBuilt()) {
            throw new IllegalStateException("Incremental Build requires a full build be completed first.");
        }
        return builder.updateResource(Paths.convert(resource));
    } 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) Module(org.guvnor.common.services.project.model.Module) KieModule(org.kie.workbench.common.services.shared.project.KieModule) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException)

Example 3 with IncrementalBuildResults

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

the class ValidatorBuildService method doValidation.

private List<ValidationMessage> doValidation(final Path resourcePath, final InputStream inputStream) throws NoModuleException {
    final ValidatorResultBuilder resultBuilder = new ValidatorResultBuilder();
    final Module module = module(resourcePath);
    final org.uberfire.java.nio.file.Path nioResourcePath = Paths.convert(resourcePath);
    // Incremental Build does not support Java classes
    if (isIncrementalBuildPossible(resourcePath)) {
        // Build the Builder from the cache so it's "built" state can be preserved for re-use
        BuildInfo buildInfo = buildInfoService.getBuildInfo(module);
        final Builder clone = ((BuildInfoImpl) buildInfo).getBuilder().clone();
        // First delete resource otherwise if the resource already had errors following builder.build()
        // the incremental compilation will not report any additional errors and the resource will be
        // considered valid.
        clone.deleteResource(nioResourcePath);
        final IncrementalBuildResults incrementalBuildResults = clone.updateResource(nioResourcePath, inputStream);
        resultBuilder.add(incrementalBuildResults.getAddedMessages());
    } else {
        Builder builder = builderCache.assertBuilder(module(resourcePath));
        final Builder clone = builder.clone();
        resultBuilder.add(clone.build(nioResourcePath, inputStream).getMessages());
    }
    return resultBuilder.results();
}
Also used : IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) BuildInfo(org.kie.workbench.common.services.backend.builder.service.BuildInfo) Builder(org.kie.workbench.common.services.backend.builder.core.Builder) Module(org.guvnor.common.services.project.model.Module)

Example 4 with IncrementalBuildResults

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

the class BuildPipelineTest method doTestIncrementalBuildResourceExecution.

private void doTestIncrementalBuildResourceExecution(KieModule module, String resourceUri, LocalBuildConfig.BuildType buildType) {
    // prepare the pipeline input.
    Input input = createIncrementalBuildInput(ROOT_PATH_URI, resourceUri, buildType.name());
    // execute the pipeline and verify the result.
    pipelineInitializer.getExecutor().execute(input, pipe, (Consumer<LocalBinaryConfig>) localBinaryConfig -> {
        assertEquals(incrementalBuildResults, localBinaryConfig.getIncrementalBuildResults());
    }, pipelineEventListener);
    // verify that all stages were properly invoked.
    verifyLocalSourceConfigWasInvoked();
    verifyLocalProjectConfigWasInvoked();
    verifyLocalBuildConfigExecutorWasInvoked(module, resourceUri, buildType.name());
    verifyLocalBuildExecConfigExecutorWasInvoked(module, Paths.convert(getNioPath(resourceUri)), buildType);
    // verify the pipeline events where properly raised.
    verifyPipelineEvents();
}
Also used : Builder(org.kie.workbench.common.services.backend.builder.core.Builder) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) Stage(org.guvnor.ala.pipeline.Stage) Mock(org.mockito.Mock) ConfigExecutor(org.guvnor.ala.pipeline.ConfigExecutor) RunWith(org.junit.runner.RunWith) InMemoryPipelineRegistry(org.guvnor.ala.registry.inmemory.InMemoryPipelineRegistry) ArrayList(java.util.ArrayList) BeforePipelineExecutionEvent(org.guvnor.ala.pipeline.events.BeforePipelineExecutionEvent) Paths(org.uberfire.backend.server.util.Paths) Pipeline(org.guvnor.ala.pipeline.Pipeline) ArgumentCaptor(org.mockito.ArgumentCaptor) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Map(java.util.Map) AfterPipelineExecutionEvent(org.guvnor.ala.pipeline.events.AfterPipelineExecutionEvent) ResourceChange(org.uberfire.workbench.events.ResourceChange) Source(org.guvnor.ala.source.Source) AfterStageExecutionEvent(org.guvnor.ala.pipeline.events.AfterStageExecutionEvent) Path(org.uberfire.backend.vfs.Path) Before(org.junit.Before) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) PipelineRegistry(org.guvnor.ala.registry.PipelineRegistry) Input(org.guvnor.ala.pipeline.Input) Collection(java.util.Collection) Test(org.junit.Test) BuildHelper(org.kie.workbench.common.services.backend.builder.core.BuildHelper) KieModule(org.kie.workbench.common.services.shared.project.KieModule) PipelineEventListener(org.guvnor.ala.pipeline.events.PipelineEventListener) Consumer(java.util.function.Consumer) BeforeStageExecutionEvent(org.guvnor.ala.pipeline.events.BeforeStageExecutionEvent) Mockito(org.mockito.Mockito) List(java.util.List) DeploymentMode(org.guvnor.common.services.project.service.DeploymentMode) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Assert(org.junit.Assert) Input(org.guvnor.ala.pipeline.Input)

Example 5 with IncrementalBuildResults

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

the class ResourceChangeIncrementalBuilderTest method testResourceDeleted.

@Test
public void testResourceDeleted() throws Exception {
    final URL resourceUrl = this.getClass().getResource("/BuildChangeListenerRepo/src/main/resources/delete.drl");
    final org.uberfire.java.nio.file.Path nioResourcePath = fs.getPath(resourceUrl.toURI());
    final Path resourcePath = paths.convert(nioResourcePath);
    // Force full build before attempting incremental changes
    final KieModule module = moduleService.resolveModule(resourcePath);
    final BuildResults buildResults = buildService.build(module);
    assertNotNull(buildResults);
    assertEquals(0, buildResults.getErrorMessages().size());
    assertEquals(1, buildResults.getInformationMessages().size());
    // Perform incremental build
    buildChangeListener.deleteResource(resourcePath);
    waitForIncrementalBuildResults(buildResultsObserver);
    final IncrementalBuildResults incrementalBuildResults = buildResultsObserver.getIncrementalBuildResults();
    assertNotNull(incrementalBuildResults);
    assertEquals(0, incrementalBuildResults.getAddedMessages().size());
    assertEquals(0, incrementalBuildResults.getRemovedMessages().size());
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) URL(java.net.URL) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

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