From 73a024cf458d6af0ffcad6a24afff3c2c9cec1ce Mon Sep 17 00:00:00 2001 From: Eduardo Martins Date: Wed, 29 May 2024 11:30:48 +0100 Subject: [PATCH] [CMTOOL-372] skips migration of internal modules --- .../migration/core/jboss/JBossServer.java | 17 ++++++++ .../core/jboss/ModulesMigrationTask.java | 10 +++-- testsuite/server-migration-simple-test-raw.sh | 39 +++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100755 testsuite/server-migration-simple-test-raw.sh diff --git a/core/src/main/java/org/jboss/migration/core/jboss/JBossServer.java b/core/src/main/java/org/jboss/migration/core/jboss/JBossServer.java index 9e9b16f9a..dd63b9d84 100644 --- a/core/src/main/java/org/jboss/migration/core/jboss/JBossServer.java +++ b/core/src/main/java/org/jboss/migration/core/jboss/JBossServer.java @@ -347,6 +347,14 @@ public static class Modules { private final List addonDirs; private final Path overlayDir; + private static final ModuleIdentifier[] INTERNAL_MODULES = { + ModuleIdentifier.fromString("java.desktop"), + ModuleIdentifier.fromString("java.logging"), + ModuleIdentifier.fromString("java.sql"), + ModuleIdentifier.fromString("java.xml"), + ModuleIdentifier.fromString("org.jboss.modules") + }; + public Modules(Path serverBaseDir) { this.modulesDir = serverBaseDir.resolve("modules"); this.layerDirs = new ArrayList<>(); @@ -459,6 +467,15 @@ public Path getModuleDir(ModuleIdentifier moduleId) { } return modulesDir.resolve(modulePath); } + + public boolean isInternalModule(ModuleIdentifier moduleIdentifier) { + for (ModuleIdentifier internalModuleIdentifier : INTERNAL_MODULES) { + if (internalModuleIdentifier.equals(moduleIdentifier)) { + return true; + } + } + return false; + } } public static class Extensions { diff --git a/core/src/main/java/org/jboss/migration/core/jboss/ModulesMigrationTask.java b/core/src/main/java/org/jboss/migration/core/jboss/ModulesMigrationTask.java index 72957ebe3..6aa37190e 100644 --- a/core/src/main/java/org/jboss/migration/core/jboss/ModulesMigrationTask.java +++ b/core/src/main/java/org/jboss/migration/core/jboss/ModulesMigrationTask.java @@ -123,14 +123,18 @@ public void migrateModule(final ModuleIdentifier moduleIdentifier, final String context.getLogger().debugf("Skipping module %s migration, it's excluded by environment.", moduleIdentifier); return; } - final JBossServer.Module sourceModule = sourceModules.getModule(moduleIdentifier); - if (sourceModule == null) { - throw new IllegalStateException("Migration of module "+moduleIdentifier+" required, but module not found in source server."); + if (targetModules.isInternalModule(moduleIdentifier)) { + context.getLogger().debugf("Skipping module %s migration, it's an internal target server's module.", moduleIdentifier); + return; } if (targetModules.getModule(moduleIdentifier) != null) { context.getLogger().debugf("Skipping module %s migration, already exists in target.", moduleIdentifier, reason); return; } + final JBossServer.Module sourceModule = sourceModules.getModule(moduleIdentifier); + if (sourceModule == null) { + throw new IllegalStateException("Migration of module "+moduleIdentifier+" required, but module not found in source server."); + } final ServerMigrationTaskName taskName = new ServerMigrationTaskName.Builder(context.getTaskName().getName()+".migrate-module").addAttribute("id", moduleIdentifier.toString()).build(); final ServerMigrationTask subtask = new ServerMigrationTask() { @Override diff --git a/testsuite/server-migration-simple-test-raw.sh b/testsuite/server-migration-simple-test-raw.sh new file mode 100755 index 000000000..b8106246e --- /dev/null +++ b/testsuite/server-migration-simple-test-raw.sh @@ -0,0 +1,39 @@ +#!/bin/sh +set -e +set -o pipefail + +DIRNAME=`dirname "$0"` +TEST_DIR=`cd "$DIRNAME"; pwd` +TEST_BEFORE_DIR=$TEST_DIR/before/dist +TEST_AFTER_DIR=$TEST_DIR/after +TOOL_DIR="$TEST_DIR/jboss-server-migration" +SOURCE_DIST_DIR="$1" +TARGET_DIST_DIR="$2" + +if [ "x$SOURCE_DIST_DIR" != "x" ]; then + if [[ $SOURCE_DIST_DIR != /* ]]; then + SOURCE_DIST_DIR="$TEST_DIR/$SOURCE_DIST_DIR" + fi +else + echo "### Usage: ./server-migration-simple-test.sh SOURCE_DIST_DIR TARGET_DIST_DIR" + exit +fi + +if [ ! -d $SOURCE_DIST_DIR ]; then + echo "### Source Server base directory $SOURCE_DIST_DIR does not exists!" + exit 1; +fi +echo "### Source Server base directory: $SOURCE_DIST_DIR" + +if [ ! -d $TARGET_DIST_DIR ]; then + echo "### Target Server dist directory $TARGET_DIST_DIR does not exists!" + exit 1; +fi +echo "### Target Server dist directory: $TARGET_DIST_DIR" + +echo "### Preparing JBoss Server Migration Tool binary..." +rm -Rf $TOOL_DIR +unzip $TEST_DIR/../dist/standalone/target/jboss-server-migration-*.zip -d $TEST_DIR + +echo "### Executing the migration..." +$TOOL_DIR/jboss-server-migration.sh -n -s $SOURCE_DIST_DIR -t $TARGET_DIST_DIR -Djboss.server.migration.modules.excludes="" \ No newline at end of file