Skip to content

Commit a3a9f65

Browse files
committed
refactor: move away from rewrite YAML scripts
1 parent 58c9d62 commit a3a9f65

13 files changed

Lines changed: 238 additions & 112 deletions

File tree

tools/migration/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
<dependency>
5151
<groupId>org.openrewrite</groupId>
5252
<artifactId>rewrite-properties</artifactId>
53-
<scope>runtime</scope>
5453
</dependency>
5554

5655
<!-- Testing -->
@@ -87,16 +86,6 @@
8786
<filtering>true</filtering>
8887
</resource>
8988
</resources>
90-
<plugins>
91-
<plugin>
92-
<artifactId>maven-dependency-plugin</artifactId>
93-
<configuration>
94-
<ignoredUnusedDeclaredDependencies> <!-- These dependencies are used in the YAMLs. -->
95-
<dependency>org.openrewrite:rewrite-maven:jar</dependency>
96-
</ignoredUnusedDeclaredDependencies>
97-
</configuration>
98-
</plugin>
99-
</plugins>
10089
</build>
10190

10291
</project>

tools/migration/src/main/filtered-resources/META-INF/rewrite/ChangeVersion.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=${project.version}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package ai.timefold.solver.migration;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.util.List;
6+
import java.util.Properties;
7+
8+
import org.openrewrite.Recipe;
9+
import org.openrewrite.maven.ChangePropertyValue;
10+
11+
final class ChangeVersionRecipe extends AbstractRecipe {
12+
13+
private final String version;
14+
15+
public ChangeVersionRecipe() {
16+
try (var is = ChangeVersionRecipe.class.getResourceAsStream("rewrite-timefold-solver-version.properties")) {
17+
var props = new Properties();
18+
props.load(is);
19+
version = props.getProperty("version");
20+
} catch (IOException e) {
21+
throw new IllegalStateException("Failed to load rewrite-timefold-solver-version.properties.", e);
22+
}
23+
}
24+
25+
@Override
26+
public String getName() {
27+
return "ai.timefold.solver.migration.ChangeVersion";
28+
}
29+
30+
@Override
31+
public String getDisplayName() {
32+
return "Change the Timefold version";
33+
}
34+
35+
@Override
36+
public String getDescription() {
37+
return "Replaces the version of Timefold";
38+
}
39+
40+
@Override
41+
public List<Recipe> getRecipeList() {
42+
return List.of(
43+
new ChangePropertyValue("version.ai.timefold.solver", version, false, true),
44+
new ChangePropertyValue("version.timefold", version, false, true),
45+
new ChangePropertyValue("ai.timefold.solver.version", version, false, true),
46+
new ChangePropertyValue("timefold.version", version, false, true),
47+
new ChangePropertyValue("timefoldVersion", version, false, true));
48+
}
49+
50+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package ai.timefold.solver.migration;
2+
3+
import java.util.List;
4+
5+
import ai.timefold.solver.migration.v2.ConstraintArgRemovalMigrationRecipe;
6+
import ai.timefold.solver.migration.v2.GeneralDependencyDeleteMigrationRecipe;
7+
import ai.timefold.solver.migration.v2.GeneralMethodChangeNameMigrationRecipe;
8+
import ai.timefold.solver.migration.v2.GeneralMethodDeleteInvocationMigrationRecipe;
9+
import ai.timefold.solver.migration.v2.GeneralPackageRenameMigrationRecipe;
10+
import ai.timefold.solver.migration.v2.GeneralTypeChangeMigrationRecipe;
11+
import ai.timefold.solver.migration.v2.PlanningSolutionAnnotationCleanupMigrationRecipe;
12+
import ai.timefold.solver.migration.v2.ProblemIdDeletionMigrationRecipe;
13+
import ai.timefold.solver.migration.v2.SolverConfigOverrideSolutionDeletionMigrationRecipe;
14+
import ai.timefold.solver.migration.v2.TestingAPIsMigrationRecipe;
15+
16+
import org.openrewrite.Recipe;
17+
import org.openrewrite.java.RemoveUnusedImports;
18+
19+
public final class ToLatestRecipe extends AbstractRecipe {
20+
21+
@Override
22+
public String getName() {
23+
return "ai.timefold.solver.migration.ToLatest";
24+
}
25+
26+
@Override
27+
public String getDisplayName() {
28+
return "Upgrade to the latest Timefold Solver";
29+
}
30+
31+
@Override
32+
public String getDescription() {
33+
return "Replace all your calls to deleted/deprecated types and methods of Timefold Solver with their proper alternatives.";
34+
}
35+
36+
@Override
37+
public List<Recipe> getRecipeList() {
38+
return List.of(
39+
new ToLatestV1Recipe(),
40+
new ChangeVersionRecipe(),
41+
new ConstraintArgRemovalMigrationRecipe(),
42+
new PlanningSolutionAnnotationCleanupMigrationRecipe(),
43+
new GeneralMethodDeleteInvocationMigrationRecipe(),
44+
new GeneralMethodChangeNameMigrationRecipe(),
45+
new GeneralTypeChangeMigrationRecipe(),
46+
new ProblemIdDeletionMigrationRecipe(),
47+
new TestingAPIsMigrationRecipe(),
48+
new GeneralDependencyDeleteMigrationRecipe(),
49+
new GeneralPackageRenameMigrationRecipe(),
50+
new SolverConfigOverrideSolutionDeletionMigrationRecipe(),
51+
new RemoveUnusedImports());
52+
}
53+
54+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package ai.timefold.solver.migration;
2+
3+
import java.util.List;
4+
5+
import ai.timefold.solver.migration.v1.AsConstraintRecipe;
6+
import ai.timefold.solver.migration.v1.ConstraintRefRecipe;
7+
import ai.timefold.solver.migration.v1.NullableRecipe;
8+
import ai.timefold.solver.migration.v1.RemoveConstraintPackageRecipe;
9+
import ai.timefold.solver.migration.v1.ScoreGettersRecipe;
10+
import ai.timefold.solver.migration.v1.ScoreManagerMethodsRecipe;
11+
import ai.timefold.solver.migration.v1.SingleConstraintAssertionMethodsRecipe;
12+
import ai.timefold.solver.migration.v1.SolutionManagerRecommendAssignmentRecipe;
13+
import ai.timefold.solver.migration.v1.SolverManagerBuilderRecipe;
14+
import ai.timefold.solver.migration.v1.SortingMigrationRecipe;
15+
16+
import org.openrewrite.Recipe;
17+
import org.openrewrite.java.ChangeMethodName;
18+
import org.openrewrite.java.ChangeType;
19+
import org.openrewrite.properties.ChangePropertyKey;
20+
21+
public final class ToLatestV1Recipe extends AbstractRecipe {
22+
23+
@Override
24+
public String getName() {
25+
return "ai.timefold.solver.migration.ToLatestV1";
26+
}
27+
28+
@Override
29+
public String getDisplayName() {
30+
return "Upgrade to the latest Timefold Solver 1.x";
31+
}
32+
33+
@Override
34+
public String getDescription() {
35+
return "Replace all your calls to deleted/deprecated types and methods of Timefold Solver with their proper alternatives.";
36+
}
37+
38+
@Override
39+
public List<Recipe> getRecipeList() {
40+
return List.of(
41+
new ChangePropertyKey("timefold.solver.solve-length", "timefold.solver.solve.duration", null, null),
42+
new ChangePropertyKey("quarkus.timefold.solver.solve-length", "quarkus.timefold.solver.solve.duration",
43+
null, null),
44+
new ChangeMethodName("ai.timefold.solver.core.api.score.stream.ConstraintFactory from(Class)",
45+
"forEach", true, false),
46+
new ChangeMethodName(
47+
"ai.timefold.solver.core.api.score.stream.ConstraintFactory fromUnfiltered(Class)",
48+
"forEachIncludingUnassigned", true, false),
49+
new ChangeMethodName(
50+
"ai.timefold.solver.core.api.score.stream.ConstraintFactory fromUniquePair(..)",
51+
"forEachUniquePair", true, false),
52+
new ScoreManagerMethodsRecipe(),
53+
new ChangeType("ai.timefold.solver.core.api.score.ScoreManager",
54+
"ai.timefold.solver.core.api.solver.SolutionManager", true),
55+
new ScoreGettersRecipe(),
56+
new ConstraintRefRecipe(),
57+
new SolverManagerBuilderRecipe(),
58+
new NullableRecipe(),
59+
new SingleConstraintAssertionMethodsRecipe(),
60+
new AsConstraintRecipe(),
61+
new RemoveConstraintPackageRecipe(),
62+
new SolutionManagerRecommendAssignmentRecipe(),
63+
new SortingMigrationRecipe());
64+
}
65+
66+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package ai.timefold.solver.migration.v2;
2+
3+
import java.util.List;
4+
5+
import ai.timefold.solver.migration.AbstractRecipe;
6+
7+
import org.openrewrite.Recipe;
8+
import org.openrewrite.java.DeleteMethodArgument;
9+
10+
public final class ConstraintArgRemovalMigrationRecipe extends AbstractRecipe {
11+
12+
@Override
13+
public String getDisplayName() {
14+
return "Remove constraint package argument from ConstraintRef and ConstraintBuilder";
15+
}
16+
17+
@Override
18+
public String getDescription() {
19+
return "Removes the first (package) argument from ConstraintRef.of() and ConstraintBuilder.asConstraint().";
20+
}
21+
22+
@Override
23+
public List<Recipe> getRecipeList() {
24+
return List.of(
25+
new DeleteMethodArgument(
26+
"ai.timefold.solver.core.api.score.constraint.ConstraintRef of(String, String)", 0),
27+
new DeleteMethodArgument(
28+
"ai.timefold.solver.core.api.score.stream.ConstraintBuilder asConstraint(String, String)", 0));
29+
}
30+
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package ai.timefold.solver.migration.v2;
2+
3+
import java.util.List;
4+
5+
import ai.timefold.solver.migration.AbstractRecipe;
6+
7+
import org.openrewrite.Recipe;
8+
import org.openrewrite.java.RemoveAnnotationAttribute;
9+
10+
public final class PlanningSolutionAnnotationCleanupMigrationRecipe extends AbstractRecipe {
11+
12+
@Override
13+
public String getDisplayName() {
14+
return "Remove deprecated attributes from @PlanningSolution";
15+
}
16+
17+
@Override
18+
public String getDescription() {
19+
return "Removes deprecated lookUpStrategyType and autoDiscoverMemberType attributes from @PlanningSolution.";
20+
}
21+
22+
@Override
23+
public List<Recipe> getRecipeList() {
24+
return List.of(
25+
new RemoveAnnotationAttribute("ai.timefold.solver.core.api.domain.solution.PlanningSolution",
26+
"lookUpStrategyType"),
27+
new RemoveAnnotationAttribute("ai.timefold.solver.core.api.domain.solution.PlanningSolution",
28+
"autoDiscoverMemberType"));
29+
}
30+
31+
}

tools/migration/src/main/java/ai/timefold/solver/migration/v2/SolverConfigOverrideSolutionDeletionMigrationRecipe.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import java.util.List;
44

55
import ai.timefold.solver.migration.AbstractRecipe;
6-
import ai.timefold.solver.migration.common.RemoveGenericTypeFromMethodRecipe;
76
import ai.timefold.solver.migration.common.RemoveGenericTypeRecipe;
7+
88
import org.openrewrite.Recipe;
99

1010
public class SolverConfigOverrideSolutionDeletionMigrationRecipe extends AbstractRecipe {
@@ -21,7 +21,6 @@ public String getDescription() {
2121
@Override
2222
public List<Recipe> getRecipeList() {
2323
return List.of(
24-
new RemoveGenericTypeRecipe("ai.timefold.solver.core.api.solver.SolverConfigOverride", 0)
25-
);
24+
new RemoveGenericTypeRecipe("ai.timefold.solver.core.api.solver.SolverConfigOverride", 0));
2625
}
2726
}

tools/migration/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
requires rewrite.core;
99
requires rewrite.java;
1010
requires rewrite.maven;
11+
requires rewrite.properties;
1112

1213
}

0 commit comments

Comments
 (0)