Search in sources :

Example 21 with BuildResults

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

the class BuildExecutorTest method mockBuildService.

private void mockBuildService(final BuildService buildService) {
    when(buildService.build(any(KieModule.class))).thenReturn(new BuildResults());
    when(buildService.buildAndDeploy(any(KieModule.class), any(DeploymentMode.class))).thenReturn(new BuildResults());
}
Also used : BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) DeploymentMode(org.guvnor.common.services.project.service.DeploymentMode) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 22 with BuildResults

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

the class BuilderConcurrencyIntegrationTest method testBuilderConcurrency.

@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1145105
void testBuilderConcurrency() throws URISyntaxException {
    final URL pomUrl = this.getClass().getResource("/BuilderConcurrencyRepo/pom.xml");
    final org.uberfire.java.nio.file.Path nioPomPath = fs.getPath(pomUrl.toURI());
    final Path pomPath = paths.convert(nioPomPath);
    final URL resourceUrl = this.getClass().getResource("/BuilderConcurrencyRepo/src/main/resources/update.drl");
    final org.uberfire.java.nio.file.Path nioResourcePath = fs.getPath(resourceUrl.toURI());
    final Path resourcePath = paths.convert(nioResourcePath);
    final SessionInfo sessionInfo = mock(SessionInfo.class);
    // Force full build before attempting incremental changes
    final KieModule project = moduleService.resolveModule(resourcePath);
    final BuildResults buildResults = buildService.build(project);
    assertNotNull(buildResults);
    assertEquals(0, buildResults.getErrorMessages().size());
    assertEquals(1, buildResults.getInformationMessages().size());
    // Perform incremental build
    final int THREADS = 200;
    final Result result = new Result();
    ExecutorService es = Executors.newCachedThreadPool();
    for (int i = 0; i < THREADS; i++) {
        switch(i % 3) {
            case 0:
                es.execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            logger.debug("Thread " + Thread.currentThread().getName() + " has started: BuildService.build( project )");
                            buildService.build(project);
                            logger.debug("Thread " + Thread.currentThread().getName() + " has completed.");
                        } catch (Throwable e) {
                            result.setFailed(true);
                            result.setMessage(e.getMessage());
                            logger.debug(e.getMessage());
                        }
                    }
                });
                break;
            case 1:
                es.execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            logger.debug("Thread " + Thread.currentThread().getName() + " has started: LRUModuleDataModelOracleCache.invalidateModuleCache(...)");
                            moduleDMOCache.invalidateModuleCache(new InvalidateDMOModuleCacheEvent(sessionInfo, project, pomPath));
                            logger.debug("Thread " + Thread.currentThread().getName() + " has completed.");
                        } catch (Throwable e) {
                            result.setFailed(true);
                            result.setMessage(e.getMessage());
                            logger.debug(e.getMessage());
                        }
                    }
                });
                break;
            default:
                es.execute(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            logger.debug("Thread " + Thread.currentThread().getName() + " has started: LRUBuilderCache.assertBuilder( project ).getKieModuleIgnoringErrors();");
                            builderCache.assertBuilder(project).getKieModuleIgnoringErrors();
                            logger.debug("Thread " + Thread.currentThread().getName() + " has completed.");
                        } catch (Throwable e) {
                            result.setFailed(true);
                            result.setMessage(e.getMessage());
                            logger.debug(e.getMessage());
                        }
                    }
                });
        }
    }
    es.shutdown();
    try {
        es.awaitTermination(5, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
    }
    if (result.isFailed()) {
        fail(result.getMessage());
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) InvalidateDMOModuleCacheEvent(org.guvnor.common.services.project.builder.events.InvalidateDMOModuleCacheEvent) SessionInfo(org.uberfire.rpc.SessionInfo) URL(java.net.URL) ExecutorService(java.util.concurrent.ExecutorService) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 23 with BuildResults

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

the class BuildHelper method build.

public BuildResult build(final Module module) {
    try {
        cache.invalidateCache(module);
        Builder builder = cache.assertBuilder(module);
        final BuildResults results = builder.build();
        BuildMessage infoMsg = new BuildMessage();
        infoMsg.setLevel(Level.INFO);
        infoMsg.setText(buildResultMessage(module, results).toString());
        results.addBuildMessage(0, infoMsg);
        return new BuildResult(builder, results);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return new BuildResult(null, buildExceptionResults(e, module.getPom().getGav()));
    }
}
Also used : BuildMessage(org.guvnor.common.services.project.builder.model.BuildMessage) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException)

