use of org.guvnor.common.services.project.builder.service.BuildValidationHelper 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.service.BuildValidationHelper in project kie-wb-common by kiegroup.
the class DataModelServiceConstructorTest method testConstructor.
@Test
public void testConstructor() throws IllegalArgumentException, FileSystemNotFoundException, SecurityException, URISyntaxException {
final URL packageUrl = this.getClass().getResource("/DataModelServiceConstructorTest/src/main/java/t1p1");
final RenameService renameService = mock(RenameService.class);
final SaveAndRenameServiceImpl saveAndRenameService = mock(SaveAndRenameServiceImpl.class);
RepositoryService repoService = mock(RepositoryService.class);
IOService ioService = new IOServiceDotFileImpl();
Collection<Role> roles = new ArrayList<>();
Collection<Group> groups = new ArrayList<>();
User user = new UserImpl("admin", roles, groups);
SessionInfo sessionInfo = new SessionInfoImpl("admin", user);
Instance<User> userInstance = mock(Instance.class);
when(userInstance.get()).thenReturn(user);
ConfigIOServiceProducer cfiosProducer = new ConfigIOServiceProducer();
cfiosProducer.setup();
IOService configIOService = cfiosProducer.configIOService();
MetadataService metadataService = new MetadataServiceImpl(ioService, configIOService, sessionInfo);
POMContentHandler pomContentHandler = new POMContentHandler();
M2RepoServiceImpl m2RepoService = new M2RepoServiceImpl();
POMService pomService = new POMServiceImpl(ioService, pomContentHandler, m2RepoService, metadataService);
KModuleContentHandler moduleContentHandler = new KModuleContentHandler();
CommentedOptionFactory commentedOptionFactory = new CommentedOptionFactoryImpl(sessionInfo);
ProjectConfigurationContentHandler moduleConfigurationContentHandler = new ProjectConfigurationContentHandler();
ProjectImportsService moduleImportsService = new ProjectImportsServiceImpl(ioService, moduleConfigurationContentHandler, renameService, saveAndRenameService);
Event<NewModuleEvent> newModuleEvent = new EventSourceMock<>();
Event<NewPackageEvent> newPackageEvent = new EventSourceMock<>();
Event<RenameModuleEvent> renameModuleEvent = new EventSourceMock<>();
Event<InvalidateDMOModuleCacheEvent> invalidateDMOCache = new EventSourceMock<>();
PermissionTypeRegistry permissionTypeRegistry = new DefaultPermissionTypeRegistry();
DotNamedPermissionType permissionType = new DotNamedPermissionType(REPOSITORY_TYPE.getName());
permissionType.createPermission(REPOSITORY_TYPE, RepositoryAction.READ, true);
permissionType.createPermission(REPOSITORY_TYPE, RepositoryAction.CREATE, true);
permissionType.createPermission(REPOSITORY_TYPE, RepositoryAction.UPDATE, true);
permissionType.createPermission(REPOSITORY_TYPE, RepositoryAction.DELETE, true);
permissionTypeRegistry.register(permissionType);
ModuleRepositoryResolver repositoryResolver = new ModuleRepositoryResolverImpl(ioService, null, null);
FileDiscoveryService fileDiscoveryService = new FileDiscoveryServiceImpl();
HackedKieModuleServiceImpl moduleService = null;
HackedKModuleServiceImpl kModuleService = new HackedKModuleServiceImpl(ioService, moduleService, metadataService, moduleContentHandler);
KieResourceResolver resourceResolver = new KieResourceResolver(ioService, pomService, commentedOptionFactory, kModuleService, resourcePathResolversInstance);
ModuleSaver moduleSaver = null;
moduleService = new HackedKieModuleServiceImpl(ioService, moduleSaver, pomService, repoService, newModuleEvent, newPackageEvent, renameModuleEvent, invalidateDMOCache, sessionInfo, commentedOptionFactory, mock(ModuleFinder.class), resourceResolver, repositoryResolver);
ModuleRepositoriesContentHandler contentHandler = new ModuleRepositoriesContentHandler();
ModuleRepositoriesService moduleRepositoriesService = new KieModuleRepositoriesServiceImpl(ioService, repositoryResolver, resourceResolver, contentHandler, commentedOptionFactory);
DependencyService dependencyService = new DependencyServiceImpl();
PackageNameSearchProvider packageNameSearchProvider = new PackageNameSearchProvider(dependencyService);
PackageNameWhiteListLoader loader = new PackageNameWhiteListLoader(packageNameSearchProvider, ioService);
MetadataServerSideService serverSideMetdataService = new MetadataServiceImpl(ioService, configIOService, sessionInfo);
PackageNameWhiteListSaver saver = new PackageNameWhiteListSaver(ioService, serverSideMetdataService, commentedOptionFactory);
PackageNameWhiteListService packageNameWhiteListService = new PackageNameWhiteListServiceImpl(ioService, moduleService, loader, saver);
moduleSaver = new ModuleSaver(ioService, pomService, kModuleService, newModuleEvent, newPackageEvent, resourceResolver, moduleImportsService, moduleRepositoriesService, packageNameWhiteListService, commentedOptionFactory, sessionInfo);
moduleService.setModuleSaver(moduleSaver);
kModuleService.setModuleService(moduleService);
ProjectImportsService importsService = new ProjectImportsServiceImpl(ioService, moduleConfigurationContentHandler, renameService, saveAndRenameService);
Instance<BuildValidationHelper> buildValidationHelperBeans = null;
Instance<Predicate<String>> classFilterBeans = null;
HackedLRUModuleDependenciesClassLoaderCache dependenciesClassLoaderCache = new HackedLRUModuleDependenciesClassLoaderCache();
LRUPomModelCache pomModelCache = new LRUPomModelCache();
LRUBuilderCache builderCache = new LRUBuilderCache(ioService, moduleService, importsService, buildValidationHelperBeans, dependenciesClassLoaderCache, pomModelCache, packageNameWhiteListService, classFilterBeans);
Instance<PostBuildHandler> handlerInstance = mock(Instance.class);
Iterator<PostBuildHandler> mockIterator = mock(Iterator.class);
when(handlerInstance.iterator()).thenReturn(mockIterator);
when(mockIterator.hasNext()).thenReturn(false);
DeploymentVerifier deploymentVerifier = new DeploymentVerifier(repositoryResolver, moduleRepositoriesService);
BuildHelper buildHelper = new BuildHelper(pomService, m2RepoService, moduleService, deploymentVerifier, builderCache, handlerInstance, userInstance);
PipelineRegistry pipelineRegistry = new InMemoryPipelineRegistry();
BuildPipelineInitializer pipelineInitializer = new BuildPipelineInitializer(pipelineRegistry, getConfigExecutors(moduleService, buildHelper));
BuildPipelineInvoker pipelineInvoker = new BuildPipelineInvoker(pipelineInitializer.getExecutor(), pipelineRegistry);
BuildServiceHelper buildServiceHelper = new BuildServiceHelper(pipelineInvoker, deploymentVerifier);
BuildService buildService = new BuildServiceImpl(moduleService, buildServiceHelper, builderCache);
BuildInfoService buildInfoService = new BuildInfoService(buildService, builderCache);
ModuleDataModelOracleBuilderProvider builderProvider = new ModuleDataModelOracleBuilderProvider(packageNameWhiteListService, importsService);
LRUModuleDataModelOracleCache cacheModules = new LRUModuleDataModelOracleCache(builderProvider, moduleService, buildInfoService);
dependenciesClassLoaderCache.setBuildInfoService(buildInfoService);
LRUDataModelOracleCache cachePackages = new LRUDataModelOracleCache(ioService, fileDiscoveryService, cacheModules, moduleService, buildInfoService, dataModelExtensionProvider, new RawMVELEvaluator());
DataModelService dataModelService = new DataModelServiceImpl(cachePackages, cacheModules, moduleService);
final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
final Path packagePath = Paths.convert(nioPackagePath);
final ModuleDataModelOracle oracle = dataModelService.getModuleDataModel(packagePath);
assertNotNull(oracle);
assertEquals(4, oracle.getModuleModelFields().size());
assertContains("t1p1.Bean1", oracle.getModuleModelFields().keySet());
assertContains("t1p1.DRLBean", oracle.getModuleModelFields().keySet());
assertContains("t1p2.Bean2", oracle.getModuleModelFields().keySet());
assertContains("java.lang.String", oracle.getModuleModelFields().keySet());
assertEquals(TypeSource.JAVA_PROJECT, oracle.getModuleTypeSources().get("t1p1.Bean1"));
assertEquals(TypeSource.DECLARED, oracle.getModuleTypeSources().get("t1p1.DRLBean"));
assertEquals(TypeSource.JAVA_PROJECT, oracle.getModuleTypeSources().get("t1p2.Bean2"));
assertEquals(TypeSource.JAVA_PROJECT, oracle.getModuleTypeSources().get("java.lang.String"));
}
use of org.guvnor.common.services.project.builder.service.BuildValidationHelper in project kie-wb-common by kiegroup.
the class Builder method deleteResource.
public IncrementalBuildResults deleteResource(final Path resource) {
checkNotNull("resource", resource);
checkAFullBuildHasBeenPerformed();
// Resource Type might have been validated "externally" (i.e. it's not covered by Kie). Clear any errors.
final IncrementalBuildResults results = new IncrementalBuildResults(projectGAV);
final BuildValidationHelper validator = getBuildValidationHelper(resource);
if (validator != null) {
nonKieResourceValidationHelpers.remove(resource);
results.addAllRemovedMessages(convertValidationMessages(nonKieResourceValidationHelperMessages.remove(resource)));
}
synchronized (kieFileSystem) {
removeResource(resource);
buildIncrementally(results, destinationPath(resource));
}
return results;
}
use of org.guvnor.common.services.project.builder.service.BuildValidationHelper in project kie-wb-common by kiegroup.
the class Builder method visitPaths.
private void visitPaths(final DirectoryStream<Path> directoryStream) {
for (final Path path : directoryStream) {
if (Files.isDirectory(path)) {
visitPaths(Files.newDirectoryStream(path));
} else {
// Don't process dotFiles
if (!dotFileFilter.accept(path)) {
// Resource Type might require "external" validation (i.e. it's not covered by Kie)
final BuildValidationHelper validator = getBuildValidationHelper(path);
if (validator != null) {
nonKieResourceValidationHelpers.put(path, validator);
}
addNewResource(path, ioService.newInputStream(path));
}
}
}
}
use of org.guvnor.common.services.project.builder.service.BuildValidationHelper in project kie-wb-common by kiegroup.
the class Builder method update.
private void update(final List<ValidationMessage> nonKieResourceValidatorAddedMessages, final List<ValidationMessage> nonKieResourceValidatorRemovedMessages, final Path resource) {
// Resource Type might require "external" validation (i.e. it's not covered by Kie)
final BuildValidationHelper validator = getBuildValidationHelper(resource);
if (validator != null) {
final List<ValidationMessage> addedValidationMessages = validator.validate(Paths.convert(resource));
if (!(addedValidationMessages == null || addedValidationMessages.isEmpty())) {
for (ValidationMessage validationMessage : addedValidationMessages) {
nonKieResourceValidatorAddedMessages.add(validationMessage);
}
}
final List<ValidationMessage> removedValidationMessages = nonKieResourceValidationHelperMessages.remove(resource);
if (!(removedValidationMessages == null || removedValidationMessages.isEmpty())) {
for (ValidationMessage validationMessage : removedValidationMessages) {
nonKieResourceValidatorRemovedMessages.add(validationMessage);
}
}
nonKieResourceValidationHelpers.put(resource, validator);
nonKieResourceValidationHelperMessages.put(resource, addedValidationMessages);
}
addNewResource(resource, ioService.newInputStream(resource));
}
Aggregations