Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync main branch with Apache main branch #20

Merged
merged 8 commits into from
Feb 5, 2024
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.kie.internal.builder.conf.ParallelRulesBuildThresholdOption;
import org.kie.internal.builder.conf.ProcessStringEscapesOption;
import org.kie.internal.builder.conf.PropertySpecificOption;
import org.kie.internal.builder.conf.ReproducibleExecutableModelGenerationOption;
import org.kie.internal.builder.conf.SingleValueKieBuilderOption;
import org.kie.internal.builder.conf.TrimCellsInDTableOption;
import org.kie.internal.conf.CompositeConfiguration;
Expand Down Expand Up @@ -99,6 +100,8 @@ public class KnowledgeBuilderRulesConfigurationImpl extends BaseConfiguration<Kn
private boolean trimCellsInDTable = true;
private boolean groupDRLsInKieBasesByFolder = false;

private boolean reproducibleExecutableModelGeneration = false;

private boolean externaliseCanonicalModelLambda = true;
private boolean parallelLambdaExternalization = true;

Expand Down Expand Up @@ -162,6 +165,9 @@ private void init() {

setProperty(ParallelLambdaExternalizationOption.PROPERTY_NAME,
getPropertyValue(ParallelLambdaExternalizationOption.PROPERTY_NAME,"true"));

setProperty(ReproducibleExecutableModelGenerationOption.PROPERTY_NAME,
getPropertyValue(ReproducibleExecutableModelGenerationOption.PROPERTY_NAME,"false"));
}

