use of org.kie.internal.builder.KnowledgeBuilderResult in project drools by kiegroup.
the class KnowledgeBuilderImpl method compileRulesLevel.
private void compileRulesLevel(PackageDescr packageDescr, PackageRegistry pkgRegistry, List<RuleDescr> rules) {
boolean parallelRulesBuild = this.kBase == null && rules.size() > PARALLEL_RULES_BUILD_THRESHOLD;
if (parallelRulesBuild) {
Map<String, RuleBuildContext> ruleCxts = new ConcurrentHashMap<>();
rules.stream().parallel().filter(ruleDescr -> filterAccepts(ResourceChange.Type.RULE, ruleDescr.getNamespace(), ruleDescr.getName())).forEach(ruleDescr -> {
initRuleDescr(packageDescr, pkgRegistry, ruleDescr);
RuleBuildContext context = buildRuleBuilderContext(pkgRegistry, ruleDescr);
ruleCxts.put(ruleDescr.getName(), context);
List<? extends KnowledgeBuilderResult> results = addRule(context);
if (!results.isEmpty()) {
synchronized (this.results) {
this.results.addAll(results);
}
}
});
for (RuleDescr ruleDescr : rules) {
RuleBuildContext context = ruleCxts.get(ruleDescr.getName());
if (context != null) {
pkgRegistry.getPackage().addRule(context.getRule());
}
}
} else {
for (RuleDescr ruleDescr : rules) {
if (filterAccepts(ResourceChange.Type.RULE, ruleDescr.getNamespace(), ruleDescr.getName())) {
initRuleDescr(packageDescr, pkgRegistry, ruleDescr);
RuleBuildContext context = buildRuleBuilderContext(pkgRegistry, ruleDescr);
this.results.addAll(addRule(context));
pkgRegistry.getPackage().addRule(context.getRule());
}
}
}
}
use of org.kie.internal.builder.KnowledgeBuilderResult in project drools by kiegroup.
the class KnowledgeBuilderImpl method getResultList.
private List<KnowledgeBuilderResult> getResultList(ResultSeverity... severities) {
List<ResultSeverity> typesToFetch = Arrays.asList(severities);
ArrayList<KnowledgeBuilderResult> problems = new ArrayList<KnowledgeBuilderResult>();
for (KnowledgeBuilderResult problem : results) {
if (typesToFetch.contains(problem.getSeverity())) {
problems.add(problem);
}
}
return problems;
}
use of org.kie.internal.builder.KnowledgeBuilderResult in project drools by kiegroup.
the class PMML4Compiler method compile.
public String compile(InputStream source, ClassLoader classLoader) {
this.results = new ArrayList<KnowledgeBuilderResult>();
PMML pmml = loadModel(PMML, source);
helper.setResolver(classLoader);
if (getResults().isEmpty()) {
return generateTheory(pmml);
} else {
return null;
}
}
use of org.kie.internal.builder.KnowledgeBuilderResult in project drools by kiegroup.
the class Misc2Test method testIsGetClash.
@Test
public void testIsGetClash() {
// DROOLS-18
String str = "import org.drools.compiler.integrationtests.Misc2Test.Foo3;\n" + "" + "global java.util.List list;" + "\n" + "" + "rule \"Init\" when\n" + " $x : Foo3( x == true, y == true, z == \"ok\", isZ() == true ) \n" + "then\n" + " list.add( \"ok\" ); \n" + "end\n" + "";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
assertEquals(2, kbuilder.getResults(ResultSeverity.WARNING).size());
for (KnowledgeBuilderResult res : kbuilder.getResults(ResultSeverity.WARNING)) {
System.out.println(res.getMessage());
}
}
use of org.kie.internal.builder.KnowledgeBuilderResult in project drools by kiegroup.
the class DroolsJaxbHelperProviderImpl method addXsdModel.
public static String[] addXsdModel(Resource resource, KnowledgeBuilderImpl kBuilder, Options xjcOpts, String systemId) throws IOException {
InputSource source = new InputSource(new CachingRewindableReader(resource.getReader()));
source.setSystemId(systemId.trim().startsWith(".") ? systemId : "." + systemId);
xjcOpts.addGrammar(source);
try {
xjcOpts.parseArguments(new String[] { "-npa" });
} catch (BadCommandLineException e) {
throw new IllegalArgumentException("Unable to parse arguments", e);
}
ErrorReceiver errorReceiver = new JaxbErrorReceiver4Drools();
Model model = ModelLoader.load(xjcOpts, new JCodeModel(), errorReceiver);
model.generateCode(xjcOpts, errorReceiver);
MapVfsCodeWriter codeWriter = new MapVfsCodeWriter();
model.codeModel.build(xjcOpts.createCodeWriter(codeWriter));
MemoryResourceReader src = new MemoryResourceReader();
boolean useProjectClassLoader = kBuilder.getRootClassLoader() instanceof ProjectClassLoader;
List<String> classNames = new ArrayList<String>();
List<String> srcNames = new ArrayList<String>();
for (Entry<String, byte[]> entry : codeWriter.getMap().entrySet()) {
String name = entry.getKey();
int dotPos = name.lastIndexOf('.');
String pkgName = name.substring(0, dotPos);
if (!name.endsWith("package-info.java")) {
classNames.add(pkgName);
}
dotPos = pkgName.lastIndexOf('.');
if (dotPos != -1) {
pkgName = pkgName.substring(0, dotPos);
}
PackageRegistry pkgReg = kBuilder.getPackageRegistry(pkgName);
if (pkgReg == null) {
kBuilder.addPackage(new PackageDescr(pkgName));
pkgReg = kBuilder.getPackageRegistry(pkgName);
}
if (useProjectClassLoader) {
String srcName = convertToResource(entry.getKey());
src.add(srcName, entry.getValue());
srcNames.add(srcName);
} else {
JavaDialect dialect = (JavaDialect) pkgReg.getDialectCompiletimeRegistry().getDialect("java");
dialect.addSrc(convertToResource(entry.getKey()), entry.getValue());
}
}
if (useProjectClassLoader) {
ProjectJavaCompiler compiler = new ProjectJavaCompiler(kBuilder.getBuilderConfiguration());
List<KnowledgeBuilderResult> results = compiler.compileAll((ProjectClassLoader) kBuilder.getRootClassLoader(), srcNames, src);
for (String className : classNames) {
Class<?> clazz = null;
try {
clazz = Class.forName(className, true, kBuilder.getRootClassLoader());
} catch (ClassNotFoundException e) {
continue;
}
String pkgName = className.substring(0, className.lastIndexOf('.'));
PackageRegistry pkgReg = kBuilder.getPackageRegistry(pkgName);
pkgReg.getPackage().addTypeDeclaration(TypeDeclaration.createTypeDeclarationForBean(clazz));
}
kBuilder.updateResults(results);
} else {
kBuilder.compileAll();
kBuilder.updateResults();
}
return classNames.toArray(new String[classNames.size()]);
}
Aggregations