class Builder implements Serializable {

    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;
    }

    public  Builder(final Module project,
                   final IOService ioService,
                   final KieModuleService moduleService,
                   final ProjectImportsService importsService,
                   final List<BuildValidationHelper> buildValidationHelpers,
                   final LRUModuleDependenciesClassLoaderCache dependenciesClassLoaderCache,
                   final LRUPomModelCache pomModelCache,
                   final PackageNameWhiteListService packageNameWhiteListService,
                   final Predicate<String> classFilter,
                   final KieBuilder kieBuilder,
                   final KieFileSystem kieFileSystem);
    public  Builder(final Module project,
                   final IOService ioService,
                   final KieModuleService moduleService,
                   final ProjectImportsService importsService,
                   final List<BuildValidationHelper> buildValidationHelpers,
                   final LRUModuleDependenciesClassLoaderCache dependenciesClassLoaderCache,
                   final LRUPomModelCache pomModelCache,
                   final PackageNameWhiteListService packageNameWhiteListService,
                   final Predicate<String> classFilter);

}