コード例 #1
0
ファイル: MessageImplTests.java プロジェクト: Koehler/drools
  @Test
  public void testMessageWithIncrementalBuild() throws Exception {
    // Some suitably duff DSL to generate errors
    String dsl1 = "bananna\n";

    // Some suitably valid DRL
    String drl1 =
        "import org.drools.compiler.Person;\n"
            + "rule R1\n"
            + "when\n"
            + "There is a Person\n"
            + "then\n"
            + "end\n";

    // Some suitably valid DRL
    String drl2 = "rule R2\n" + "when\n" + "then\n" + "end\n";

    KieServices ks = KieServices.Factory.get();

    KieFileSystem kfs =
        ks.newKieFileSystem()
            .write("src/main/resources/dsl.dsl", dsl1)
            .write("src/main/resources/drl.dslr", drl1);

    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results fullBuildResults = kieBuilder.getResults();
    assertEquals(3, fullBuildResults.getMessages().size());

    kfs.write("src/main/resources/r2.drl", drl2);
    IncrementalResults incrementalBuildResults =
        ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();

    assertEquals(0, incrementalBuildResults.getAddedMessages().size());
    assertEquals(0, incrementalBuildResults.getRemovedMessages().size());
  }
コード例 #2
0
  private void buildIncrementally(
      final IncrementalBuildResults results, final String... destinationPath) {
    try {
      final IncrementalResults incrementalResults =
          ((InternalKieBuilder) kieBuilder).createFileSet(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));
    }
  }