Skip to content

Commit 0ebe266

Browse files
authored
Add maven execution context (#1751)
1 parent 24c217a commit 0ebe266

21 files changed

Lines changed: 175 additions & 80 deletions

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/extractor/FetchMetadataTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.jenkins.tools.pluginmodernizer.core.model.Platform;
1212
import io.jenkins.tools.pluginmodernizer.core.recipes.DeclarativeRecipesTest;
1313
import io.jenkins.tools.pluginmodernizer.core.recipes.FetchMetadata;
14+
import io.jenkins.tools.pluginmodernizer.core.utils.Utils;
1415
import java.util.LinkedHashMap;
1516
import java.util.LinkedHashSet;
1617
import java.util.LinkedList;
@@ -24,6 +25,7 @@
2425
import org.junit.jupiter.api.parallel.ExecutionMode;
2526
import org.openrewrite.Issue;
2627
import org.openrewrite.java.JavaParser;
28+
import org.openrewrite.test.RecipeSpec;
2729
import org.openrewrite.test.RewriteTest;
2830

2931
/**
@@ -182,6 +184,11 @@ public class FetchMetadataTest implements RewriteTest {
182184
</project>
183185
""";
184186

187+
@Override
188+
public void defaults(RecipeSpec spec) {
189+
spec.executionContext(Utils.getMavenExecutionContext());
190+
}
191+
185192
@Test
186193
void testWithPomOnly(TestInfo testInfo) throws Exception {
187194
rewriteRun(recipeSpec -> recipeSpec.recipe(new FetchMetadata(testInfo.getDisplayName())), pomXml(POM_XML));

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/AddDetachedPluginDependencyTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.openrewrite.java.Assertions.srcTestJava;
66
import static org.openrewrite.maven.Assertions.pomXml;
77

8+
import io.jenkins.tools.pluginmodernizer.core.utils.Utils;
89
import org.junit.jupiter.api.Test;
910
import org.junit.jupiter.api.parallel.Execution;
1011
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -26,7 +27,8 @@ public class AddDetachedPluginDependencyTest implements RewriteTest {
2627
@Test
2728
void detectsDetachedPluginUsageAndAddsDependencyWithoutBom() {
2829
rewriteRun(
29-
spec -> spec.recipe(new AddDetachedPluginDependency("2.440.3")), // language=xml
30+
spec -> spec.executionContext(Utils.getMavenExecutionContext())
31+
.recipe(new AddDetachedPluginDependency("2.440.3")), // language=xml
3032
pomXml("""
3133
<?xml version="1.0" encoding="UTF-8"?>
3234
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -375,7 +377,8 @@ public class MatrixProject {}
375377
@Test
376378
void detectsDetachedPluginUsageAndAddsDependencyWithBom() {
377379
rewriteRun(
378-
spec -> spec.recipe(new AddDetachedPluginDependency("2.346.3")),
380+
spec -> spec.executionContext(Utils.getMavenExecutionContext())
381+
.recipe(new AddDetachedPluginDependency("2.346.3")),
379382
// language=xml
380383
pomXml("""
381384
<?xml version="1.0" encoding="UTF-8"?>

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/AddIncrementalsTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import io.jenkins.tools.pluginmodernizer.core.config.Settings;
88
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
9+
import io.jenkins.tools.pluginmodernizer.core.utils.Utils;
910
import org.junit.jupiter.api.Test;
1011
import org.junit.jupiter.api.parallel.Execution;
1112
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -20,7 +21,7 @@ class AddIncrementalsTest implements RewriteTest {
2021
@Test
2122
void shouldAddIncrementalsToBasicPlugin() {
2223
rewriteRun(
23-
spec -> spec.recipe(new AddIncrementals()),
24+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new AddIncrementals()),
2425
// language=xml
2526
pomXml("""
2627
<?xml version="1.0" encoding="UTF-8"?>
@@ -113,7 +114,7 @@ void shouldAddIncrementalsToBasicPlugin() {
113114
@Test
114115
void shouldNotModifyIfAlreadyUsingIncrementals() {
115116
rewriteRun(
116-
spec -> spec.recipe(new AddIncrementals()),
117+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new AddIncrementals()),
117118
// language=xml
118119
pomXml("""
119120
<?xml version="1.0" encoding="UTF-8"?>
@@ -158,7 +159,7 @@ void shouldNotModifyIfAlreadyUsingIncrementals() {
158159
@Test
159160
void shouldNotCreateFilesIfAlreadyExist() {
160161
rewriteRun(
161-
spec -> spec.recipe(new AddIncrementals()),
162+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new AddIncrementals()),
162163
// language=xml
163164
pomXml("""
164165
<?xml version="1.0" encoding="UTF-8"?>

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/AddPropertyTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.openrewrite.maven.Assertions.pomXml;
44

5+
import io.jenkins.tools.pluginmodernizer.core.utils.Utils;
56
import org.junit.jupiter.api.Test;
67
import org.junit.jupiter.api.parallel.Execution;
78
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -16,7 +17,8 @@ public class AddPropertyTest implements RewriteTest {
1617
@Test
1718
void shouldAddProperty() {
1819
rewriteRun(
19-
spec -> spec.recipe(new AddProperty("ban-junit4-imports.skip", "false")),
20+
spec -> spec.executionContext(Utils.getMavenExecutionContext())
21+
.recipe(new AddProperty("ban-junit4-imports.skip", "false")),
2022
// language=xml
2123
pomXml("""
2224
<?xml version="1.0" encoding="UTF-8"?>
@@ -87,7 +89,8 @@ void shouldAddProperty() {
8789
@Test
8890
void shouldNotAddDuplicateProperty() {
8991
rewriteRun(
90-
spec -> spec.recipe(new AddProperty("ban-junit4-imports.skip", "false")),
92+
spec -> spec.executionContext(Utils.getMavenExecutionContext())
93+
.recipe(new AddProperty("ban-junit4-imports.skip", "false")),
9194
// language=xml
9295
pomXml("""
9396
<?xml version="1.0" encoding="UTF-8"?>

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/CreateJenkinsFileTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.openrewrite.maven.Assertions.pomXml;
55

66
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
7+
import io.jenkins.tools.pluginmodernizer.core.utils.Utils;
78
import org.junit.jupiter.api.Test;
89
import org.openrewrite.test.RewriteTest;
910

@@ -12,7 +13,7 @@ class CreateJenkinsFileTest implements RewriteTest {
1213
@Test
1314
void shouldAddJenkinsfileFromPomVersion() {
1415
rewriteRun(
15-
spec -> spec.recipe(new CreateJenkinsFile()),
16+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new CreateJenkinsFile()),
1617
// language=xml
1718
pomXml("""
1819
<?xml version="1.0" encoding="UTF-8"?>
@@ -58,7 +59,7 @@ void shouldAddJenkinsfileFromPomVersion() {
5859
@Test
5960
void shouldNotAddJenkinsfileIfAlreadyPresent() {
6061
rewriteRun(
61-
spec -> spec.recipe(new CreateJenkinsFile()),
62+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new CreateJenkinsFile()),
6263
// language=xml
6364
pomXml("""
6465
<?xml version="1.0" encoding="UTF-8"?>
@@ -91,7 +92,7 @@ void shouldNotAddJenkinsfileIfAlreadyPresent() {
9192
@Test
9293
void shouldNotAddJenkinsfileIfNoJenkinsVersion() {
9394
rewriteRun(
94-
spec -> spec.recipe(new CreateJenkinsFile()),
95+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new CreateJenkinsFile()),
9596
// language=xml
9697
pomXml("""
9798
<?xml version="1.0" encoding="UTF-8"?>
@@ -109,7 +110,7 @@ void shouldNotAddJenkinsfileIfNoJenkinsVersion() {
109110
@Test
110111
void shouldHandleDifferentJenkinsVersions() {
111112
rewriteRun(
112-
spec -> spec.recipe(new CreateJenkinsFile()),
113+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new CreateJenkinsFile()),
113114
// language=xml
114115
pomXml("""
115116
<?xml version="1.0" encoding="UTF-8"?>
@@ -155,7 +156,7 @@ void shouldHandleDifferentJenkinsVersions() {
155156
@Test
156157
void shouldHandleOlderJenkinsVersions() {
157158
rewriteRun(
158-
spec -> spec.recipe(new CreateJenkinsFile()),
159+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new CreateJenkinsFile()),
159160
// language=xml
160161
pomXml("""
161162
<?xml version="1.0" encoding="UTF-8"?>

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/DeclarativeRecipesTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.jenkins.tools.pluginmodernizer.core.config.Settings;
1616
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
1717
import io.jenkins.tools.pluginmodernizer.core.recipes.code.ReplaceRemovedSSHLauncherConstructorTest;
18+
import io.jenkins.tools.pluginmodernizer.core.utils.Utils;
1819
import java.io.IOException;
1920
import java.nio.file.Files;
2021
import java.nio.file.Path;
@@ -28,6 +29,7 @@
2829
import org.junit.jupiter.api.parallel.ExecutionMode;
2930
import org.openrewrite.java.JavaParser;
3031
import org.openrewrite.maven.MavenParser;
32+
import org.openrewrite.test.RecipeSpec;
3133
import org.openrewrite.test.RewriteTest;
3234
import org.slf4j.Logger;
3335
import org.slf4j.LoggerFactory;
@@ -96,6 +98,11 @@ public class DeclarativeRecipesTest implements RewriteTest {
9698
*/
9799
private static final Logger LOG = LoggerFactory.getLogger(DeclarativeRecipesTest.class);
98100

101+
@Override
102+
public void defaults(RecipeSpec spec) {
103+
spec.executionContext(Utils.getMavenExecutionContext());
104+
}
105+
99106
/**
100107
* Test declarative recipe
101108
* See @{{@link io.jenkins.tools.pluginmodernizer.core.extractor.FetchMetadataTest} for more tests

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/EnableCDTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.openrewrite.yaml.Assertions.yaml;
66

77
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
8+
import io.jenkins.tools.pluginmodernizer.core.utils.Utils;
89
import org.junit.jupiter.api.Test;
910
import org.junit.jupiter.api.parallel.Execution;
1011
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -76,7 +77,7 @@ class EnableCDTest implements RewriteTest {
7677
@Test
7778
void shouldEnableCDForBasicPlugin() {
7879
rewriteRun(
79-
spec -> spec.recipe(new EnableCD()),
80+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnableCD()),
8081
// language=xml
8182
pomXml("""
8283
<?xml version="1.0" encoding="UTF-8"?>
@@ -163,7 +164,7 @@ void shouldEnableCDForBasicPlugin() {
163164
@Test
164165
void shouldEnableCDWithRevisionPrefix() {
165166
rewriteRun(
166-
spec -> spec.recipe(new EnableCD()),
167+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnableCD()),
167168
// language=xml
168169
pomXml("""
169170
<?xml version="1.0" encoding="UTF-8"?>
@@ -236,7 +237,7 @@ void shouldEnableCDWithRevisionPrefix() {
236237
@Test
237238
void shouldNotModifyIfAlreadyUsingCD() {
238239
rewriteRun(
239-
spec -> spec.recipe(new EnableCD()),
240+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnableCD()),
240241
// language=xml
241242
pomXml("""
242243
<?xml version="1.0" encoding="UTF-8"?>
@@ -278,7 +279,7 @@ void shouldNotModifyIfAlreadyUsingCD() {
278279
@Test
279280
void shouldUpdateExistingMavenConfig() {
280281
rewriteRun(
281-
spec -> spec.recipe(new EnableCD()),
282+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnableCD()),
282283
// language=xml
283284
pomXml("""
284285
<?xml version="1.0" encoding="UTF-8"?>
@@ -352,7 +353,7 @@ void shouldUpdateExistingMavenConfig() {
352353
@Test
353354
void shouldSkipIfNoPropertiesSection() {
354355
rewriteRun(
355-
spec -> spec.recipe(new EnableCD()),
356+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnableCD()),
356357
// language=xml
357358
pomXml("""
358359
<?xml version="1.0" encoding="UTF-8"?>
@@ -387,7 +388,7 @@ void shouldSkipIfNoPropertiesSection() {
387388
@Test
388389
void shouldDeleteReleaseDrafterWorkflow() {
389390
rewriteRun(
390-
spec -> spec.recipe(new EnableCD()),
391+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnableCD()),
391392
// language=xml
392393
pomXml("""
393394
<?xml version="1.0" encoding="UTF-8"?>
@@ -474,7 +475,7 @@ void shouldDeleteReleaseDrafterWorkflow() {
474475
@Test
475476
void shouldConvertRevisionChangelistToChangelist() {
476477
rewriteRun(
477-
spec -> spec.recipe(new EnableCD()),
478+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnableCD()),
478479
// language=xml
479480
pomXml("""
480481
<?xml version="1.0" encoding="UTF-8"?>
@@ -551,7 +552,7 @@ void shouldNotModifyPluginAlreadyUsingRevisionDashChangelist() {
551552
// Test for API plugins like asm-api that use ${revision}-${changelist} format
552553
// This is a valid CD format and should NOT be modified
553554
rewriteRun(
554-
spec -> spec.recipe(new EnableCD()),
555+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnableCD()),
555556
// language=xml
556557
pomXml("""
557558
<?xml version="1.0" encoding="UTF-8"?>
@@ -596,7 +597,7 @@ void shouldNotModifyPluginAlreadyUsingRevisionDotChangelist() {
596597
// Test for plugins that use ${revision}.${changelist} format
597598
// This is a valid CD format and should NOT be modified
598599
rewriteRun(
599-
spec -> spec.recipe(new EnableCD()),
600+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnableCD()),
600601
// language=xml
601602
pomXml("""
602603
<?xml version="1.0" encoding="UTF-8"?>

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/EnsureIndexJellyTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.openrewrite.test.SourceSpecs.text;
77

88
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
9+
import io.jenkins.tools.pluginmodernizer.core.utils.Utils;
910
import org.junit.jupiter.api.Test;
1011
import org.junit.jupiter.api.parallel.Execution;
1112
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -19,15 +20,17 @@ public class EnsureIndexJellyTest implements RewriteTest {
1920

2021
@Test
2122
void shouldNotReplaceJellyFile() {
22-
rewriteRun(spec -> spec.recipe(new EnsureIndexJelly()), text("jelly", sourceSpecs -> {
23-
sourceSpecs.path(ArchetypeCommonFile.INDEX_JELLY.getPath());
24-
}));
23+
rewriteRun(
24+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnsureIndexJelly()),
25+
text("jelly", sourceSpecs -> {
26+
sourceSpecs.path(ArchetypeCommonFile.INDEX_JELLY.getPath());
27+
}));
2528
}
2629

2730
@Test
2831
void createFromDescription() {
2932
rewriteRun(
30-
spec -> spec.recipe(new EnsureIndexJelly()),
33+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnsureIndexJelly()),
3134
// language=xml
3235
pomXml("""
3336
<project>
@@ -58,7 +61,7 @@ void createFromDescription() {
5861
@Test
5962
void createNoCreateIfNotAPlugin() {
6063
rewriteRun(
61-
spec -> spec.recipe(new EnsureIndexJelly()),
64+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnsureIndexJelly()),
6265
// language=xml
6366
pomXml("""
6467
<project>
@@ -73,7 +76,7 @@ void createNoCreateIfNotAPlugin() {
7376
@Test
7477
void createFromArtifactIdEmptyDescription() {
7578
rewriteRun(
76-
spec -> spec.recipe(new EnsureIndexJelly()),
79+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnsureIndexJelly()),
7780
// language=xml
7881
pomXml("""
7982
<project>
@@ -104,7 +107,7 @@ void createFromArtifactIdEmptyDescription() {
104107
@Test
105108
void createFromArtifactIdNoDescription() {
106109
rewriteRun(
107-
spec -> spec.recipe(new EnsureIndexJelly()),
110+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnsureIndexJelly()),
108111
// language=xml
109112
pomXml("""
110113
<project>
@@ -134,7 +137,7 @@ void createFromArtifactIdNoDescription() {
134137
@Test
135138
void shouldCreateMultipleNestedIndexJellies() {
136139
rewriteRun(
137-
spec -> spec.recipe(new EnsureIndexJelly()),
140+
spec -> spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnsureIndexJelly()),
138141
mavenProject(
139142
"parent",
140143
// language=xml

plugin-modernizer-core/src/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/EnsureRelativePathTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.openrewrite.yaml.Assertions.yaml;
55

66
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile;
7+
import io.jenkins.tools.pluginmodernizer.core.utils.Utils;
78
import org.junit.jupiter.api.Test;
89
import org.junit.jupiter.api.parallel.Execution;
910
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -15,7 +16,7 @@ public class EnsureRelativePathTest implements RewriteTest {
1516

1617
@Override
1718
public void defaults(RecipeSpec spec) {
18-
spec.recipe(new EnsureRelativePath());
19+
spec.executionContext(Utils.getMavenExecutionContext()).recipe(new EnsureRelativePath());
1920
}
2021

2122
@Test

0 commit comments

Comments
 (0)