Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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```.*

Expand All @@ -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\```

Expand Down
22 changes: 18 additions & 4 deletions installRecipes.bat
Original file line number Diff line number Diff line change
@@ -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
10 changes: 4 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
</licenses>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>16</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<iaf.version>7.7.7</iaf.version>
Expand Down Expand Up @@ -511,10 +510,9 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>16</source>
<target>16</target>
<testSource>17</testSource>
<testTarget>17</testTarget>
<release>16</release>
<testSource>16</testSource>
<testTarget>16</testTarget>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
Expand Down
59 changes: 36 additions & 23 deletions reciperunner/runRecipes.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
@echo off

REM Check if the argument is provided
if "%~dp1"=="" (
echo Error: No target directory provided.
echo Usage: script.bat [target_directory]
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"
Expand All @@ -16,43 +17,50 @@ 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%" (
echo Error: Target directory "%TARGET_DIR%" does not exist.
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
)

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
Expand All @@ -75,20 +83,27 @@ 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 (
echo Source version, %SOURCE_VERSION%, not supported, make sure the source version is in version range: %VALID_VERSIONS%
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
Expand All @@ -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 (
Expand All @@ -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.
exit /b 0
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.frankrewrite.recipes.visitors;

import org.frankrewrite.recipes.util.TagHandler;
Expand All @@ -17,29 +32,30 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext executionContext) {
){
List<Xml.Tag> 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<Content> resultContent = new ArrayList<>(tag.getContent());
Map<Xml.Tag, String> fromToMap = collectPipeForwardPathNameMap(etagHandlers);
Map<Xml.Tag, String> 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<Xml.Tag> apiHandler = resultContent.stream().filter(c -> c instanceof Xml.Tag t &&
Optional<Xml.Tag> apiListener = resultContent.stream().filter(c -> c instanceof Xml.Tag t &&
t.getName().equals("ApiListener")).findFirst().map(Xml.Tag.class::cast);
if (apiHandler.isPresent()) {
Optional<Xml.Attribute> attribute = TagHandler.getAttributeFromTagByKey(apiHandler.get(), "updateEtag");
List<Xml.Attribute> attributes = apiHandler.get().getAttributes();
if (apiListener.isPresent()) {//update the etag and ApiListener attribute
Optional<Xml.Attribute> attribute = TagHandler.getAttributeFromTagByKey(apiListener.get(), "updateEtag");
List<Xml.Attribute> attributes = apiListener.get().getAttributes();
attribute.ifPresent(attributes::remove);
//language=xml
attributes.add(Xml.Tag.build("<x updateEtag='true'> </x>").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);
}
}
Expand Down Expand Up @@ -81,8 +97,8 @@ private Map<Xml.Tag, String> collectPipeForwardPathNameMap(List<Xml.Tag> 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")
));
}
}