Search in sources :

Example 26 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project kie-wb-common by kiegroup.

the class Builder method buildIncrementally.

private void buildIncrementally(final IncrementalBuildResults results, final String... destinationPath) {
    try {
        final IncrementalResults incrementalResults = ((InternalKieBuilder) kieBuilder).createFileSet(Message.Level.WARNING, destinationPath).build();
        results.addAllAddedMessages(convertMessages(incrementalResults.getAddedMessages(), handles));
        results.addAllRemovedMessages(convertMessages(incrementalResults.getRemovedMessages(), handles));
        // Tidy-up removed message handles
        for (Message message : incrementalResults.getRemovedMessages()) {
            handles.remove(Handles.RESOURCE_PATH + "/" + getBaseFileName(message.getPath()));
        }
    } catch (LinkageError e) {
        final String msg = MessageFormat.format(ERROR_CLASS_NOT_FOUND, e.getLocalizedMessage());
        logger.warn(msg);
        results.addAddedMessage(makeWarningMessage(msg));
    } catch (Throwable e) {
        final String msg = e.getLocalizedMessage();
        logger.error(msg, e);
        results.addAddedMessage(makeErrorMessage(msg));
    }
}
Also used : ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) BuildMessage(org.guvnor.common.services.project.builder.model.BuildMessage) BuildMessageBuilder.makeWarningMessage(org.kie.workbench.common.services.backend.builder.core.BuildMessageBuilder.makeWarningMessage) Message(org.kie.api.builder.Message) BuildMessageBuilder.makeErrorMessage(org.kie.workbench.common.services.backend.builder.core.BuildMessageBuilder.makeErrorMessage) IncrementalResults(org.kie.internal.builder.IncrementalResults)

Example 27 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class KieBuilderSetImpl method build.

@Override
public IncrementalResults build() {
    Collection<String> srcFiles = files != null ? asList(files) : kieBuilder.getModifiedResourcesSinceLastMark();
    Collection<String> filesToBuild = new ArrayList<>();
    if (srcFiles.isEmpty()) {
        return new IncrementalResultsImpl();
    }
    kieBuilder.cloneKieModuleForIncrementalCompilation();
    for (String file : srcFiles) {
        if (!file.endsWith(".properties")) {
            String trgFile = kieBuilder.copySourceToTarget(KiePath.of(file));
            if (trgFile != null) {
                filesToBuild.add(trgFile);
            }
        }
    }
    IncrementalResults result = buildChanges(filesToBuild);
    files = null;
    kieBuilder.markSource();
    return result;
}
Also used : ArrayList(java.util.ArrayList) IncrementalResults(org.kie.internal.builder.IncrementalResults)

Example 28 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class KieBuilderSetImplTest method testBuild.

@Test
public void testBuild() throws Exception {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("src/main/resources/rule%201.drl", ruleContent());
    final KieBuilderSetImpl kieBuilderSet = new KieBuilderSetImpl(kieBuilder(ks, kfs));
    kieBuilderSet.setFiles(new String[] { "src/main/resources/rule%201.drl" });
    final IncrementalResults build = kieBuilderSet.build();
    assertEquals(0, build.getAddedMessages().size());
    assertEquals(0, build.getRemovedMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieBuilderSetImpl(org.drools.compiler.kie.builder.impl.KieBuilderSetImpl) KieServices(org.kie.api.KieServices) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 29 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class KieBuilderSetImplTest method testBuildPercentageAndWhiteSpaceInName.

@Test
@Ignore("RHPAM-1184, RHDM-601")
public void testBuildPercentageAndWhiteSpaceInName() throws Exception {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("src/main/resources/my rule 100% okay.rdrl", ResourceFactory.newInputStreamResource(this.getClass().getResourceAsStream("my rule 100% okay.rdrl")));
    final KieBuilderSetImpl kieBuilderSet = new KieBuilderSetImpl(kieBuilder(ks, kfs));
    kieBuilderSet.setFiles(new String[] { "src/main/resources/my rule 100% okay.rdrl" });
    final IncrementalResults build = kieBuilderSet.build();
    assertEquals(0, build.getAddedMessages().size());
    assertEquals(0, build.getRemovedMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieBuilderSetImpl(org.drools.compiler.kie.builder.impl.KieBuilderSetImpl) KieServices(org.kie.api.KieServices) IncrementalResults(org.kie.internal.builder.IncrementalResults) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class IncrementalCompilationTest method testIncrementalCompilationFromEmptyProject2.

@Test
public void testIncrementalCompilationFromEmptyProject2() {
    // DROOLS-5584
    final String drl1 = "package org.drools.test;\n" + "global java.util.List list;\n" + "rule \"test1\" when then end\n";
    final KieServices ks = KieServices.Factory.get();
    ReleaseId id = ks.newReleaseId("org.test", "foo", "1.0-SNAPSHOT");
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.generateAndWritePomXML(id);
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
    assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
    kfs.write("src/main/resources/r1.drl", drl1);
    final IncrementalResults addResults1 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r1.drl").build();
    assertEquals(0, addResults1.getAddedMessages().size());
    KieContainer kieContainer = ks.newKieContainer(id);
    KieSession kieSession = kieContainer.newKieSession();
    assertEquals(1, kieSession.getKieBase().getKiePackages().size());
    assertNotNull(kieSession.getKieBase().getKiePackage("org.drools.test"));
    kieSession.setGlobal("list", new ArrayList());
    Collection<String> globals = kieSession.getGlobals().getGlobalKeys();
    assertEquals(1, globals.size());
    assertEquals("list", globals.iterator().next());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

IncrementalResults (org.kie.internal.builder.IncrementalResults)44 Test (org.junit.Test)42 KieServices (org.kie.api.KieServices)42 KieFileSystem (org.kie.api.builder.KieFileSystem)42 KieBuilder (org.kie.api.builder.KieBuilder)39 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)39 KieContainer (org.kie.api.runtime.KieContainer)14 ReleaseId (org.kie.api.builder.ReleaseId)13 KieSession (org.kie.api.runtime.KieSession)10 Results (org.kie.api.builder.Results)8 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)8 Message (org.kie.api.builder.Message)5 ArrayList (java.util.ArrayList)4 StringReader (java.io.StringReader)3 Message (org.drools.testcoverage.common.model.Message)3 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)3 KieBuilderSetImpl (org.drools.compiler.kie.builder.impl.KieBuilderSetImpl)2 KieModuleModel (org.kie.api.builder.model.KieModuleModel)2 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)2 InputStream (java.io.InputStream)1