protected ClassLoader getFunctionFactoryClassLoader() {
Expand Down Expand Up @@ -206,6 +212,9 @@ public boolean setInternalProperty(String name, String value) {
} case ParallelLambdaExternalizationOption.PROPERTY_NAME: {
setParallelLambdaExternalization(Boolean.parseBoolean(value));
break;
} case ReproducibleExecutableModelGenerationOption.PROPERTY_NAME: {
setReproducibleExecutableModelGeneration(Boolean.parseBoolean(value));
break;
} case AlphaNetworkCompilerOption.PROPERTY_NAME: {
try {
setAlphaNetworkCompilerOption(AlphaNetworkCompilerOption.determineAlphaNetworkCompilerMode(value.toUpperCase()));
Expand Down Expand Up @@ -244,6 +253,8 @@ public String getInternalProperty(String name) {
return String.valueOf(isExternaliseCanonicalModelLambda());
} case ParallelLambdaExternalizationOption.PROPERTY_NAME: {
return String.valueOf(isParallelLambdaExternalization());
} case ReproducibleExecutableModelGenerationOption.PROPERTY_NAME: {
return String.valueOf(isReproducibleExecutableModelGeneration());
} default: {
if (name.startsWith(AccumulateFunctionOption.PROPERTY_NAME)) {
int index = AccumulateFunctionOption.PROPERTY_NAME.length();
Expand Down Expand Up @@ -412,6 +423,14 @@ public void setParallelLambdaExternalization(boolean parallelLambdaExternalizati
this.parallelLambdaExternalization = parallelLambdaExternalization;
}

public boolean isReproducibleExecutableModelGeneration() {
return reproducibleExecutableModelGeneration;
}

public void setReproducibleExecutableModelGeneration(boolean reproducibleExecutableModelGeneration) {
this.reproducibleExecutableModelGeneration = reproducibleExecutableModelGeneration;
}

public AlphaNetworkCompilerOption getAlphaNetworkCompilerOption() {
return alphaNetworkCompilerOption;
}
Expand Down Expand Up @@ -444,6 +463,9 @@ public <T extends SingleValueKieBuilderOption> T getOption(OptionKey<T> option)
case ParallelLambdaExternalizationOption.PROPERTY_NAME: {
return (T) (parallelLambdaExternalization ? ParallelLambdaExternalizationOption.ENABLED : ParallelLambdaExternalizationOption.DISABLED);
}
case ReproducibleExecutableModelGenerationOption.PROPERTY_NAME: {
return (T) (reproducibleExecutableModelGeneration ? ReproducibleExecutableModelGenerationOption.ENABLED : ReproducibleExecutableModelGenerationOption.DISABLED);
}
case ParallelRulesBuildThresholdOption.PROPERTY_NAME: {
return (T) parallelRulesBuildThreshold;
}
Expand Down Expand Up @@ -524,6 +546,10 @@ public <T extends KnowledgeBuilderOption> void setOption(T option) {
this.parallelLambdaExternalization = ((ParallelLambdaExternalizationOption) option).isLambdaExternalizationParallel();
break;
}
case ReproducibleExecutableModelGenerationOption.PROPERTY_NAME: {
this.reproducibleExecutableModelGeneration = ((ReproducibleExecutableModelGenerationOption) option).isReproducibleExecutableModelGeneration();
break;
}
case ParallelRulesBuildThresholdOption.PROPERTY_NAME: {
this.parallelRulesBuildThreshold = (ParallelRulesBuildThresholdOption)option;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public IteratingPhase(Collection<CompositePackageDescr> packages, PackageRegistr
public void process() {
for (CompositePackageDescr compositePackageDescr : packages) {
PackageRegistry packageRegistry = pkgRegistryManager.getOrCreatePackageRegistry(compositePackageDescr);
CompilationPhase phase = phaseFactory.create(
packageRegistry,
compositePackageDescr);
CompilationPhase phase = phaseFactory.create( packageRegistry, compositePackageDescr );
phase.process();
this.results.addAll(phase.getResults());
if (this.results.hasErrors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
Expand Down Expand Up @@ -222,7 +223,7 @@ public KnowledgeBuilder buildKnowledgePackages( KieBaseModelImpl kBaseModel, Bui
public KnowledgeBuilder buildKnowledgePackages( KieBaseModelImpl kBaseModel, BuildContext buildContext, Predicate<String> buildFilter ) {
boolean useFolders = useFolders( kBaseModel );

Set<Asset> assets = new HashSet<>();
Set<Asset> assets = new LinkedHashSet<>();

boolean allIncludesAreValid = true;
for (String include : getTransitiveIncludes(kBaseModel)) {
Expand Down Expand Up @@ -361,5 +362,10 @@ public int hashCode() {
result = 31 * result + name.hashCode();
return result;
}

@Override
public String toString() {
return "Asset: " + name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
/*
* Licensed 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.compiler.lang;

import java.util.ArrayList;
Expand Down Expand Up @@ -579,4 +566,4 @@ protected String evaluatorSufix(final boolean isNegated) {
private DumperContext createContext() {
return new DumperContext();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlRootElement;

import org.drools.base.common.RuleBasePartitionId;
import org.drools.base.factmodel.traits.TraitTypeEnum;
import org.drools.base.rule.EntryPointId;
import org.drools.core.WorkingMemoryEntryPoint;
Expand Down Expand Up @@ -369,10 +370,6 @@ public void addLastLeftTuple( TupleImpl leftTuple ) {
linkedTuples.addLastLeftTuple( leftTuple );
}

public void addTupleInPosition( TupleImpl tuple ) {
linkedTuples.addTupleInPosition( tuple );
}

public void removeLeftTuple( TupleImpl leftTuple ) {
linkedTuples.removeLeftTuple( leftTuple );
}
Expand Down Expand Up @@ -510,48 +507,6 @@ public void addLastLeftTuple( TupleImpl leftTuple) {
lastLeftTuple = leftTuple;
}

@Override
public void addTupleInPosition( TupleImpl tuple ) {
boolean left = tuple.isLeftTuple();
ObjectTypeNodeId otnId = tuple.getInputOtnId();
if (otnId == null) { // can happen only in tests // @FIXME fix this
addLastTuple( tuple, left );
return;
}

TupleImpl previous = left ? lastLeftTuple : lastRightTuple;
if ( previous == null ) {
// no other LeftTuples, just add.
tuple.setHandlePrevious( null );
tuple.setHandleNext( null );
setFirstTuple( tuple, left );
setLastTuple( tuple, left );
return;
} else if (previous.getSink() == null || !otnId.before(previous.getInputOtnId()) ) {
// the last LeftTuple comes before the new one so just add it at the end
tuple.setHandlePrevious( previous );
tuple.setHandleNext( null );
previous.setHandleNext( tuple );
setLastTuple( tuple, left );
return;
}

TupleImpl next = previous;
previous = previous.getHandlePrevious();
while (previous != null && otnId.before( previous.getInputOtnId()) ) {
next = previous;
previous = previous.getHandlePrevious();
}
tuple.setHandleNext( next );
next.setHandlePrevious( tuple );
tuple.setHandlePrevious( previous );
if ( previous != null ) {
previous.setHandleNext( tuple );
} else {
setFirstTuple( tuple, left );
}
}

private void addLastTuple(TupleImpl tuple, boolean left) {
if (left) {
addLastLeftTuple(tuple);
Expand Down Expand Up @@ -715,6 +670,82 @@ public TupleImpl getFirstRightTuple(int partition) {
TupleImpl getFirstRightTuple() {
return firstRightTuple;
}

public TupleImpl detachLeftTupleAfter(RuleBasePartitionId partitionId, ObjectTypeNodeId otnId) {
TupleImpl tuple = lastLeftTuple;
TupleImpl detached = null;
// Find the first Tuple that comes after the current ID, so it can be detached.
while (tuple != null && otnId.before(tuple.getInputOtnId())) {
detached = tuple;
tuple = tuple.getHandlePrevious();
}

if (detached != null) {
if (firstLeftTuple == detached) {
firstLeftTuple = null;
}

if (lastLeftTuple == detached) {
lastLeftTuple = null;
}

if (detached.getHandlePrevious() != null) {
lastLeftTuple = detached.getHandlePrevious();
detached.setHandlePrevious(null);
lastLeftTuple.setHandleNext(null);
}
}

return detached;
}

public TupleImpl detachRightTupleAfter(RuleBasePartitionId partitionId, ObjectTypeNodeId otnId) {
TupleImpl tuple = lastRightTuple;
TupleImpl detached = null;
// Find the first Tuple that comes after the current ID, so it can be detached.
while (tuple != null && otnId.before(tuple.getInputOtnId())) {
detached = tuple;
tuple = tuple.getHandlePrevious();
}

if (detached != null) {
if (firstRightTuple == detached) {
firstRightTuple = null;
}

if (lastRightTuple == detached) {
lastRightTuple = null;
}

if (detached.getHandlePrevious() != null) {
lastRightTuple = detached.getHandlePrevious();
detached.setHandlePrevious(null);
lastRightTuple.setHandleNext(null);
}
}

return detached;
}

public void reattachToLeft(TupleImpl tuple) {
if (lastLeftTuple == null) {
lastLeftTuple = tuple;
} else {
lastLeftTuple.setHandleNext(tuple);
tuple.setHandlePrevious(lastLeftTuple);
lastLeftTuple = tuple;
}
}

public void reattachToRight(TupleImpl tuple) {
if (lastRightTuple == null) {
lastRightTuple = tuple;
} else {
lastRightTuple.setHandleNext(tuple);
tuple.setHandlePrevious(lastRightTuple);
lastRightTuple = tuple;
}
}
}

public static class CompositeLinkedTuples implements LinkedTuples {
Expand Down Expand Up @@ -780,11 +811,6 @@ public void addLastLeftTuple( TupleImpl leftTuple ) {
getOrCreatePartitionedTuple(leftTuple).addLastLeftTuple( leftTuple );
}

@Override
public void addTupleInPosition( TupleImpl tuple ) {
getOrCreatePartitionedTuple(tuple).addTupleInPosition( tuple );
}

@Override
public void removeLeftTuple( TupleImpl leftTuple ) {
getPartitionedTuple(leftTuple).removeLeftTuple( leftTuple );
Expand All @@ -807,6 +833,26 @@ public void removeRightTuple( TupleImpl rightTuple ) {
}
}

@Override
public TupleImpl detachLeftTupleAfter(RuleBasePartitionId partitionId, ObjectTypeNodeId otnId) {
return getOrCreatePartitionedTuple(partitionId.getId()).detachLeftTupleAfter(partitionId, otnId);
}

@Override
public TupleImpl detachRightTupleAfter(RuleBasePartitionId partitionId, ObjectTypeNodeId otnId) {
return getOrCreatePartitionedTuple(partitionId.getId()).detachRightTupleAfter(partitionId, otnId);
}

@Override
public void reattachToLeft(TupleImpl tuple) {
getOrCreatePartitionedTuple(tuple).reattachToLeft(tuple);
}

@Override
public void reattachToRight(TupleImpl tuple) {
getOrCreatePartitionedTuple(tuple).reattachToRight(tuple);
}

@Override
public void clearLeftTuples() {
for (int i = 0; i < partitionedTuples.length; i++) {
Expand Down Expand Up @@ -900,11 +946,6 @@ public void addLastLeftTuple(TupleImpl leftTuple) {
throw new UnsupportedOperationException();
}

@Override
public void addTupleInPosition(TupleImpl tuple) {
throw new UnsupportedOperationException();
}

@Override
public void removeLeftTuple(TupleImpl leftTuple) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,6 @@ public void addLastRightTuple(TupleImpl rightTuple) {
throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_ERROR_MESSAGE);
}

public void addTupleInPosition(TupleImpl rightTuple) {
throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_ERROR_MESSAGE);
}

public void removeRightTuple(TupleImpl rightTuple) {
throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_ERROR_MESSAGE);
}
Expand Down
Loading
Loading