This is an automated email from the ASF dual-hosted git repository.
gitgabrio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-drools.git
The following commit(s) were added to refs/heads/main by this push:
new d02f6e13b9 kie-issues-957 - removing unnecessary module (#5733)
d02f6e13b9 is described below
commit d02f6e13b99b02bc0caf6c793f438fb4e9aec87f
Author: Alex Porcelli <[email protected]>
AuthorDate: Fri Feb 23 09:50:38 2024 -0500
kie-issues-957 - removing unnecessary module (#5733)
---
jpmml-migration-recipe/Readme.md | 53 -
jpmml-migration-recipe/pom.xml | 200 ----
.../openrewrite/recipe/jpmml/JPMMLCodeRecipe.java | 77 --
.../kie/openrewrite/recipe/jpmml/JPMMLVisitor.java | 506 ---------
.../main/resources/META-INF/rewrite/rewrite.yml | 49 -
.../recipe/jpmml/CommonTestingUtilities.java | 205 ----
.../recipe/jpmml/JPMMLCodeRecipeTest.java | 150 ---
.../openrewrite/recipe/jpmml/JPMMLRecipeTest.java | 424 --------
.../openrewrite/recipe/jpmml/JPMMLVisitorTest.java | 1148 --------------------
.../src/test/resources/logback.xml | 39 -
pom.xml | 1 -
11 files changed, 2852 deletions(-)
diff --git a/jpmml-migration-recipe/Readme.md b/jpmml-migration-recipe/Readme.md
deleted file mode 100644
index dbf554dcea..0000000000
--- a/jpmml-migration-recipe/Readme.md
+++ /dev/null
@@ -1,53 +0,0 @@
-JPPML migration recipe
-======================
-
-The jpmml-recipe contains code needed to migrate jpmml from version 1.5.1 to
1.6.4.
-
-The main `JPMMLRecipe` features the OpenRewrite recipe declarative
chain-ability to re-use some already existing recipes, so that
-
-1. It invokes `ChangeType` for classes that changed name/package, but kept the
same method signature
-2. It invokes `JPMMLCodeRecipe` for more fine-grained manipulation, e.g.
removal of `FieldName` usage and replacement of `ScoreDistribution`; this is
actually done inside `JPMMLVisitor`
-3. It invokes `RemoveUnusedImports` to remove unused imports
-
-There are three main modification steps:
-
-1. `JPMMLVisitor`
-2. `JPMMLCodeRecipe`
-3. `JPMMLRecipe`
-
-for each of which there is a specific unit test class.
-Testing of `JPMMLVisitor` is focused on very low level LST modification.
-Testing of `JPMMLCodeRecipe` is focused on the overall modifications
implemented in this module.
-Testing of `JPMMLRecipe` is focused on the full modifications applied by all
the involved recipes. It is at this phase that the final, expected result
should be evaluated.
-
-The `CommonTestingUtilities` has been thought to be re-usable by different
recipes, even if currently defined in that module
-
-Usage
-=====
-
-To execute `JPMMLRecipe`, simply add the following snippet in the target
project's pom
-
-```xml
- <plugin>
- <groupId>org.openrewrite.maven</groupId>
- <artifactId>rewrite-maven-plugin</artifactId>
- <configuration>
- <activeRecipes>
-
<activeRecipe>org.kie.openrewrite.recipe.jpmml.JPMMLRecipe</activeRecipe>
- </activeRecipes>
- </configuration>
- <dependencies>
- <dependency>
- <groupId>org.kie</groupId>
- <artifactId>jpmml-migration-recipe</artifactId>
- </dependency>
- </dependencies>
- </plugin>
-```
-
-and issue
-
-`mvn rewrite:run`
-
-
-
diff --git a/jpmml-migration-recipe/pom.xml b/jpmml-migration-recipe/pom.xml
deleted file mode 100644
index 7efc9d5232..0000000000
--- a/jpmml-migration-recipe/pom.xml
+++ /dev/null
@@ -1,200 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- 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.
-
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.kie</groupId>
- <artifactId>drools-build-parent</artifactId>
- <version>999-SNAPSHOT</version>
- <relativePath>../build-parent/pom.xml</relativePath>
- </parent>
-
- <artifactId>jpmml-migration-recipe</artifactId>
-
- <name>Kie :: Jpmml Migration Recipe</name>
- <description>OpenRewrite recipe to migrate JPMML model library from 1.5.1 to
1.6.4</description>
-
- <properties>
- <java.module.name>org.kie.jpmml.migration.recipe</java.module.name>
- </properties>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.openrewrite.recipe</groupId>
- <artifactId>rewrite-recipe-bom</artifactId>
- <version>1.19.4</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- <dependency>
- <groupId>org.jpmml</groupId>
- <artifactId>pmml-model</artifactId>
- <version>1.5.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <dependencies>
-
- <!-- rewrite-java depedencies only necessary for Java Recipe development
-->
- <dependency>
- <groupId>org.openrewrite</groupId>
- <artifactId>rewrite-java</artifactId>
- <scope>compile</scope>
- <exclusions>
- <exclusion>
- <groupId>org.jboss</groupId>
- <artifactId>jandex</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <!-- You only need the version that corresponds to your current
- Java version. It is fine to add all of them, though, as
- they can coexist on a classpath. -->
- <dependency>
- <groupId>org.openrewrite</groupId>
- <artifactId>rewrite-java-11</artifactId>
- <scope>runtime</scope>
- </dependency>
-
- <!-- rewrite-maven dependency only necessary for Maven Recipe development
-->
- <dependency>
- <groupId>org.openrewrite</groupId>
- <artifactId>rewrite-maven</artifactId>
- <scope>compile</scope>
- </dependency>
-
- <!-- rewrite-yaml dependency only necessary for Yaml Recipe development -->
- <dependency>
- <groupId>org.openrewrite</groupId>
- <artifactId>rewrite-yaml</artifactId>
- <scope>compile</scope>
- </dependency>
-
- <!-- rewrite-properties dependency only necessary for Properties Recipe
development -->
- <dependency>
- <groupId>org.openrewrite</groupId>
- <artifactId>rewrite-properties</artifactId>
- <scope>compile</scope>
- </dependency>
-
- <!-- rewrite-xml dependency only necessary for XML Recipe development -->
- <dependency>
- <groupId>org.openrewrite</groupId>
- <artifactId>rewrite-xml</artifactId>
- <scope>compile</scope>
- </dependency>
-
-
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
-
- <!-- For authoring tests for any kind of Recipe -->
- <dependency>
- <groupId>org.openrewrite</groupId>
- <artifactId>rewrite-test</artifactId>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>org.jpmml</groupId>
- <artifactId>pmml-model</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <scope>test</scope>
- </dependency>
-
-
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-api</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <scope>test</scope>
- </dependency>
- <!-- Optional dependency on assertJ to provide fluent assertions. -->
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <dependencies>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <version>${version.org.junit}</version>
- </dependency>
- </dependencies>
- </plugin>
- <!-- This is needed to always download the new version in the .m2
repository, and have it available for tests/migration
- together with the old one -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>download_new_pmml</id>
- <goals>
- <goal>get</goal>
- </goals>
- <phase>validate</phase>
- <configuration>
- <groupId>org.jpmml</groupId>
- <artifactId>pmml-model</artifactId>
- <version>1.6.4</version>
- <transitive>false</transitive>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
-</project>
diff --git
a/jpmml-migration-recipe/src/main/java/org/kie/openrewrite/recipe/jpmml/JPMMLCodeRecipe.java
b/jpmml-migration-recipe/src/main/java/org/kie/openrewrite/recipe/jpmml/JPMMLCodeRecipe.java
deleted file mode 100644
index e2071a3171..0000000000
---
a/jpmml-migration-recipe/src/main/java/org/kie/openrewrite/recipe/jpmml/JPMMLCodeRecipe.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.kie.openrewrite.recipe.jpmml;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import org.jetbrains.annotations.NotNull;
-import org.openrewrite.ExecutionContext;
-import org.openrewrite.Option;
-import org.openrewrite.Recipe;
-import org.openrewrite.java.JavaVisitor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class JPMMLCodeRecipe extends Recipe {
-
- private static final Logger logger =
LoggerFactory.getLogger(JPMMLCodeRecipe.class);
-
- @Option(displayName = "Old fully-qualified type name",
- description = "Fully-qualified class name of the original
instantiated type.",
- example = "org.dmg.pmml.ScoreDistribution")
- @NotNull
- String oldInstantiatedFullyQualifiedTypeName;
-
- @Option(displayName = "New fully-qualified type name",
- description = "Fully-qualified class name of the replacement type.
The `OuterClassName$NestedClassName` naming convention should be used for
nested classes.",
- example = "org.dmg.pmml.ComplexScoreDistributions")
- @NotNull
- String newInstantiatedFullyQualifiedTypeName;
-
- @JsonCreator
- public JPMMLCodeRecipe(@NotNull
@JsonProperty("oldInstantiatedFullyQualifiedTypeName") String
oldInstantiatedFullyQualifiedTypeName,
- @NotNull
@JsonProperty("newInstantiatedFullyQualifiedTypeName") String
newInstantiatedFullyQualifiedTypeName) {
- this.oldInstantiatedFullyQualifiedTypeName =
oldInstantiatedFullyQualifiedTypeName;
- this.newInstantiatedFullyQualifiedTypeName =
newInstantiatedFullyQualifiedTypeName;
- logger.info("Created new instance... ");
- }
-
-
-
- @Override
- public String getDisplayName() {
- return "JPMML Update Code recipe";
- }
-
- @Override
- public String getDescription() {
- return "Migrate JPMML Code version from 1.5.1 to 1.6.4.";
- }
-
-
-
- @Override
- protected JavaVisitor<ExecutionContext> getVisitor() {
- logger.info("Retrieving new visitor...");
- return new JPMMLVisitor(oldInstantiatedFullyQualifiedTypeName,
newInstantiatedFullyQualifiedTypeName);
- }
-
-
-
-}
\ No newline at end of file
diff --git
a/jpmml-migration-recipe/src/main/java/org/kie/openrewrite/recipe/jpmml/JPMMLVisitor.java
b/jpmml-migration-recipe/src/main/java/org/kie/openrewrite/recipe/jpmml/JPMMLVisitor.java
deleted file mode 100644
index ba8db77801..0000000000
---
a/jpmml-migration-recipe/src/main/java/org/kie/openrewrite/recipe/jpmml/JPMMLVisitor.java
+++ /dev/null
@@ -1,506 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.kie.openrewrite.recipe.jpmml;
-
-import org.openrewrite.ExecutionContext;
-import org.openrewrite.Tree;
-import org.openrewrite.java.ChangeType;
-import org.openrewrite.java.JavaParser;
-import org.openrewrite.java.JavaTemplate;
-import org.openrewrite.java.JavaVisitor;
-import org.openrewrite.java.tree.*;
-import org.openrewrite.marker.Markers;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.nio.file.Path;
-import java.util.*;
-
-public class JPMMLVisitor extends JavaVisitor<ExecutionContext> {
-
- public static final String NEW_JPMML_MODEL = "pmml-model-1.6.4.jar";
-
- public static final String NEW_JPMML_MAVEN_PATH =
String.format("%1$s%2$s.m2%2$srepository%2$sorg%2$sjpmml%2$spmml-model%2$s1.6.4%2$s%3$s",
System.getProperty("user.home"), File.separator, NEW_JPMML_MODEL);
-
- private static final Logger logger =
LoggerFactory.getLogger(JPMMLVisitor.class);
- static final String JPMML_MODEL_PACKAGE_BASE = "org.jpmml.model";
- static final String DMG_PMML_MODEL_PACKAGE_BASE = "org.dmg.pmml";
- final JavaType.Class originalInstantiatedType;
- final JavaType targetInstantiatedType;
-
- private static final String FIELD_NAME_FQDN = "org.dmg.pmml.FieldName";
- private static final String MODEL_NAME_FQDN = "org.dmg.pmml.Model";
- private static final String MINING_FUNCTION_NAME_FQDN =
"org.dmg.pmml.MiningFunction";
- private static final String MINING_SCHEMA_NAME_FQDN =
"org.dmg.pmml.MiningSchema";
-
- private static final String NUMERIC_PREDICTOR_FQDN =
"org.dmg.pmml.regression.NumericPredictor";
-
- private static final String CATEGORICAL_PREDICTOR_FQDN =
"org.dmg.pmml.regression.CategoricalPredictor";
-
- private static final List<String> GET_NAME_TO_GET_FIELD_CLASSES =
Arrays.asList(NUMERIC_PREDICTOR_FQDN,
- CATEGORICAL_PREDICTOR_FQDN);
-
- private static final String DATADICTIONARY_FQDN =
"org.dmg.pmml.DataDictionary";
-
- private static final Map<String, RemovedListTuple>
REMOVED_LIST_FROM_INSTANTIATION = Map.of(DATADICTIONARY_FQDN,
- new RemovedListTuple("addDataFields",
JavaType.buildType("org.dmg.pmml.DataField")));
-
-
- private static final J.Identifier STRING_IDENTIFIER = new
J.Identifier(Tree.randomId(), Space.build(" ", Collections.emptyList()),
Markers.EMPTY, "String", JavaType.buildType(String.class.getCanonicalName()),
null);
-
- private static final J.Identifier PREDICTOR_GET_FIELD_IDENTIFIER = new
J.Identifier(Tree.randomId(), Space.EMPTY, Markers.EMPTY, "getField",
JavaType.Primitive.String, null);
-
-
- private static final JavaType LIST_JAVA_TYPE =
JavaType.buildType(List.class.getCanonicalName());
-
- private static final JavaType.Parameterized LIST_GENERIC_JAVA_TYPE = new
JavaType.Parameterized(null, (JavaType.FullyQualified) LIST_JAVA_TYPE,
List.of(JavaType.GenericTypeVariable.Primitive.String));
-
- private static final JavaParser NEW_JPMMLMODEL_JAVAPARSER =
getNewJPMMLJavaParser();
-
- private final JavaTemplate requireMiningFunctionTemplate =
JavaTemplate.builder(this::getCursor,
- "@Override\n" +
- " public MiningFunction requireMiningFunction()
{\n" +
- " return null;\n" +
- " }\n")
- .javaParser(() -> NEW_JPMMLMODEL_JAVAPARSER)
- .build();
-
- private final JavaTemplate requireMiningSchemaTemplate =
JavaTemplate.builder(this::getCursor,
- "@Override\n" +
- " public MiningSchema requireMiningSchema()
{\n" +
- " return null;\n" +
- " }\n")
- .javaParser(() -> NEW_JPMMLMODEL_JAVAPARSER)
- .build();
-
-
- public JPMMLVisitor(String oldInstantiatedFullyQualifiedTypeName, String
newInstantiatedFullyQualifiedTypeName) {
- this.originalInstantiatedType =
JavaType.ShallowClass.build(oldInstantiatedFullyQualifiedTypeName);
- this.targetInstantiatedType =
JavaType.buildType(newInstantiatedFullyQualifiedTypeName);
- }
-
-
- @Override
- public J visitBinary(J.Binary binary, ExecutionContext executionContext) {
- logger.trace("visitBinary {}", binary);
- Expression left = (Expression) super.visitExpression(binary.getLeft(),
executionContext);
- Expression right = (Expression)
super.visitExpression(binary.getRight(), executionContext);
- binary = binary
- .withLeft(left)
- .withRight(right);
- return super.visitBinary(binary, executionContext);
- }
-
- @Override
- public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration
classDecl, ExecutionContext executionContext) {
- if (extendsModel(classDecl)) {
- classDecl = addMissingMethod(classDecl, "requireMiningFunction",
requireMiningFunctionTemplate);
- classDecl = addMissingMethod(classDecl, "requireMiningSchema",
requireMiningSchemaTemplate);
- }
- return (J.ClassDeclaration) super.visitClassDeclaration(classDecl,
executionContext);
- }
-
- @Override
- public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu,
ExecutionContext executionContext) {
- logger.trace("visitCompilationUnit {}", cu);
- String cuName = cu.getSourcePath().toString();
- boolean toMigrate = toMigrate(cu.getImports());
- if (!toMigrate) {
- logger.info("Skipping {}", cuName);
- return cu;
- } else {
- logger.info("Going to migrate {}", cuName);
- }
- try {
- cu = (J.CompilationUnit) super.visitCompilationUnit(cu,
executionContext);
- maybeAddImport(targetInstantiatedType.toString());
- maybeAddImport(MINING_FUNCTION_NAME_FQDN);
- maybeAddImport(MINING_SCHEMA_NAME_FQDN);
- maybeRemoveImport(FIELD_NAME_FQDN);
- cu = (J.CompilationUnit) new ChangeType(FIELD_NAME_FQDN,
String.class.getCanonicalName(), false)
- .getVisitor()
- .visitCompilationUnit(cu, executionContext);
- return cu;
- } catch (Throwable t) {
- logger.error("Failed to visit {}", cu, t);
- return cu;
- }
- }
-
- @Override
- public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext
executionContext) {
- logger.trace("visitMethodInvocation {}", method);
- if (isFieldNameCreate(method)) {
- Expression createArgument = method.getArguments().get(0);
- createArgument = (Expression) super.visit(createArgument,
executionContext);
- return createArgument;
- }
- if (useFieldNameGetValue(method)) {
- return method.getSelect();
- }
- if (isFieldNameGetNameToGetFieldMapped(method)) {
- JavaType.Method methodType = method
- .getMethodType()
- .withReturnType(JavaType.Primitive.String);
- return method
- .withName(PREDICTOR_GET_FIELD_IDENTIFIER)
- .withMethodType(methodType);
- }
- if (hasFieldNameParameter(method)) {
- JavaType.Method methodType = method.getMethodType()
-
.withParameterTypes(Collections.singletonList(JavaType.Primitive.String));
- return method.withMethodType(methodType);
- }
- return super.visitMethodInvocation(method, executionContext);
- }
-
-
- @Override
- public J visitNewClass(J.NewClass newClass, ExecutionContext
executionContext) {
- logger.trace("visitNewClass {}", newClass);
- J toReturn = replaceInstantiation(newClass);
- if (toReturn != newClass) {
- return toReturn;
- } else {
- return super.visitNewClass(newClass, executionContext);
- }
- }
-
- @Override
- public J.VariableDeclarations.NamedVariable
visitVariable(J.VariableDeclarations.NamedVariable variable, ExecutionContext
executionContext) {
- logger.trace("visitVariable {}", variable);
- if (variable.getType() != null &&
variable.getType().toString().equals(FIELD_NAME_FQDN)) {
- variable = variable
- .withType(JavaType.Primitive.String)
-
.withVariableType(variable.getVariableType().withType(JavaType.Primitive.String));
- }
- return (J.VariableDeclarations.NamedVariable)
super.visitVariable(variable, executionContext);
- }
-
- @Override
- public J.VariableDeclarations
visitVariableDeclarations(J.VariableDeclarations multiVariable,
- ExecutionContext
executionContext) {
- logger.trace("visitVariableDeclarations {}", multiVariable);
- multiVariable = (J.VariableDeclarations)
super.visitVariableDeclarations(multiVariable, executionContext);
- if (multiVariable.getTypeAsFullyQualified() != null &&
-
multiVariable.getTypeAsFullyQualified().getFullyQualifiedName() != null &&
-
multiVariable.getTypeAsFullyQualified().getFullyQualifiedName().equals(FIELD_NAME_FQDN))
{
- multiVariable =
multiVariable.withType(JavaType.Primitive.String).withTypeExpression(STRING_IDENTIFIER);
- }
- return multiVariable;
- }
-
- /**
- * Return <code>true</code> if the given <code>J.ClassDeclaration</code>
extends it extends <code>org.dmg.pmml.Model</code>
- *
- * @param classDecl
- * @return
- */
- protected boolean extendsModel(J.ClassDeclaration classDecl) {
- return classDecl.getType() != null &&
- classDecl.getType().getSupertype() != null &&
-
MODEL_NAME_FQDN.equals(classDecl.getType().getSupertype().getFullyQualifiedName());
- }
-
- /**
- * Return <code>true</code> if the given <code>J.CompilationUnit</code>
contains an {@see #FIELD_NAME_FQDN} import,
- * <code>false</code> otherwise
- *
- * @param toCheck
- * @return
- */
- protected boolean hasFieldNameImport(J.CompilationUnit toCheck) {
- return toCheck.getImports().stream().anyMatch(this::isFieldNameImport);
- }
-
- /**
- * Return <code>true</code> if the given <code>J.Import</code> is {@see
#FIELD_NAME_FQDN},
- * <code>false</code> otherwise
- *
- * @param toCheck
- * @return
- */
- protected boolean isFieldNameImport(J.Import toCheck) {
- return isSpecificImport(toCheck, FIELD_NAME_FQDN);
- }
-
- /**
- * Return <code>true</code> if the given <code>J.Import</code> is fqdn,
- * <code>false</code> otherwise
- *
- * @param toCheck
- * @return
- */
- protected boolean isSpecificImport(J.Import toCheck, String fqdn) {
- return (toCheck.getQualid().getType() instanceof JavaType.Class) &&
((JavaType.Class)
toCheck.getQualid().getType()).getFullyQualifiedName().equals(fqdn);
- }
-
- /**
- * Add a <code>J.MethodDeclaration</code> to the given
<code>J.ClassDeclaration</code> if the latter does not contain the
<b>searchedMethod</b>,
- * otherwise it does nothing
- *
- * @param classDecl
- * @param searchedMethod
- * @param javaTemplate
- * @return
- */
- protected J.ClassDeclaration addMissingMethod(J.ClassDeclaration
classDecl, String searchedMethod, JavaTemplate javaTemplate) {
- if (methodExists(classDecl, searchedMethod)) {
- return classDecl;
- }
- classDecl = classDecl.withBody(
- classDecl.getBody().withTemplate(
- javaTemplate,
- classDecl.getBody().getCoordinates().lastStatement()
- ));
- return classDecl;
- }
-
- /**
- * Return <code>true</code> if the given <code>J.ClassDeclaration</code>
contains the <b>searchedMethod</b>,
- * <code>false</code> otherwise
- *
- * @param toCheck
- * @param searchedMethod
- * @return
- */
- protected boolean methodExists(J.ClassDeclaration toCheck, String
searchedMethod) {
- return toCheck.getBody().getStatements().stream()
- .filter(statement -> statement instanceof J.MethodDeclaration)
- .map(J.MethodDeclaration.class::cast)
- .anyMatch(methodDeclaration ->
methodDeclaration.getName().getSimpleName().equals(searchedMethod));
- }
-
- /**
- * @param newClass
- * @return
- */
- protected Expression replaceInstantiation(J.NewClass newClass) {
- logger.trace("replaceInstantiation {}", newClass);
- newClass = replaceOriginalToTargetInstantiation(newClass);
- return replaceInstantiationListRemoved(newClass);
- }
-
- /**
- * Returns a new <code>J.NewClass</code> with the
<code>originalInstantiatedType</code>
- * replaced by <code>targetInstantiatedType</code>, if present.
- * Otherwise, returns the original newClass.
- *
- * @param newClass
- * @return
- */
- protected J.NewClass replaceOriginalToTargetInstantiation(J.NewClass
newClass) {
- logger.trace("replaceOriginalToTargetInstantiation {}", newClass);
- if (newClass.getType() != null &&
newClass.getType().toString().equals(originalInstantiatedType.toString())) {
- JavaType.Method updatedMethod =
updateMethodToTargetInstantiatedType(newClass.getConstructorType());
- TypeTree typeTree =
updateTypeTreeToTargetInstantiatedType(newClass);
- newClass = newClass.withConstructorType(updatedMethod)
- .withClazz(typeTree);
- }
- return newClass;
- }
-
- /**
- * Returns a new <code>J.NewClass</code> with the
<code>originalInstantiatedType</code>
- * replaced by <code>targetInstantiatedType</code>, if present.
- * Otherwise, returns the original newClass.
- *
- * @param newClass
- * @return
- */
- protected Expression replaceInstantiationListRemoved(J.NewClass newClass) {
- logger.trace("replaceInstantiationListRemoved {}", newClass);
- Optional<RemovedListTuple> optionalRetrieved =
getRemovedListTuple(newClass);
- if (optionalRetrieved.isPresent()) {
- RemovedListTuple removedListTuple = optionalRetrieved.get();
- return removedListTuple.getJMethod(newClass);
- } else {
- return newClass;
- }
- }
-
- /**
- * Return <code>Optional<RemovedListTuple></code> if the given
<code>J.NewClass</code> constructor has not the <b>List</b> anymore
- * <code>Optional.empty()</code> otherwise
- *
- * @param toCheck
- * @return
- */
- protected Optional<RemovedListTuple> getRemovedListTuple(J.NewClass
toCheck) {
- return toCheck.getType() != null &&
-
REMOVED_LIST_FROM_INSTANTIATION.containsKey(toCheck.getType().toString()) &&
- toCheck.getArguments() != null &&
- !toCheck.getArguments().isEmpty()
- && (toCheck.getArguments().get(0) instanceof J.Identifier) ?
Optional.of(REMOVED_LIST_FROM_INSTANTIATION.get(toCheck.getType().toString()))
: Optional.empty();
- }
-
- /**
- * Return <code>true</code> if the given <code>J.MethodInvocation</code>
is <b>FieldName.create(...)</b>,
- * <code>false</code> otherwise
- *
- * @param toCheck
- * @return
- */
- protected boolean isFieldNameCreate(J.MethodInvocation toCheck) {
- return toCheck.getType() != null &&
toCheck.getType().toString().equals(FIELD_NAME_FQDN) &&
toCheck.getName().toString().equals("create");
- }
-
- /**
- * Return <code>true</code> if the given <code>J.MethodInvocation</code>
is <b>FieldName.create(...)</b>,
- * <code>false</code> otherwise
- *
- * @param toCheck
- * @return
- */
- protected boolean hasFieldNameParameter(J.MethodInvocation toCheck) {
- return toCheck.getMethodType() != null &&
- toCheck.getMethodType().getParameterTypes() != null &&
-
toCheck.getMethodType().getParameterTypes().stream().anyMatch(javaType ->
javaType != null && javaType.toString().equals(FIELD_NAME_FQDN));
- }
-
- /**
- * Return <code>true</code> if the given <code>J.MethodInvocation</code>
is <b>#FieldName(_any_).getName(...)</b>,
- * and the modified method is <b>String(_any_).getField(...)</b>
- * <code>false</code> otherwise.
- * Mapped elements are defined in {@link #GET_NAME_TO_GET_FIELD_CLASSES}
- *
- * @param toCheck
- * @return
- */
- protected boolean isFieldNameGetNameToGetFieldMapped(J.MethodInvocation
toCheck) {
- return toCheck.getMethodType() != null &&
- toCheck.getMethodType().getDeclaringType() != null &&
-
GET_NAME_TO_GET_FIELD_CLASSES.contains(toCheck.getMethodType().getDeclaringType().toString())
&&
- toCheck.getName().toString().equals("getName");
- }
-
-
- /**
- * Return <code>true</code> if the given <code>J.MethodInvocation</code>
invokes <b>(_field_).getValue()</b>,
- * <code>false</code> otherwise
- *
- * @param toCheck
- * @return
- */
- protected boolean useFieldNameGetValue(J.MethodInvocation toCheck) {
- return toCheck.getMethodType() != null &&
- toCheck.getMethodType().getDeclaringType() != null &&
-
toCheck.getMethodType().getDeclaringType().getFullyQualifiedName() != null &&
-
toCheck.getMethodType().getDeclaringType().getFullyQualifiedName().equals(FIELD_NAME_FQDN)
&& toCheck.getMethodType().getName().equals("getValue");
- }
-
- protected boolean toMigrate(List<J.Import> imports) {
- return imports.stream()
- .anyMatch(anImport ->
anImport.getPackageName().startsWith(JPMML_MODEL_PACKAGE_BASE) ||
-
anImport.getPackageName().startsWith(DMG_PMML_MODEL_PACKAGE_BASE));
- }
-
- protected JavaType.Method
updateMethodToTargetInstantiatedType(JavaType.Method oldMethodType) {
- if (oldMethodType != null) {
- JavaType.Method method = oldMethodType;
- method = method.withDeclaringType((JavaType.FullyQualified)
targetInstantiatedType)
- .withReturnType(targetInstantiatedType);
- return method;
- }
- return null;
- }
-
- protected TypeTree updateTypeTreeToTargetInstantiatedType(J.NewClass
newClass) {
- return ((J.Identifier) newClass.getClazz())
- .withSimpleName(((JavaType.ShallowClass)
targetInstantiatedType).getClassName())
- .withType(targetInstantiatedType);
- }
-
- static class RemovedListTuple {
-
- private final String addMethodName;
-
- private final J.Identifier elementIdentifier;
-
- private final JavaType.Array elementArray;
-
- private final J.Identifier elementToArrayIdentifier;
- private final J.Identifier addMethodIdentifier;
-
- public RemovedListTuple(String addMethodName, JavaType
elementJavaType) {
- this.addMethodName = addMethodName;
- elementIdentifier = new J.Identifier(Tree.randomId(),
Space.build(" ", Collections.emptyList()), Markers.EMPTY,
elementJavaType.toString(), elementJavaType, null);
- elementArray = new JavaType.Array(null, elementJavaType);
- JavaType.Parameterized elementListJavaType = new
JavaType.Parameterized(null, (JavaType.FullyQualified) LIST_JAVA_TYPE,
List.of(elementJavaType));
- elementToArrayIdentifier = new J.Identifier(Tree.randomId(),
Space.EMPTY, Markers.EMPTY, "toArray", elementListJavaType, null);
- addMethodIdentifier = new J.Identifier(Tree.randomId(),
Space.EMPTY, Markers.EMPTY, addMethodName, elementListJavaType, null);
- }
-
- public J.MethodInvocation getJMethod(J.NewClass newClass) {
- J.Identifier originalListIdentifier = (J.Identifier)
newClass.getArguments().get(0);
- J.Literal literal = new J.Literal(Tree.randomId(), Space.EMPTY,
Markers.EMPTY, 0, "0", null, JavaType.Primitive.Int);
- J.ArrayDimension arrayDimension = new
J.ArrayDimension(Tree.randomId(), Space.EMPTY, Markers.EMPTY,
JRightPadded.build(literal));
- J.NewArray newArray = new J.NewArray(Tree.randomId(), Space.EMPTY,
Markers.EMPTY, elementIdentifier, Collections.singletonList(arrayDimension),
null, elementArray);
- JavaType.Method methodType = new JavaType.Method(null, 1025,
LIST_GENERIC_JAVA_TYPE, "toArray",
- elementArray,
- Collections.singletonList("arg0"),
- Collections.singletonList(elementArray), null, null);
- J.MethodInvocation toArrayInvocation = new
J.MethodInvocation(Tree.randomId(), Space.EMPTY, Markers.EMPTY, null, null,
- elementToArrayIdentifier,
- JContainer.build(Collections.emptyList()),
- methodType)
- .withSelect(originalListIdentifier)
- .withArguments(Collections.singletonList(newArray));
- JavaType.Method constructorType = newClass.getConstructorType()
- .withParameterTypes(Collections.emptyList())
- .withParameterNames(Collections.emptyList());
- J.NewClass noArgClass =
newClass.withArguments(Collections.emptyList())
- .withConstructorType(constructorType);
-
- JavaType.Method addMethodInvocation = new JavaType.Method(null,
1025,
- (JavaType.FullyQualified)
JavaType.buildType(noArgClass.getType().toString()),
- addMethodName,
- JavaType.Primitive.Void,
- Collections.singletonList("toAdd"),
- Collections.singletonList(elementArray), null, null);
-
- return new J.MethodInvocation(Tree.randomId(), Space.EMPTY,
Markers.EMPTY, null, null,
- addMethodIdentifier,
- JContainer.build(Collections.emptyList()),
- addMethodInvocation)
- .withSelect(noArgClass)
-
.withArguments(Collections.singletonList(toArrayInvocation));
- }
- }
-
- private static JavaParser getNewJPMMLJavaParser() {
- List<Path> paths = JavaParser.runtimeClasspath();
- Path newJpmmlModel = getNewJPMMLModelPath();
- paths.add(newJpmmlModel);
- return JavaParser.fromJavaVersion()
- .classpath(paths)
- .logCompilationWarningsAndErrors(true).build();
- }
-
- public static Path getNewJPMMLModelPath() {
- // The new version is expected to have been downloaded by maven plugin
at validate phase
- File defaultTarget = new File(NEW_JPMML_MAVEN_PATH);
- if (!defaultTarget.exists()) {
- throw new RuntimeException("Failed to find " +
NEW_JPMML_MAVEN_PATH);
- }
- return defaultTarget.toPath();
- }
-
-}
diff --git
a/jpmml-migration-recipe/src/main/resources/META-INF/rewrite/rewrite.yml
b/jpmml-migration-recipe/src/main/resources/META-INF/rewrite/rewrite.yml
deleted file mode 100644
index 188d842ec0..0000000000
--- a/jpmml-migration-recipe/src/main/resources/META-INF/rewrite/rewrite.yml
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you 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
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# 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.
-#
-
----
-type: specs.openrewrite.org/v1beta/recipe
-name: org.kie.openrewrite.recipe.jpmml.JPMMLRecipe
-recipeList:
- - org.openrewrite.java.ChangeType:
- oldFullyQualifiedTypeName: org.jpmml.model.inlinetable.OutputCell
- newFullyQualifiedTypeName: org.jpmml.model.cells.OutputCell
- ignoreDefinition: true
- - org.openrewrite.java.ChangeType:
- oldFullyQualifiedTypeName: org.jpmml.model.inlinetable.InputCell
- newFullyQualifiedTypeName: org.jpmml.model.cells.InputCell
- ignoreDefinition: true
- - org.kie.openrewrite.recipe.jpmml.JPMMLCodeRecipe:
- oldInstantiatedFullyQualifiedTypeName: org.dmg.pmml.ScoreDistribution
- newInstantiatedFullyQualifiedTypeName:
org.dmg.pmml.ComplexScoreDistribution
- - org.openrewrite.maven.ChangePropertyValue:
- key: version.org.jpmml.model
- newValue: 1.6.4
-
-# This creates issue with generic imports like
-#
-# import org.kie.api.event.rule.*;
-# import org.kie.api.event.rule.AgendaGroupPoppedEvent;
-# import org.kie.api.event.rule.AgendaGroupPushedEvent;
-# import org.kie.api.event.rule.RuleFlowGroupActivatedEvent;
-# import org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent;
-#
-# origin:
https://github.com/kiegroup/drools/blob/main/drools-core/src/main/java/org/drools/core/event/DefaultAgendaEventListener.java
-#
-# - org.openrewrite.java.RemoveUnusedImports
\ No newline at end of file
diff --git
a/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/CommonTestingUtilities.java
b/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/CommonTestingUtilities.java
deleted file mode 100644
index 52d7596ae2..0000000000
---
a/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/CommonTestingUtilities.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.kie.openrewrite.recipe.jpmml;
-
-import org.openrewrite.ExecutionContext;
-import org.openrewrite.InMemoryExecutionContext;
-import org.openrewrite.java.Java11Parser;
-import org.openrewrite.java.JavaIsoVisitor;
-import org.openrewrite.java.JavaParser;
-import org.openrewrite.java.tree.Expression;
-import org.openrewrite.java.tree.J;
-
-import java.nio.file.Path;
-import java.util.List;
-import java.util.Optional;
-
-public class CommonTestingUtilities {
-
- private static final List<Path> paths = JavaParser.runtimeClasspath();
-
- private CommonTestingUtilities() {
- }
-
- public static J.CompilationUnit getCompilationUnitFromClassSource(String
classSource) {
- JavaParser parser = Java11Parser.builder()
- .classpath(paths)
- .logCompilationWarningsAndErrors(true)
- .build();
- return parser.parse(classSource).get(0);
- }
-
- public static Optional<J.Binary> getBinaryFromClassSource(String
classSource,
-
String binaryString) {
- J.CompilationUnit compilationUnit =
getCompilationUnitFromClassSource(classSource);
- TestingVisitor testingVisitor = new TestingVisitor(J.Binary.class,
binaryString);
- testingVisitor.visit(compilationUnit, getExecutionContext(null));
- return (Optional<J.Binary>) testingVisitor.getFoundItem();
- }
-
- public static Optional<J.ClassDeclaration>
getClassDeclarationFromClassSource(String classSource,
-
String className) {
- J.CompilationUnit compilationUnit =
getCompilationUnitFromClassSource(classSource);
- TestingVisitor testingVisitor = new
TestingVisitor(J.ClassDeclaration.class, className);
- testingVisitor.visit(compilationUnit, getExecutionContext(null));
- return (Optional<J.ClassDeclaration>) testingVisitor.getFoundItem();
- }
-
- public static Optional<J.ClassDeclaration>
getClassDeclarationFromCompilationUnit(J.CompilationUnit compilationUnit,
-
String className) {
- TestingVisitor testingVisitor = new
TestingVisitor(J.ClassDeclaration.class, className);
- testingVisitor.visit(compilationUnit, getExecutionContext(null));
- return (Optional<J.ClassDeclaration>) testingVisitor.getFoundItem();
- }
-
- public static Optional<J.MethodInvocation>
getMethodInvocationFromClassSource(String classSource,
-
String methodInvocation) {
- J.CompilationUnit compilationUnit =
getCompilationUnitFromClassSource(classSource);
- TestingVisitor testingVisitor = new
TestingVisitor(J.MethodInvocation.class, methodInvocation);
- testingVisitor.visit(compilationUnit, getExecutionContext(null));
- return (Optional<J.MethodInvocation>) testingVisitor.getFoundItem();
- }
-
- public static Optional<J.NewClass> getNewClassFromClassSource(String
classSource,
- String
fqdnInstantiatedClass) {
- J.CompilationUnit compilationUnit =
getCompilationUnitFromClassSource(classSource);
- TestingVisitor testingVisitor = new TestingVisitor(J.NewClass.class,
fqdnInstantiatedClass);
- testingVisitor.visit(compilationUnit, getExecutionContext(null));
- return (Optional<J.NewClass>) testingVisitor.getFoundItem();
- }
-
- public static Optional<J.VariableDeclarations>
getVariableDeclarationsFromClassSource(String classSource,
-
String variableDeclaration) {
- J.CompilationUnit compilationUnit =
getCompilationUnitFromClassSource(classSource);
- TestingVisitor testingVisitor = new
TestingVisitor(J.VariableDeclarations.class, variableDeclaration);
- testingVisitor.visit(compilationUnit, getExecutionContext(null));
- return (Optional<J.VariableDeclarations>)
testingVisitor.getFoundItem();
- }
-
- public static Optional<Expression> getExpressionFromClassSource(String
classSource, String expression) {
- J.CompilationUnit compilationUnit =
getCompilationUnitFromClassSource(classSource);
- TestingVisitor testingVisitor = new TestingVisitor(Expression.class,
expression);
- testingVisitor.visit(compilationUnit, getExecutionContext(null));
- return (Optional<Expression>) testingVisitor.getFoundItem();
- }
-
- public static Optional<Expression>
getExpressionFromCompilationUnit(J.CompilationUnit compilationUnit, String
expression) {
- TestingVisitor testingVisitor = new TestingVisitor(Expression.class,
expression);
- testingVisitor.visit(compilationUnit, getExecutionContext(null));
- return (Optional<Expression>) testingVisitor.getFoundItem();
- }
-
- public static List<J.Import> getImportsFromClassSource(String classSource)
{
- J.CompilationUnit compilationUnit =
getCompilationUnitFromClassSource(classSource);
- return compilationUnit.getImports();
- }
-
-
- public static ExecutionContext getExecutionContext(Throwable expected) {
- return new InMemoryExecutionContext(throwable ->
org.assertj.core.api.Assertions.assertThat(throwable).isEqualTo(expected));
- }
-
- private static class TestingVisitor extends
JavaIsoVisitor<ExecutionContext> {
-
- private final Class<? extends J> SEARCHED_J;
- private final String SEARCHED_STRING;
-
- private Optional<? extends J> foundItem;
-
- public TestingVisitor(Class<? extends J> SEARCHED_J, String
SEARCHED_STRING) {
- this.SEARCHED_J = SEARCHED_J;
- this.SEARCHED_STRING = SEARCHED_STRING;
- foundItem = Optional.empty();
- }
-
- public Optional<? extends J> getFoundItem() {
- return foundItem;
- }
-
- @Override
- public J.Binary visitBinary(J.Binary binary, ExecutionContext
executionContext) {
- if (SEARCHED_J.equals(J.Binary.class) &&
binary.toString().equals(SEARCHED_STRING)) {
- foundItem = Optional.of(binary);
- return binary;
- } else {
- return super.visitBinary(binary, executionContext);
- }
- }
-
- @Override
- public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu,
ExecutionContext executionContext) {
- if (SEARCHED_J.equals(J.CompilationUnit.class)) {
- foundItem = Optional.of(cu);
- return cu;
- } else {
- return super.visitCompilationUnit(cu, executionContext);
- }
- }
-
- @Override
- public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration
classDecl, ExecutionContext executionContext) {
- if (SEARCHED_J.equals(J.ClassDeclaration.class) &&
classDecl.getSimpleName().equals(SEARCHED_STRING)) {
- foundItem = Optional.of(classDecl);
- return classDecl;
- } else {
- return super.visitClassDeclaration(classDecl,
executionContext);
- }
- }
-
- @Override
- public J.MethodInvocation visitMethodInvocation(J.MethodInvocation
method, ExecutionContext executionContext) {
- if (SEARCHED_J.equals(J.MethodInvocation.class) &&
method.toString().startsWith(SEARCHED_STRING + "(")) {
- foundItem = Optional.of(method);
- return method;
- } else {
- return super.visitMethodInvocation(method, executionContext);
- }
- }
-
- @Override
- public J.NewClass visitNewClass(J.NewClass newClass, ExecutionContext
executionContext) {
- if (SEARCHED_J.equals(J.NewClass.class) &&
newClass.getType().toString().equals(SEARCHED_STRING)) {
- foundItem = Optional.of(newClass);
- return newClass;
- } else {
- return super.visitNewClass(newClass, executionContext);
- }
- }
-
- @Override
- public J.VariableDeclarations
visitVariableDeclarations(J.VariableDeclarations multiVariable,
ExecutionContext executionContext) {
- if (SEARCHED_J.equals(J.VariableDeclarations.class) &&
multiVariable.toString().startsWith(SEARCHED_STRING)) {
- foundItem = Optional.of(multiVariable);
- return multiVariable;
- } else {
- return super.visitVariableDeclarations(multiVariable,
executionContext);
- }
- }
-
- @Override
- public Expression visitExpression(Expression expression,
ExecutionContext executionContext) {
- if (SEARCHED_J.equals(Expression.class) &&
expression.toString().equals(SEARCHED_STRING)) {
- foundItem = Optional.of(expression);
- return expression;
- } else {
- return super.visitExpression(expression, executionContext);
- }
- }
- }
-}
diff --git
a/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/JPMMLCodeRecipeTest.java
b/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/JPMMLCodeRecipeTest.java
deleted file mode 100644
index ea72a3e8c6..0000000000
---
a/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/JPMMLCodeRecipeTest.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.kie.openrewrite.recipe.jpmml;
-
-import org.intellij.lang.annotations.Language;
-import org.junit.jupiter.api.Test;
-import org.openrewrite.java.Assertions;
-import org.openrewrite.java.Java11Parser;
-import org.openrewrite.java.JavaParser;
-import org.openrewrite.test.RecipeSpec;
-import org.openrewrite.test.RewriteTest;
-
-import java.nio.file.Path;
-import java.util.List;
-
-class JPMMLCodeRecipeTest implements RewriteTest {
-
- @Override
- public void defaults(RecipeSpec spec) {
- List<Path> paths = JavaParser.runtimeClasspath();
- spec.recipe(new JPMMLCodeRecipe("org.dmg.pmml.ScoreDistribution",
-
"org.dmg.pmml.ComplexScoreDistribution"));
- spec.parser(Java11Parser.builder()
- .classpath(paths)
- .logCompilationWarningsAndErrors(true));
- }
-
- @Test
- void removeFieldNameCreate() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "class FooBar {\n" +
- "static void method() {\n" +
- "System.out.println(FieldName.create(\"OUTPUT_\"));\n" +
- "}\n" +
- "}";
- @Language("java")
- String after = "package com.yourorg;\n" +
- "class FooBar {\n" +
- "static void method() {\n" +
- "System.out.println(\"OUTPUT_\");\n" +
- "}\n" +
- "}";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
- @Test
- public void changeInstantiation_ScoreDistribution() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "import org.dmg.pmml.ScoreDistribution;\n" +
- "class FooBar {\n" +
- "static void method() {\n" +
- "ScoreDistribution toReturn = new ScoreDistribution();\n" +
- "}\n" +
- "}";
- @Language("java")
- String after = "package com.yourorg;\n" +
- "import org.dmg.pmml.ComplexScoreDistribution;\n" +
- "import org.dmg.pmml.ScoreDistribution;\n" +
- "\n" +
- "class FooBar {\n" +
- "static void method() {\n" +
- "ScoreDistribution toReturn = new
ComplexScoreDistribution();\n" +
- "}\n" +
- "}";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
- @Test
- public void changeInstantiation_DataDictionary() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "import java.util.List;\n" +
- "import org.dmg.pmml.DataDictionary;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "class FooBar {\n" +
- "static void method(List<DataField> dataFields) {\n" +
- "DataDictionary dataDictionary = new
DataDictionary(dataFields);\n" +
- "}\n" +
- "}";
- @Language("java")
- String after = "package com.yourorg;\n" +
- "import java.util.List;\n" +
- "import org.dmg.pmml.DataDictionary;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "class FooBar {\n" +
- "static void method(List<DataField> dataFields) {\n" +
- "DataDictionary dataDictionary = new
DataDictionary().addDataFields(dataFields.toArray(new
org.dmg.pmml.DataField[0]));\n" +
- "}\n" +
- "}";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
- @Test
- public void changeUsage_FieldNameCreateWithBinary() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.DataField;\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "\n" +
- "public class Stub {\n" +
- " \n" +
- " public void hello(DataField dataField) {\n" +
- " System.out.println(FieldName.create(\"OUTPUT_\" +
dataField.getName().getValue()));\n" +
- " }\n" +
- "\n" +
- "}";
- @Language("java")
- String after = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.DataField;\n" +
- "\n" +
- "public class Stub {\n" +
- " \n" +
- " public void hello(DataField dataField) {\n" +
- " System.out.println(\"OUTPUT_\"
+dataField.getName());\n" +
- " }\n" +
- "\n" +
- "}";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
-}
\ No newline at end of file
diff --git
a/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/JPMMLRecipeTest.java
b/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/JPMMLRecipeTest.java
deleted file mode 100644
index f8ea02630d..0000000000
---
a/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/JPMMLRecipeTest.java
+++ /dev/null
@@ -1,424 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.kie.openrewrite.recipe.jpmml;
-
-import org.intellij.lang.annotations.Language;
-import org.junit.jupiter.api.Test;
-import org.openrewrite.java.Assertions;
-import org.openrewrite.java.Java11Parser;
-import org.openrewrite.java.JavaParser;
-import org.openrewrite.test.RecipeSpec;
-import org.openrewrite.test.RewriteTest;
-
-import java.io.InputStream;
-import java.nio.file.Path;
-import java.util.List;
-
-import static
org.kie.openrewrite.recipe.jpmml.JPMMLVisitor.getNewJPMMLModelPath;
-
-
-public class JPMMLRecipeTest implements RewriteTest {
-
- private static final String JPMML_RECIPE_NAME =
"org.kie.openrewrite.recipe.jpmml.JPMMLRecipe";
-
- @Override
- public void defaults(RecipeSpec spec) {
- List<Path> paths = JavaParser.runtimeClasspath();
- Path newJpmmlModel = getNewJPMMLModelPath();
- paths.add(newJpmmlModel);
- try (InputStream inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/rewrite/rewrite.yml"))
{
- assert inputStream != null;
- spec.recipe(inputStream, JPMML_RECIPE_NAME);
- spec.parser(Java11Parser.builder()
- .classpath(paths)
- .logCompilationWarningsAndErrors(true)
- );
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void changeInstantiation_DataDictionary() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "\n" +
- "import java.util.List;\n" +
- "import org.dmg.pmml.DataDictionary;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "\n" +
- "public class Stub {\n" +
- "\n" +
- " public String hello(List<DataField> dataFields) {\n" +
- " new DataDictionary(dataFields);\n" +
- " return \"Hello from com.yourorg.FooLol!\";\n" +
- " }\n" +
- "\n" +
- "}";
- @Language("java")
- String after = "package com.yourorg;\n" +
- "\n" +
- "import java.util.List;\n" +
- "import org.dmg.pmml.DataDictionary;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "\n" +
- "public class Stub {\n" +
- "\n" +
- " public String hello(List<DataField> dataFields) {\n" +
- " new
DataDictionary().addDataFields(dataFields.toArray(new
org.dmg.pmml.DataField[0]));\n" +
- " return \"Hello from com.yourorg.FooLol!\";\n" +
- " }\n" +
- "\n" +
- "}";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
- @Test
- public void addMissingMethods_Model() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.LocalTransformations;\n" +
- "import org.dmg.pmml.MathContext;\n" +
- "import org.dmg.pmml.MiningFunction;\n" +
- "import org.dmg.pmml.MiningSchema;\n" +
- "import org.dmg.pmml.Model;\n" +
- "import org.dmg.pmml.Visitor;\n" +
- "import org.dmg.pmml.VisitorAction;\n" +
- "\n" +
- "public class SubModel extends Model {\n" +
- " @Override\n" +
- " public String getModelName() {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setModelName(String modelName) {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public MiningFunction getMiningFunction() {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setMiningFunction(MiningFunction
miningFunction) {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public String getAlgorithmName() {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setAlgorithmName(String algorithmName) {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public boolean isScorable() {\n" +
- " return false;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setScorable(Boolean scorable) {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public MathContext getMathContext() {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setMathContext(MathContext mathContext) {\n"
+
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public MiningSchema getMiningSchema() {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setMiningSchema(MiningSchema miningSchema)
{\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public LocalTransformations getLocalTransformations()
{\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setLocalTransformations(LocalTransformations
localTransformations) {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public VisitorAction accept(Visitor visitor) {\n" +
- " return null;\n" +
- " }\n" +
- "}\n";
- @Language("java")
- String after = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.LocalTransformations;\n" +
- "import org.dmg.pmml.MathContext;\n" +
- "import org.dmg.pmml.MiningFunction;\n" +
- "import org.dmg.pmml.MiningSchema;\n" +
- "import org.dmg.pmml.Model;\n" +
- "import org.dmg.pmml.Visitor;\n" +
- "import org.dmg.pmml.VisitorAction;\n" +
- "\n" +
- "public class SubModel extends Model {\n" +
- " @Override\n" +
- " public String getModelName() {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setModelName(String modelName) {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public MiningFunction getMiningFunction() {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setMiningFunction(MiningFunction
miningFunction) {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public String getAlgorithmName() {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setAlgorithmName(String algorithmName) {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public boolean isScorable() {\n" +
- " return false;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setScorable(Boolean scorable) {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public MathContext getMathContext() {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setMathContext(MathContext mathContext) {\n"
+
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public MiningSchema getMiningSchema() {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setMiningSchema(MiningSchema miningSchema)
{\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public LocalTransformations getLocalTransformations()
{\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public Model setLocalTransformations(LocalTransformations
localTransformations) {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public VisitorAction accept(Visitor visitor) {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public MiningFunction requireMiningFunction() {\n" +
- " return null;\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public MiningSchema requireMiningSchema() {\n" +
- " return null;\n" +
- " }\n" +
- "}\n";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
- @Test
- public void changeImports() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "import org.jpmml.model.inlinetable.InputCell;\n" +
- "class FooBar {\n" +
- "static public void method() {\n" +
- "InputCell input = null;\n" +
- "}\n" +
- "}";
- @Language("java")
- String after = "package com.yourorg;\n" +
- "\n" +
- "import org.jpmml.model.cells.InputCell;\n" +
- "\n" +
- "class FooBar {\n" +
- "static public void method() {\n" +
- "InputCell input = null;\n" +
- "}\n" +
- "}";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
- @Test
- public void changeFieldNameVariableDeclaration() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "class FooBar {\n" +
- "static public void method() {\n" +
- "FieldName fieldName = FieldName.create(\"OUTPUT_\");\n" +
- "}\n" +
- "}";
- @Language("java")
- String after = "package com.yourorg;\n" +
- "class FooBar {\n" +
- "static public void method() {\n" +
- " String fieldName =\"OUTPUT_\";\n" +
- "}\n" +
- "}";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
- @Test
- public void changeFieldNameVariableNull() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "class FooBar {\n" +
- "static public void method() {\n" +
- "FieldName fieldName = null;\n" +
- "}\n" +
- "}";
- @Language("java")
- String after = "package com.yourorg;\n" +
- "class FooBar {\n" +
- "static public void method() {\n" +
- " String fieldName = null;\n" +
- "}\n" +
- "}";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
- @Test
- public void removeFieldNameCreate() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "class FooBar {\n" +
- "static public void method() {\n" +
- "System.out.println(FieldName.create(\"OUTPUT_\"));\n" +
- "}\n" +
- "}";
- @Language("java")
- String after = "package com.yourorg;\n" +
- "class FooBar {\n" +
- "static public void method() {\n" +
- "System.out.println(\"OUTPUT_\");\n" +
- "}\n" +
- "}";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
- @Test
- public void removeFieldNameGetValue() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "import org.dmg.pmml.OutputField;\n" +
- "class FooBar {\n" +
- "static public void method(OutputField toConvert) {\n" +
- "final String name = toConvert.getName() != null ?
toConvert.getName().getValue() : null;\n" +
- "}\n" +
- "}";
- String after = "package com.yourorg;\n" +
- "import org.dmg.pmml.OutputField;\n" +
- "class FooBar {\n" +
- "static public void method(OutputField toConvert) {\n" +
- "final String name = toConvert.getName() != null
?toConvert.getName() : null;\n" +
- "}\n" +
- "}";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
-
- @Test
- public void changeInstantiation_ScoreDistribution() {
- @Language("java")
- String before = "package com.yourorg;\n" +
- "import org.dmg.pmml.ScoreDistribution;\n" +
- "class FooBar {\n" +
- "static public void method() {\n" +
- "ScoreDistribution toReturn = new ScoreDistribution();\n" +
- "}\n" +
- "}";
- @Language("java")
- String after = "package com.yourorg;\n" +
- "import org.dmg.pmml.ComplexScoreDistribution;\n" +
- "import org.dmg.pmml.ScoreDistribution;\n" +
- "\n" +
- "class FooBar {\n" +
- "static public void method() {\n" +
- "ScoreDistribution toReturn = new
ComplexScoreDistribution();\n" +
- "}\n" +
- "}";
- rewriteRun(
- Assertions.java(before, after)
- );
- }
-
-}
\ No newline at end of file
diff --git
a/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/JPMMLVisitorTest.java
b/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/JPMMLVisitorTest.java
deleted file mode 100644
index 8fd003771c..0000000000
---
a/jpmml-migration-recipe/src/test/java/org/kie/openrewrite/recipe/jpmml/JPMMLVisitorTest.java
+++ /dev/null
@@ -1,1148 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.kie.openrewrite.recipe.jpmml;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.openrewrite.Cursor;
-import org.openrewrite.ExecutionContext;
-import org.openrewrite.java.JavaTemplate;
-import org.openrewrite.java.tree.Expression;
-import org.openrewrite.java.tree.J;
-import org.openrewrite.java.tree.JavaType;
-import org.openrewrite.java.tree.TypeTree;
-
-import java.util.Collections;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.kie.openrewrite.recipe.jpmml.CommonTestingUtilities.*;
-
-class JPMMLVisitorTest {
-
- private JPMMLVisitor jpmmlVisitor;
-
- @BeforeEach
- public void init() {
- jpmmlVisitor = new JPMMLVisitor("org.dmg.pmml.ScoreDistribution",
"org.dmg.pmml.ComplexScoreDistribution");
- }
-
- @Test
- public void visitBinary_StringFieldNameGetValue() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello(DataField dataField) {\n" +
- " FieldName.create(\"DER_\" +
dataField.getName().getValue());\n" +
- " }\n" +
- "}";
- String binary = "\"DER_\" + dataField.getName().getValue()";
- J.Binary toTest = getBinaryFromClassSource(classTested, binary)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.Binary " + binary));
- J retrieved = jpmmlVisitor.visitBinary(toTest,
getExecutionContext(null));
- String expected = "\"DER_\" +dataField.getName()";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.Binary.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitBinary_FieldNameGetValueString() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello(DataField dataField) {\n" +
- " FieldName.create(dataField.getName().getValue() +
\"DER_\");\n" +
- " }\n" +
- "}";
- String binary = "dataField.getName().getValue() + \"DER_\"";
- J.Binary toTest = getBinaryFromClassSource(classTested, binary)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.Binary " + binary));
- J retrieved = jpmmlVisitor.visitBinary(toTest,
getExecutionContext(null));
- String expected = "dataField.getName() + \"DER_\"";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.Binary.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitBinary_FieldNameGetValueFieldNameGetValue() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello(DataField dataField) {\n" +
- " FieldName.create(dataField.getName().getValue() +
dataField.getName().getValue());\n" +
- " }\n" +
- "}";
- String binary = "dataField.getName().getValue() +
dataField.getName().getValue()";
- J.Binary toTest = getBinaryFromClassSource(classTested, binary)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.Binary " + binary));
- J retrieved = jpmmlVisitor.visitBinary(toTest,
getExecutionContext(null));
- String expected = "dataField.getName() +dataField.getName()";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.Binary.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitMethodInvocation_NumericPredictorGetName() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.regression.NumericPredictor;\n" +
- "\n" +
- "class Stub {\n" +
- " public String bye(NumericPredictor numericPredictor) {\n"
+
- " FieldName fieldName = numericPredictor.getName();\n" +
- " return fieldName.getValue();\n" +
- " }" +
- "}";
- String methodTested = "numericPredictor.getName";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, methodTested)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation numericPredictor.getName()"));
- assertThat(toTest).isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitMethodInvocation(toTest,
executionContext);
- String expected = "numericPredictor.getField()";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitMethodInvocation_CategoricalPredictorGetName() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.regression.CategoricalPredictor;\n" +
- "\n" +
- "class Stub {\n" +
- " public String bye(CategoricalPredictor
categoricalPredictor) {\n" +
- " FieldName fieldName =
categoricalPredictor.getName();\n" +
- " return fieldName.getValue();\n" +
- " }" +
- "}";
- String methodTested = "categoricalPredictor.getName";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, methodTested)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation categoricalPredictor.getName()"));
- assertThat(toTest).isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitMethodInvocation(toTest,
executionContext);
- String expected = "categoricalPredictor.getField()";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitMethodInvocation_FieldNameCreate() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello() {\n" +
- " System.out.println(FieldName.create(\"OUTPUT_\"));\n"
+
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- String expressionTested = "FieldName.create";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, expressionTested)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation FieldName.create(\"OUTPUT_\")"));
- assertThat(toTest)
- .isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitMethodInvocation(toTest,
executionContext);
- String expected = "OUTPUT_";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.Literal.class);
- assertThat(((J.Literal) retrieved).getValue()).isEqualTo(expected);
- }
-
- @Test
- public void visitMethodInvocation_FieldNameCreateWithBinary() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.DataField;\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello(DataField dataField) {\n" +
- " System.out.println(FieldName.create(\"OUTPUT_\" +
dataField.getName().getValue()));\n" +
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- String expressionTested = "System.out.println";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, expressionTested)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation System.out.println(FieldName.create(\"OUTPUT_\" +
dataField.getName().getValue()))"));
- assertThat(toTest)
- .isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitMethodInvocation(toTest,
executionContext);
- String expected = "System.out.println(\"OUTPUT_\"
+dataField.getName())";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class);
- assertThat(((J.MethodInvocation) retrieved)).hasToString(expected);
- }
-
- @Test
- public void visitMethodInvocation_AccessFieldName() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.DataType;\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.MiningField;\n" +
- "import org.dmg.pmml.mining.MiningModel;\n" +
- "import org.dmg.pmml.OpType;\n" +
- "import org.dmg.pmml.OutputField;\n" +
- "import org.dmg.pmml.Target;\n" +
- "\n" +
- "class Stub {\n" +
- " public String bye() {\n" +
- " MiningField toReturn = new
MiningField(FieldName.create(new String(\"TestingFIeld\")));\n" +
- " OutputField toConvert = new
OutputField(FieldName.create(\"FIELDNAME\"), OpType.CATEGORICAL," +
- " DataType.BOOLEAN);\n" +
- " final String name = toConvert.getName() != null ?
toConvert.getName().getValue() : null;\n" +
- " Target target = new Target();\n" +
- " String field = target.getField().getValue();\n" +
- " String key = target.getKey().getValue();\n" +
- " return name;\n" +
- " }" +
- "}";
- String methodTested = "toConvert.getName().getValue";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, methodTested)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation toConvert.getName().getValue"));
- assertThat(toTest).isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitMethodInvocation(toTest,
executionContext);
- String expected = "toConvert.getName()";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class)
- .hasToString(expected);
-
- methodTested = "target.getField().getValue";
- toTest = getMethodInvocationFromClassSource(classTested, methodTested)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation target.getField().getValue"));
- assertThat(toTest).isNotNull();
- retrieved = jpmmlVisitor.visitMethodInvocation(toTest,
executionContext);
- expected = "target.getField()";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class)
- .hasToString(expected);
-
- methodTested = "target.getKey().getValue";
- toTest = getMethodInvocationFromClassSource(classTested, methodTested)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation target.getKey().getValue"));
- assertThat(toTest).isNotNull();
- retrieved = jpmmlVisitor.visitMethodInvocation(toTest,
executionContext);
- expected = "target.getKey()";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitMethodInvocation_FieldNameGetValue() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import java.util.List;\n" +
- "import java.util.Objects;\n" +
- "\n" +
- "import org.dmg.pmml.DataField;\n" +
- "import org.dmg.pmml.Field;\n" +
- "\n" +
- "public class Stub {\n" +
- "\n" +
- " private List<Field<?>> fields;\n" +
- "\n" +
- " public void bye() {\n" +
- " DataField targetDataField = this.fields.stream()\n" +
- " .filter(DataField.class::isInstance)\n" +
- " .map(DataField.class::cast)\n" +
- " .filter(field ->
Objects.equals(getTargetFieldName(), field.getName().getValue()))\n" +
- " .findFirst().orElse(null);\n" +
- " }\n" +
- " public String getTargetFieldName() {\n" +
- " return \"targetDataFieldName\";\n" +
- " }\n" +
- "}";
- String expressionTested = "field.getName().getValue";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, expressionTested)
- .orElseThrow(() -> new RuntimeException("Failed to find
Expression FieldName.create(\"OUTPUT_\")"));
- assertThat(toTest)
- .isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitMethodInvocation(toTest,
executionContext);
- String expected = "field.getName()";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitMethodInvocation_FieldNameGetNameToGetFieldMapped() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.regression.CategoricalPredictor;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello(CategoricalPredictor
categoricalPredictor) {\n" +
- " FieldName fieldName =
categoricalPredictor.getName();\n" +
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- String methodInvocation = "categoricalPredictor.getName";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, methodInvocation)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation categoricalPredictor.getName()"));
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitMethodInvocation(toTest,
executionContext);
- String expected = "categoricalPredictor.getField()";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitMethodInvocation_HasFieldNameParameter() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "import org.dmg.pmml.DerivedField;\n" +
- "import java.util.Objects;\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello(DataField dataField) {\n" +
- " DerivedField toReturn = new DerivedField();\n" +
- " toReturn.setName(FieldName.create(\"DER_\" +
dataField.getName().getValue()));\n" +
- " }\n" +
- "}";
- String methodInvocation = "toReturn.setName";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, methodInvocation)
- .orElseThrow(() -> new RuntimeException("Failed to
toReturn.setName"));
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitMethodInvocation(toTest,
executionContext);
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class);
- String expected = "String";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class);
-
assertThat(((J.MethodInvocation)retrieved).getMethodType().getParameterTypes().get(0))
- .hasToString(expected);
- }
-
- @Test
- public void visitNewClass_FieldNameCreate() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.MiningField;\n" +
- "\n" +
- "public class Stub {\n" +
- "\n" +
- " public String hello() {\n" +
- " MiningField toReturn = new
MiningField(FieldName.create(new String(\"TestingField\")));\n" +
- " return \"Hello from com.yourorg.FooLol!\";\n" +
- " }\n" +
- "\n" +
- "}";
- String classInstantiated = "org.dmg.pmml.MiningField";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
classInstantiated)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass org.dmg.pmml.MiningField"));
- assertThat(toTest)
- .isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitNewClass(toTest, executionContext);
- String expected = "new MiningField(new String(\"TestingField\"))";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.NewClass.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitNewClass_AccessFieldNameInsideConstructor() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.Target;\n" +
- "\n" +
- "class Stub {\n" +
- " public String bye() {\n" +
- " Target target = new Target();\n" +
- " String name = new
String(target.getKey().getValue());\n" +
- " return name;\n" +
- " }" +
- "}";
- String classInstantiated = "java.lang.String";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
classInstantiated)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass java.lang.String"));
- assertThat(toTest).isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitNewClass(toTest, executionContext);
- String expected = "new String(target.getKey())";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.NewClass.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitNewClass_ScoreDistribution() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.ScoreDistribution;\n" +
- "\n" +
- "public class Stub {\n" +
- "\n" +
- " public String hello() {\n" +
- " ScoreDistribution scoreDistribution = new
ScoreDistribution();\n" +
- " return \"Hello from com.yourorg.FooLol!\";\n" +
- " }\n" +
- "\n" +
- "}";
- String classInstantiated = "org.dmg.pmml.ScoreDistribution";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
classInstantiated)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass org.dmg.pmml.ScoreDistribution"));
- assertThat(toTest)
- .isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitNewClass(toTest, executionContext);
- String expected = "new ComplexScoreDistribution()";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.NewClass.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitNewClass_DataDictionary() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import java.util.List;\n" +
- "import org.dmg.pmml.DataDictionary;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "\n" +
- "public class Stub {\n" +
- "\n" +
- " public String hello(List<DataField> dataFields) {\n" +
- " DataDictionary dataDictionary = new
DataDictionary(dataFields);\n" +
- " return \"Hello from com.yourorg.FooLol!\";\n" +
- " }\n" +
- "\n" +
- "}";
- String classInstantiated = "org.dmg.pmml.DataDictionary";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
classInstantiated)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass org.dmg.pmml.DataDictionary"));
- assertThat(toTest)
- .isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J retrieved = jpmmlVisitor.visitNewClass(toTest, executionContext);
- String expected = "new
DataDictionary().addDataFields(dataFields.toArray(new
org.dmg.pmml.DataField[0]))";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class)
- .hasToString(expected);
- }
-
- @Test
- public void visitVariableDeclarations_AccessFieldNameAsSecondParameter() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import java.util.List;\n" +
- "import java.util.Objects;\n" +
- "\n" +
- "import org.dmg.pmml.DataField;\n" +
- "import org.dmg.pmml.Field;\n" +
- "\n" +
- "public class Stub {\n" +
- "\n" +
- " private List<Field<?>> fields;\n" +
- "\n" +
- " public void bye() {\n" +
- " DataField targetDataField = this.fields.stream()\n" +
- " .filter(DataField.class::isInstance)\n" +
- " .map(DataField.class::cast)\n" +
- " .filter(field ->
Objects.equals(getTargetFieldName(), field.getName().getValue()))\n" +
- " .findFirst().orElse(null);\n" +
- " }\n" +
- " public String getTargetFieldName() {\n" +
- " return \"targetDataFieldName\";\n" +
- " }\n" +
- "}";
- String variableDeclaration = "DataField targetDataField = ";
- J.VariableDeclarations toTest =
getVariableDeclarationsFromClassSource(classTested, variableDeclaration)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.VariableDeclarations DataField targetDataField = "));
- assertThat(toTest).isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J.VariableDeclarations retrieved =
jpmmlVisitor.visitVariableDeclarations(toTest, executionContext);
- String expected = "DataField targetDataField = this.fields.stream()\n"
+
- " .filter(DataField.class::isInstance)\n" +
- " .map(DataField.class::cast)\n" +
- " .filter(field ->
Objects.equals(getTargetFieldName(),field.getName()))\n" +
- " .findFirst().orElse(null)";
- assertThat(retrieved).isNotNull()
- .hasToString(expected);
- }
-
- @Test
- public void visitVariableDeclarations_FieldName() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello() {\n" +
- " FieldName fieldName =
FieldName.create(\"OUTPUT_\");\n" +
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- String variableDeclaration = "FieldName fieldName =
FieldName.create(\"OUTPUT_\")";
- J.VariableDeclarations toTest =
getVariableDeclarationsFromClassSource(classTested, variableDeclaration)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.VariableDeclarations FieldName fieldName = FieldName.create(\"OUTPUT_\")"));
- assertThat(toTest)
- .isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J.VariableDeclarations retrieved =
jpmmlVisitor.visitVariableDeclarations(toTest, executionContext);
- String expected = "String fieldName =\"OUTPUT_\"";
- assertThat(retrieved)
- .isNotNull()
- .hasToString(expected);
- }
-
- @Test
- public void visitVariableDeclarations_CategoricalPredictorGetName() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.regression.CategoricalPredictor;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello(CategoricalPredictor
categoricalPredictor) {\n" +
- " FieldName fieldName =
categoricalPredictor.getName();\n" +
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- String variableDeclaration = "FieldName fieldName =
categoricalPredictor.getName()";
- J.VariableDeclarations toTest =
getVariableDeclarationsFromClassSource(classTested, variableDeclaration)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.VariableDeclarations FieldName fieldName = categoricalPredictor.getName()"));
- assertThat(toTest)
- .isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J.VariableDeclarations retrieved =
jpmmlVisitor.visitVariableDeclarations(toTest, executionContext);
- String expected = "String fieldName = categoricalPredictor.getField()";
- assertThat(retrieved)
- .isNotNull()
- .hasToString(expected);
- }
-
- @Test
- public void visitVariableDeclarations_NumericPredictorGetName() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.regression.NumericPredictor;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello(NumericPredictor numericPredictor)
{\n" +
- " FieldName fieldName = numericPredictor.getName();\n" +
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- String variableDeclaration = "FieldName fieldName =
numericPredictor.getName()";
- J.VariableDeclarations toTest =
getVariableDeclarationsFromClassSource(classTested, variableDeclaration)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.VariableDeclarations FieldName fieldName = FieldName.create(\"OUTPUT_\")"));
- assertThat(toTest)
- .isNotNull();
- ExecutionContext executionContext = getExecutionContext(null);
- J.VariableDeclarations retrieved =
jpmmlVisitor.visitVariableDeclarations(toTest, executionContext);
- String expected = "String fieldName = numericPredictor.getField()";
- assertThat(retrieved)
- .isNotNull()
- .hasToString(expected);
- }
-
- @Test
- public void hasFieldNameImport_true() {
- String classTested = "package com.yourorg;\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import java.util.List;\n" +
- "class FooBar {\n" +
- "};";
- J.CompilationUnit toTest =
getCompilationUnitFromClassSource(classTested);
- assertThat(jpmmlVisitor.hasFieldNameImport(toTest))
- .isTrue();
- }
-
- @Test
- public void hasFieldNameImport_false() {
- String classTested = "package com.yourorg;\n" +
- "import java.util.List;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "class FooBar {\n" +
- "};";
- J.CompilationUnit toTest =
getCompilationUnitFromClassSource(classTested);
- assertThat(jpmmlVisitor.hasFieldNameImport(toTest))
- .isFalse();
- }
-
- @Test
- public void isFieldNameImport_true() {
- String classTested = "package com.yourorg;\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "class FooBar {\n" +
- "};";
- J.Import toTest = getImportsFromClassSource(classTested).get(0);
- assertThat(jpmmlVisitor.isFieldNameImport(toTest))
- .isTrue();
- }
-
- @Test
- public void isFieldNameImport_false() {
- String classTested = "package com.yourorg;\n" +
- "import java.util.List;\n" +
- "class FooBar {\n" +
- "};";
- J.Import toTest = getImportsFromClassSource(classTested).get(0);
- assertThat(jpmmlVisitor.isFieldNameImport(toTest))
- .isFalse();
- }
-
- @Test
- public void addMissingMethod_Add() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello() {\n" +
- " System.out.println(\"Hello\");\n" +
- " }\n" +
- "}";
- String className = "Stub";
- J.CompilationUnit cu = getCompilationUnitFromClassSource(classTested);
- J.ClassDeclaration toTest = getClassDeclarationFromCompilationUnit(cu,
className)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.ClassDeclaration Stub"));
- Cursor cursor = new Cursor(jpmmlVisitor.getCursor(), cu);
- JavaTemplate requireMiningSchemaTemplate = JavaTemplate.builder(() ->
cursor,
- " public boolean requireMiningSchema() {\n" +
- " return null;\n" +
- " }\n")
- .build();
- J.ClassDeclaration retrieved = jpmmlVisitor.addMissingMethod(toTest,
"requireMiningSchema", requireMiningSchemaTemplate);
- assertThat(retrieved)
- .isEqualTo(toTest);
- assertThat(jpmmlVisitor.methodExists(retrieved, "requireMiningSchema"))
- .isTrue();
- }
-
- @Test
- public void addMissingMethod_NotAdd() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello() {\n" +
- " System.out.println(\"Hello\");\n" +
- " }\n" +
- "}";
- String className = "Stub";
- J.ClassDeclaration toTest =
getClassDeclarationFromClassSource(classTested, className)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.ClassDeclaration Stub"));
- assertThat(jpmmlVisitor.addMissingMethod(toTest, "hello", null))
- .isEqualTo(toTest);
- }
-
- @Test
- public void methodExists_true() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello() {\n" +
- " System.out.println(\"Hello\");\n" +
- " }\n" +
- "}";
- String className = "Stub";
- J.ClassDeclaration toTest =
getClassDeclarationFromClassSource(classTested, className)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.ClassDeclaration Stub"));
- assertThat(jpmmlVisitor.methodExists(toTest, "hello"))
- .isTrue();
- }
-
- @Test
- public void methodExists_false() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello() {\n" +
- " System.out.println(\"Hello\");\n" +
- " }\n" +
- "}";
- String className = "Stub";
- J.ClassDeclaration toTest =
getClassDeclarationFromClassSource(classTested, className)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.ClassDeclaration Stub"));
- assertThat(jpmmlVisitor.methodExists(toTest, "notHello"))
- .isFalse();
- }
-
- @Test
- public void replaceOriginalToTargetInstantiation_replaced() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.ScoreDistribution;\n" +
- "\n" +
- "public class Stub {\n" +
- "\n" +
- " public String hello() {\n" +
- " ScoreDistribution scoreDistribution = new
ScoreDistribution();\n" +
- " return \"Hello from com.yourorg.FooLol!\";\n" +
- " }\n" +
- "\n" +
- "}";
- String classInstantiated = "org.dmg.pmml.ScoreDistribution";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
classInstantiated)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass org.dmg.pmml.ScoreDistribution"));
- assertThat(toTest)
- .isNotNull();
- J.NewClass retrieved =
jpmmlVisitor.replaceOriginalToTargetInstantiation(toTest);
- String expected = "new ComplexScoreDistribution()";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.NewClass.class)
- .hasToString(expected);
- }
-
- @Test
- public void replaceOriginalToTargetInstantiation_notReplaced() {
- String classTested = "package com.yourorg;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "class FooBar {\n" +
- "static void method() {\n" +
- " DataField dataField = new DataField();\n" +
- "}\n" +
- "}";
- String instantiatedClass = "org.dmg.pmml.DataField";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
instantiatedClass)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass org.dmg.pmml.DataField"));
- assertThat(toTest)
- .isNotNull();
- Expression retrieved =
jpmmlVisitor.replaceOriginalToTargetInstantiation(toTest);
- assertThat(retrieved)
- .isNotNull()
- .isEqualTo(toTest);
- }
-
- @Test
- public void replaceInstantiationListRemoved_replaced() {
- String classTested = "package com.yourorg;\n" +
- "import java.util.List;\n" +
- "import org.dmg.pmml.DataDictionary;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "class FooBar {\n" +
- "static void method(List<DataField> dataFields) {\n" +
- "DataDictionary dataDictionary = new
DataDictionary(dataFields);\n" +
- "}\n" +
- "}";
- String instantiatedClass = "org.dmg.pmml.DataDictionary";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
instantiatedClass)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass org.dmg.pmml.DataDictionary"));
- assertThat(toTest)
- .isNotNull();
- Expression retrieved =
jpmmlVisitor.replaceInstantiationListRemoved(toTest);
- String expected = "new
DataDictionary().addDataFields(dataFields.toArray(new
org.dmg.pmml.DataField[0]))";
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.MethodInvocation.class)
- .hasToString(expected);
- }
-
- @Test
- public void replaceInstantiationListRemoved_notReplaced() {
- String classTested = "package com.yourorg;\n" +
- "import org.dmg.pmml.ScoreDistribution;\n" +
- "class FooBar {\n" +
- "static void method() {\n" +
- " ScoreDistribution scoreDistribution = new
ScoreDistribution();\n" +
- "}\n" +
- "}";
- String instantiatedClass = "org.dmg.pmml.ScoreDistribution";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
instantiatedClass)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass org.dmg.pmml.DataDictionary"));
- assertThat(toTest)
- .isNotNull();
- Expression retrieved =
jpmmlVisitor.replaceInstantiationListRemoved(toTest);
- assertThat(retrieved)
- .isNotNull()
- .isEqualTo(toTest);
- }
-
- @Test
- public void getRemovedListTuple_present() {
- String classTested = "package com.yourorg;\n" +
- "import java.util.List;\n" +
- "import org.dmg.pmml.DataDictionary;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "class FooBar {\n" +
- "static void method(List<DataField> dataFields) {\n" +
- "DataDictionary dataDictionary = new
DataDictionary(dataFields);\n" +
- "}\n" +
- "}";
- String instantiatedClass = "org.dmg.pmml.DataDictionary";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
instantiatedClass)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass org.dmg.pmml.DataDictionary"));
- assertThat(toTest)
- .isNotNull();
- assertThat(jpmmlVisitor.getRemovedListTuple(toTest))
- .isPresent();
- }
-
- @Test
- public void getRemovedListTuple_notPresent() {
- String classTested = "package com.yourorg;\n" +
- "import org.dmg.pmml.ScoreDistribution;\n" +
- "class FooBar {\n" +
- "static void method() {\n" +
- " ScoreDistribution scoreDistribution = new
ScoreDistribution();\n" +
- "}\n" +
- "}";
- String instantiatedClass = "org.dmg.pmml.ScoreDistribution";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
instantiatedClass)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass org.dmg.pmml.ScoreDistribution"));
- assertThat(toTest)
- .isNotNull();
- assertThat(jpmmlVisitor.getRemovedListTuple(toTest))
- .isNotPresent();
- }
-
- @Test
- public void isFieldNameCreate_true() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello() {\n" +
- " System.out.println(FieldName.create(\"OUTPUT_\"));\n"
+
- " }\n" +
- "}";
- String expressionTested = "FieldName.create";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, expressionTested)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation FieldName.create(\"OUTPUT_\")"));
- assertThat(toTest)
- .isNotNull();
- assertThat(jpmmlVisitor.isFieldNameCreate(toTest))
- .isTrue();
- }
-
- @Test
- public void isFieldNameCreate_false() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello() {\n" +
- " System.out.println(FieldName.create(\"OUTPUT_\"));\n"
+
- " }\n" +
- "}";
- String expressionTested = "System.out.println";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, expressionTested)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation System.out.println(FieldName.create(\"OUTPUT_\"))"));
- assertThat(toTest)
- .isNotNull();
- assertThat(jpmmlVisitor.isFieldNameCreate(toTest))
- .isFalse();
- }
-
- @Test
- public void hasFieldNameParameter_true() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "import org.dmg.pmml.DerivedField;\n" +
- "import java.util.Objects;\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello(DataField dataField) {\n" +
- " DerivedField toReturn = new DerivedField();\n" +
- " toReturn.setName(FieldName.create(\"DER_\" +
dataField.getName().getValue()));\n" +
- " }\n" +
- "}";
- String methodInvocation = "toReturn.setName";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, methodInvocation)
- .orElseThrow(() -> new RuntimeException("Failed to
toReturn.setName"));
- assertThat(jpmmlVisitor.hasFieldNameParameter(toTest))
- .isTrue();
- }
-
- @Test
- public void hasFieldNameParameter_false() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "import java.util.Objects;\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello(DataField field) {\n" +
- " Objects.equals(null, field.getName().getValue());\n" +
- " }\n" +
- "}";
- String methodInvocation = "Objects.equals";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, methodInvocation)
- .orElseThrow(() -> new RuntimeException("Failed to find
Objects.equals"));
- assertThat(jpmmlVisitor.hasFieldNameParameter(toTest))
- .isFalse();
- classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import java.util.Objects;\n" +
- "\n" +
- "class Stub {\n" +
- " public void hello(FieldName fieldName) {\n" +
- " Objects.equals(null, fieldName.getValue());\n" +
- " }\n" +
- "}";
- toTest = getMethodInvocationFromClassSource(classTested,
methodInvocation)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation numericPredictor.getName()"));
- assertThat(jpmmlVisitor.hasFieldNameParameter(toTest))
- .isFalse();
- }
-
- @Test
- public void isFieldNameGetNameToGetFieldMapped_true() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.regression.CategoricalPredictor;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello(CategoricalPredictor
categoricalPredictor) {\n" +
- " FieldName fieldName =
categoricalPredictor.getName();\n" +
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- String methodInvocation = "categoricalPredictor.getName";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, methodInvocation)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation categoricalPredictor.getName()"));
-
assertThat(jpmmlVisitor.isFieldNameGetNameToGetFieldMapped(toTest)).isTrue();
- classTested ="package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.regression.NumericPredictor;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello(NumericPredictor numericPredictor)
{\n" +
- " FieldName fieldName = numericPredictor.getName();\n" +
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- methodInvocation = "numericPredictor.getName";
- toTest = getMethodInvocationFromClassSource(classTested,
methodInvocation)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation numericPredictor.getName()"));
-
assertThat(jpmmlVisitor.isFieldNameGetNameToGetFieldMapped(toTest)).isTrue();
- }
-
- @Test
- public void isFieldNameGetNameToGetFieldMapped_false() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello(DataField dataField) {\n" +
- " FieldName fieldName = dataField.getName();\n" +
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- String methodInvocation = "dataField.getName";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, methodInvocation)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation dataField.getName()"));
-
assertThat(jpmmlVisitor.isFieldNameGetNameToGetFieldMapped(toTest)).isFalse();
- }
-
- @Test
- public void useFieldNameGetValue_true() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.DataField;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello(DataField field) {\n" +
- " System.out.println(field.getName().getValue());\n" +
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- String methodInvocation = "field.getName().getValue";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, methodInvocation)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation field.getName().getValue()"));
- assertThat(jpmmlVisitor.useFieldNameGetValue(toTest)).isTrue();
- classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello(FieldName field) {\n" +
- " System.out.println(field.getValue());\n" +
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- methodInvocation = "field.getValue";
- toTest = getMethodInvocationFromClassSource(classTested,
methodInvocation)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation field.getValue()"));
- assertThat(jpmmlVisitor.useFieldNameGetValue(toTest)).isTrue();
- }
-
- @Test
- public void useFieldNameGetValue_false() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.DataField;\n" +
- "\n" +
- "class Stub {\n" +
- " public String hello(DataField field) {\n" +
- " System.out.println(field.getName().getValue());\n" +
- " return \"Hello from com.yourorg.FooBar!\";\n" +
- " }\n" +
- "}";
- String methodInvocation = "System.out.println";
- J.MethodInvocation toTest =
getMethodInvocationFromClassSource(classTested, methodInvocation)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.MethodInvocation System.out.println()"));
- assertThat(jpmmlVisitor.useFieldNameGetValue(toTest)).isFalse();
- }
-
- @Test
- public void toMigrate_False() {
- String classTested = "package com.yourorg;\n" +
- "import java.util.List;\n" +
- "import java.util.Map;\n" +
- "class FooBar {\n" +
- "};";
- List<J.Import> toTest = getImportsFromClassSource(classTested);
- assertThat(jpmmlVisitor.toMigrate(toTest))
- .isFalse();
- assertThat(toTest).hasSize(2);
- }
-
- @Test
- public void toMigrate_True() {
- String classTested = "package com.yourorg;\n" +
- "import java.util.List;\n" +
- "import org.dmg.pmml.FieldName;\n" +
- "class FooBar {\n" +
- "};";
- List<J.Import> toTest = getImportsFromClassSource(classTested);
- assertThat(jpmmlVisitor.toMigrate(toTest))
- .isTrue();
- classTested = "package com.yourorg;\n" +
- "import java.util.List;\n" +
- "import org.jpmml.model.inlinetable.InputCell;\n" +
- "class FooBar {\n" +
- "};";
- toTest = getImportsFromClassSource(classTested);
- assertThat(jpmmlVisitor.toMigrate(toTest))
- .isTrue();
- }
-
- @Test
- public void updateMethodToTargetInstantiatedType() {
- JavaType.Method toTest = new JavaType.Method(null, 1025,
jpmmlVisitor.originalInstantiatedType, "toArray",
- jpmmlVisitor.originalInstantiatedType,
- Collections.emptyList(),
- Collections.emptyList(), null, null);
- JavaType.Method retrieved =
jpmmlVisitor.updateMethodToTargetInstantiatedType(toTest);
-
assertThat(retrieved.getDeclaringType()).isEqualTo(jpmmlVisitor.targetInstantiatedType);
-
assertThat(retrieved.getReturnType()).isEqualTo(jpmmlVisitor.targetInstantiatedType);
- }
-
- @Test
- public void updateTypeTreeToTargetInstantiatedType() {
- String classTested = "package com.yourorg;\n" +
- "\n" +
- "import org.dmg.pmml.ScoreDistribution;\n" +
- "\n" +
- "public class Stub {\n" +
- "\n" +
- " public void hello() {\n" +
- " ScoreDistribution scoreDistribution = new
ScoreDistribution();\n" +
- " }\n" +
- "\n" +
- "}";
- String classInstantiated = "org.dmg.pmml.ScoreDistribution";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
classInstantiated)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass org.dmg.pmml.ScoreDistribution"));
- assertThat(toTest)
- .isNotNull();
- TypeTree retrieved =
jpmmlVisitor.updateTypeTreeToTargetInstantiatedType(toTest);
- assertThat(retrieved)
- .isNotNull()
- .isInstanceOf(J.Identifier.class);
-
assertThat(retrieved.getType()).isEqualTo(jpmmlVisitor.targetInstantiatedType);
- assertThat(((J.Identifier)
retrieved).getSimpleName()).isEqualTo(((JavaType.ShallowClass)
jpmmlVisitor.targetInstantiatedType).getClassName());
- }
-
- @Test
- public void removedListaTuple_getJMethod() {
- JPMMLVisitor.RemovedListTuple removedListTuple = new
JPMMLVisitor.RemovedListTuple("addDataFields",
JavaType.buildType("org.dmg.pmml.DataField"));
- String classTested = "package com.yourorg;\n" +
- "import java.util.List;\n" +
- "import org.dmg.pmml.DataDictionary;\n" +
- "import org.dmg.pmml.DataField;\n" +
- "class FooBar {\n" +
- "static void method(List<DataField> dataFields) {\n" +
- "DataDictionary dataDictionary = new
DataDictionary(dataFields);\n" +
- "}\n" +
- "}";
- String classInstantiated = "org.dmg.pmml.DataDictionary";
- J.NewClass toTest = getNewClassFromClassSource(classTested,
classInstantiated)
- .orElseThrow(() -> new RuntimeException("Failed to find
J.NewClass org.dmg.pmml.DataDictionary"));
- J.MethodInvocation retrieved = removedListTuple.getJMethod(toTest);
- String expected = "new
DataDictionary().addDataFields(dataFields.toArray(new
org.dmg.pmml.DataField[0]))";
- assertThat(retrieved)
- .isNotNull()
- .hasToString(expected);
-
- }
-}
\ No newline at end of file
diff --git a/jpmml-migration-recipe/src/test/resources/logback.xml
b/jpmml-migration-recipe/src/test/resources/logback.xml
deleted file mode 100644
index fb76bdf46b..0000000000
--- a/jpmml-migration-recipe/src/test/resources/logback.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- 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.
-
--->
-<configuration>
-
- <appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
- <encoder>
- <pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %class{36}.%method:%line
- %msg%n</pattern>
- </encoder>
- </appender>
-
- <logger name="org.openrewrite" level="info"/>
- <logger name="org.kie.openrewrite.recipe.jpmml" level="info"/>
-
- <root level="warn">
- <appender-ref ref="consoleAppender" />
- </root>
-
-</configuration>
-
-
diff --git a/pom.xml b/pom.xml
index 581c84bf95..7dcdf4c004 100644
--- a/pom.xml
+++ b/pom.xml
@@ -210,7 +210,6 @@
<module>kie-maven-plugin</module>
<module>kie-archetypes</module>
<module>drools-quarkus-extension</module>
- <module>jpmml-migration-recipe</module>
<module>drools-reliability</module>
<module>drools-drlonyaml-parent</module>
</modules>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]