Skip to content

Commit

Permalink
Upgrade Struts 1 dependency to Struts 2 (#11)
Browse files Browse the repository at this point in the history
* Upgrade Struts 1 dependency to Struts 2

* Add rewrite-maven as test dependency
  • Loading branch information
timtebeek authored Aug 15, 2024
1 parent 86a2bd2 commit e812a0e
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
// Need to have a slf4j binding to see any output enabled from the parser.
runtimeOnly("ch.qos.logback:logback-classic:1.2.+")

testImplementation("org.openrewrite:rewrite-maven")
"testWithStruts6Implementation"("org.apache.struts:struts2-core:latest.release")
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/META-INF/rewrite/struts6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ recipeList:
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.struts.migrate6.UpgradeStruts6Dependencies
displayName: Upgrade Struts 6.0 dependencies
description: Upgrade Struts 2.x dependencies to Struts 6.0
description: Upgrade Struts 2.x dependencies to Struts 6.0.
recipeList:
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.apache.struts
oldArtifactId: struts-core
newArtifactId: struts2-core
newVersion: 6.x
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: org.apache.struts
artifactId: '*'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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.migrate6;

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.maven.Assertions.pomXml;

class UpgradeStruts6DependenciesTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec.recipeFromResources("org.openrewrite.java.struts.migrate6.UpgradeStruts6Dependencies");
}

@Test
@DocumentExample
void upgradeDependencies() {
rewriteRun(
pomXml(
//language=xml
"""
<project>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>1</version>
<properties>
<struts2.version>2.5.22</struts2.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-config-browser-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts2.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
</dependencies>
</project>
""",
spec -> spec.after(pomXml -> {
assertThat(pomXml).contains("<struts2.version>6.");
return pomXml;
})
)
);
}

@Test
void changeStruts1Dependency() {
rewriteRun(
pomXml(
//language=xml
"""
<project>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-core</artifactId>
<version>1.3.10</version>
</dependency>
</dependencies>
</project>
""",
spec -> spec.after(pomXml -> {
assertThat(pomXml).contains("<version>6.");
return pomXml;
})
)
);
}
}

0 comments on commit e812a0e

Please sign in to comment.