Skip to content

Commit

Permalink
[KOGITO-9061] Quarkus 3: Update to Quarkus 3.0.0.Final (#2917)
Browse files Browse the repository at this point in the history
* Quarkus 3: Update to Quarkus 3.0.0.Final

* removed temp patch

as https://github.com/kiegroup/kogito-runtimes/pull/2951 is merged

* corrected standalone rewrite pipeline

* [Quarkus 3 migration] Update Openrewrite recipe

* [Quarkus 3 migration] Updated Openrewrite patch

* corrected jenkins jobs

* [Quarkus 3 migration] Update Openrewrite recipe

* [Quarkus 3 migration] Updated Openrewrite patch

---------

Co-authored-by: radtriste <[email protected]>
Co-authored-by: Jenkins CI <[email protected]>
  • Loading branch information
3 people authored Apr 27, 2023
1 parent b7e16b8 commit 09bbdcd
Show file tree
Hide file tree
Showing 33 changed files with 19,976 additions and 930 deletions.
81 changes: 81 additions & 0 deletions .ci/environments/quarkus-3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# quarkus-3 environment scripts

This folder contains specific script(s)/patch(es) for the Quarkus 3 migration.

**Here is the command:**

```bash
.ci/environments/update.sh quarkus-3
```

Steps of the basic execution:

- Execute `before.sh` script
In the basic execution, this script will skip the rewrite commands, which is taking a lot of time to perform.
If you want to perform the rewrite or update the "before.sh" patch, please see next sections.
- Apply all patches from `patches` folder

## Full execution

**Command:**

```bash
.ci/environments/update.sh quarkus-3 rewrite
```

Steps of the full execution:

- Execute the rewrite execution
- Synchronize the libraries' version with Quarkus BOM
- Store the changes from previous steps into the `patches/001_before_sh.patch` file
- Apply patches from `patches` folder

## Patches information

1. the `0001_before_sh.patch` is generated executing the `before.sh` script; it then contains all the `openrewrite` migration and the synchronization of libraries with quarkus ones (see next section)
2. all other patches have been made manually
3. if some other modifications are needed, they should be created as `patch`, following numerations
4. if some patch does not apply anymore, it has to be recreated manually; in case of the first one, it means to execute the `before.sh` script again

## How to recreate the `001_before_sh.patch` file ?

The `001_before_sh.patch` file contains all changes from a rewrite execution.
In case of a full execution, this file will be overriden with the new changes.

You can also regenerate that file without having to run the full quarkus-3 environment migration.
To do so, just run:

```bash
.ci/environments/quarkus-3/before.sh rewrite
```

## Recipe files

There are 3 recipe files:

- `project-recipe.yml` is the recipe file to update in case you need a new recipe
- `quarkus3-base-recipe.yml` is the base recipe setup by Quarkus team in https://github.com/quarkusio/quarkus-updates. You should not modify it !
- `quarkus3.yml` is the final recipe file and is a compute of the previous 2 files, plus some processing.
See also comments in [Jbang script](jbang/CreateQuarkusDroolsMigrationRecipe.java) for more details on the generation.

### How to reset the quarkus3.yaml recipe file ?

The `before.sh` script should handle the reset of the `quarkus3.yml` recipe file when executed with `rewrite` command.

In case you want to do manually, just run:

```bash
cd .ci/environments/quarkus-3 && curl -Ls https://sh.jbang.dev | bash -s - jbang/CreateQuarkusDroolsMigrationRecipe.java; cd -
```

### How to update the Quarkus version ?

If you are setting a new Quarkus version:

1. Update `quarkus-devtools-common` version in `jbang/CreateQuarkusDroolsMigrationRecipe.java` file
2. Update `QUARKUS_VERSION` in `jbang/CreateQuarkusDroolsMigrationRecipe.java` file
3. Update `QUARKUS_UPDATES_BASE_URL` with the corresponding released version of https://github.com/quarkusio/quarkus-updates recipe file
4. Run the jbang script to update the `quarkus3.yml` file
```bash
cd .ci/environments/quarkus-3 && curl -Ls https://sh.jbang.dev | bash -s - jbang/CreateQuarkusDroolsMigrationRecipe.java true; cd -
```
53 changes: 43 additions & 10 deletions .ci/environments/quarkus-3/before.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,52 @@ script_dir_path=$(cd `dirname "${BASH_SOURCE[0]}"`; pwd -P)
mvn_cmd="mvn ${BUILD_MVN_OPTS:-} ${BUILD_MVN_OPTS_QUARKUS_UPDATE:-}"
ci="${CI:-false}"

quarkus_version=${QUARKUS_VERSION:-3.0.0.Alpha5}
quarkus_file="${script_dir_path}/quarkus3.yml"
rewrite_plugin_version=4.43.0
quarkus_version=${QUARKUS_VERSION:-3.0.0.CR1}
project_version='quarkus-3-SNAPSHOT'

quarkus_file="${script_dir_path}/quarkus3.yml"
patch_file="${script_dir_path}"/patches/0001_before_sh.patch

rewrite=${1:-'none'}
echo "rewrite "${rewrite}

if [ "rewrite" != ${rewrite} ]; then
echo "No rewrite to be done. Exited"
exit 0
fi

export MAVEN_OPTS="-Xmx16192m"

echo "Update project with Quarkus version ${quarkus_version}"

set -x

# Update recipe file with correct quarkus 3 version
sed -i "s|{QUARKUS_VERSION}|${quarkus_version}|g" "${quarkus_file}"

# In CI we need the main branch snapshot artifacts deployed locally
if [ "${ci}" = "true" ]; then
# In CI we need the main branch snapshot artifacts deployed locally
${mvn_cmd} clean install -Dquickly
fi

# Use a different version to not enter in conflict locally with other artifacts
# Change version
${mvn_cmd} -e -N -Dfull -DnewVersion=${project_version} -DallowSnapshots=true -DgenerateBackupPoms=false versions:set
${mvn_cmd} -e -Dproperty=version.org.kie -DnewVersion=${project_version} -DallowSnapshots=true -DgenerateBackupPoms=false versions:set-property

# Make sure artifacts are updated locally
${mvn_cmd} clean install -Dquickly

# Regenerate quarkus3 recipe
cd ${script_dir_path}
curl -Ls https://sh.jbang.dev | bash -s - jbang/CreateQuarkusDroolsMigrationRecipe.java
cd -
if [ "$(git status --porcelain ${quarkus_file})" != '' ]; then
git add "${quarkus_file}"
git commit -m '[Quarkus 3 migration] Update Openrewrite recipe'
fi

# Launch Quarkus 3 Openrewrite
${mvn_cmd} org.openrewrite.maven:rewrite-maven-plugin:4.36.0:run \
${mvn_cmd} org.openrewrite.maven:rewrite-maven-plugin:${rewrite_plugin_version}:run \
-Drewrite.configLocation="${quarkus_file}" \
-DactiveRecipes=io.quarkus.openrewrite.Quarkus3 \
-DactiveRecipes=io.quarkus.openrewrite.Quarkus \
-Drewrite.recipeArtifactCoordinates=org.kie:jpmml-migration-recipe:"${project_version}" \
-Denforcer.skip \
-fae \
-Dexclusions=**/target \
Expand All @@ -48,3 +67,17 @@ ${mvn_cmd} \
-DupdateDependencies=true \
-DgenerateBackupPoms=false \
versions:compare-dependencies

# Create the `patches/0001_before_sh.patch` file
git add .
git diff --cached > "${patch_file}"
git reset

# Commit the change on patch
if [ "$(git status --porcelain ${patch_file})" != '' ]; then
git add "${patch_file}"
git commit -m '[Quarkus 3 migration] Updated Openrewrite patch'
fi

# Reset all other changes as they will be applied next by the `patches/0001_before_sh.patch` file
git reset --hard
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;

import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.update.QuarkusUpdateRecipe;
import io.quarkus.devtools.project.update.QuarkusUpdateRecipeIO;
import io.quarkus.devtools.project.update.operations.UpdatePropertyOperation;

///usr/bin/env jbang "$0" "$@" ; exit $?
// Version to be changed when needed
//DEPS io.quarkus:quarkus-devtools-common:3.0.0.Final

/*
* This script will generate the final `quarkus3.yml` file based on:
* - quarkus recipe file (see `QUARKUS_UPDATES_BASE_URL` constant)
* - local project-recipe.yaml => Specific project repository rules
*
* We use a lot of managed dependencies, it concatenates both files but it also add some new rules:
* In the Quarkus recipe, the dependencies rules are modified only for direct dependencies but not for managed dependencies.
* So the script adds a new step:
* - Reads all modified direct dependencies from the Quarkus recipe
* - Generates one managed dependency rule for each of them
*/
class CreateQuarkusProjectMigrationRecipe {

static final String QUARKUS_VERSION = "3.0.0.Final";
static final String QUARKUS_UPDATES_BASE_URL = "https://raw.githubusercontent.com/quarkusio/quarkus-updates/1.0.0/recipes/src/main/resources/quarkus-updates/core/3alpha.yaml";

static final Path quarkus3DownloadedRecipePath = Paths.get("quarkus3-base-recipe.yml");
static final Path quarkus3GeneratedRecipePath = Paths.get("quarkus3.yml");
static final Path projectBaseRecipePath = Paths.get("project-recipe.yml");

public static void main(String... args) throws Exception {
boolean downloadQuarkusRecipe = false;
if (args.length > 0) {
downloadQuarkusRecipe = Boolean.parseBoolean(args[0]);
}

if (downloadQuarkusRecipe) {
Files.write(quarkus3DownloadedRecipePath, new URL(QUARKUS_UPDATES_BASE_URL).openStream().readAllBytes());
}

if (!Files.exists(quarkus3DownloadedRecipePath)) {
System.out.println("The Quarkus base recipe (" + quarkus3DownloadedRecipePath.getFileName()
+ ") does not exist into the folder. Please download it manually or add the `true` parameter to the script call !");
System.exit(1);
}

List<Object> quarkusRecipes = QuarkusUpdateRecipeIO
.readRecipesYaml(Files.readString(quarkus3DownloadedRecipePath));
QuarkusUpdateRecipe mainRecipe = new QuarkusUpdateRecipe()
.buildTool(BuildTool.MAVEN)
.addOperation(new UpdatePropertyOperation("version.io.quarkus", QUARKUS_VERSION));

if (Files.exists(projectBaseRecipePath)) {
System.out.println("Adding Project base recipe(s)");
mainRecipe.addRecipes(QuarkusUpdateRecipeIO.readRecipesYaml(Files.readString(projectBaseRecipePath)));
} else {
System.out.println("No Project base recipe(s) available. Nothing done here ...");
}

System.out.println("Adding Managed dependency recipe(s)");
Map<String, Object> managedDependencyMainRecipe = Map.of(
"type", "specs.openrewrite.org/v1beta/recipe",
"name", "org.kie.ManagedDependencies",
"displayName", "Update Managed Dependencies",
"description", "Update all managed dependencies based on dependency updates from Quarkus.",
"recipeList", retrieveAllChangeDependencyRecipesToManagedDependency(quarkusRecipes));
mainRecipe.addRecipe(managedDependencyMainRecipe);

System.out.println("Adding Quarkus base recipe(s)");
mainRecipe.addRecipes(quarkusRecipes);

System.out.println("Writing main recipe");
QuarkusUpdateRecipeIO.write(quarkus3GeneratedRecipePath, mainRecipe);
}

private static List<Object> retrieveAllChangeDependencyRecipesToManagedDependency(List<Object> recipes) {
List<Object> changeDependencyRecipeList = new ArrayList<>();
recipes.forEach(r -> {
if (r instanceof Map) {
List<Object> recipeList = (List<Object>) ((Map<String, Object>) r).get("recipeList");
recipeList.forEach(recipeMap -> {
if (recipeMap instanceof Map) {
((Map<String, Map<String, Object>>) recipeMap).forEach((recipeName, args) -> {
if (recipeName.equals("org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId")) {
args.remove("overrideManagedVersion");
if (!args.containsKey("newArtifactId")) {
args.put("newArtifactId", args.get("oldArtifactId"));
}
changeDependencyRecipeList.add(Map
.of("org.openrewrite.maven.ChangeManagedDependencyGroupIdAndArtifactId", args));
}
});
}
});
}
});
return changeDependencyRecipeList;
}
}
Loading

0 comments on commit 09bbdcd

Please sign in to comment.