From fba2eebff4b8d9b1b200bd23d06e56a31c4a503a Mon Sep 17 00:00:00 2001 From: Angelo Heringa <48793053+AngeloHeringa@users.noreply.github.com> Date: Sat, 22 Mar 2025 15:10:30 +0100 Subject: [PATCH 1/6] replace target/source version with release to specify minimum version instead --- pom.xml | 10 +++--- .../RemoveEtagHandlerPipeVisitor.java | 34 ++++++++++++++----- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index c2f3cdf..a1e90f1 100644 --- a/pom.xml +++ b/pom.xml @@ -17,8 +17,7 @@ - 11 - 11 + 16 UTF-8 UTF-8 7.7.7 @@ -511,10 +510,9 @@ maven-compiler-plugin 3.13.0 - 16 - 16 - 17 - 17 + 16 + 16 + 16 -parameters diff --git a/src/main/java/org/frankrewrite/recipes/visitors/RemoveEtagHandlerPipeVisitor.java b/src/main/java/org/frankrewrite/recipes/visitors/RemoveEtagHandlerPipeVisitor.java index cc722f2..e3f7a86 100644 --- a/src/main/java/org/frankrewrite/recipes/visitors/RemoveEtagHandlerPipeVisitor.java +++ b/src/main/java/org/frankrewrite/recipes/visitors/RemoveEtagHandlerPipeVisitor.java @@ -1,3 +1,18 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://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.frankrewrite.recipes.visitors; import org.frankrewrite.recipes.util.TagHandler; @@ -17,29 +32,30 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext executionContext) { ){ List etagHandlers = tag.getContent().stream() .filter(c -> c instanceof Xml.Tag t - &&t.getName().equals("EtagHandlerPipe")) + &&t.getName().equals("EtagHandlerPipe")) // Get all the EtagHandlers in the pipeline .map(Xml.Tag.class::cast).toList(); List resultContent = new ArrayList<>(tag.getContent()); - Map fromToMap = collectPipeForwardPathNameMap(etagHandlers); + Map fromToMap = collectPipeForwardPathNameMap(etagHandlers);// return map of EtagHandler tags and forward path values if name is success for (var entry : fromToMap.entrySet()) { resultContent.remove(entry.getKey()); // Remove etagHandler from pipeline resultContent = resultContent.stream() + // Update the path of the corresponding forwards referring to the found EtagHandlers or check their children recursively until there's no more children .map(content -> updateForwardTagsRecursively(content, entry.getKey(), entry.getValue())) .collect(Collectors.toList()); } if (!fromToMap.isEmpty()) { - Optional apiHandler = resultContent.stream().filter(c -> c instanceof Xml.Tag t && + Optional apiListener = resultContent.stream().filter(c -> c instanceof Xml.Tag t && t.getName().equals("ApiListener")).findFirst().map(Xml.Tag.class::cast); - if (apiHandler.isPresent()) { - Optional attribute = TagHandler.getAttributeFromTagByKey(apiHandler.get(), "updateEtag"); - List attributes = apiHandler.get().getAttributes(); + if (apiListener.isPresent()) {//update the etag and ApiListener attribute + Optional attribute = TagHandler.getAttributeFromTagByKey(apiListener.get(), "updateEtag"); + List attributes = apiListener.get().getAttributes(); attribute.ifPresent(attributes::remove); //language=xml attributes.add(Xml.Tag.build(" ").getAttributes().get(0)); - resultContent.set(resultContent.indexOf(apiHandler.get()), apiHandler.get().withAttributes(attributes)); + resultContent.set(resultContent.indexOf(apiListener.get()), apiListener.get().withAttributes(attributes)); return tag.withContent(resultContent); } } @@ -81,8 +97,8 @@ private Map collectPipeForwardPathNameMap(List etagHan ) .findFirst() .map(Xml.Tag.class::cast) - .flatMap(forwardTag -> TagHandler.getAttributeValueFromTagByKey(forwardTag, "path")) - .orElse("NoMatchingForwardPath") // Default if no match is found + .flatMap(forwardTag -> TagHandler.getAttributeValueFromTagByKey(forwardTag, "path")) // return map of EtagHandler tags and forward path values if name is success + .orElse("NoMatchingForwardPath") )); } } From df5bce12b1c2f6e5f60b1009382bda263eb4e5a5 Mon Sep 17 00:00:00 2001 From: Angelo Heringa Date: Mon, 24 Mar 2025 13:09:10 +0100 Subject: [PATCH 2/6] use frankrunner java versions --- installRecipes.bat | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/installRecipes.bat b/installRecipes.bat index 4c950eb..ca354ac 100644 --- a/installRecipes.bat +++ b/installRecipes.bat @@ -1,14 +1,28 @@ @echo off -set profiles=default 7_4 7_5 7_6 7_7 7_8 7_9 8_0 8_1 8_2 8_3 9_0 +set FRANK_RUNNER_DIR=..\frank-runner\ + +if not exist "%FRANK_RUNNER_DIR%" ( + echo "Frank-runner directory not found: %FRANK_RUNNER_DIR%" + exit /b 1 +) + +set MVN_BAT=%FRANK_RUNNER_DIR%\mvn.bat +if not exist "%MVN_BAT%" ( + echo "mvn.bat not found in frank-runner directory." + exit /b 1 +) + +set profiles=default 7_4 7_5 7_6 7_7 7_8 7_9 8_0 8_1 8_2 8_3 9_0 for %%p in (%profiles%) do ( if "%%p"=="default" ( echo Building with default profile... - call ./mvnw clean package install -U -DargLine="-XX:+EnableDynamicAgentLoading" + call %MVN_BAT% clean package install -U -DargLine="-XX:+EnableDynamicAgentLoading" ) else ( echo Building with profile: %%p - call ./mvnw clean package install -U -P%%p -DargLine="-XX:+EnableDynamicAgentLoading" + call %MVN_BAT% clean package install -U -P%%p -DargLine="-XX:+EnableDynamicAgentLoading" ) ) -pause + +pause \ No newline at end of file From 55c05f369fe699449ba6b8c411b41307d349b7e6 Mon Sep 17 00:00:00 2001 From: Angelo Heringa Date: Mon, 24 Mar 2025 13:22:25 +0100 Subject: [PATCH 3/6] also adapt runrecipes.bat to work with the mvn.bat file from frankrunner --- reciperunner/runRecipes.bat | 43 +++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/reciperunner/runRecipes.bat b/reciperunner/runRecipes.bat index f3d1b63..ea20345 100644 --- a/reciperunner/runRecipes.bat +++ b/reciperunner/runRecipes.bat @@ -1,4 +1,5 @@ @echo off + REM Check if the argument is provided if "%~dp1"=="" ( echo Error: No target directory provided. @@ -16,7 +17,7 @@ set "TARGET_PROFILE=%2" set "SOURCE_VERSION=%3" REM Define the valid version list -set "VALID_VERSIONS=7_3 7_4 7_5 7_6 7_8 7_9 8_0 8_1 8_2 8_3 9_0" +set "VALID_VERSIONS=7_3 7_4 7_5 7_6 7_7 7_8 7_9 8_0 8_1 8_2 8_3 9_0" REM Ensure the target directory exists if not exist "%TARGET_DIR%" ( @@ -30,18 +31,21 @@ if not exist "%SOURCE_DIR%\rewritepom.xml" ( exit /b 1 ) -REM Navigate to the target directory -pushd "%TARGET_DIR%" || ( - echo Error: Failed to navigate to target directory "%TARGET_DIR%". - exit /b 1 -) - REM Copy the pom.xml to the target directory echo Copying pom.xml to target directory... -copy "%SOURCE_DIR%\rewritepom.xml" "rewritepom.xml" +copy "%SOURCE_DIR%\rewritepom.xml" "%TARGET_DIR%\rewritepom.xml" if errorlevel 1 ( echo Error: Failed to copy pom.xml to target directory. - popd + exit /b 1 +) + +REM Define the frank runner directory and mvn.bat location +set "FRANK_RUNNER_DIR=..\..\frank-runner\" +set "MVN_BAT=%FRANK_RUNNER_DIR%\mvn.bat" + +REM Check if mvn.bat exists +if not exist "%MVN_BAT%" ( + echo "mvn.bat not found in frank-runner directory." exit /b 1 ) @@ -49,10 +53,10 @@ REM Run the Maven rewrite:run command echo Running rewrite:run with profile... if "%TARGET_PROFILE%"=="" ( REM No target arg found, running default profile - call mvn rewrite:run -f rewritepom.xml -Dmaven.test.skip=true -Dmaven.main.skip=true + call "%MVN_BAT%" rewrite:run -f "%TARGET_DIR%\rewritepom.xml" -Dmaven.test.skip=true -Dmaven.main.skip=true ) else if "%SOURCE_VERSION%"=="" ( REM No source arg found, but found target profile - call mvn rewrite:run -f rewritepom.xml -Dmaven.test.skip=true -Dmaven.main.skip=true -P%TARGET_PROFILE% + call "%MVN_BAT%" rewrite:run -f "%TARGET_DIR%\rewritepom.xml" -Dmaven.test.skip=true -Dmaven.main.skip=true -P%TARGET_PROFILE% ) else ( REM Both the target and source arg found setlocal enabledelayedexpansion @@ -83,12 +87,11 @@ if "%TARGET_PROFILE%"=="" ( exit /b 1 ) - REM Run recipes for specified profile range for %%V in (%VALID_VERSIONS%) do ( if !SHOULD_DO!==true ( echo Running recipes from profile: %%V - call mvn rewrite:run -f rewritepom.xml -Dmaven.test.skip=true -Dmaven.main.skip=true -P%%V + call "%MVN_BAT%" rewrite:run -f "%TARGET_DIR%\rewritepom.xml" -Dmaven.test.skip=true -Dmaven.main.skip=true -P%%V ) REM When target profile is reached stop executing the rewrite plugin @@ -100,13 +103,13 @@ if "%TARGET_PROFILE%"=="" ( REM When source version is reached start executing the rewrite plugin REM At the end of the for loop to prevent the previous profile from executing if !SHOULD_DO!==false ( - echo Comparing: "%%V" with "%SOURCE_VERSION%" if /i "%%V"=="%SOURCE_VERSION%" ( echo Found matching source version: %%V set SHOULD_DO=true ) ) ) + endlocal ) if errorlevel 1 ( @@ -118,14 +121,12 @@ echo Cleaning up pom.xml... del "%TARGET_DIR%\rewritepom.xml" if errorlevel 1 ( echo Warning: Failed to delete pom.xml in target directory. - popd exit /b 1 ) -cd %TARGET_DIR% -echo Done. Running ant in directory %CD%.. -call ant -REM Return to the original directory -popd +echo Done. Running ant in directory %TARGET_DIR%.. +cd /d "%TARGET_DIR%" +call ant +cd /d "%SOURCE_DIR%" -exit /b 0. \ No newline at end of file +exit /b 0 \ No newline at end of file From a568e2ab7132e7aab7d34592fe5d76d46a2a8b5d Mon Sep 17 00:00:00 2001 From: Angelo Heringa Date: Mon, 24 Mar 2025 13:39:30 +0100 Subject: [PATCH 4/6] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 31ffa34..a805c06 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The project uses OpenRewrite, a framework for programmatically transforming and * **`Limited coverage:`** Currently we don't provide full coverage for all needed migrations. This project is still a work in progress and should be treated as such, don't blindly trust the output before commiting any changes to your project! ## Requirements -* **`Java version requirement:`** To run the install script users need to have at minimum Java version 16 installed. +* **`Required frank-runner installation:`** To run the installRecipes and runRecipes scripts users need to have [frank-runner](https://github.com/wearefrank/frank-runner) installed in the same directory as this project. *Tip: To check which version of Java you have installed currently you can run the following command in powershell or cmd: ```java --version```.* @@ -22,12 +22,12 @@ The project uses OpenRewrite, a framework for programmatically transforming and ```cd rewrite-frankframework``` ### 2. Build the project -Run the install script using the commandline. This might take a while. +Run the installation script using the commandline. This might take a while. ```.\installRecipes.bat``` The batch script installs the recipes using the provided Maven wrapper, so there's no need to have Maven installed locally. ### 3. Run recipes -Run recipes on your Frank!Framework project by providing the relative path to your target project. +Run recipes on your Frank!Framework project by providing the relative or absolute path to your target project. After proving the path you should provide the target version of Frank!Framework to reference the needed recipes. This requires a certain syntax: [major version]_[minor version] (for example "7_4" references the recipes needed to migrate from 7.3.x to 7.4.x). Optionally you can provide your current Frank!Framework version if you want to run a range of recipes, without this argument it only runs a single recipe for the specified minor version. From 82979e43a76eb0bf0b8f8ab8bf509bfb61a1fc74 Mon Sep 17 00:00:00 2001 From: Angelo Heringa Date: Mon, 24 Mar 2025 14:57:56 +0100 Subject: [PATCH 5/6] Update readme, and use mvn.bat for reciperunner --- README.md | 6 ++++-- reciperunner/runRecipes.bat | 42 +++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a805c06..a04bb02 100644 --- a/README.md +++ b/README.md @@ -22,14 +22,16 @@ The project uses OpenRewrite, a framework for programmatically transforming and ```cd rewrite-frankframework``` ### 2. Build the project -Run the installation script using the commandline. This might take a while. +Run the installation script using Command Prompt (applies to the next script, as well). This might take a while. ```.\installRecipes.bat``` The batch script installs the recipes using the provided Maven wrapper, so there's no need to have Maven installed locally. ### 3. Run recipes Run recipes on your Frank!Framework project by providing the relative or absolute path to your target project. After proving the path you should provide the target version of Frank!Framework to reference the needed recipes. This requires a certain syntax: [major version]_[minor version] (for example "7_4" references the recipes needed to migrate from 7.3.x to 7.4.x). -Optionally you can provide your current Frank!Framework version if you want to run a range of recipes, without this argument it only runs a single recipe for the specified minor version. +Optionally you can provide your current Frank!Framework version if you want to run a range of recipes, without this argument it only runs a single recipe for the specified minor version. + +**Note: Not correctly ending the target path with a "\" (for example: ..\..\myproject, instead of ..\..\myproject\) when using runRecipes.bat will run the script in the parent directory (the wrong directory), and could cause unwanted changes to other projects!** ```cd .\reciperunner\``` diff --git a/reciperunner/runRecipes.bat b/reciperunner/runRecipes.bat index ea20345..3fa4ba7 100644 --- a/reciperunner/runRecipes.bat +++ b/reciperunner/runRecipes.bat @@ -7,11 +7,19 @@ if "%~dp1"=="" ( exit /b 1 ) -REM Store the current directory (where pom.xml is assumed to be located) +REM Store the current directory set "SOURCE_DIR=%cd%" REM Store the target directory from the argument set "TARGET_DIR=%~dp1" +REM Normalize forward slashes to backslashes +set "TARGET_DIR=%TARGET_DIR:/=\%" + +REM Ensure TARGET_DIR ends with a backslash +if not "%TARGET_DIR:~-1%"=="\" set "TARGET_DIR=%TARGET_DIR%\" + +ECHO %TARGET_DIR% + REM Store target maven profile from argument set "TARGET_PROFILE=%2" set "SOURCE_VERSION=%3" @@ -25,7 +33,7 @@ if not exist "%TARGET_DIR%" ( exit /b 1 ) -REM Check if pom.xml exists in the current directory +REM Check if rewritepom.xml exists in the source directory if not exist "%SOURCE_DIR%\rewritepom.xml" ( echo Error: rewritepom.xml not found in the current directory %SOURCE_DIR%. exit /b 1 @@ -40,12 +48,12 @@ if errorlevel 1 ( ) REM Define the frank runner directory and mvn.bat location -set "FRANK_RUNNER_DIR=..\..\frank-runner\" +set "FRANK_RUNNER_DIR=%SOURCE_DIR%\..\..\frank-runner" set "MVN_BAT=%FRANK_RUNNER_DIR%\mvn.bat" REM Check if mvn.bat exists if not exist "%MVN_BAT%" ( - echo "mvn.bat not found in frank-runner directory." + echo Error: mvn.bat not found in frank-runner directory at %MVN_BAT%. exit /b 1 ) @@ -53,10 +61,14 @@ REM Run the Maven rewrite:run command echo Running rewrite:run with profile... if "%TARGET_PROFILE%"=="" ( REM No target arg found, running default profile - call "%MVN_BAT%" rewrite:run -f "%TARGET_DIR%\rewritepom.xml" -Dmaven.test.skip=true -Dmaven.main.skip=true + pushd "%TARGET_DIR%" + call "%MVN_BAT%" rewrite:run -f "rewritepom.xml" -Dmaven.test.skip=true -Dmaven.main.skip=true + popd ) else if "%SOURCE_VERSION%"=="" ( REM No source arg found, but found target profile - call "%MVN_BAT%" rewrite:run -f "%TARGET_DIR%\rewritepom.xml" -Dmaven.test.skip=true -Dmaven.main.skip=true -P%TARGET_PROFILE% + pushd "%TARGET_DIR%" + call "%MVN_BAT%" rewrite:run -f "rewritepom.xml" -Dmaven.test.skip=true -Dmaven.main.skip=true -P%TARGET_PROFILE% + popd ) else ( REM Both the target and source arg found setlocal enabledelayedexpansion @@ -79,7 +91,7 @@ if "%TARGET_PROFILE%"=="" ( REM Exit on invalid args with debug message if !TARGET_FOUND!==false ( - echo Target, %TARGET_PROFILE%, not found or reached, either target profile doesn't exists in rewritepom.xml or in version range: %VALID_VERSIONS% + echo Target, %TARGET_PROFILE%, not found or reached, either target profile doesn't exist in rewritepom.xml or in version range: %VALID_VERSIONS% exit /b 1 ) if !SOURCE_FOUND!==false ( @@ -91,7 +103,15 @@ if "%TARGET_PROFILE%"=="" ( for %%V in (%VALID_VERSIONS%) do ( if !SHOULD_DO!==true ( echo Running recipes from profile: %%V - call "%MVN_BAT%" rewrite:run -f "%TARGET_DIR%\rewritepom.xml" -Dmaven.test.skip=true -Dmaven.main.skip=true -P%%V + + REM Change to the target directory before running Maven + pushd "%TARGET_DIR%" + echo Running in directory: %cd% + + call "%MVN_BAT%" rewrite:run -f "rewritepom.xml" -Dmaven.test.skip=true -Dmaven.main.skip=true -P%%V + + REM Return to original directory + popd ) REM When target profile is reached stop executing the rewrite plugin @@ -125,8 +145,8 @@ if errorlevel 1 ( ) echo Done. Running ant in directory %TARGET_DIR%.. -cd /d "%TARGET_DIR%" +pushd "%TARGET_DIR%" call ant -cd /d "%SOURCE_DIR%" +popd -exit /b 0 \ No newline at end of file +exit /b 0 From 03be2b8b4364635ec563e7f035422dd4682c5e24 Mon Sep 17 00:00:00 2001 From: Angelo Heringa Date: Mon, 24 Mar 2025 14:58:21 +0100 Subject: [PATCH 6/6] remove debug messages --- reciperunner/runRecipes.bat | 8 -------- 1 file changed, 8 deletions(-) diff --git a/reciperunner/runRecipes.bat b/reciperunner/runRecipes.bat index 3fa4ba7..990448d 100644 --- a/reciperunner/runRecipes.bat +++ b/reciperunner/runRecipes.bat @@ -12,14 +12,6 @@ set "SOURCE_DIR=%cd%" REM Store the target directory from the argument set "TARGET_DIR=%~dp1" -REM Normalize forward slashes to backslashes -set "TARGET_DIR=%TARGET_DIR:/=\%" - -REM Ensure TARGET_DIR ends with a backslash -if not "%TARGET_DIR:~-1%"=="\" set "TARGET_DIR=%TARGET_DIR%\" - -ECHO %TARGET_DIR% - REM Store target maven profile from argument set "TARGET_PROFILE=%2" set "SOURCE_VERSION=%3"