Skip to content

Commit

Permalink
MigrateStruts6Constants
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Mar 5, 2024
1 parent d0c6418 commit 5b113bd
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java.struts.search;

import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.xml.search.FindTags;

public class FindStrutsXml extends Recipe {
@Override
public String getDisplayName() {
return "Find struts XML files";
}

@Override
public String getDescription() {
return "Struts XML files may have any name, and may be outside a resources directory, so " +
"the true test is to look at the content of the file.";
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new FindTags("/struts").getVisitor();
}
}
99 changes: 73 additions & 26 deletions src/main/resources/META-INF/rewrite/struts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,78 +36,125 @@ type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.struts.MigrateStruts6Constants
displayName: Migrate to Struts 6 constants
description: All Xwork constants had been already deprecated, with this version all of them have been removed and Struts constants have been used instead.
#preconditions:
# - org.openrewrite.FindSourceFiles:
# filePattern: '**/struts.xml'
preconditions:
- org.openrewrite.java.struts.search.FindStrutsXml
recipeList:
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldAttributeValue: collectionConverter
oldValue: collectionConverter
newValue: struts.converter.collection
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldAttributeValue: dateConverter
oldValue: dateConverter
newValue: struts.converter.date
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldAttributeValue: numberConverter
oldValue: numberConverter
newValue: struts.converter.number
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldAttributeValue: stringConverter
oldValue: stringConverter
newValue: struts.converter.string
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldAttributeValue: arrayConverter
oldValue: arrayConverter
newValue: struts.converter.array
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldAttributeValue: devMode
oldValue: devMode
newValue: struts.devMode
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldAttributeValue: logMissingProperties
oldValue: logMissingProperties
newValue: struts.ognl.logMissingProperties
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldAttributeValue: enableOGNLExpressionCache
oldValue: enableOGNLExpressionCache
newValue: struts.ognl.enableExpressionCache
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldAttributeValue: enableOGNLEvalExpression
oldValue: enableOGNLEvalExpression
newValue: struts.ognl.enableEvalExpression
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldAttributeValue: reloadXmlConfiguration
oldValue: reloadXmlConfiguration
newValue: struts.configuration.xml.reload
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldAttributeValue: allowStaticMethodAccess
oldValue: allowStaticMethodAccess
newValue: struts.ognl.allowStaticMethodAccess
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: ognlExcludedClasses
newValue: struts.excludedClasses
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: ognlExcludedPackageNamePatterns
newValue: struts.excludedPackageNamePatterns
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: ognlExcludedPackageNames
newValue: struts.excludedPackageNames
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: additionalExcludedPatterns
newValue: struts.additional.excludedPatterns
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: additionalAcceptedPatterns
newValue: struts.additional.acceptedPatterns
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: overrideExcludedPatterns
newValue: struts.override.excludedPatterns
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: overrideAcceptedPatterns
newValue: struts.override.acceptedPatterns
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: struts.xwork.chaining.copyErrors
newValue: struts.chaining.copyErrors
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: struts.xwork.chaining.copyFieldErrors
newValue: struts.chaining.copyFieldErrors
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: struts.xwork.chaining.copyMessages
newValue: struts.chaining.copyMessages
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: xwork.autoGrowCollectionLimit
newValue: struts.ognl.autoGrowthCollectionLimit
- org.openrewrite.xml.ChangeTagAttribute:
elementName: constant
attributeName: name
oldValue: objectFactory.classloader
newValue: struts.objectFactory.classloader
# xwork.loggerFactory <not used any more>
# ognlExcludedClasses struts.excludedClasses
# ognlExcludedPackageNamePatterns struts.excludedPackageNamePatterns
# ognlExcludedPackageNames struts.excludedPackageNames
# additionalExcludedPatterns struts.additional.excludedPatterns
# additionalAcceptedPatterns struts.additional.acceptedPatterns
# overrideExcludedPatterns struts.override.excludedPatterns
# overrideAcceptedPatterns struts.override.acceptedPatterns
# struts.xwork.chaining.copyErrors struts.chaining.copyErrors
# struts.xwork.chaining.copyFieldErrors struts.chaining.copyFieldErrors
# struts.xwork.chaining.copyMessages struts.chaining.copyMessages
# xwork.autoGrowCollectionLimit struts.ognl.autoGrowthCollectionLimit
# objectFactory.classloader struts.objectFactory.classloader
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.struts.MigrateAwareInterfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public void defaults(RecipeSpec spec) {
.expectedCyclesThatMakeChanges(1).cycles(1);
}

@Disabled
@Test
void inStrutsXml() {
rewriteRun(
Expand Down

0 comments on commit 5b113bd

Please sign in to comment.