Example 24 with BuildResults

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

the class Builder method getKieContainer.

public KieContainer getKieContainer() {
    BuildResults results = null;
    // Kie classes are only available once built
    if (!isBuilt()) {
        results = build();
    } else {
        results = new BuildResults();
        results.addAllBuildMessages(convertMessages(kieBuilder.getResults().getMessages(), handles));
    }
    // It's impossible to retrieve a KieContainer if the KieModule contains errors
    if (results.getErrorMessages().isEmpty()) {
        // Do not retrieve the KieContainer with KieServices.newKieContainer(releaseId) since this looks-up the KieModule to
        // create the KieContainer from KieRepository. This holds the most recent KieModule (for the ReleaseId) that was built with
        // kieBuilder.buildAll() which *may* be a KieModule created during asset validation and hence will lack many assets.
        // See https://bugzilla.redhat.com/show_bug.cgi?id=1202551
        final org.kie.api.builder.KieModule kieModule = kieBuilder.getKieModule();
        final ReleaseId releaseId = kieModule.getReleaseId();
        final org.drools.compiler.kie.builder.impl.KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieBuilder.getKieModule(), null);
        final KieContainer kieContainer = new KieContainerImpl(kieProject, KieServices.Factory.get().getRepository(), releaseId);
        return kieContainer;
    } else {
        return null;
    }
}
Also used : BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) ReleaseId(org.kie.api.builder.ReleaseId) KieModuleKieProject(org.drools.compiler.kie.builder.impl.KieModuleKieProject) KieContainer(org.kie.api.runtime.KieContainer)

Example 25 with BuildResults

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

the class BuilderTest method testBuilderKModuleHasSnapshotDependency.

@Test
public void testBuilderKModuleHasSnapshotDependency() throws Exception {
    URL url = this.getClass().getResource("/GuvnorM2RepoDependencyExample2Snapshot");
    SimpleFileSystemProvider p = new SimpleFileSystemProvider();
    org.uberfire.java.nio.file.Path path = p.getPath(url.toURI());
    final Module module = moduleService.resolveModule(Paths.convert(path));
    final Builder builder = new Builder(module, ioService, moduleService, importsService, new ArrayList<>(), dependenciesClassLoaderCache, pomModelCache, getPackageNameWhiteListService(), alwaysTrue);
    final BuildResults results = builder.build();
    // Debug output
    if (!results.getMessages().isEmpty()) {
        for (BuildMessage m : results.getMessages()) {
            logger.debug(m.getText());
        }
    }
    assertTrue(results.getMessages().isEmpty());
}
Also used : SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) BuildMessage(org.guvnor.common.services.project.builder.model.BuildMessage) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) Module(org.guvnor.common.services.project.model.Module) URL(java.net.URL) Test(org.junit.Test)

Aggregations

BuildResults (org.guvnor.common.services.project.builder.model.BuildResults)36 Test (org.junit.Test)29 IncrementalBuildResults (org.guvnor.common.services.project.builder.model.IncrementalBuildResults)25 URL (java.net.URL)19 Path (org.uberfire.backend.vfs.Path)15 KieModule (org.kie.workbench.common.services.shared.project.KieModule)13 BuildMessage (org.guvnor.common.services.project.builder.model.BuildMessage)8 CreationalContext (javax.enterprise.context.spi.CreationalContext)6 Bean (javax.enterprise.inject.spi.Bean)6 Module (org.guvnor.common.services.project.model.Module)4 SimpleFileSystemProvider (org.uberfire.java.nio.fs.file.SimpleFileSystemProvider)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 ExecutorService (java.util.concurrent.ExecutorService)2 ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)2 DeploymentMode (org.guvnor.common.services.project.service.DeploymentMode)2 KieModuleMetaData (org.kie.scanner.KieModuleMetaData)2 ResourceAdded (org.uberfire.workbench.events.ResourceAdded)2 ResourceChange (org.uberfire.workbench.events.ResourceChange)2