Skip to content

Commit

Permalink
Merge pull request #13 from sullis/add-recipe-commons-math-3x
Browse files Browse the repository at this point in the history
add recipe for Apache Commons Math 3.x
  • Loading branch information
sambsnyd authored Mar 28, 2024
2 parents 37852f3 + b796ee3 commit c456ec2
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ dependencies {
testImplementation("commons-collections:commons-collections:3.2.2")
testImplementation("org.apache.commons:commons-collections4:4.4")

testImplementation("org.apache.commons:commons-math:2.2")
testImplementation("org.apache.commons:commons-math3:3.+")

testImplementation("commons-lang:commons-lang:2.6")
testImplementation("org.apache.commons:commons-lang3:3.+")

Expand Down
46 changes: 46 additions & 0 deletions src/main/resources/META-INF/rewrite/apache-commons-math-2-3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Copyright 2024 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.
#

########################################################################################################################
# Apache Commons Math
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.apache.commons.math.UpgradeApacheCommonsMath_2_3
displayName: Migrates to Apache Commons Math 3.x
description: >
Migrate applications to the latest Apache Commons Math 3.x release. This recipe modifies
application's build files, make changes to deprecated/preferred APIs, and migrates configuration settings that have
changes between versions.
tags:
- apache
- commons
- math
recipeList:
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.apache.commons
oldArtifactId: commons-math
newGroupId: org.apache.commons
newArtifactId: commons-math3
newVersion: 3.x
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: commons-math
oldArtifactId: commons-math
newGroupId: org.apache.commons
newArtifactId: commons-math3
newVersion: 3.x
- org.openrewrite.java.ChangePackage:
oldPackageName: org.apache.commons.math
newPackageName: org.apache.commons.math3
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.apache.commons.math;

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.config.Environment;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.java.Assertions.java;


class UpgradeApacheCommonsMath_2_3Test implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec
.parser(JavaParser.fromJavaVersion().classpath(
"commons-math", "commons-math3"))
.recipe(Environment.builder()
.scanRuntimeClasspath("org.openrewrite")
.build()
.activateRecipes("org.openrewrite.apache.commons.math.UpgradeApacheCommonsMath_2_3")
);
}

@DocumentExample
@Test
void apacheCommonsMath() {
rewriteRun(
//language=java
java(
"""
import org.apache.commons.math.Field;
import org.apache.commons.math.stat.StatUtils;
class Test {
static void helloApacheMath() {
Field field = null;
double[] data = new double[] { 25.1d, 35.2d };
double max = StatUtils.max(data);
}
}
""",
"""
import org.apache.commons.math3.Field;
import org.apache.commons.math3.stat.StatUtils;
class Test {
static void helloApacheMath() {
Field field = null;
double[] data = new double[] { 25.1d, 35.2d };
double max = StatUtils.max(data);
}
}
"""
)
);
}
}

0 comments on commit c456ec2

Please sign in to comment.