generated from moderneinc/rewrite-recipe-starter
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement hudson.Util.getPastTimeString migration
Issue #6
- Loading branch information
Showing
2 changed files
with
130 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
type: specs.openrewrite.org/v1beta/recipe | ||
name: org.openrewrite.jenkins.migrate.hudson.UtilGetPastTimeStringToGetTimeSpanString | ||
displayName: Replace `hudson.Util.getPastTimeString` with `getTimeSpanString` | ||
description: > | ||
`hudson.Util.getPastTimeString` has been [deprecated](https://github.com/jenkinsci/jenkins/pull/4174) | ||
since the [2.204.1 LTS release](https://www.jenkins.io/changelog-stable/#v2.204.1) on 2019-12-18. | ||
recipeList: | ||
- org.openrewrite.java.ChangeMethodName: | ||
methodPattern: hudson.Util getPastTimeString(long) | ||
newMethodName: getTimeSpanString | ||
matchOverrides: false | ||
ignoreDefinition: true |
117 changes: 117 additions & 0 deletions
117
...ava/org/openrewrite/jenkins/migrate/hudson/UtilGetPastTimeStringToTimeSpanStringTest.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,117 @@ | ||
package org.openrewrite.jenkins.migrate.hudson; | ||
|
||
import org.intellij.lang.annotations.Language; | ||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.java.JavaParser; | ||
import org.openrewrite.test.RecipeSpec; | ||
import org.openrewrite.test.RewriteTest; | ||
|
||
import static org.openrewrite.java.Assertions.java; | ||
|
||
class UtilGetPastTimeStringToTimeSpanStringTest implements RewriteTest { | ||
@Language("java") | ||
// language=java | ||
private final String hudsonUtil = """ | ||
package hudson; | ||
public class Util { | ||
public static String getTimeSpanString(long duration) { | ||
return "anything"; | ||
} | ||
@Deprecated | ||
public static String getPastTimeString(long duration) { | ||
return getTimeSpanString(duration); | ||
} | ||
} | ||
""".stripIndent(); | ||
|
||
@Override | ||
public void defaults(RecipeSpec spec) { | ||
spec.parser(JavaParser.fromJavaVersion().dependsOn(hudsonUtil)); | ||
spec.recipeFromResource("/META-INF/rewrite/hudson-migrations.yml", "org.openrewrite.jenkins.migrate.hudson.UtilGetPastTimeStringToGetTimeSpanString"); | ||
} | ||
|
||
@Test | ||
void shouldReplaceFullyQualifiedMethodCall() { | ||
// language=java | ||
rewriteRun(java( | ||
""" | ||
package org.example; | ||
class MyConsumer { | ||
String format(long timestamp) { | ||
return hudson.Util.getPastTimeString(timestamp); | ||
} | ||
} | ||
""".stripIndent(), | ||
""" | ||
package org.example; | ||
class MyConsumer { | ||
String format(long timestamp) { | ||
return hudson.Util.getTimeSpanString(timestamp); | ||
} | ||
} | ||
""".stripIndent() | ||
)); | ||
} | ||
|
||
@Test | ||
void shouldReplaceImportedMethodCall() { | ||
// language=java | ||
rewriteRun(java( | ||
""" | ||
package org.example; | ||
import hudson.Util; | ||
class MyConsumer { | ||
String format(long timestamp) { | ||
return Util.getPastTimeString(timestamp); | ||
} | ||
} | ||
""".stripIndent(), | ||
""" | ||
package org.example; | ||
import hudson.Util; | ||
class MyConsumer { | ||
String format(long timestamp) { | ||
return Util.getTimeSpanString(timestamp); | ||
} | ||
} | ||
""".stripIndent() | ||
)); | ||
} | ||
|
||
@Test | ||
void shouldReplaceStaticImportedMethodCall() { | ||
// language=java | ||
rewriteRun(java( | ||
""" | ||
package org.example; | ||
import static hudson.Util.getPastTimeString; | ||
class MyConsumer { | ||
String format(long timestamp) { | ||
return getPastTimeString(timestamp); | ||
} | ||
} | ||
""".stripIndent(), | ||
""" | ||
package org.example; | ||
import static hudson.Util.getTimeSpanString; | ||
class MyConsumer { | ||
String format(long timestamp) { | ||
return getTimeSpanString(timestamp); | ||
} | ||
} | ||
""".stripIndent() | ||
)); | ||
} | ||
} |