From 78debd0639a7dbdb151cdb1c2ab8ce6b446a8c13 Mon Sep 17 00:00:00 2001 From: Carter Cundiff Date: Thu, 29 Aug 2024 11:42:17 -0400 Subject: [PATCH] #306 Resolve migration issues from Orphedomos to Fabric8 --- build-parent/pom.xml | 6 +- .../aissemble-configuration-store/pom.xml | 2 +- .../pom.xml | 2 +- .../aissemble-fastapi/pom.xml | 2 +- .../aissemble-hive-mysql/pom.xml | 2 +- .../aissemble-hive-service/pom.xml | 2 +- .../aissemble-jenkins-agent/pom.xml | 2 +- .../aissemble-jenkins-controller/pom.xml | 2 +- .../aissemble-metadata/pom.xml | 2 +- .../pom.xml | 2 +- .../aissemble-model-training-api/pom.xml | 2 +- .../aissemble-nvidia/pom.xml | 2 +- .../aissemble-pipeline-invocation/pom.xml | 2 +- .../aissemble-policy-decision-point/pom.xml | 2 +- .../aissemble-quarkus/pom.xml | 2 +- .../aissemble-spark-infrastructure/pom.xml | 4 +- .../aissemble-spark-operator/pom.xml | 2 +- .../extensions-docker/aissemble-spark/pom.xml | 2 +- .../extensions-docker/aissemble-vault/pom.xml | 2 +- .../aissemble-versioning/pom.xml | 2 +- extensions/extensions-docker/pom.xml | 2 +- .../__rootArtifactId__-docker/pom.xml | 7 +- .../__rootArtifactId__-tests-docker/pom.xml | 4 +- .../sagemaker-training.docker.pom.xml.vm | 2 +- .../v1_8_0/OrphedomosToFabric8Migration.java | 475 ++++++++---------- .../OrphedomosToFabric8MigrationSteps.java | 150 +++--- .../orphedomos-to-fabric8-migration.feature | 40 +- .../migrate-profile/integration-test/pom.xml | 128 ----- .../migration/multi-profile/pom.xml | 164 ++++++ .../migration/skip-migrate/pom.xml | 37 ++ .../standard-image}/pom.xml | 20 +- .../standard-parent}/pom.xml | 32 +- .../validation/multi-profile/pom.xml | 156 ++++++ .../validation/skip-migrate/pom.xml | 37 ++ .../validation/standard-image/pom.xml | 94 ++++ .../ci => validation/standard-parent}/pom.xml | 51 +- pom.xml | 2 +- 37 files changed, 887 insertions(+), 560 deletions(-) delete mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-profile/integration-test/pom.xml create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/multi-profile/pom.xml create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/skip-migrate/pom.xml rename foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/{migrate-packaging-only => migration/standard-image}/pom.xml (84%) rename foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/{migrate-configuration => migration/standard-parent}/pom.xml (73%) create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/multi-profile/pom.xml create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/skip-migrate/pom.xml create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/standard-image/pom.xml rename foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/{migrate-profile/ci => validation/standard-parent}/pom.xml (63%) diff --git a/build-parent/pom.xml b/build-parent/pom.xml index e27769e6a..1d4e7056c 100644 --- a/build-parent/pom.xml +++ b/build-parent/pom.xml @@ -84,6 +84,8 @@ 0.45-tb-0.1.0 linux/amd64,linux/arm64 + + org.technologybrewery.fabric8 @@ -558,7 +560,7 @@ This can be removed once https://github.com/fabric8io/docker-maven-plugin/issues/1804 is incorporated into the io.fabric8 plugin directly. --> - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin ${version.fabric8.docker.maven.plugin} true @@ -1025,7 +1027,7 @@ To suppress enforce-helm-version rule, you must add following plugin to the root - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin ${version.fabric8.docker.maven.plugin} diff --git a/extensions/extensions-docker/aissemble-configuration-store/pom.xml b/extensions/extensions-docker/aissemble-configuration-store/pom.xml index e33ee4c73..7eaeb3e8f 100644 --- a/extensions/extensions-docker/aissemble-configuration-store/pom.xml +++ b/extensions/extensions-docker/aissemble-configuration-store/pom.xml @@ -40,7 +40,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-data-lineage-http-consumer/pom.xml b/extensions/extensions-docker/aissemble-data-lineage-http-consumer/pom.xml index 3a9b44acd..f85ea3368 100644 --- a/extensions/extensions-docker/aissemble-data-lineage-http-consumer/pom.xml +++ b/extensions/extensions-docker/aissemble-data-lineage-http-consumer/pom.xml @@ -51,7 +51,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-fastapi/pom.xml b/extensions/extensions-docker/aissemble-fastapi/pom.xml index 82c601db8..155004c3f 100644 --- a/extensions/extensions-docker/aissemble-fastapi/pom.xml +++ b/extensions/extensions-docker/aissemble-fastapi/pom.xml @@ -17,7 +17,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-hive/aissemble-hive-mysql/pom.xml b/extensions/extensions-docker/aissemble-hive/aissemble-hive-mysql/pom.xml index 10de25eea..a8b6d8911 100644 --- a/extensions/extensions-docker/aissemble-hive/aissemble-hive-mysql/pom.xml +++ b/extensions/extensions-docker/aissemble-hive/aissemble-hive-mysql/pom.xml @@ -17,7 +17,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-hive/aissemble-hive-service/pom.xml b/extensions/extensions-docker/aissemble-hive/aissemble-hive-service/pom.xml index 37ab0ae45..34e66943e 100644 --- a/extensions/extensions-docker/aissemble-hive/aissemble-hive-service/pom.xml +++ b/extensions/extensions-docker/aissemble-hive/aissemble-hive-service/pom.xml @@ -35,7 +35,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-jenkins/aissemble-jenkins-agent/pom.xml b/extensions/extensions-docker/aissemble-jenkins/aissemble-jenkins-agent/pom.xml index 5bd78cb9f..50d81beaa 100644 --- a/extensions/extensions-docker/aissemble-jenkins/aissemble-jenkins-agent/pom.xml +++ b/extensions/extensions-docker/aissemble-jenkins/aissemble-jenkins-agent/pom.xml @@ -17,7 +17,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-jenkins/aissemble-jenkins-controller/pom.xml b/extensions/extensions-docker/aissemble-jenkins/aissemble-jenkins-controller/pom.xml index fd7856de5..1d22f683c 100644 --- a/extensions/extensions-docker/aissemble-jenkins/aissemble-jenkins-controller/pom.xml +++ b/extensions/extensions-docker/aissemble-jenkins/aissemble-jenkins-controller/pom.xml @@ -17,7 +17,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-metadata/pom.xml b/extensions/extensions-docker/aissemble-metadata/pom.xml index 587116724..8079d5185 100644 --- a/extensions/extensions-docker/aissemble-metadata/pom.xml +++ b/extensions/extensions-docker/aissemble-metadata/pom.xml @@ -41,7 +41,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-model-training-api-containers/aissemble-model-training-api-sagemaker/pom.xml b/extensions/extensions-docker/aissemble-model-training-api-containers/aissemble-model-training-api-sagemaker/pom.xml index ad2d248d3..a53ec0779 100644 --- a/extensions/extensions-docker/aissemble-model-training-api-containers/aissemble-model-training-api-sagemaker/pom.xml +++ b/extensions/extensions-docker/aissemble-model-training-api-containers/aissemble-model-training-api-sagemaker/pom.xml @@ -21,7 +21,7 @@ habushu-maven-plugin - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-model-training-api-containers/aissemble-model-training-api/pom.xml b/extensions/extensions-docker/aissemble-model-training-api-containers/aissemble-model-training-api/pom.xml index 09a4e1347..7ad43d62c 100644 --- a/extensions/extensions-docker/aissemble-model-training-api-containers/aissemble-model-training-api/pom.xml +++ b/extensions/extensions-docker/aissemble-model-training-api-containers/aissemble-model-training-api/pom.xml @@ -21,7 +21,7 @@ habushu-maven-plugin - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-nvidia/pom.xml b/extensions/extensions-docker/aissemble-nvidia/pom.xml index 07e9a5950..1c664bf24 100644 --- a/extensions/extensions-docker/aissemble-nvidia/pom.xml +++ b/extensions/extensions-docker/aissemble-nvidia/pom.xml @@ -17,7 +17,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-pipeline-invocation/pom.xml b/extensions/extensions-docker/aissemble-pipeline-invocation/pom.xml index db9451589..0e877cb7c 100644 --- a/extensions/extensions-docker/aissemble-pipeline-invocation/pom.xml +++ b/extensions/extensions-docker/aissemble-pipeline-invocation/pom.xml @@ -55,7 +55,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-policy-decision-point/pom.xml b/extensions/extensions-docker/aissemble-policy-decision-point/pom.xml index 390514492..82feefb41 100644 --- a/extensions/extensions-docker/aissemble-policy-decision-point/pom.xml +++ b/extensions/extensions-docker/aissemble-policy-decision-point/pom.xml @@ -38,7 +38,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-quarkus/pom.xml b/extensions/extensions-docker/aissemble-quarkus/pom.xml index de2e155fe..d33810dad 100644 --- a/extensions/extensions-docker/aissemble-quarkus/pom.xml +++ b/extensions/extensions-docker/aissemble-quarkus/pom.xml @@ -17,7 +17,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-spark-infrastructure/pom.xml b/extensions/extensions-docker/aissemble-spark-infrastructure/pom.xml index 7a6f561e4..63d006c09 100644 --- a/extensions/extensions-docker/aissemble-spark-infrastructure/pom.xml +++ b/extensions/extensions-docker/aissemble-spark-infrastructure/pom.xml @@ -56,7 +56,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin @@ -89,7 +89,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-spark-operator/pom.xml b/extensions/extensions-docker/aissemble-spark-operator/pom.xml index af06e6088..38d65ee65 100644 --- a/extensions/extensions-docker/aissemble-spark-operator/pom.xml +++ b/extensions/extensions-docker/aissemble-spark-operator/pom.xml @@ -56,7 +56,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-spark/pom.xml b/extensions/extensions-docker/aissemble-spark/pom.xml index 73d4edcdd..abb66043e 100644 --- a/extensions/extensions-docker/aissemble-spark/pom.xml +++ b/extensions/extensions-docker/aissemble-spark/pom.xml @@ -62,7 +62,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-vault/pom.xml b/extensions/extensions-docker/aissemble-vault/pom.xml index 7f0724011..ea45f165c 100644 --- a/extensions/extensions-docker/aissemble-vault/pom.xml +++ b/extensions/extensions-docker/aissemble-vault/pom.xml @@ -17,7 +17,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/aissemble-versioning/pom.xml b/extensions/extensions-docker/aissemble-versioning/pom.xml index b1b70e40d..86d310cac 100644 --- a/extensions/extensions-docker/aissemble-versioning/pom.xml +++ b/extensions/extensions-docker/aissemble-versioning/pom.xml @@ -21,7 +21,7 @@ habushu-maven-plugin - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/extensions/extensions-docker/pom.xml b/extensions/extensions-docker/pom.xml index 1d0763707..e3482f2be 100644 --- a/extensions/extensions-docker/pom.xml +++ b/extensions/extensions-docker/pom.xml @@ -24,7 +24,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/foundation/foundation-archetype/src/main/resources/archetype-resources/__rootArtifactId__-docker/pom.xml b/foundation/foundation-archetype/src/main/resources/archetype-resources/__rootArtifactId__-docker/pom.xml index 16282440f..62112b896 100644 --- a/foundation/foundation-archetype/src/main/resources/archetype-resources/__rootArtifactId__-docker/pom.xml +++ b/foundation/foundation-archetype/src/main/resources/archetype-resources/__rootArtifactId__-docker/pom.xml @@ -61,7 +61,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin true @@ -81,14 +81,13 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin false - ${docker.project.repository.url}/${project.artifactId}:${project.version} - + ${docker.project.repository.url}${project.artifactId}:${project.version} diff --git a/foundation/foundation-archetype/src/main/resources/archetype-resources/__rootArtifactId__-tests/__rootArtifactId__-tests-docker/pom.xml b/foundation/foundation-archetype/src/main/resources/archetype-resources/__rootArtifactId__-tests/__rootArtifactId__-tests-docker/pom.xml index e2fb84df5..2a404d8e5 100644 --- a/foundation/foundation-archetype/src/main/resources/archetype-resources/__rootArtifactId__-tests/__rootArtifactId__-tests-docker/pom.xml +++ b/foundation/foundation-archetype/src/main/resources/archetype-resources/__rootArtifactId__-tests/__rootArtifactId__-tests-docker/pom.xml @@ -28,7 +28,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin true @@ -56,7 +56,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin false diff --git a/foundation/foundation-mda/src/main/resources/templates/general-docker/sagemaker-training.docker.pom.xml.vm b/foundation/foundation-mda/src/main/resources/templates/general-docker/sagemaker-training.docker.pom.xml.vm index 9630b93d9..896544e2d 100755 --- a/foundation/foundation-mda/src/main/resources/templates/general-docker/sagemaker-training.docker.pom.xml.vm +++ b/foundation/foundation-mda/src/main/resources/templates/general-docker/sagemaker-training.docker.pom.xml.vm @@ -64,7 +64,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin diff --git a/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_8_0/OrphedomosToFabric8Migration.java b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_8_0/OrphedomosToFabric8Migration.java index a13e6e927..b9a9550f2 100644 --- a/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_8_0/OrphedomosToFabric8Migration.java +++ b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_8_0/OrphedomosToFabric8Migration.java @@ -13,22 +13,26 @@ import com.boozallen.aissemble.upgrade.migration.AbstractAissembleMigration; import org.technologybrewery.baton.util.pom.LocationAwareMavenReader; import org.apache.maven.model.Build; +import org.apache.maven.model.BuildBase; import org.apache.maven.model.InputLocation; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.Profile; -import org.technologybrewery.baton.util.FileUtils; import org.technologybrewery.baton.util.pom.PomHelper; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; import java.util.stream.Collectors; import org.technologybrewery.baton.util.pom.PomModifications; +import org.technologybrewery.baton.util.pom.PomModifications.Modification; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,13 +48,16 @@ */ public class OrphedomosToFabric8Migration extends AbstractAissembleMigration { - private static final Logger logger = LoggerFactory.getLogger(OrphedomosToFabric8Migration.class); private static final String ORPHEDOMOS_GROUP_ID = "org.technologybrewery.orphedomos"; private static final String ORPHEDOMOS_ARTIFACT_ID = "orphedomos-maven-plugin"; - private static final String FABRIC8_GROUP_ID = "io.fabric8"; + private static final String ORPHEDOMOS_PACKAGING = "orphedomos"; + private static final String FABRIC8_GROUP_ID = "${group.fabric8.plugin}"; private static final String FABRIC8_ARTIFACT_ID = "docker-maven-plugin"; + private static final String FABRIC8_PACKAGING = "docker-build"; + private static final String SPACE = " "; + private static final Logger logger = LoggerFactory.getLogger(OrphedomosToFabric8Migration.class); private static final String EXTRACT_PACKAGING_REGEX = "()orphedomos(<\\/packaging>)"; - private static final String SECOND_REGEX_GROUPING = "$2"; + private static final String PACKAGING = "packaging"; private static final String GROUP_ID = "groupId"; private static final String ARTIFACT_ID = "artifactId"; private static final String VERSION = "version"; @@ -60,10 +67,10 @@ public class OrphedomosToFabric8Migration extends AbstractAissembleMigration { private static final String CONFIGURATION = "configuration"; private static final String CI = "ci"; private static final String INTEGRATION_TEST = "integration-test"; - private static String imageName; - private static String imageVersion; - private static String repoUrl; - private static String profile; + + private String buildImageName; + private String buildImageVersion; + private String buildRepoUrl; /** * Function to validate whether migration should be performed or not. @@ -74,15 +81,15 @@ public class OrphedomosToFabric8Migration extends AbstractAissembleMigration { protected boolean shouldExecuteOnFile(File file) { Model model = getLocationAnnotatedModel(file); - Plugin orphedomosBuildPlugin = getBuildPlugin(model, ORPHEDOMOS_ARTIFACT_ID); - - Plugin orphedomosCiProfilePlugin = getProfilePlugin(model, ORPHEDOMOS_ARTIFACT_ID, CI); - Plugin orphedomosItProfilePlugin = getProfilePlugin(model, ORPHEDOMOS_ARTIFACT_ID, INTEGRATION_TEST); + Boolean hasOrphedomosBuildPluginsCount = !getAllBuildPluginsByGroupIdAndArtifactId(model, ORPHEDOMOS_GROUP_ID, ORPHEDOMOS_ARTIFACT_ID).isEmpty(); + Boolean hasOrphedomosProfilePluginsCount = !getAllProfilePluginsByGroupIdAndArtifactId(model, ORPHEDOMOS_GROUP_ID, ORPHEDOMOS_ARTIFACT_ID).isEmpty(); - return orphedomosBuildPlugin != null - || orphedomosCiProfilePlugin != null - || orphedomosItProfilePlugin != null - || containsOrphedomosPackaging(file); + if (hasOrphedomosBuildPluginsCount|| hasOrphedomosProfilePluginsCount || containsOrphedomosPackaging(file)) { + logger.info("Orphedomos plugin configuration found. Migrating the following file: {}", file.getAbsolutePath()); + return true; + } else { + return false; + } } /** @@ -93,321 +100,265 @@ protected boolean shouldExecuteOnFile(File file) { @Override protected boolean performMigration(File file) { Model model = getLocationAnnotatedModel(file); - Plugin buildPlugin = getBuildPlugin(model, ORPHEDOMOS_ARTIFACT_ID); - boolean replacedBuildConfig = false; - boolean replacedCiProfile = false; - boolean replacedItProfile = false; - boolean replacedPackaging = false; + PomModifications modifications = new PomModifications(); - Xpp3Dom config; - - if (buildPlugin != null) { - config = getConfiguration(buildPlugin); - } else { - config = null; - logger.info("Orphedomos plugin configuration not found. Skipping configuration migration."); - } - - // check if pom file has orphedomos-maven-plugin configuration - if (config != null) { - replacedBuildConfig = executeBuildConfigMigration(file, config, buildPlugin); + List buildPlugins = getAllBuildPluginsByGroupIdAndArtifactId(model, ORPHEDOMOS_GROUP_ID, ORPHEDOMOS_ARTIFACT_ID); + if (!buildPlugins.isEmpty()) { + for (Plugin buildPlugin: buildPlugins) { + modifications.addAll(getAllPluginModifications(file, buildPlugin, null)); + } } - // check if pom file has orphedomos and replace + //check if pom file has orphedomos and replace if (containsOrphedomosPackaging(file)) { - replacedPackaging = executePackagingMigration(file); + modifications.add(getPackagingMigrationMod(model)); } - model = getLocationAnnotatedModel(file); - Plugin ciProfilePlugin = getProfilePlugin(model, ORPHEDOMOS_ARTIFACT_ID, CI); - Plugin itProfilePlugin = getProfilePlugin(model, ORPHEDOMOS_ARTIFACT_ID, INTEGRATION_TEST); - - // check if pom file has orphedomos plugin in profile - if (ciProfilePlugin != null) { - profile = CI; - replacedCiProfile = executeProfileMigration(file, ciProfilePlugin, CI); - } - if (itProfilePlugin != null) { - profile = INTEGRATION_TEST; - replacedItProfile = executeProfileMigration(file, itProfilePlugin, INTEGRATION_TEST); + List> profilePluginPairs = getAllProfilePluginsByGroupIdAndArtifactId(model, ORPHEDOMOS_GROUP_ID, ORPHEDOMOS_ARTIFACT_ID); + if (!profilePluginPairs.isEmpty()) { + for (Pair profilePluginPair: profilePluginPairs) { + modifications.addAll(getAllPluginModifications(file, profilePluginPair.getRight(), profilePluginPair.getLeft())); + } } - return replacedBuildConfig || replacedCiProfile || replacedItProfile || replacedPackaging; + return writeModifications(file, modifications.finalizeMods()); + } + + private Predicate getFilterByGroupAndArtifactId(String pluginGroupId, String pluginArtifactId) { + return plugin -> plugin.getGroupId().equals(pluginGroupId) + && plugin.getArtifactId().equals(pluginArtifactId); } /** - * Returns instance of Plugin class with name equal to the pluginName provided, in the pom's build block + * Returns alls instances of {@link Plugin} with the matching group id and artifact id in the build section of a given pom model * @param model the model to check - * @param pluginName the name of the plugin - * @return Plugin with the plugin name specified + * @param pluginGroupId the group id of the plugin + * @param pluginArtifactId the artifact id of the plugin + * @return {@link List} of {@link Plugin}s */ - private Plugin getBuildPlugin(Model model, String pluginName) { + private List getAllBuildPluginsByGroupIdAndArtifactId(Model model, String pluginGroupId, String pluginArtifactId) { + List plugins = new ArrayList(); + Predicate pluginGroupArtifactIdFilter = getFilterByGroupAndArtifactId(pluginGroupId, pluginArtifactId); + + // Check the main build Build build = model.getBuild(); if (build != null) { - List plugins = build.getPlugins(); - for (Plugin plugin : plugins) { - if (pluginName.equalsIgnoreCase(plugin.getArtifactId())) { - return plugin; - } + // Get the build plugins + plugins.addAll(build.getPlugins().stream() + .filter(pluginGroupArtifactIdFilter) + .collect(Collectors.toCollection(ArrayList::new)) + ); + + // Get the build plugin management + if (build.getPluginManagement() != null) { + plugins.addAll(build.getPluginManagement().getPlugins().stream() + .filter(pluginGroupArtifactIdFilter) + .collect(Collectors.toCollection(ArrayList::new)) + ); } } - return null; + + return plugins; } /** - * Returns instance of Plugin class with name equal to the pluginName provided, in the pom's profiles block + * Returns alls instances of {@link Plugin} with the matching group id and artifact id in the profile section of a given pom model * @param model the model to check - * @param pluginName the name of the plugin - * @param profileId the profile housing the plugin - * @return Plugin with the plugin name specified + * @param pluginGroupId the group id of the plugin + * @param pluginArtifactId the artifact id of the plugin + * @return {@link List} of {@link Pair}s of the {@link String} profile name paired with its respective {@link Plugin} */ - private Plugin getProfilePlugin(Model model, String pluginName, String profileId) { + private List> getAllProfilePluginsByGroupIdAndArtifactId(Model model, String pluginGroupId, String pluginArtifactId) { + List> profilePluginsPairs = new ArrayList<>(); + Predicate pluginGroupArtifactIdFilter = getFilterByGroupAndArtifactId(pluginGroupId, pluginArtifactId); + + // Check the build within each profile List profiles = model.getProfiles(); - if (profiles != null) { - List plugins = profiles.stream() - .filter(profile -> profile.getId().equals(profileId)) - .flatMap(profile -> profile.getBuild().getPlugins().stream()) - .collect(Collectors.toCollection(ArrayList::new)); - for (Plugin plugin : plugins) { - if (pluginName.equalsIgnoreCase(plugin.getArtifactId())) { - return plugin; - } - } - } - return null; - } + for (Profile profile: profiles) { - private Xpp3Dom getConfiguration(Plugin plugin) { - Object pluginConfiguration = plugin.getConfiguration(); - return (Xpp3Dom) pluginConfiguration; - } + BuildBase profileBuild = profile.getBuild(); - private String getConfigValue(Xpp3Dom configuration, String parameter) { - String parameterValue; - if (hasConfigurationItem(configuration, parameter)) { - parameterValue = configuration.getChild(parameter).getValue(); - } else { - parameterValue = null; - } - return parameterValue; - } + if (profileBuild != null) { + List matchingPlugins = new ArrayList<>(); - private static boolean hasConfigurationItem(Xpp3Dom configuration, String configurationItem) { - return configuration.getChildren(configurationItem).length > 0; - } + // Check the profile build plugins + matchingPlugins.addAll(profileBuild.getPlugins().stream() + .filter(pluginGroupArtifactIdFilter) + .collect(Collectors.toCollection(ArrayList::new)) + ); - /** - * Function to check whether a given pom file has its packaging type set to Orphedomos - */ - private boolean containsOrphedomosPackaging(File file) { - boolean shouldExecute; - try { - List orphedomosPackaging = getRegExCaptureGroups(EXTRACT_PACKAGING_REGEX, file); - shouldExecute = CollectionUtils.isNotEmpty(orphedomosPackaging); - } catch (IOException e) { - throw new BatonException("Unable to determine if Orphedomos packaging migration must be executed", e); + // Check the profile build plugin management + if (profileBuild.getPluginManagement() != null) { + matchingPlugins.addAll(profileBuild.getPluginManagement().getPlugins().stream() + .filter(pluginGroupArtifactIdFilter) + .collect(Collectors.toCollection(ArrayList::new)) + ); + } + + // If there are matching plugins, add them to the list of pairs + if (!matchingPlugins.isEmpty()) { + matchingPlugins.stream().forEach(plugin -> profilePluginsPairs.add(Pair.of(profile.getId(), plugin))); + } + } } - return shouldExecute; + + return profilePluginsPairs; } - private boolean executeBuildConfigMigration(File file, Xpp3Dom config, Plugin buildPlugin) { - // grab the old imageVersion and imageName - imageVersion = getConfigValue(config, IMAGE_VERSION); - imageName = getConfigValue(config, IMAGE_NAME); - - if (imageName == null) { - imageName = "${project.artifactId}"; - } - if (imageVersion == null) { - imageVersion = "${project.version}"; - } + /** + * Returns all {@link Modification}s necessary for migrating an Orphedomos {@link Plugin} instance to fabric8 + * @param file + * @param plugin + * @param profileName + * @return + */ + private List getAllPluginModifications(File file, Plugin plugin, String profileName) { + List modifications = new ArrayList<>(); // Replace groupID and artifactID - PomModifications modifyPlugin = getReplaceGroupIdArtifactIdMod(buildPlugin); - boolean replacedGroupIdArtifactId = writeModifications(file, modifyPlugin.finalizeMods()); + modifications.addAll(getReplaceGroupIdArtifactIdMod(plugin)); - // get the latest plugin after previous modification - Plugin fabric8Plugin = getCurrentBuildPlugin(file); + // check if pom file has orphedomos configuration + Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration(); - // delete old orphedomos configuration - PomModifications removeOldConfig = new PomModifications(); - if (fabric8Plugin != null) { - updateModWithDeleteOrphedomosConfig(fabric8Plugin, removeOldConfig); - - // delete single line version tag if it exists - if (fabric8Plugin.getVersion() != null) { - updateModWithDeleteSingleLineVersionTag(fabric8Plugin, removeOldConfig); - } - } - - boolean replacedConfig = writeModifications(file, removeOldConfig.finalizeMods()); + if (config != null) { + // grab the old imageVersion and imageName and repoUrl + String imageVersion = getConfigValue(config, IMAGE_VERSION); + String imageName = getConfigValue(config, IMAGE_NAME); + String repoUrl = getConfigValue(config, REPO_URL); + + // check if it's a profile or build plugin instance + if (profileName == null) { + if (imageName == null) { + imageName = "${project.artifactId}"; + } + if (imageVersion == null) { + imageVersion = "${project.version}"; + } - // get the latest plugin after previous modification - Plugin updatedBuildPlugin = getCurrentBuildPlugin(file); + // set the values from the build plugin so they can be used as defaults in the profile config + buildRepoUrl = repoUrl; + buildImageName = imageName; + buildImageVersion = imageVersion; - // add the plugin image configuration - boolean replacedImageConfig = false; - PomModifications modifyConfig = getImageConfigAddMod(updatedBuildPlugin); - replacedImageConfig = writeModifications(file, modifyConfig.finalizeMods()); + } else { + // Use values from build plugin config as defaults if available + if (imageName == null) { + imageName = buildImageName != null ? buildImageName : "${project.artifactId}"; + } + if (imageVersion == null) { + imageVersion = buildImageVersion != null ? buildImageVersion : "${project.version}"; + } + if (repoUrl == null && !profileName.equals(INTEGRATION_TEST)) { + repoUrl = buildRepoUrl != null ? buildRepoUrl : "${docker.project.repository.url}"; + } + } - return replacedGroupIdArtifactId || replacedImageConfig || replacedConfig; - } + // Replace orphedomos configuration + modifications.add(getReplaceOrphedomosConfigMod(plugin, repoUrl, imageName, imageVersion, profileName)); + } - private Plugin getCurrentBuildPlugin(File file) { - Model updatedModel = getLocationAnnotatedModel(file); - return getBuildPlugin(updatedModel, FABRIC8_ARTIFACT_ID); - } + // delete single line version tag if it exists + if (plugin.getVersion() != null) { + modifications.add(getDeleteSingleLineVersionTagMod(plugin)); + } - private Plugin getCurrentProfilePlugin(File file, String profileName) { - Model updatedModel = getLocationAnnotatedModel(file); - return getProfilePlugin(updatedModel, FABRIC8_ARTIFACT_ID, profileName); + return modifications; } - private PomModifications getReplaceGroupIdArtifactIdMod(Plugin plugin) { - PomModifications modifyPlugin = new PomModifications(); + private List getReplaceGroupIdArtifactIdMod(Plugin plugin) { InputLocation startGroupId = plugin.getLocation(GROUP_ID); InputLocation endGroupId = PomHelper.incrementColumn(startGroupId, ORPHEDOMOS_GROUP_ID.length()); InputLocation startArtifactId = plugin.getLocation(ARTIFACT_ID); InputLocation endArtifactId = PomHelper.incrementColumn(startArtifactId, ORPHEDOMOS_ARTIFACT_ID.length()); - modifyPlugin.add(new PomModifications.Replacement(startGroupId, endGroupId, FABRIC8_GROUP_ID)); - modifyPlugin.add(new PomModifications.Replacement(startArtifactId, endArtifactId, FABRIC8_ARTIFACT_ID)); - return modifyPlugin; + List pomReplacements = new ArrayList<>(); + pomReplacements.add(new PomModifications.Replacement(startGroupId, endGroupId, FABRIC8_GROUP_ID)); + pomReplacements.add(new PomModifications.Replacement(startArtifactId, endArtifactId, FABRIC8_ARTIFACT_ID)); + return pomReplacements; } - private PomModifications getImageConfigAddMod(Plugin updatedBuildPlugin) { - PomModifications modifyImages = new PomModifications(); + private PomModifications.Replacement getPackagingMigrationMod(Model model) { + InputLocation startPackaging = model.getLocation(PACKAGING); + InputLocation endPackaging = PomHelper.incrementColumn(startPackaging, ORPHEDOMOS_PACKAGING.length()); - // add new configuration code - int indent = 4; - int startConfigCodeRow = updatedBuildPlugin.getLocation(ARTIFACT_ID).getLineNumber(); - InputLocation startConfigCode = new InputLocation(startConfigCodeRow + 1, updatedBuildPlugin.getLocation(ARTIFACT_ID).getColumnNumber()); - modifyImages.add(new PomModifications.Insertion(startConfigCode, indent, OrphedomosToFabric8Migration::getBuildConfigCode)); - - return modifyImages; + return new PomModifications.Replacement(startPackaging, endPackaging, FABRIC8_PACKAGING); } - /** - * Function that creates the new Fabric8 docker-maven-plugin configuration code. - */ - private static String getBuildConfigCode(String indent) { - return StringUtils.repeat(indent, 5) + "\n" + - StringUtils.repeat(indent, 6) + "true\n" + - StringUtils.repeat(indent, 6) + "\n" + - StringUtils.repeat(indent, 7) + "\n" + - StringUtils.repeat(indent, 8) + "" + imageName + ":" + imageVersion + "\n" + - StringUtils.repeat(indent, 7) + "\n" + - StringUtils.repeat(indent, 6) + "\n" + - StringUtils.repeat(indent, 5) + "\n"; - } + private PomModifications.Deletion getDeleteSingleLineVersionTagMod(Plugin plugin) { + InputLocation startVersionLocation = plugin.getLocation(VERSION + LocationAwareMavenReader.START); + InputLocation endVersionLocation = plugin.getLocation(VERSION + LocationAwareMavenReader.END); - private void updateModWithDeleteOrphedomosConfig(Plugin fabric8Plugin, PomModifications removeOldConfig) { - InputLocation startConfigLocation = fabric8Plugin.getLocation(CONFIGURATION + LocationAwareMavenReader.START); - InputLocation endConfigLocation = fabric8Plugin.getLocation(CONFIGURATION + LocationAwareMavenReader.END); - PomModifications.Deletion pomDeletePreviousConfig = new PomModifications.Deletion(startConfigLocation, endConfigLocation); - removeOldConfig.add(pomDeletePreviousConfig); + return new PomModifications.Deletion(startVersionLocation, endVersionLocation); } - private void updateModWithDeleteSingleLineVersionTag(Plugin fabric8Plugin, PomModifications removeOldConfig) { - InputLocation startVersionLocation = fabric8Plugin.getLocation(VERSION + LocationAwareMavenReader.START); - InputLocation endVersionLocation = fabric8Plugin.getLocation(VERSION + LocationAwareMavenReader.END); + private PomModifications.Replacement getReplaceOrphedomosConfigMod(Plugin plugin, String repoUrl, String imageName, String imageVersion, String profileName) { + InputLocation startConfigLocation = plugin.getLocation(CONFIGURATION + LocationAwareMavenReader.START); + InputLocation endConfigLocation = plugin.getLocation(CONFIGURATION + LocationAwareMavenReader.END); - PomModifications.Deletion pomDeletePreviousVersion = new PomModifications.Deletion(startVersionLocation, endVersionLocation); - removeOldConfig.add(pomDeletePreviousVersion); + return new PomModifications.Replacement(startConfigLocation, endConfigLocation, 1, getPluginConfig(repoUrl, imageName, imageVersion, profileName)); } - private boolean executeProfileMigration(File file, Plugin profilePlugin, String profileId) { - Xpp3Dom config = getConfiguration(profilePlugin); - repoUrl = getConfigValue(config, REPO_URL); - imageVersion = getConfigValue(config, IMAGE_VERSION); - imageName = getConfigValue(config, IMAGE_NAME); - - if (repoUrl == null) { - repoUrl = "${docker.project.repository.url}"; - } - if (imageName == null) { - imageName = "${project.artifactId}"; - } - if (imageVersion == null) { - imageVersion = "${project.version}"; - } - - // Replace groupID and artifactID in the profile's plugin - PomModifications modifyPlugin = getReplaceGroupIdArtifactIdMod(profilePlugin); - boolean replacedGroupIdArtifactId = writeModifications(file, modifyPlugin.finalizeMods()); - - // get the latest plugin after previous modification - Plugin fabric8Plugin = getCurrentProfilePlugin(file, profileId); - - // delete old orphedomos configuration - PomModifications removeOldConfig = new PomModifications(); - if (fabric8Plugin != null) { - updateModWithDeleteOrphedomosConfig(fabric8Plugin, removeOldConfig); - - // delete single line version tag if it exists - if (fabric8Plugin.getVersion() != null) { - updateModWithDeleteSingleLineVersionTag(fabric8Plugin, removeOldConfig); - } + /** + * Function that creates the new Fabric8 docker-maven-plugin configuration code. + */ + private static UnaryOperator getPluginConfig(String repoUrl, String imageName, String imageVersion, String profileName) { + // set the specific config for all build plugins and these two profiles + if (profileName == null || profileName.equals(INTEGRATION_TEST) || profileName.equals(CI)) { + Boolean shouldSkip = profileName == null ? true : false; // profiles should to set skip to false + return (indent) -> + indent + "\n" + + indent + StringUtils.repeat(SPACE, 4) + "" + shouldSkip.toString() + "\n" + + indent + StringUtils.repeat(SPACE, 4) + "\n" + + indent + StringUtils.repeat(SPACE, 4 * 2) + "\n" + + indent + StringUtils.repeat(SPACE, 4 * 3) + "" + getNameConfig(repoUrl, imageName, imageVersion, profileName) + "\n" + + indent + StringUtils.repeat(SPACE, 4 * 2) + "\n" + + indent + StringUtils.repeat(SPACE, 4) + "\n" + + indent + "\n"; + } + // set the config to blank for all other profiles + else { + return (indent) -> + indent + "\n" + + indent + StringUtils.repeat(SPACE, 4) + "\n" + + indent + "\n"; } - boolean replacedConfig = writeModifications(file, removeOldConfig.finalizeMods()); - - // get the latest plugin after previous modification - Plugin updatedProfilePlugin = getCurrentProfilePlugin(file, profileId); - - // add the relevant profile's configuration accordingly - boolean replacedProfilePluginConfig; - PomModifications modifyPluginConfig = getProfilePluginConfigMod(updatedProfilePlugin); - replacedProfilePluginConfig = writeModifications(file, modifyPluginConfig.finalizeMods()); - - return replacedGroupIdArtifactId || replacedProfilePluginConfig || replacedConfig; - } - - private PomModifications getProfilePluginConfigMod(Plugin updatedProfilePlugin) { - PomModifications modifyProfile = new PomModifications(); - int indent = 4; - int startConfigCodeRow = updatedProfilePlugin.getLocation(ARTIFACT_ID).getLineNumber(); - InputLocation startConfigCode = new InputLocation(startConfigCodeRow + 1, updatedProfilePlugin.getLocation(ARTIFACT_ID).getColumnNumber()); - modifyProfile.add(new PomModifications.Insertion(startConfigCode, indent, OrphedomosToFabric8Migration::getProfilePluginConfig)); - return modifyProfile; } - private static String getProfilePluginConfig(String indent) { - return StringUtils.repeat(indent, 5) + "\n" + - StringUtils.repeat(indent, 6) + "false\n" + - StringUtils.repeat(indent, 6) + "\n" + - StringUtils.repeat(indent, 7) + "\n" + - getNameConfig(indent) + - StringUtils.repeat(indent, 7) + "\n" + - StringUtils.repeat(indent, 6) + "\n" + - StringUtils.repeat(indent, 5) + "\n"; - } - - private static String getNameConfig(String indent) { - if (profile.equals(INTEGRATION_TEST)) { - return StringUtils.repeat(indent, 8) + "" + imageName + ":" + imageVersion + "\n"; + private static String getNameConfig(String repoUrl, String imageName, String imageVersion, String profileName) { + if (repoUrl != null && !repoUrl.isBlank()) { + return repoUrl + imageName + ":" + imageVersion; } else { - return StringUtils.repeat(indent, 8) + "" + repoUrl + "/" + imageName + ":" + imageVersion + "\n"; + return imageName + ":" + imageVersion; } } /** - * Function that performs the migration on the pom file's packaging type. + * Function to check whether a given pom file has its packaging type set to Orphedomos */ - private boolean executePackagingMigration(File file) { - boolean performedSuccessfully = false; - String replacementText = FIRST_REGEX_GROUPING + "docker-build" + SECOND_REGEX_GROUPING; + private boolean containsOrphedomosPackaging(File file) { + boolean shouldExecute; try { - performedSuccessfully = FileUtils.replaceInFile( - file, - EXTRACT_PACKAGING_REGEX, - replacementText - ); - } catch (Exception e) { - logger.error("Unable to perform packaging type migration due to exception", e); + List orphedomosPackaging = getRegExCaptureGroups(EXTRACT_PACKAGING_REGEX, file); + shouldExecute = CollectionUtils.isNotEmpty(orphedomosPackaging); + } catch (IOException e) { + throw new BatonException("Unable to determine if Orphedomos packaging migration must be executed", e); } + return shouldExecute; + } - return performedSuccessfully; + private String getConfigValue(Xpp3Dom configuration, String parameter) { + String parameterValue; + if (hasConfigurationItem(configuration, parameter)) { + parameterValue = configuration.getChild(parameter).getValue(); + } else { + parameterValue = null; + } + return parameterValue; } -} + private static boolean hasConfigurationItem(Xpp3Dom configuration, String configurationItem) { + return configuration.getChildren(configurationItem).length > 0; + } +} \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_8_0/OrphedomosToFabric8MigrationSteps.java b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_8_0/OrphedomosToFabric8MigrationSteps.java index ba0a57d03..9a4a1daf6 100644 --- a/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_8_0/OrphedomosToFabric8MigrationSteps.java +++ b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_8_0/OrphedomosToFabric8MigrationSteps.java @@ -11,99 +11,121 @@ */ import com.boozallen.aissemble.upgrade.migration.AbstractMigrationTest; -import org.technologybrewery.baton.util.pom.PomHelper; -import io.cucumber.java.en.And; -import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.io.FileUtils; +import io.cucumber.java.en.Given; +import org.apache.maven.model.BuildBase; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; +import org.apache.maven.model.Profile; +import org.technologybrewery.baton.util.pom.PomHelper; -import java.util.ArrayList; +import java.io.File; +import java.io.IOException; import java.util.List; -import java.util.stream.Collectors; +import java.util.Objects; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertNotNull; public class OrphedomosToFabric8MigrationSteps extends AbstractMigrationTest { - - protected List profilePluginsArtifactIds; - - @Given("A pom with Orphedomos in the plugin management") - public void a_pom_with_orphedomos_in_the_plugin_management() { - testFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/migrate-configuration/pom.xml"); - } - @When("The migration executes") - public void the_migration_executes() { - performMigration(new OrphedomosToFabric8Migration()); - assertTrue("The migration should execute", shouldExecute); + public static final String FABRIC8_ARTIFACT = "docker-maven-plugin"; + public static final String FABRIC8_GROUP = "${group.fabric8.plugin}"; + private File validationFile; + + @Given("a the default POM for the parent module of a project's Docker moduels") + public void aTheDefaultPOMForTheParentModuleOfAProjectsDockerModuels() { + testFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/migration/standard-parent/pom.xml"); + validationFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/validation/standard-parent/pom.xml"); } - @Then("The pom is updated to use the Fabric8 docker-maven-plugin") - public void the_pom_is_updated_to_use_the_fabric8_docker_maven_plugin() { - Model model = PomHelper.getLocationAnnotatedModel(testFile); - Object artifactId = model.getBuild().getPlugins().get(1).getArtifactId(); - assertEquals("docker-maven-plugin", artifactId.toString()); - Object groupId = model.getBuild().getPlugins().get(1).getGroupId(); - assertEquals("io.fabric8", groupId.toString()); + @Given("a default POM for a Docker module") + public void aDefaultPOMForADockerModule() { + testFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/migration/standard-image/pom.xml"); + validationFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/validation/standard-image/pom.xml"); + } + @Given("a POM that uses Orphedomos in multiple profiles") + public void aPOMThatUsesOrphedomosInMultipleProfiles() { + testFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/migration/multi-profile/pom.xml"); + validationFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/validation/multi-profile/pom.xml"); } - @And("Fabric8 is configured properly") - public void fabric8_is_configured_properly(){ - Model model = PomHelper.getLocationAnnotatedModel(testFile); - Object configuration = model.getBuild().getPlugins().get(1).getConfiguration(); - assertNotNull("The configuration was not added properly", configuration); + @Given("a POM that does not use the Orphedomos plugin") + public void aPOMThatDoesNotUseTheOrphedomosPlugin() { + testFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/migration/skip-migrate/pom.xml"); + validationFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/validation/skip-migrate/pom.xml"); } - @Then("the previous configuration was removed") - public void the_previous_configuration_was_removed() { - Model model = PomHelper.getLocationAnnotatedModel(testFile); - boolean hasOrphedomosArtifactId = model.getBuild().getPluginManagement().getPlugins().stream() - .map(Plugin::getArtifactId) - .anyMatch(artifactId -> artifactId.equals("orphedomos-maven-plugin")); - assertFalse("The previous orphedomos plugin was not removed successfully", hasOrphedomosArtifactId); + + @When("the Fabric8 migration executes") + public void theMigrationExecutes() { + performMigration(new OrphedomosToFabric8Migration()); } + @Then("the Orphedomos plugin is replaced with Fabric8") + public void theOrphedomosPluginIsReplacedWithFabric() throws IOException { + assertValidationFile("Orphedomos plugin should be replaced with Fabric8"); + } - @Given("A pom with its packaging set to Orphedomos") - public void a_pom_with_its_packaging_set_to_orphedomos() { - testFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/migrate-packaging-only/pom.xml"); + @Then("the Orphedomos packaging is replaced with Fabric8's docker-build packaging") + public void theOrphedomosPackagingIsReplacedWithFabric8sDockerBuildPackaging() throws IOException { + assertValidationFile("Orphedomos packaging should be replaced with `docker-maven-plugin`"); } - @Then("The pom is updated to use packaging type of docker-build") - public void the_pom_is_updated_to_use_packaging_type_of_docker_build() { - Model model = PomHelper.getLocationAnnotatedModel(testFile); - Object packaging = model.getPackaging(); - assertEquals("docker-build", packaging); + + @Then("the Orphedomos plugin is replaced with Fabric8 in all profiles") + public void theOrphedomosPluginIsReplacedWithFabricInAllProfiles() throws IOException { + assertValidationFile("Orphedomos plugin in profiles should be replaced with Fabric8"); } - @When("The migration is executed") - public void the_migration_is_executed() { - performMigration(new OrphedomosToFabric8Migration()); + @Then("the {string} profile configuration is updated") + public void theProfileConfigurationIsUpdated(String profile) { + Model expectedModel = PomHelper.getLocationAnnotatedModel(validationFile); + Model actualModel = PomHelper.getLocationAnnotatedModel(testFile); + BuildBase expectedProfile = getProfile(expectedModel, profile).getBuild(); + BuildBase actualProfile = getProfile(actualModel, profile).getBuild(); + + assertEquals("The profile configuration should be updated", + getFabric8PluginConfig(expectedProfile.getPlugins()), + getFabric8PluginConfig(actualProfile.getPlugins())); + + if (expectedProfile.getPluginManagement() != null) { + assertEquals("The profile configuration should be updated in pluginManagement", + getFabric8PluginConfig(expectedProfile.getPluginManagement().getPlugins()), + getFabric8PluginConfig(actualProfile.getPluginManagement().getPlugins())); + } + } + @Then("the POM is not modified") + public void thePOMIsNotModified() { + assertFalse("Migration should not have executed", shouldExecute); } - @Given("A pom with an Orphedomos config in a {string} profile") - public void a_pom_with_an_orphedomos_config_in_a_profile(String profile) { - testFile = getTestFile(String.format("v1_8_0/OrphedomosToFabric8Migration/migrate-profile/%s/pom.xml", profile)); + private void assertValidationFile(String message) throws IOException { + String expectedContent = FileUtils.readFileToString(validationFile, "UTF-8"); + String actualContent = FileUtils.readFileToString(testFile, "UTF-8"); + assertEquals(message, expectedContent, actualContent); } - @Then("Fabric8 is configured properly in the {string} profile") - public void fabric8_is_configured_properly_in_the_profile(String profileId) { - Model model = PomHelper.getLocationAnnotatedModel(testFile); - profilePluginsArtifactIds = model.getProfiles().stream() - .filter(profile -> profile.getId().equals(profileId)) - .flatMap(profile -> profile.getBuild().getPlugins().stream()) - .map(Plugin::getArtifactId) - .collect(Collectors.toCollection(ArrayList::new)); - assertTrue(String.format("Orphedomos should not be present in profile \"%s\".", profileId), profilePluginsArtifactIds.contains("docker-maven-plugin")); + private static Profile getProfile(Model model, String id) { + for (Profile profile : model.getProfiles()) { + if (profile.getId().equals(id)) { + return profile; + } + } + throw new RuntimeException("Profile not found: " + id); } - @And("the previous {string} profile configuration was removed") - public void the_previous_profile_configuration_was_removed(String profileId) { - assertFalse(String.format("Orphedomos should not be present in profile \"%s\".", profileId), profilePluginsArtifactIds.contains("orphedomos-maven-plugin")); + private static String getFabric8PluginConfig(List plugins) { + if (CollectionUtils.isEmpty(plugins)) { + return null; + } + for (Plugin plugin : plugins) { + if (FABRIC8_GROUP.equals(plugin.getGroupId()) && FABRIC8_ARTIFACT.equals(plugin.getArtifactId())) { + return Objects.toString(plugin.getConfiguration()); + } + } + throw new RuntimeException("Fabric8 plugin not found"); } } diff --git a/foundation/foundation-upgrade/src/test/resources/specifications/v1_8_0/orphedomos-to-fabric8-migration.feature b/foundation/foundation-upgrade/src/test/resources/specifications/v1_8_0/orphedomos-to-fabric8-migration.feature index 1861e7b6a..fc3d9a935 100644 --- a/foundation/foundation-upgrade/src/test/resources/specifications/v1_8_0/orphedomos-to-fabric8-migration.feature +++ b/foundation/foundation-upgrade/src/test/resources/specifications/v1_8_0/orphedomos-to-fabric8-migration.feature @@ -1,24 +1,26 @@ Feature: Migrate from using Orphedomos to Fabric8 docker-maven-plugin - Scenario: Pom file with Orphedomos plugin configuration is migrated to Fabric8 docker-maven-plugin - Given A pom with Orphedomos in the plugin management - When The migration executes - Then The pom is updated to use the Fabric8 docker-maven-plugin - And Fabric8 is configured properly - And the previous configuration was removed + Scenario: A standard Docker parent POM is migrated to Fabric8 + Given a the default POM for the parent module of a project's Docker moduels + When the Fabric8 migration executes + Then the Orphedomos plugin is replaced with Fabric8 + And the "ci" profile configuration is updated - Scenario Outline: Pom file with Orphedomos plugin configuration in a profile is migrated to Fabric8 docker-maven-plugin - Given A pom with an Orphedomos config in a "" profile - When The migration executes - Then Fabric8 is configured properly in the "" profile - And the previous "" profile configuration was removed - Examples: - | profile | - | integration-test | - | ci | + Scenario: A standard Docker module POM is migrated to Fabric8 + Given a default POM for a Docker module + When the Fabric8 migration executes + Then the Orphedomos packaging is replaced with Fabric8's docker-build packaging - Scenario: Pom file with Orphedomos packaging type is migrated to Fabric8 docker-build - Given A pom with its packaging set to Orphedomos - When The migration executes - Then The pom is updated to use packaging type of docker-build + Scenario: Pom file with Orphedomos plugin configuration in profile(s) plugin management section is migrated to Fabric8 docker-maven-plugin + Given a POM that uses Orphedomos in multiple profiles + When the Fabric8 migration executes + Then the Orphedomos plugin is replaced with Fabric8 in all profiles + And the "ci" profile configuration is updated + And the "integration-test" profile configuration is updated + And the "other-profile" profile configuration is updated + + Scenario: A non-applicable POM is not migrated + Given a POM that does not use the Orphedomos plugin + When the Fabric8 migration executes + And the POM is not modified diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-profile/integration-test/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-profile/integration-test/pom.xml deleted file mode 100644 index 4874d14bc..000000000 --- a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-profile/integration-test/pom.xml +++ /dev/null @@ -1,128 +0,0 @@ - - - - - 4.0.0 - - - com.boozallen.aissemble.test - test-project-tests - 1.0.0-SNAPSHOT - - - test-project-tests-docker - test-project::Tests::Docker - Integration test docker image for test-project - - orphedomos - - - - - org.technologybrewery.fermenter - fermenter-mda - false - - com.boozallen.aissemble.test - integration-test-docker - - - - org.technologybrewery.orphedomos - orphedomos-maven-plugin - ${version.orphedomos.plugin} - - true - - - - - - - - com.boozallen.aissemble.test - ${project.parent.artifactId}-java - ${project.version} - - - - - - integration-test - - - - org.technologybrewery.orphedomos - orphedomos-maven-plugin - ${version.orphedomos.plugin} - - false - latest - - - - maven-resources-plugin - - - copy-docker-resources - prepare-package - - copy-resources - - - ${project.build.directory}/specifications/ - - - ${project.parent.basedir}/${project.parent.artifactId}-java/src/main/resources/specifications/ - - ** - - false - - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy - prepare-package - - copy - - - - - ${project.groupId} - ${project.parent.artifactId}-java - ${project.version} - jar - true - ${project.artifactId}.jar - ${project.build.directory} - - - true - - - - - - - - - diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/multi-profile/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/multi-profile/pom.xml new file mode 100644 index 000000000..d878c1dbf --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/multi-profile/pom.xml @@ -0,0 +1,164 @@ + + + + + + + org.test + test-docker + 1.0.0-SNAPSHOT + + + test-spark-worker-docker + + orphedomos + + Test::Docker::Spark + Build for a Spark Docker container which contains all pipelines + 4.0.0 + + + + + org.technologybrewery.fermenter + fermenter-mda + + com.boozallen.aiops.cookbook + aissemble-spark-worker-docker + + + + org.technologybrewery.orphedomos + orphedomos-maven-plugin + 1.0.0 + + + default-build + none + + build + + + + + + + + + + integration-test + + + + + org.technologybrewery.orphedomos + orphedomos-maven-plugin + ${version.orphedomos.plugin} + + false + boozallen/${project.artifactId} + ${project.version} + + + + + + + + org.technologybrewery.orphedomos + orphedomos-maven-plugin + + false + boozallen/${project.artifactId} + ${project.version} + + ${docker.project.repository.url} + + + + org.test + test-plugin + ${version.test} + + true + + + + + + + ci + + + + + org.technologybrewery.orphedomos + orphedomos-maven-plugin + ${version.orphedomos.plugin} + + false + boozallen/${project.artifactId} + ${project.version} + + ${docker.project.repository.url} + + + + + + + + other-profile + + + + + org.technologybrewery.orphedomos + orphedomos-maven-plugin + + false + boozallen/${project.artifactId} + ${project.version} + + ${docker.project.repository.url} + + + + org.test + test-plugin + ${version.test} + + true + + + + + + + org.technologybrewery.orphedomos + orphedomos-maven-plugin + ${version.orphedomos.plugin} + + false + boozallen/${project.artifactId} + ${project.version} + + ${docker.project.repository.url} + + + + + + + + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/skip-migrate/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/skip-migrate/pom.xml new file mode 100644 index 000000000..6627e87d7 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/skip-migrate/pom.xml @@ -0,0 +1,37 @@ + + + + + 4.0.0 + + org.test + test-project-other + + test-project::Other + Contains the non-docker things + + not-docker + + + + + org.test + test-plugin + ${version.test} + + true + + + + + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-packaging-only/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/standard-image/pom.xml similarity index 84% rename from foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-packaging-only/pom.xml rename to foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/standard-image/pom.xml index 98bdd13ad..27d1c606a 100644 --- a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-packaging-only/pom.xml +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/standard-image/pom.xml @@ -15,15 +15,15 @@ org.test - test-project-docker + test-docker 1.0.0-SNAPSHOT - test-project-spark-worker-docker + test-spark-worker-docker orphedomos - test-project::Docker::Spark + Test::Docker::Spark Build for a Spark Docker container which contains all pipelines 4.0.0 @@ -72,8 +72,8 @@ ${project.groupId} - test-project-pipeline-models - ${project.parent.parent.basedir}/test-project-pipelines/ + test-pipeline-models + ${project.parent.parent.basedir}/test-pipelines/ ${project.build.directory}/dockerbuild/ ${version.habushu.dist.artifact} @@ -83,20 +83,12 @@ ${project.groupId} - test-project-pipeline-models + test-pipeline-models ${project.version} - - - ${project.groupId} - spark-pipeline - ${project.version} - pom - - diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-configuration/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/standard-parent/pom.xml similarity index 73% rename from foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-configuration/pom.xml rename to foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/standard-parent/pom.xml index 0f4cbef48..ab0ef13a2 100644 --- a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-configuration/pom.xml +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migration/standard-parent/pom.xml @@ -16,21 +16,21 @@ org.test - test-project + test 1.0.0-SNAPSHOT - test-project-docker + test-docker - test-project::Docker - Contains the Docker Build this test-project + Test::Docker + Contains the Docker Build pom - - test-project-spark-worker-docker - test-project-policy-decision-point-docker - test-project-vault-docker + test-policy-decision-point-docker + test-spark-worker-docker + test-training-step-docker + test-inference-step-docker @@ -41,13 +41,13 @@ fermenter-mda org.test - - test-project-pipeline-models + test-pipeline-models - test-project-pipeline-models + test-pipeline-models ${version.aissemble} @@ -56,7 +56,7 @@ ${project.groupId} - test-project-pipeline-models + test-pipeline-models ${project.version} @@ -76,11 +76,10 @@ org.technologybrewery.orphedomos orphedomos-maven-plugin - ${version.orphedomos.plugin} true ${project.version} - ${project.artifactId} + boozallen/${project.artifactId} @@ -97,14 +96,11 @@ false ${project.version} - - - ${docker.project.repository.url} + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/multi-profile/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/multi-profile/pom.xml new file mode 100644 index 000000000..185c5b772 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/multi-profile/pom.xml @@ -0,0 +1,156 @@ + + + + + + + org.test + test-docker + 1.0.0-SNAPSHOT + + + test-spark-worker-docker + + docker-build + + Test::Docker::Spark + Build for a Spark Docker container which contains all pipelines + 4.0.0 + + + + + org.technologybrewery.fermenter + fermenter-mda + + com.boozallen.aiops.cookbook + aissemble-spark-worker-docker + + + + ${group.fabric8.plugin} + docker-maven-plugin + + + default-build + none + + build + + + + + + + + + + integration-test + + + + + ${group.fabric8.plugin} + docker-maven-plugin + + false + + + boozallen/${project.artifactId}:${project.version} + + + + + + + + + ${group.fabric8.plugin} + docker-maven-plugin + + false + + + ${docker.project.repository.url}boozallen/${project.artifactId}:${project.version} + + + + + + org.test + test-plugin + ${version.test} + + true + + + + + + + ci + + + + + ${group.fabric8.plugin} + docker-maven-plugin + + false + + + ${docker.project.repository.url}boozallen/${project.artifactId}:${project.version} + + + + + + + + + + other-profile + + + + + ${group.fabric8.plugin} + docker-maven-plugin + + + + + + org.test + test-plugin + ${version.test} + + true + + + + + + + ${group.fabric8.plugin} + docker-maven-plugin + + + + + + + + + + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/skip-migrate/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/skip-migrate/pom.xml new file mode 100644 index 000000000..f3af3d751 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/skip-migrate/pom.xml @@ -0,0 +1,37 @@ + + + + + 4.0.0 + + org.test + test-project-other + + test-project::Other + Contains the non-docker things + + orphedomos + + + + + org.test + test-plugin + ${version.test} + + true + + + + + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/standard-image/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/standard-image/pom.xml new file mode 100644 index 000000000..577469d6f --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/standard-image/pom.xml @@ -0,0 +1,94 @@ + + + + + + + org.test + test-docker + 1.0.0-SNAPSHOT + + + test-spark-worker-docker + + docker-build + + Test::Docker::Spark + Build for a Spark Docker container which contains all pipelines + 4.0.0 + + + + + org.technologybrewery.fermenter + fermenter-mda + + com.boozallen.aiops.cookbook + aissemble-spark-worker-docker + + + + maven-resources-plugin + + + copy-docker-resources + prepare-package + + copy-resources + + + ${project.build.directory} + + + ${project.basedir}/src/main/resources/docker + false + + + + + + + + com.boozallen.aissemble + mda-maven-plugin + + + copy-pipeline-artifacts + prepare-package + + copy-pipeline-artifacts + + + + + ${project.groupId} + test-pipeline-models + ${project.parent.parent.basedir}/test-pipelines/ + ${project.build.directory}/dockerbuild/ + ${version.habushu.dist.artifact} + + data-flow + + + + + ${project.groupId} + test-pipeline-models + ${project.version} + + + + + + + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-profile/ci/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/standard-parent/pom.xml similarity index 63% rename from foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-profile/ci/pom.xml rename to foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/standard-parent/pom.xml index ceab8b797..dd6da7ff2 100644 --- a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-profile/ci/pom.xml +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/validation/standard-parent/pom.xml @@ -16,21 +16,21 @@ org.test - test-project + test 1.0.0-SNAPSHOT - test-project-docker + test-docker - test-project::Docker - Contains the Docker Build this test-project + Test::Docker + Contains the Docker Build pom - - test-project-spark-worker-docker - test-project-policy-decision-point-docker - test-project-vault-docker + test-policy-decision-point-docker + test-spark-worker-docker + test-training-step-docker + test-inference-step-docker @@ -41,13 +41,13 @@ fermenter-mda org.test - - test-project-pipeline-models + test-pipeline-models - test-project-pipeline-models + test-pipeline-models ${version.aissemble} @@ -56,7 +56,7 @@ ${project.groupId} - test-project-pipeline-models + test-pipeline-models ${project.version} @@ -74,13 +74,15 @@ - org.technologybrewery.orphedomos - orphedomos-maven-plugin - ${version.orphedomos.plugin} + ${group.fabric8.plugin} + docker-maven-plugin true - ${project.version} - ${project.artifactId} + + + boozallen/${project.artifactId}:${project.version} + + @@ -92,19 +94,20 @@ - org.technologybrewery.orphedomos - orphedomos-maven-plugin + ${group.fabric8.plugin} + docker-maven-plugin false - ${project.version} - - - ${docker.project.repository.url} + + + ${docker.project.repository.url}boozallen/${project.artifactId}:${project.version} + + + diff --git a/pom.xml b/pom.xml index eddf62b70..d82513e15 100644 --- a/pom.xml +++ b/pom.xml @@ -245,7 +245,7 @@ - org.technologybrewery.fabric8 + ${group.fabric8.plugin} docker-maven-plugin true