@Test public void testNonPackageResourceUpdated() throws Exception { // This tests changes to a resource that is neither pom.xml nor kmodule.xml nor within a Package final Bean buildChangeListenerBean = (Bean) beanManager .getBeans(org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class) .iterator() .next(); final CreationalContext cc = beanManager.createCreationalContext(buildChangeListenerBean); final org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder buildChangeListener = (org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder) beanManager.getReference( buildChangeListenerBean, org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class, cc); final URL resourceUrl = this.getClass().getResource("/BuildChangeListenerRepo/project.imports"); 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 KieProject project = projectService.resolveProject(resourcePath); final BuildResults buildResults = buildService.build(project); assertNotNull(buildResults); assertEquals(0, buildResults.getErrorMessages().size()); assertEquals(1, buildResults.getInformationMessages().size()); // Perform incremental build (Without a full Build first) buildChangeListener.updateResource(resourcePath); final IncrementalBuildResults incrementalBuildResults = buildResultsObserver.getIncrementalBuildResults(); assertNull(incrementalBuildResults); }
private Overview loadOverview(final Path path) { final Overview overview = new Overview(); try { // Some older versions in our example do not have metadata. This should be impossible in any // kie-wb version overview.setMetadata(metadataService.getMetadata(path)); } catch (Exception e) { logger.warn( "No metadata found for file: " + path.getFileName() + ", full path [" + path.toString() + "]"); } // Some resources are not within a Project (e.g. categories.xml) so don't assume we can set the // project name final KieProject project = projectService.resolveProject(path); if (project == null) { logger.info( "File: " + path.getFileName() + ", full path [" + path.toString() + "] was not within a Project. Project Name cannot be set."); } else { overview.setProjectName(project.getProjectName()); } return overview; }
@Override public List<JBPMProcessModel> getAvailableProcessModels(Path path) { Project project = projectService.resolveProject(path); FileUtils utils = FileUtils.getInstance(); List<org.uberfire.java.nio.file.Path> nioPaths = new ArrayList<>(); nioPaths.add(Paths.convert(project.getRootPath())); Collection<FileUtils.ScanResult> processes = utils.scan(ioService, nioPaths, "bpmn2", true); List<JBPMProcessModel> result = new ArrayList<>(); for (FileUtils.ScanResult process : processes) { org.uberfire.java.nio.file.Path formPath = process.getFile(); try { ResourceSet resourceSet = new ResourceSetImpl(); resourceSet .getResourceFactoryRegistry() .getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new DroolsResourceFactoryImpl()); resourceSet.getPackageRegistry().put(DroolsPackage.eNS_URI, DroolsPackage.eINSTANCE); resourceSet .getResourceFactoryRegistry() .getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new Bpmn2ResourceFactoryImpl()); resourceSet .getPackageRegistry() .put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE); XMLResource outResource = (XMLResource) resourceSet.createResource( URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); outResource.setEncoding("UTF-8"); Map<String, Object> options = new HashMap<String, Object>(); options.put(XMLResource.OPTION_ENCODING, "UTF-8"); outResource.load(ioService.newInputStream(formPath), options); DocumentRoot root = (DocumentRoot) outResource.getContents().get(0); Definitions definitions = root.getDefinitions(); BusinessProcessFormModel processFormModel = bpmnFormModelGenerator.generateProcessFormModel(definitions); List<TaskFormModel> taskModels = bpmnFormModelGenerator.generateTaskFormModels(definitions); result.add(new JBPMProcessModel(processFormModel, taskModels)); } catch (IOException e) { e.printStackTrace(); } } return result; }
@Before public void setUp() throws Exception { kieProject = spy(new KieProject()); when(kieProject.getKModuleXMLPath()).thenReturn(kmodulePath); kModule = new KModuleModel(); kModule.getKBases().put("kbase1", getKBase("kbase1", "ksession1")); kModule.getKBases().put("kbase2", getKBase("kbase2", "ksession2", "ksession3")); kModule.getKBases().put("kbase3", getKBase("kbase3")); view = mock(KSessionSelectorView.class); when(kieProjectService.resolveProject(path)).thenReturn(kieProject); when(kModuleService.load(kmodulePath)).thenReturn(kModule); selector = new KSessionSelector( view, new CallerMock<KieProjectService>(kieProjectService), new CallerMock<KModuleService>(kModuleService)); }
private void updateDependenciesClassLoader( final Project project, final KieModuleMetaData kieModuleMetaData) { KieProject kieProject = projectService.resolveProject(project.getPomXMLPath()); if (kieProject != null) { dependenciesClassLoaderCache.setDependenciesClassLoader( kieProject, LRUProjectDependenciesClassLoaderCache.buildClassLoader(kieProject, kieModuleMetaData)); } }
private void makeNewJavaTypes( final Path context, final List<String> declaredTypes, final ConversionResult result) { if (declaredTypes == null || declaredTypes.isEmpty()) { return; } final KieProject project = projectService.resolveProject(context); for (String declaredType : declaredTypes) { final FactModels factModels = FactModelPersistence.unmarshal(declaredType); final String packageName = factModels.getPackageName(); final DataModel dataModel = new DataModelImpl(); for (FactMetaModel factMetaModel : factModels.getModels()) { final DataObject dataObject = new DataObjectImpl(factMetaModel.getName(), packageName); dataObject.setSuperClassName(factMetaModel.getSuperType()); final List<AnnotationMetaModel> annotationMetaModel = factMetaModel.getAnnotations(); addAnnotations(dataObject, annotationMetaModel); final List<FieldMetaModel> fields = factMetaModel.getFields(); for (FieldMetaModel fieldMetaModel : fields) { final String fieldName = fieldMetaModel.name; final String fieldType = fieldMetaModel.type; // Guvnor 5.5 (and earlier) does not have MultipleType boolean isMultiple = false; boolean isBaseType = orderedBaseTypes.containsValue(fieldType); ObjectProperty property = new ObjectPropertyImpl(fieldName, fieldType, isMultiple); property.setBaseType(isBaseType); // field has no annotation in Guvnor 5.5 (and earlier) dataObject.addProperty(property); result.addMessage( "Created Java Type " + getJavaTypeFQCN(dataObject), ConversionMessageType.INFO); } dataModel.getDataObjects().add(dataObject); } modellerService.saveModel(dataModel, project); } }
@Override public KObject toKObject(final Path path) { KObject index = null; try { final String drl = ioService.readAllString(path); final DrlParser drlParser = new DrlParser(); final PackageDescr packageDescr = drlParser.parse(true, drl); if (drlParser.hasErrors()) { final List<DroolsError> errors = drlParser.getErrors(); logger.warn( ErrorMessageUtilities.makeErrorMessage( path, errors.toArray(new DroolsError[errors.size()]))); return index; } if (packageDescr == null) { logger.warn(ErrorMessageUtilities.makeErrorMessage(path)); return index; } final ProjectDataModelOracle dmo = getProjectDataModelOracle(path); final Project project = projectService.resolveProject(Paths.convert(path)); final Package pkg = projectService.resolvePackage(Paths.convert(path)); final DefaultIndexBuilder builder = new DefaultIndexBuilder(project, pkg); final PackageDescrIndexVisitor visitor = new PackageDescrIndexVisitor(dmo, builder, packageDescr); visitor.visit(); index = KObjectUtil.toKObject(path, builder.build()); } catch (Exception e) { logger.error("Unable to index '" + path.toUri().toString() + "'.", e); } return index; }
@Test public void testResourceDeleted() throws Exception { final Bean buildChangeListenerBean = (Bean) beanManager .getBeans(org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class) .iterator() .next(); final CreationalContext cc = beanManager.createCreationalContext(buildChangeListenerBean); final org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder buildChangeListener = (org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder) beanManager.getReference( buildChangeListenerBean, org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class, cc); 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 KieProject project = projectService.resolveProject(resourcePath); final BuildResults buildResults = buildService.build(project); assertNotNull(buildResults); assertEquals(0, buildResults.getErrorMessages().size()); assertEquals(1, buildResults.getInformationMessages().size()); // Perform incremental build buildChangeListener.deleteResource(resourcePath); final IncrementalBuildResults incrementalBuildResults = buildResultsObserver.getIncrementalBuildResults(); assertNotNull(incrementalBuildResults); assertEquals(0, incrementalBuildResults.getAddedMessages().size()); assertEquals(0, incrementalBuildResults.getRemovedMessages().size()); }
@Test public void testBatchResourceChanges() throws Exception { final Bean buildChangeListenerBean = (Bean) beanManager .getBeans(org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class) .iterator() .next(); final CreationalContext cc = beanManager.createCreationalContext(buildChangeListenerBean); final org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder buildChangeListener = (org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder) beanManager.getReference( buildChangeListenerBean, org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class, cc); final URL resourceUrl1 = this.getClass().getResource("/BuildChangeListenerRepo/src/main/resources/add.drl"); final org.uberfire.java.nio.file.Path nioResourcePath1 = fs.getPath(resourceUrl1.toURI()); final Path resourcePath1 = paths.convert(nioResourcePath1); final URL resourceUrl2 = this.getClass().getResource("/BuildChangeListenerRepo/src/main/resources/update.drl"); final org.uberfire.java.nio.file.Path nioResourcePath2 = fs.getPath(resourceUrl2.toURI()); final Path resourcePath2 = paths.convert(nioResourcePath2); final URL resourceUrl3 = this.getClass().getResource("/BuildChangeListenerRepo/src/main/resources/delete.drl"); final org.uberfire.java.nio.file.Path nioResourcePath3 = fs.getPath(resourceUrl3.toURI()); final Path resourcePath3 = paths.convert(nioResourcePath3); // final Set<ResourceChange> batch = new HashSet<ResourceChange>(); // batch.add( new ResourceChange( ChangeType.ADD, // resourcePath1, // new SessionInfoImpl( "id", // new IdentityImpl( "user", // // Collections.<Role>emptyList() ) ) ) ); // batch.add( new ResourceChange( ChangeType.UPDATE, // resourcePath2, // new SessionInfoImpl( "id", // new IdentityImpl( "user", // // Collections.<Role>emptyList() ) ) ) ); // batch.add( new ResourceChange( ChangeType.DELETE, // resourcePath3, // new SessionInfoImpl( "id", // new IdentityImpl( "user", // // Collections.<Role>emptyList() ) ) ) ); final Map<Path, Collection<ResourceChange>> batch = new HashMap<Path, Collection<ResourceChange>>(); batch.put( resourcePath1, new ArrayList<ResourceChange>() { { add(new ResourceAdded()); } }); batch.put( resourcePath2, new ArrayList<ResourceChange>() { { add(new ResourceUpdated()); } }); batch.put( resourcePath3, new ArrayList<ResourceChange>() { { add(new ResourceUpdated()); } }); // Force full build before attempting incremental changes final KieProject project = projectService.resolveProject(resourcePath1); final BuildResults buildResults = buildService.build(project); assertNotNull(buildResults); assertEquals(0, buildResults.getErrorMessages().size()); assertEquals(1, buildResults.getInformationMessages().size()); // Perform incremental build buildChangeListener.batchResourceChanges(batch); final IncrementalBuildResults incrementalBuildResults = buildResultsObserver.getIncrementalBuildResults(); assertNotNull(incrementalBuildResults); assertEquals(0, incrementalBuildResults.getAddedMessages().size()); assertEquals(0, incrementalBuildResults.getRemovedMessages().size()); }