Search in sources :

Example 1 with ResourceChange

use of org.uberfire.workbench.events.ResourceChange in project kie-wb-common by kiegroup.

the class ResourceChangeIncrementalBuilderTest method testBatchResourceChanges.

@Test
public void testBatchResourceChanges() throws Exception {
    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 KieModule module = moduleService.resolveModule(resourcePath1);
    final BuildResults buildResults = buildService.build(module);
    assertNotNull(buildResults);
    assertEquals(0, buildResults.getErrorMessages().size());
    assertEquals(1, buildResults.getInformationMessages().size());
    // Perform incremental build
    buildChangeListener.batchResourceChanges(batch);
    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) HashMap(java.util.HashMap) ResourceAdded(org.uberfire.workbench.events.ResourceAdded) URL(java.net.URL) Collection(java.util.Collection) ResourceChange(org.uberfire.workbench.events.ResourceChange) KieModule(org.kie.workbench.common.services.shared.project.KieModule) ResourceUpdated(org.uberfire.workbench.events.ResourceUpdated) Test(org.junit.Test)

Example 2 with ResourceChange

use of org.uberfire.workbench.events.ResourceChange in project kie-wb-common by kiegroup.

the class ResourceChangeIncrementalBuilderWithoutFullBuildTest method testBatchResourceChanges.

@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 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(""));
        }
    });
    // batch.add( new ResourceChange( ResourceChangeType.ADD,
    // resourcePath1,
    // new SessionInfoImpl( "id",
    // new IdentityImpl( "user",
    // Collections.<Role>emptyList() ) ) ) );
    // batch.add( new ResourceChange( ResourceChangeType.UPDATE,
    // resourcePath2,
    // new SessionInfoImpl( "id",
    // new IdentityImpl( "user",
    // Collections.<Role>emptyList() ) ) ) );
    // batch.add( new ResourceChange( ResourceChangeType.DELETE,
    // resourcePath3,
    // new SessionInfoImpl( "id",
    // new IdentityImpl( "user",
    // Collections.<Role>emptyList() ) ) ) );
    // Perform incremental build (Without a full Build first)
    buildChangeListener.batchResourceChanges(batch);
    waitForBuildResults(buildResultsObserver);
    final BuildResults buildResults = buildResultsObserver.getBuildResults();
    assertNotNull(buildResults);
    assertEquals(0, buildResults.getErrorMessages().size());
    assertEquals(1, buildResults.getInformationMessages().size());
    final IncrementalBuildResults incrementalBuildResults = buildResultsObserver.getIncrementalBuildResults();
    assertNull(incrementalBuildResults);
}
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) HashMap(java.util.HashMap) ResourceAdded(org.uberfire.workbench.events.ResourceAdded) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) CreationalContext(javax.enterprise.context.spi.CreationalContext) Collection(java.util.Collection) ResourceChange(org.uberfire.workbench.events.ResourceChange) ResourceUpdated(org.uberfire.workbench.events.ResourceUpdated) Test(org.junit.Test)

Example 3 with ResourceChange

use of org.uberfire.workbench.events.ResourceChange in project kie-wb-common by kiegroup.

the class Builder method applyBatchResourceChanges.

public IncrementalBuildResults applyBatchResourceChanges(final Map<org.uberfire.backend.vfs.Path, Collection<ResourceChange>> changes) {
    checkNotNull("changes", changes);
    checkAFullBuildHasBeenPerformed();
    // Add all changes to KieFileSystem before executing the build
    final List<String> changedFilesKieBuilderPaths = new ArrayList<String>();
    final List<ValidationMessage> nonKieResourceValidatorAddedMessages = new ArrayList<ValidationMessage>();
    final List<ValidationMessage> nonKieResourceValidatorRemovedMessages = new ArrayList<ValidationMessage>();
    final IncrementalBuildResults results = new IncrementalBuildResults(projectGAV);
    synchronized (kieFileSystem) {
        for (final Map.Entry<org.uberfire.backend.vfs.Path, Collection<ResourceChange>> pathCollectionEntry : changes.entrySet()) {
            for (final ResourceChange change : pathCollectionEntry.getValue()) {
                final ResourceChangeType type = change.getType();
                final Path resource = Paths.convert(pathCollectionEntry.getKey());
                checkNotNull("type", type);
                checkNotNull("Builder.resourceĀ§", resource);
                final String destinationPath = destinationPath(resource);
                changedFilesKieBuilderPaths.add(destinationPath);
                switch(type) {
                    case ADD:
                    case UPDATE:
                        // Only files can be processed
                        if (!Files.isRegularFile(resource)) {
                            continue;
                        }
                        update(nonKieResourceValidatorAddedMessages, nonKieResourceValidatorRemovedMessages, resource);
                        break;
                    case DELETE:
                        delete(nonKieResourceValidatorRemovedMessages, resource);
                }
            }
        }
        // Perform the Incremental build and get messages from incremental build
        buildIncrementally(results, toArray(changedFilesKieBuilderPaths));
    }
    // Copy in BuildMessages for non-KIE resources
    results.addAllAddedMessages(convertValidationMessages(nonKieResourceValidatorAddedMessages));
    results.addAllRemovedMessages(convertValidationMessages(nonKieResourceValidatorRemovedMessages));
    return results;
}
Also used : Path(org.uberfire.java.nio.file.Path) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) ArrayList(java.util.ArrayList) ResourceChangeType(org.uberfire.workbench.events.ResourceChangeType) Collection(java.util.Collection) ResourceChange(org.uberfire.workbench.events.ResourceChange) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with ResourceChange

use of org.uberfire.workbench.events.ResourceChange in project kie-wb-common by kiegroup.

the class BuildPipelineTest method assertEqualsChanges.

private void assertEqualsChanges(Map<Path, Collection<ResourceChange>> expectedResourceChanges, Map<Path, Collection<ResourceChange>> resourceChanges) {
    assertEquals(expectedResourceChanges.size(), resourceChanges.size());
    for (Map.Entry<Path, Collection<ResourceChange>> entry : expectedResourceChanges.entrySet()) {
        assertNotNull(resourceChanges.get(entry.getKey()));
        assertEquals(entry.getValue().size(), resourceChanges.get(entry.getKey()).size());
        for (ResourceChange resourceChange : entry.getValue()) {
            assertEquals(1, resourceChanges.get(entry.getKey()).stream().filter(c -> resourceChange.getType().equals(c.getType())).count());
        }
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) Collection(java.util.Collection) ResourceChange(org.uberfire.workbench.events.ResourceChange) Map(java.util.Map)

Aggregations

Collection (java.util.Collection)4 ResourceChange (org.uberfire.workbench.events.ResourceChange)4 HashMap (java.util.HashMap)3 IncrementalBuildResults (org.guvnor.common.services.project.builder.model.IncrementalBuildResults)3 Path (org.uberfire.backend.vfs.Path)3 URL (java.net.URL)2 Map (java.util.Map)2 BuildResults (org.guvnor.common.services.project.builder.model.BuildResults)2 Test (org.junit.Test)2 ResourceAdded (org.uberfire.workbench.events.ResourceAdded)2 ResourceUpdated (org.uberfire.workbench.events.ResourceUpdated)2 ArrayList (java.util.ArrayList)1 CreationalContext (javax.enterprise.context.spi.CreationalContext)1 Bean (javax.enterprise.inject.spi.Bean)1 ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1 Path (org.uberfire.java.nio.file.Path)1 ResourceChangeType (org.uberfire.workbench.events.ResourceChangeType)1