Skip to content

Commit

Permalink
Merge pull request #50 from rgdoliveira/sync_main
Browse files Browse the repository at this point in the history
Sync main branch with Apache main branch
  • Loading branch information
rgdoliveira authored May 7, 2024
2 parents 834d134 + ecade58 commit 09ff6b3
Show file tree
Hide file tree
Showing 485 changed files with 8,811 additions and 5,777 deletions.
1 change: 0 additions & 1 deletion bom/kie-dmn-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down
263 changes: 38 additions & 225 deletions build-parent/pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ public class KieBaseModelImpl
public KieBaseModelImpl() {
}

public KieBaseModelImpl(KieModuleModel kModule,
String name) {
public KieBaseModelImpl(String name) {
this(null, name);
}

public KieBaseModelImpl(KieModuleModel kModule, String name) {
this.kModule = kModule;
this.includes = new HashSet<>();
this.name = name;
Expand Down Expand Up @@ -175,15 +178,6 @@ public KieBaseModel removeKieSessionModel(String qName) {
return this;
}

public void moveKSession(String oldQName,
String newQName) {
Map<String, KieSessionModel> newMap = new HashMap<>();
newMap.putAll( this.kSessions );
KieSessionModel kieSessionModel = newMap.remove( oldQName );
newMap.put(newQName, kieSessionModel);
setKSessions( newMap );
}

public List<RuleTemplateModel> getRuleTemplates() {
return Collections.unmodifiableList( ruleTemplates );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,6 @@ public void removeKieBaseModel(String qName) {
setKBases( newMap );
}

/* (non-Javadoc)
* @see org.kie.kModule.KieProject#removeKieBaseModel(org.kie.kModule.KieBaseModel)
*/
public void moveKBase(String oldQName, String newQName) {
Map<String, KieBaseModel> newMap = new HashMap<>();
newMap.putAll( this.kBases );
KieBaseModel kieBaseModel = newMap.remove( oldQName );
newMap.put( newQName, kieBaseModel);
setKBases( newMap );
}

/* (non-Javadoc)
* @see org.kie.kModule.KieProject#getKieBaseModels()
*/
public Map<String, KieBaseModel> getKieBaseModels() {
return Collections.unmodifiableMap( kBases );
}
Expand Down
4 changes: 4 additions & 0 deletions drools-examples-api/kiecontainer-from-kierepo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<groupId>org.drools</groupId>
<artifactId>drools-engine-classic</artifactId>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>named-kiesession</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

import org.drools.model.functions.Operator;

import static org.drools.model.util.OperatorUtils.areEqual;

public enum InOperator implements Operator.MultipleValue<Object, Object> {

INSTANCE;

@Override
public boolean eval( Object a, Object[] bs ) {
for (Object b : bs) {
if (a == null && b == null) {
return true;
} else if (a != null && a.equals( b )) {
if (areEqual(a, b)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/
package org.drools.codegen.common;

import org.drools.codegen.common.di.DependencyInjectionAnnotator;
import org.drools.codegen.common.rest.RestAnnotator;

import java.io.File;
import java.util.Collection;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Predicate;

import org.drools.codegen.common.di.DependencyInjectionAnnotator;
import org.drools.codegen.common.rest.RestAnnotator;

public interface DroolsModelBuildContext {

String APPLICATION_PROPERTIES_FILE_NAME = "application.properties";
Expand Down Expand Up @@ -83,16 +83,12 @@ interface Builder {

Builder withApplicationProperties(File... files);

// Builder withAddonsConfig(AddonsConfig addonsConfig);

Builder withClassAvailabilityResolver(Predicate<String> classAvailabilityResolver);

Builder withClassLoader(ClassLoader classLoader);

Builder withAppPaths(AppPaths appPaths);

// Builder withGAV(KogitoGAV gav);

DroolsModelBuildContext build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,10 @@
*/
package org.drools.codegen.common.context;

import org.drools.codegen.common.AppPaths;
import org.drools.codegen.common.DroolsModelApplicationPropertyProvider;
import org.drools.codegen.common.DroolsModelBuildContext;
import org.drools.codegen.common.di.DependencyInjectionAnnotator;
import org.drools.codegen.common.rest.RestAnnotator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.lang.model.SourceVersion;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -41,6 +31,16 @@
import java.util.Properties;
import java.util.function.Predicate;

import javax.lang.model.SourceVersion;

import org.drools.codegen.common.AppPaths;
import org.drools.codegen.common.DroolsModelApplicationPropertyProvider;
import org.drools.codegen.common.DroolsModelBuildContext;
import org.drools.codegen.common.di.DependencyInjectionAnnotator;
import org.drools.codegen.common.rest.RestAnnotator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractDroolsModelBuildContext implements DroolsModelBuildContext {

public static final String DEFAULT_GROUP_ID = "org.kie.kogito";
Expand Down Expand Up @@ -149,9 +149,9 @@ protected abstract static class AbstractBuilder implements Builder {

protected String packageName = DEFAULT_PACKAGE_NAME;
protected DroolsModelApplicationPropertyProvider applicationProperties = DroolsModelApplicationPropertyProvider.of(new Properties());
// protected AddonsConfig addonsConfig;
protected ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
protected Predicate<String> classAvailabilityResolver = this::hasClass;

// default fallback value (usually overridden)
protected AppPaths appPaths = AppPaths.fromProjectDir(new File(".").toPath());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import static org.drools.model.codegen.execmodel.generator.expressiontyper.ExpressionTyper.convertArithmeticBinaryToMethodCall;
import static org.drools.model.codegen.execmodel.generator.expressiontyper.ExpressionTyper.getBinaryTypeAfterConversion;
import static org.drools.model.codegen.execmodel.generator.expressiontyper.ExpressionTyper.shouldConvertArithmeticBinaryToMethodCall;
import static org.drools.model.codegen.execmodel.util.ExpressionUtils.convertBigIntegerLiteralExprOrBigDecimalLiteralExpr;
import static org.drools.util.StringUtils.lcFirstForBean;
import static org.drools.model.codegen.execmodel.generator.DrlxParseUtil.THIS_PLACEHOLDER;
import static org.drools.model.codegen.execmodel.generator.DrlxParseUtil.createConstraintCompiler;
Expand Down Expand Up @@ -356,11 +357,7 @@ private DrlxParseResult compileToJavaRecursive(Class<?> patternType,

if (drlxExpr instanceof LiteralExpr) {
Class<?> literalExpressionType = getLiteralExpressionType(((LiteralExpr) drlxExpr));
if (drlxExpr instanceof BigIntegerLiteralExpr) {
drlxExpr = ((BigIntegerLiteralExpr) drlxExpr).convertToObjectCreationExpr();
} else if (drlxExpr instanceof BigDecimalLiteralExpr) {
drlxExpr = ((BigDecimalLiteralExpr) drlxExpr).convertToObjectCreationExpr();
}
drlxExpr = convertBigIntegerLiteralExprOrBigDecimalLiteralExpr(drlxExpr);
return new SingleDrlxParseSuccess(patternType, bindingId, drlxExpr, literalExpressionType)
.setIsPredicate(isBooleanBoxedUnboxed(literalExpressionType));
}
Expand Down Expand Up @@ -984,11 +981,7 @@ public static Expression toBigDecimalExpression( TypedExpression typedExpression
if(arg.isEnclosedExpr()) {
arg = arg.asEnclosedExpr().getInner();
}
if (arg instanceof BigIntegerLiteralExpr) {
arg = ((BigIntegerLiteralExpr) arg).convertToObjectCreationExpr();
} else if (arg instanceof BigDecimalLiteralExpr ) {
arg = ((BigDecimalLiteralExpr) arg).convertToObjectCreationExpr();
}
arg = convertBigIntegerLiteralExprOrBigDecimalLiteralExpr(arg);
toBigDecimalMethod.addArgument( arg );
return toBigDecimalMethod;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.expr.UnaryExpr;
import org.drools.model.functions.Operator;
import org.drools.model.codegen.execmodel.errors.InvalidExpressionErrorResult;
import org.drools.model.codegen.execmodel.generator.RuleContext;
import org.drools.model.codegen.execmodel.generator.TypedExpression;
import org.drools.model.codegen.execmodel.generator.drlxparse.CoercedExpression;
import org.drools.model.codegen.execmodel.generator.expressiontyper.ExpressionTyper;
import org.drools.model.functions.Operator;
import org.drools.mvel.parser.ast.expr.PointFreeExpr;
import org.drools.mvel.parser.printer.PrintUtil;

import static org.drools.model.codegen.execmodel.generator.DrlxParseUtil.toStringLiteral;
import static org.drools.model.codegen.execmodel.generator.DslMethodNames.EVAL_CALL;
import static org.drools.model.codegen.execmodel.generator.DslMethodNames.createDslTopLevelMethod;
import static org.drools.model.codegen.execmodel.generator.drlxparse.ConstraintParser.getCoercedRightExpression;
import static org.drools.model.codegen.execmodel.util.ExpressionUtils.convertBigIntegerLiteralExprOrBigDecimalLiteralExpr;

public class NativeOperatorSpec implements OperatorSpec {
public static final NativeOperatorSpec INSTANCE = new NativeOperatorSpec();
Expand All @@ -60,7 +61,9 @@ public Expression getExpression(RuleContext context, PointFreeExpr pointFreeExpr
} else {
coercedRight = right;
}
methodCallExpr.addArgument(coercedRight.getExpression() );
Expression rightExpression = coercedRight.getExpression();
rightExpression = convertBigIntegerLiteralExprOrBigDecimalLiteralExpr(rightExpression);
methodCallExpr.addArgument(rightExpression);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.drools.model.codegen.execmodel.util;

import com.github.javaparser.ast.expr.Expression;
import org.drools.mvel.parser.ast.expr.BigDecimalLiteralExpr;
import org.drools.mvel.parser.ast.expr.BigIntegerLiteralExpr;

public class ExpressionUtils {

private ExpressionUtils() {
// utility class
}

public static Expression convertBigIntegerLiteralExprOrBigDecimalLiteralExpr(Expression expression) {
if (expression instanceof BigIntegerLiteralExpr) {
return ((BigIntegerLiteralExpr) expression).convertToObjectCreationExpr();
} else if (expression instanceof BigDecimalLiteralExpr) {
return ((BigDecimalLiteralExpr) expression).convertToObjectCreationExpr();
}
return expression;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
*/
package org.drools.model.codegen.project;

import org.drools.compiler.kproject.models.KieModuleModelImpl;
import org.kie.api.builder.model.KieBaseModel;
import org.kie.api.builder.model.KieModuleModel;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -33,6 +29,10 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.drools.compiler.kproject.models.KieModuleModelImpl;
import org.kie.api.builder.model.KieBaseModel;
import org.kie.api.builder.model.KieModuleModel;

import static org.drools.compiler.kie.builder.impl.KieBuilderImpl.setDefaultsforEmptyKieModule;

/**
Expand Down Expand Up @@ -73,6 +73,23 @@ private static KieModuleModel lookupKieModuleModel(Path[] resourcePaths) {
return new KieModuleModelImpl();
}

static boolean hasKieModule(Path[] resourcePaths) {
for (Path resourcePath : resourcePaths) {
if (resourcePath.toString().endsWith(".jar")) {
InputStream inputStream = fromJarFile(resourcePath);
if (inputStream != null) {
return true;
}
} else {
Path moduleXmlPath = resourcePath.resolve(KieModuleModelImpl.KMODULE_JAR_PATH.asString());
if (Files.exists(moduleXmlPath)) {
return true;
}
}
}
return false;
}

/*
* This is really a modified duplicate of org.drools.quarkus.deployment.ResourceCollector#fromJarFile(java.nio.file.Path).
* TODO: Refactor https://issues.redhat.com/browse/DROOLS-7254
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
*/
package org.drools.model.codegen.project;

import org.drools.codegen.common.DroolsModelBuildContext;
import org.drools.codegen.common.GeneratedFile;
import org.drools.codegen.common.GeneratedFileType;
import org.drools.model.codegen.execmodel.ModelSourceClass;
import org.kie.api.builder.model.KieBaseModel;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -33,6 +27,12 @@
import java.util.Map;
import java.util.Objects;

import org.drools.codegen.common.DroolsModelBuildContext;
import org.drools.codegen.common.GeneratedFile;
import org.drools.codegen.common.GeneratedFileType;
import org.drools.model.codegen.execmodel.ModelSourceClass;
import org.kie.api.builder.model.KieBaseModel;

import static java.util.stream.Collectors.toList;

/**
Expand All @@ -45,8 +45,12 @@ public class KieSessionModelBuilder {
private DroolsModelBuildContext context;

public KieSessionModelBuilder(DroolsModelBuildContext context, Collection<CodegenPackageSources> packageSources) {
this(context, packageSources, KieModuleModelWrapper.fromResourcePaths(context.getAppPaths().getPaths()).kieBaseModels());
}

public KieSessionModelBuilder(DroolsModelBuildContext context, Collection<CodegenPackageSources> packageSources, Map<String, KieBaseModel> kieBaseModels) {
this.context = context;
this.kieBaseModels = KieModuleModelWrapper.fromResourcePaths(context.getAppPaths().getPaths()).kieBaseModels();
this.kieBaseModels = kieBaseModels;
this.modelByKBase = getModelByKBase(packageSources, this.kieBaseModels);
}

Expand Down
Loading

0 comments on commit 09ff6b3

Please sign in to comment.