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());
}
}
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;
}
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;
}
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());
}
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());
}
Aggregations