diff --git a/README.md b/README.md index 31ffa34..a04bb02 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,14 +22,16 @@ 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 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 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. +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/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 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/reciperunner/runRecipes.bat b/reciperunner/runRecipes.bat index f3d1b63..990448d 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. @@ -6,7 +7,7 @@ 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" @@ -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%" ( @@ -24,24 +25,27 @@ 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 ) -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=%SOURCE_DIR%\..\..\frank-runner" +set "MVN_BAT=%FRANK_RUNNER_DIR%\mvn.bat" + +REM Check if mvn.bat exists +if not exist "%MVN_BAT%" ( + echo Error: mvn.bat not found in frank-runner directory at %MVN_BAT%. exit /b 1 ) @@ -49,10 +53,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 rewrite:run -f 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 rewrite:run -f 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 @@ -75,7 +83,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 ( @@ -83,12 +91,19 @@ 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 + + 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 @@ -100,13 +115,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 +133,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 +echo Done. Running ant in directory %TARGET_DIR%.. +pushd "%TARGET_DIR%" +call ant popd -exit /b 0. \ No newline at end of file +exit /b 0 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") )); } }