Search in sources :

Example 1 with BuildResults

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

the class BuildHelper method doBuildAndDeploy.

private BuildResults doBuildAndDeploy(final Module module, final boolean suppressHandlers) {
    try {
        // Build
        final BuildResults results = build(module).getBuildResults();
        StringBuffer message = new StringBuffer();
        message.append("Build of module '" + module.getModuleName() + "' (requested by " + getIdentifier() + ") completed.\n");
        message.append(" Build: " + (results.getErrorMessages().isEmpty() ? "SUCCESSFUL" : "FAILURE"));
        // Deploy, if no errors
        final POM pom = pomService.load(module.getPomXMLPath());
        if (results.getErrorMessages().isEmpty()) {
            final Builder builder = cache.assertBuilder(module);
            final InternalKieModule kieModule = (InternalKieModule) builder.getKieModule();
            final ByteArrayInputStream input = new ByteArrayInputStream(kieModule.getBytes());
            m2RepoService.deployJar(input, pom.getGav());
            message.append(" Maven: SUCCESSFUL");
            if (!suppressHandlers) {
                results.addParameter("RootPath", module.getRootPath().toURI());
                for (PostBuildHandler handler : handlers) {
                    try {
                        handler.process(results);
                    } catch (Exception e) {
                        logger.warn("PostBuildHandler {} failed due to {}", handler, e.getMessage());
                    }
                }
                message.append(" Deploy: " + (results.getErrorMessages().isEmpty() ? "SUCCESSFUL" : "FAILURE"));
            }
        }
        return results;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        // So, instead of throwing the exception, a BuildResults instance is produced on the fly to simulate the error in the problems widget.
        return buildExceptionResults(e, module.getPom().getGav());
    }
}
Also used : IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) ByteArrayInputStream(java.io.ByteArrayInputStream) PostBuildHandler(org.guvnor.common.services.project.builder.service.PostBuildHandler) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) POM(org.guvnor.common.services.project.model.POM) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 2 with BuildResults

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

the class BuildHelper method buildExceptionResults.

/**
 * When an exception is produced by the builder service, this method is uses to generate an instance of
 * <code>org.guvnor.common.services.project.builder.model.BuildResults</code> in generated with the exception details.
 * @param e The error exception.
 * @param gav
 * @return An instance of BuildResults with the exception details.
 */
public BuildResults buildExceptionResults(Exception e, GAV gav) {
    BuildResults exceptionResults = new BuildResults(gav);
    BuildMessage exceptionMessage = new BuildMessage();
    exceptionMessage.setLevel(Level.ERROR);
    exceptionMessage.setText(e.getMessage());
    exceptionResults.addBuildMessage(exceptionMessage);
    return exceptionResults;
}
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)

Example 3 with BuildResults

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

the class Builder method build.

public BuildResults build() {
    final BuildResults results = new BuildResults(projectGAV);
    synchronized (kieFileSystem) {
        // KieBuilder is not re-usable for successive "full" builds
        kieBuilder = createKieBuilder(kieFileSystem);
        // Record RTEs from KieBuilder - that can fail if a rule uses an inaccessible class
        try {
            final Results kieResults = ((InternalKieBuilder) kieBuilder).buildAll(classFilter).getResults();
            results.addAllBuildMessages(convertMessages(kieResults.getMessages(), handles));
        } catch (LinkageError e) {
            final String msg = MessageFormat.format(ERROR_CLASS_NOT_FOUND, e.getLocalizedMessage());
            logger.warn(msg);
            results.addBuildMessage(makeWarningMessage(msg));
        } catch (Throwable e) {
            final String msg = e.getLocalizedMessage();
            logger.error(msg, e);
            results.addBuildMessage(makeErrorMessage(msg));
        } finally {
            final PomModel pomModel = ((KieBuilderImpl) kieBuilder).getPomModel();
            if (pomModel != null) {
                pomModelCache.setEntry(project, pomModel);
            }
        }
    }
    // Add validate messages from external helpers
    for (Map.Entry<Path, BuildValidationHelper> e : nonKieResourceValidationHelpers.entrySet()) {
        final org.uberfire.backend.vfs.Path vfsPath = Paths.convert(e.getKey());
        final List<ValidationMessage> validationMessages = e.getValue().validate(vfsPath);
        nonKieResourceValidationHelperMessages.put(e.getKey(), validationMessages);
        results.addAllBuildMessages(convertValidationMessages(validationMessages));
    }
    // Check external imports are available. These are loaded when a DMO is requested, but it's better to report them early
    final Path nioExternalImportsPath = projectRoot.resolve("project.imports");
    if (Files.exists(nioExternalImportsPath)) {
        final org.uberfire.backend.vfs.Path externalImportsPath = Paths.convert(nioExternalImportsPath);
        final ProjectImports projectImports = importsService.load(externalImportsPath);
        final Imports imports = projectImports.getImports();
        for (final Import item : imports.getImports()) {
            final String fullyQualifiedClassName = item.getType();
            try {
                Class clazz = this.getClass().getClassLoader().loadClass(item.getType());
            } catch (ClassNotFoundException cnfe) {
                logger.warn(cnfe.getMessage());
                final String msg = MessageFormat.format(ERROR_CLASS_NOT_FOUND, fullyQualifiedClassName);
                results.addBuildMessage(makeWarningMessage(msg));
            }
        }
    }
    // Store the project dependencies ClassLoader for optimization purposes.
    final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(getKieModuleIgnoringErrors(), DependencyFilter.COMPILE_FILTER);
    updateDependenciesClassLoader(project, kieModuleMetaData);
    results.addAllBuildMessages(verifyClasses(kieModuleMetaData));
    return results;
}
Also used : Path(org.uberfire.java.nio.file.Path) BuildValidationHelper(org.guvnor.common.services.project.builder.service.BuildValidationHelper) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) KieBuilderImpl(org.drools.compiler.kie.builder.impl.KieBuilderImpl) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) Import(org.kie.soup.project.datamodel.imports.Import) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) ProjectImports(org.guvnor.common.services.project.model.ProjectImports) Imports(org.kie.soup.project.datamodel.imports.Imports) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) IncrementalResults(org.kie.internal.builder.IncrementalResults) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) Results(org.kie.api.builder.Results) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) PomModel(org.appformer.maven.support.PomModel) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with BuildResults

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

the class ResourceChangeIncrementalBuilderConcurrencyTest method ensureModuleBuild.

private void ensureModuleBuild() {
    final KieModule module = moduleService.resolveModule(resourcePath);
    final BuildResults buildResults = buildService.build(module);
    assertNotNull(buildResults);
    assertEquals(0, buildResults.getErrorMessages().size());
    assertEquals(1, buildResults.getInformationMessages().size());
}
Also used : BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 5 with BuildResults

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

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