Skip to content

Commit a48696c

Browse files
committed
refactor: move away from rewrite YAML scripts
1 parent 39aa1f4 commit a48696c

14 files changed

Lines changed: 522 additions & 107 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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package ai.timefold.solver.migration;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
import java.util.Properties;
6+
7+
import org.openrewrite.Recipe;
8+
import org.openrewrite.maven.ChangePropertyValue;
9+
10+
public final class ChangeVersionRecipe extends AbstractRecipe {
11+
12+
final String version;
13+
14+
public ChangeVersionRecipe() {
15+
try (var is = ChangeVersionRecipe.class.getResourceAsStream("rewrite-timefold-solver-version.properties")) {
16+
var props = new Properties();
17+
props.load(is);
18+
version = props.getProperty("version");
19+
} catch (IOException e) {
20+
throw new IllegalStateException("Failed to load rewrite-timefold-solver-version.properties.", e);
21+
}
22+
}
23+
24+
@Override
25+
public String getName() {
26+
return "ai.timefold.solver.migration.ChangeVersion";
27+
}
28+
29+
@Override
30+
public String getDisplayName() {
31+
return "Change the Timefold version";
32+
}
33+
34+
@Override
35+
public String getDescription() {
36+
return "Replaces the version of Timefold";
37+
}
38+
39+
@Override
40+
public List<Recipe> getRecipeList() {
41+
return List.of(
42+
new ChangePropertyValue("version.ai.timefold.solver", version, false, true),
43+
new ChangePropertyValue("version.timefold", version, false, true),
44+
new ChangePropertyValue("ai.timefold.solver.version", version, false, true),
45+
new ChangePropertyValue("timefold.version", version, false, true),
46+
new ChangePropertyValue("timefoldVersion", version, false, true));
47+
}
48+
49+
}
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", null,
43+
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/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
}

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)