-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose ConstraintMetaModel at build time (#1343)
Fixes #1323.
- Loading branch information
Showing
9 changed files
with
124 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
quarkus-integration/quarkus/deployment/src/build/revapi-differences.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
{ | ||
"extension": "revapi.differences", | ||
"configuration": { | ||
"differences": [ | ||
] | ||
} | ||
} | ||
] |
12 changes: 12 additions & 0 deletions
12
quarkus-integration/quarkus/deployment/src/build/revapi-filter.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"extension": "revapi.filter", | ||
"configuration": { | ||
"elements": { | ||
"include": [ | ||
"class ai\\.timefold\\.solver\\.quarkus\\.deployment\\.api.*" | ||
] | ||
} | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...src/main/java/ai/timefold/solver/quarkus/deployment/api/ConstraintMetaModelBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ai.timefold.solver.quarkus.deployment.api; | ||
|
||
import java.util.Map; | ||
|
||
import ai.timefold.solver.core.api.score.stream.ConstraintMetaModel; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* Represents a {@link ai.timefold.solver.core.api.score.stream.ConstraintMetaModel} at the build time for the purpose | ||
* of Quarkus augmentation. | ||
*/ | ||
public final class ConstraintMetaModelBuildItem extends SimpleBuildItem { | ||
|
||
private final Map<String, ConstraintMetaModel> constraintMetaModelsBySolverNames; | ||
|
||
public ConstraintMetaModelBuildItem(Map<String, ConstraintMetaModel> constraintMetaModelsBySolverNames) { | ||
this.constraintMetaModelsBySolverNames = Map.copyOf(constraintMetaModelsBySolverNames); | ||
} | ||
|
||
public Map<String, ConstraintMetaModel> constraintMetaModelsBySolverNames() { | ||
return constraintMetaModelsBySolverNames; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...rkus/deployment/src/main/java/ai/timefold/solver/quarkus/deployment/api/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Public {@link io.quarkus.builder.item.BuildItem}s consumable by other Quarkus extensions. | ||
* <p> | ||
* All classes in this package are part of the public API of this extension. | ||
* Moreover, the extension is responsible for creating instances of these classes during the build phase. | ||
*/ | ||
package ai.timefold.solver.quarkus.deployment.api; |
32 changes: 32 additions & 0 deletions
32
...s-integration/quarkus/runtime/src/main/java/ai/timefold/solver/quarkus/bean/BeanUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ai.timefold.solver.quarkus.bean; | ||
|
||
import java.util.Objects; | ||
|
||
import ai.timefold.solver.core.api.score.stream.ConstraintMetaModel; | ||
import ai.timefold.solver.core.api.solver.SolverFactory; | ||
import ai.timefold.solver.core.impl.score.stream.common.AbstractConstraintStreamScoreDirectorFactory; | ||
import ai.timefold.solver.core.impl.solver.DefaultSolverFactory; | ||
|
||
public class BeanUtil { | ||
|
||
public static ConstraintMetaModel buildConstraintMetaModel(SolverFactory<?> solverFactory) { | ||
if (Objects.requireNonNull(solverFactory) instanceof DefaultSolverFactory<?> defaultSolverFactory) { | ||
var scoreDirectorFactory = defaultSolverFactory.getScoreDirectorFactory(); | ||
if (scoreDirectorFactory instanceof AbstractConstraintStreamScoreDirectorFactory<?, ?> castScoreDirectorFactory) { | ||
return castScoreDirectorFactory.getConstraintMetaModel(); | ||
} else { | ||
throw new IllegalStateException( | ||
"Cannot provide %s because the score director does not use the Constraint Streams API." | ||
.formatted(ConstraintMetaModel.class.getSimpleName())); | ||
} | ||
} else { | ||
throw new IllegalStateException( | ||
"%s is not supported by the solver factory (%s)." | ||
.formatted(ConstraintMetaModel.class.getSimpleName(), solverFactory.getClass().getName())); | ||
} | ||
} | ||
|
||
private BeanUtil() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters