Skip to content

Commit af62254

Browse files
authored
Inline methods for Log4j2 (#253)
* Inline methods for Log4j2 * Add license header * Trim description
1 parent fde899c commit af62254

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="InlineMethodCallsRecipeGenerator" type="Application" factoryName="Application">
3+
<option name="MAIN_CLASS_NAME" value="org.openrewrite.java.internal.parser.InlineMethodCallsRecipeGenerator" />
4+
<module name="rewrite-logging-frameworks.main" />
5+
<option name="PROGRAM_PARAMETERS" value="src/main/resources/META-INF/rewrite/classpath.tsv.gz src/main/resources/META-INF/rewrite/inline-logging-methods.yml org.openrewrite.java.logging.log4j.InlineMethods" />
6+
<method v="2">
7+
<option name="Make" enabled="true" />
8+
</method>
9+
</configuration>
10+
</component>
151 Bytes
Binary file not shown.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2025 the original author or authors.
2+
# <p>
3+
# Licensed under the Moderne Source Available License (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# <p>
7+
# https://docs.moderne.io/licensing/moderne-source-available-license
8+
# <p>
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# Generated InlineMe recipes from TypeTable
16+
#
17+
18+
type: specs.openrewrite.org/v1beta/recipe
19+
name: org.openrewrite.java.logging.log4j.InlineMethods
20+
displayName: Inline methods annotated with `@InlineMe`
21+
description: >-
22+
Automatically generated recipes to inline method calls based on `@InlineMe` annotations
23+
discovered in the type table.
24+
recipeList:
25+
26+
# From org.apache.logging.log4j:log4j-api:2.25.2
27+
- org.openrewrite.java.InlineMethodCalls:
28+
methodPattern: 'org.apache.logging.log4j.message.StructuredDataId StructuredDataId(java.lang.String, int, java.lang.String[], java.lang.String[])'
29+
replacement: 'this(name, String.valueOf(enterpriseNumber), required, optional)'
30+
classpathFromResources:
31+
- 'log4j-api-2.25.2'
32+
- org.openrewrite.java.InlineMethodCalls:
33+
methodPattern: 'org.apache.logging.log4j.message.StructuredDataId StructuredDataId(java.lang.String, int, java.lang.String[], java.lang.String[], int)'
34+
replacement: 'this(name, String.valueOf(enterpriseNumber), required, optional, maxLength)'
35+
classpathFromResources:
36+
- 'log4j-api-2.25.2'
37+
- org.openrewrite.java.InlineMethodCalls:
38+
methodPattern: 'org.apache.logging.log4j.message.StructuredDataId makeId(java.lang.String, int)'
39+
replacement: 'this.makeId(defaultId, String.valueOf(anEnterpriseNumber))'
40+
classpathFromResources:
41+
- 'log4j-api-2.25.2'
42+
- org.openrewrite.java.InlineMethodCalls:
43+
methodPattern: 'org.apache.logging.log4j.message.ParameterizedMessage ParameterizedMessage(java.lang.String, java.lang.String[], java.lang.Throwable)'
44+
replacement: 'this(pattern, Arrays.stream(args).toArray(Object[]::new), throwable)'
45+
imports:
46+
- 'java.util.Arrays'
47+
classpathFromResources:
48+
- 'log4j-api-2.25.2'
49+
- org.openrewrite.java.InlineMethodCalls:
50+
methodPattern: 'org.apache.logging.log4j.MarkerManager getMarker(java.lang.String, org.apache.logging.log4j.Marker)'
51+
replacement: 'MarkerManager.getMarker(name).addParents(parent)'
52+
imports:
53+
- 'org.apache.logging.log4j.MarkerManager'
54+
classpathFromResources:
55+
- 'log4j-api-2.25.2'

src/main/resources/META-INF/rewrite/log4j.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ recipeList:
137137
newArtifactId: log4j-slf4j-impl
138138
newVersion: 2.x
139139
- org.openrewrite.java.logging.log4j.UpgradeLog4J2DependencyVersion
140+
- org.openrewrite.java.logging.log4j.InlineMethods
140141

141142
---
142143
type: specs.openrewrite.org/v1beta/recipe

src/test/java/org/openrewrite/java/logging/log4j/Log4j1ToLog4j2Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Log4j1ToLog4j2Test implements RewriteTest {
3434

3535
@Override
3636
public void defaults(RecipeSpec spec) {
37-
spec.recipeFromResource("/META-INF/rewrite/log4j.yml", "org.openrewrite.java.logging.log4j.Log4j1ToLog4j2")
37+
spec.recipeFromResources("org.openrewrite.java.logging.log4j.Log4j1ToLog4j2")
3838
.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "log4j-1"));
3939
}
4040

0 commit comments

Comments
 (0)