diff --git a/DRAFT_RELEASE_NOTES.md b/DRAFT_RELEASE_NOTES.md
index 45087158d..c5f62cc01 100644
--- a/DRAFT_RELEASE_NOTES.md
+++ b/DRAFT_RELEASE_NOTES.md
@@ -34,6 +34,7 @@ Note: instructions for adapting to these changes are outlined in the upgrade ins
# Known Issues
- There is currently a bug with the Sagemaker training Docker image generated by the `aissemble-sagemaker-training-docker` `Fermenter` profile. The installation of the `logistic-training` module's `requirements.txt` fails, due to an unresolvable set of dependencies.
+- Running a downstream project build with `-Pintegration-test` is currently broken due to incompatibilities that have remained from before the open-sourcing.
# Known Vulnerabilities
| Date
identified | Vulnerability | Severity | Package | Affected
versions | CVE | Fixed
in |
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 5c93c3e6b..e29ff6b72 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
@@ -63,19 +63,14 @@
io.fabric8
docker-maven-plugin
-
-
- default-build
-
- true
-
-
- ${project.artifactId}:${project.version}
-
-
-
-
-
+
+ true
+
+
+ ${project.artifactId}:${project.version}
+
+
+
@@ -86,15 +81,16 @@
- org.technologybrewery.orphedomos
- orphedomos-maven-plugin
+ io.fabric8
+ docker-maven-plugin
false
- ${project.version}
-
-
- ${docker.project.repository.url}
+
+
+ ${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 d4af6d9a9..3da6a2aac 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
@@ -14,7 +14,7 @@
${projectName}::Tests::Docker
Integration test docker image for ${projectName}
- orphedomos
+ docker-build
@@ -28,11 +28,15 @@
- org.technologybrewery.orphedomos
- orphedomos-maven-plugin
- ${version.orphedomos.plugin}
+ io.fabric8
+ docker-maven-plugin
true
+
+
+ ${project.artifactId}:${project.version}
+
+
@@ -52,12 +56,15 @@
- org.technologybrewery.orphedomos
- orphedomos-maven-plugin
- ${version.orphedomos.plugin}
+ io.fabric8
+ docker-maven-plugin
false
- latest
+
+
+ ${project.artifactId}:latest
+
+
@@ -73,7 +80,9 @@
${project.build.directory}/specifications/
- ${project.parent.basedir}/${project.parent.artifactId}-java/src/main/resources/specifications/
+
+ ${project.parent.basedir}/${project.parent.artifactId}-java/src/main/resources/specifications/
+
**
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 5fa53faaf..795946bdb 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
@@ -9,19 +9,22 @@
* This software package is licensed under the Booz Allen Public License. All Rights Reserved.
* #L%
*/
+
import com.boozallen.aissemble.upgrade.migration.AbstractAissembleMigration;
import com.boozallen.aissemble.upgrade.util.pom.LocationAwareMavenReader;
import org.apache.maven.model.Build;
+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 com.boozallen.aissemble.upgrade.util.pom.PomHelper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
-import org.apache.maven.model.InputLocation;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Plugin;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -40,7 +43,7 @@
* This migration is responsible for migrating pom files using Orphedomos to use the Fabric8 docker-maven-plugin.
*/
-public class OrphedomosToFabric8Migration extends AbstractAissembleMigration{
+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";
@@ -48,31 +51,102 @@ public class OrphedomosToFabric8Migration extends AbstractAissembleMigration{
private static final String FABRIC8_ARTIFACT_ID = "docker-maven-plugin";
private static final String EXTRACT_PACKAGING_REGEX = "()orphedomos(<\\/packaging>)";
private static final String SECOND_REGEX_GROUPING = "$2";
- private static final String ROOT_ARTIFACT_ID = "build-parent";
- private static final String ROOT_GROUP_ID = "com.boozallen.aissemble";
- private static final String TESTS_DOCKER_PARENT_ARTIFACT_ID = "-tests";
- private static final String TESTS_DOCKER_ARTIFACT_ID = "-tests-docker";
private static final String GROUP_ID = "groupId";
private static final String ARTIFACT_ID = "artifactId";
private static final String VERSION = "version";
- private static final String CONFIGURATION = "configuration";
private static final String IMAGE_NAME = "imageName";
private static final String IMAGE_VERSION = "imageVersion";
+ private static final String REPO_URL = "repoUrl";
+ 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;
+
+ /**
+ * Function to validate whether migration should be performed or not.
+ * @param file file to validate
+ * @return true if migration should be performed
+ */
+ @Override
+ 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);
+
+ return orphedomosBuildPlugin != null
+ || orphedomosCiProfilePlugin != null
+ || orphedomosItProfilePlugin != null
+ || containsOrphedomosPackaging(file);
+ }
+
+ /**
+ * Performs the migration if the shouldExecuteOnFile() returns true
+ * @param file file to migrate
+ * @return isSuccessful - whether file was migrated successfully or not
+ */
+ @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;
+
+ 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);
+ }
+
+ // check if pom file has orphedomos and replace
+ if (containsOrphedomosPackaging(file)) {
+ replacedPackaging = executePackagingMigration(file);
+ }
+
+ 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);
+ }
+
+ return replacedBuildConfig || replacedCiProfile || replacedItProfile || replacedPackaging;
+ }
/**
- * Function that returns instance of Plugin class with name equal to the pluginName provided
- * @param model the model to check
+ * Returns instance of Plugin class with name equal to the pluginName provided, in the pom's build block
+ * @param model the model to check
* @param pluginName the name of the plugin
* @return Plugin with the plugin name specified
*/
- private Plugin getPlugin(Model model, String pluginName) {
+ private Plugin getBuildPlugin(Model model, String pluginName) {
Build build = model.getBuild();
if (build != null) {
List plugins = build.getPlugins();
for (Plugin plugin : plugins) {
- if ((pluginName).equalsIgnoreCase(plugin.getArtifactId())) {
+ if (pluginName.equalsIgnoreCase(plugin.getArtifactId())) {
return plugin;
}
}
@@ -80,11 +154,27 @@ private Plugin getPlugin(Model model, String pluginName) {
return null;
}
- private boolean isRootProjectPom(Model model) {
- return ROOT_GROUP_ID.equals(model.getParent().getGroupId()) && ROOT_ARTIFACT_ID.equals(model.getParent().getArtifactId());
- }
- private boolean isTestDockerPom(Model model){
- return model.getParent().getArtifactId().endsWith(TESTS_DOCKER_PARENT_ARTIFACT_ID) && model.getArtifactId().endsWith(TESTS_DOCKER_ARTIFACT_ID);
+ /**
+ * Returns instance of Plugin class with name equal to the pluginName provided, in the pom's profiles block
+ * @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
+ */
+ private Plugin getProfilePlugin(Model model, String pluginName, String profileId) {
+ 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;
}
private Xpp3Dom getConfiguration(Plugin plugin) {
@@ -92,185 +182,219 @@ private Xpp3Dom getConfiguration(Plugin plugin) {
return (Xpp3Dom) pluginConfiguration;
}
- private static boolean hasConfigurationItem(Xpp3Dom configuration, String configurationItem){
+ 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;
}
/**
- * Function to validate whether migration should be performed or not.
- * @param file file to validate
- * @return true if migration should be performed
+ * Function to check whether a given pom file has its packaging type set to Orphedomos
*/
- @Override
- protected boolean shouldExecuteOnFile(File file) {
- boolean shouldExecute = false;
- boolean migrateConfiguration = false;
- boolean migratePackaging = false;
-
- Model model = getLocationAnnotatedModel(file);
- if (isRootProjectPom(model) || isTestDockerPom(model)){
- shouldExecute = false;
- } else {
- Plugin orphedomosPlugin = getPlugin(model, ORPHEDOMOS_ARTIFACT_ID);
- if (orphedomosPlugin != null){
- migrateConfiguration = true;
- }
- if(containsOrphedomosPackaging(file)){
- migratePackaging = true;
- }
- shouldExecute = migrateConfiguration || migratePackaging;
+ 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);
}
-
return shouldExecute;
}
- /**
- * Performs the migration if the shouldExecuteOnFile() returns true
- * @param file file to migrate
- * @return isSuccessful - whether file was migrated successfully or not
- */
- @Override
- protected boolean performMigration(File file) {
- Model model = getLocationAnnotatedModel(file);
- Plugin plugin = getPlugin(model, ORPHEDOMOS_ARTIFACT_ID);
- boolean replacedConfig = false;
- boolean replacedPackaging = false;
- boolean isSuccessful = false;
+ 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);
- Xpp3Dom config;
+ if (imageName == null) {
+ imageName = "${project.artifactId}";
+ }
+ if (imageVersion == null) {
+ imageVersion = "${project.version}";
+ }
- if (plugin != null){
- config = getConfiguration(plugin);
- } else {
- config = null;
- logger.info("Orphedomos plugin configuration not found. Skipping configuration migration.");
+ // Replace groupID and artifactID
+ PomModifications modifyPlugin = getReplaceGroupIdArtifactIdMod(buildPlugin);
+ boolean replacedGroupIdArtifactId = writeModifications(file, modifyPlugin.finalizeMods());
+
+ // get the latest plugin after previous modification
+ Plugin fabric8Plugin = getCurrentBuildPlugin(file);
+
+ // 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);
+ }
}
- // check if pom file has orphedomos-maven-plugin configuration
- if (config != null){
- // grab the old imageVersion and imageName
- imageVersion = getImageVersion(config);
- imageName = getImageName(config);
+ boolean replacedConfig = writeModifications(file, removeOldConfig.finalizeMods());
- // Replace groupID and artifactID
- PomModifications modifyPlugin = new PomModifications();
- InputLocation startGroupId = plugin.getLocation(GROUP_ID);
- InputLocation endGroupId = PomHelper.incrementColumn(startGroupId, ORPHEDOMOS_GROUP_ID.length());
+ // get the latest plugin after previous modification
+ Plugin updatedBuildPlugin = getCurrentBuildPlugin(file);
- InputLocation startArtifactId = plugin.getLocation(ARTIFACT_ID);
- InputLocation endArtifactId = PomHelper.incrementColumn(startArtifactId, ORPHEDOMOS_ARTIFACT_ID.length());
+ // add the plugin image configuration
+ boolean replacedImageConfig = false;
+ PomModifications modifyConfig = getImageConfigAddMod(updatedBuildPlugin);
+ replacedImageConfig = writeModifications(file, modifyConfig.finalizeMods());
- modifyPlugin.add(new PomModifications.Replacement(startGroupId, endGroupId, FABRIC8_GROUP_ID));
- modifyPlugin.add(new PomModifications.Replacement(startArtifactId, endArtifactId, FABRIC8_ARTIFACT_ID));
+ return replacedGroupIdArtifactId || replacedImageConfig || replacedConfig;
+ }
- writeModifications(file, modifyPlugin.finalizeMods());
+ private Plugin getCurrentBuildPlugin(File file) {
+ Model updatedModel = getLocationAnnotatedModel(file);
+ return getBuildPlugin(updatedModel, FABRIC8_ARTIFACT_ID);
+ }
- Model updatedModel = getLocationAnnotatedModel(file);
- Plugin updatedPlugin = getPlugin(updatedModel, FABRIC8_ARTIFACT_ID);
+ private Plugin getCurrentProfilePlugin(File file, String profileName) {
+ Model updatedModel = getLocationAnnotatedModel(file);
+ return getProfilePlugin(updatedModel, FABRIC8_ARTIFACT_ID, profileName);
+ }
- if (imageVersion != null && imageName != null) {
- PomModifications modifyImages = new PomModifications();
- // add new configuration code
- int indent = 4;
- int startConfigCodeRow = updatedPlugin.getLocation(ARTIFACT_ID).getLineNumber();
- InputLocation startConfigCode = new InputLocation(startConfigCodeRow + 1, updatedPlugin.getLocation(ARTIFACT_ID).getColumnNumber());
- modifyImages.add(new PomModifications.Insertion(startConfigCode, indent, OrphedomosToFabric8Migration::getConfigCode));
+ private PomModifications getReplaceGroupIdArtifactIdMod(Plugin plugin) {
+ PomModifications modifyPlugin = new PomModifications();
+ InputLocation startGroupId = plugin.getLocation(GROUP_ID);
+ InputLocation endGroupId = PomHelper.incrementColumn(startGroupId, ORPHEDOMOS_GROUP_ID.length());
- replacedConfig = writeModifications(file, modifyImages.finalizeMods());
+ 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;
+ }
- Model fabric8Model = getLocationAnnotatedModel(file);
- Plugin fabric8Plugin = getPlugin(fabric8Model, FABRIC8_ARTIFACT_ID);
- PomModifications removeOldConfig = new PomModifications();
+ private PomModifications getImageConfigAddMod(Plugin updatedBuildPlugin) {
+ PomModifications modifyImages = new PomModifications();
- // delete single line version tag if it exists
- String version = fabric8Plugin.getVersion();
- if (version != null) {
- InputLocation startVersionLocation = fabric8Plugin.getLocation(VERSION + LocationAwareMavenReader.START);
- InputLocation endVersionLocation = fabric8Plugin.getLocation(VERSION + LocationAwareMavenReader.END);
+ // 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));
- PomModifications.Deletion pomDeletePreviousVersion = new PomModifications.Deletion(startVersionLocation, endVersionLocation);
- removeOldConfig.add(pomDeletePreviousVersion);
- }
+ return modifyImages;
+ }
- // delete old orphedomos configuration
- 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);
+ /**
+ * 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";
+ }
- writeModifications(file, removeOldConfig.finalizeMods());
- }
+ 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);
+ }
- // check if pom file has orphedomos and replace
- if (containsOrphedomosPackaging(file)){
- replacedPackaging = executePackagingMigration(file);
+ private void updateModWithDeleteSingleLineVersionTag(Plugin fabric8Plugin, PomModifications removeOldConfig) {
+ InputLocation startVersionLocation = fabric8Plugin.getLocation(VERSION + LocationAwareMavenReader.START);
+ InputLocation endVersionLocation = fabric8Plugin.getLocation(VERSION + LocationAwareMavenReader.END);
+
+ PomModifications.Deletion pomDeletePreviousVersion = new PomModifications.Deletion(startVersionLocation, endVersionLocation);
+ removeOldConfig.add(pomDeletePreviousVersion);
+ }
+
+ 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}";
}
- isSuccessful = replacedConfig || replacedPackaging;
+ // Replace groupID and artifactID in the profile's plugin
+ PomModifications modifyPlugin = getReplaceGroupIdArtifactIdMod(profilePlugin);
+ boolean replacedGroupIdArtifactId = writeModifications(file, modifyPlugin.finalizeMods());
- return isSuccessful;
- }
+ // 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);
- private String getImageName(Xpp3Dom configuration){
- String imageName;
- if (hasConfigurationItem(configuration, IMAGE_NAME)) {
- imageName = configuration.getChild(IMAGE_NAME).getValue();
- } else {
- imageName = null;
+ // delete single line version tag if it exists
+ if (fabric8Plugin.getVersion() != null) {
+ updateModWithDeleteSingleLineVersionTag(fabric8Plugin, removeOldConfig);
+ }
}
- return imageName;
+ 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 String getImageVersion(Xpp3Dom configuration){
- String imageVersion;
- if (hasConfigurationItem(configuration, IMAGE_VERSION)) {
- imageVersion = configuration.getChild(IMAGE_VERSION).getValue();
- } else {
- imageVersion = null;
- }
- return imageVersion;
+ 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;
}
- /**
- * Function that creates the new Fabric8 docker-maven-plugin configuration code.
- */
- private static String getConfigCode(String indent){
- return StringUtils.repeat(indent, 4) + "\n" +
- StringUtils.repeat(indent, 5) + "\n" +
- StringUtils.repeat(indent, 6) + "default-build\n" +
- StringUtils.repeat(indent, 6) + "\n" +
- StringUtils.repeat(indent, 7) + "true\n" +
- StringUtils.repeat(indent, 7) + "\n" +
- StringUtils.repeat(indent, 8) + "\n" +
- StringUtils.repeat(indent, 9) + "" + imageName + ":" + imageVersion + "\n" +
- StringUtils.repeat(indent, 8) + "\n" +
- StringUtils.repeat(indent, 7) + "\n" +
- StringUtils.repeat(indent, 6) + "\n" +
- StringUtils.repeat(indent, 5) + "\n" +
- StringUtils.repeat(indent, 4) + "\n";
+ 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";
}
- /**
- * Function to check whether a given pom file has its packaging type set to Orphedomos
- */
- private boolean containsOrphedomosPackaging(File file){
- boolean shouldExecute = false;
- 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);
+ private static String getNameConfig(String indent) {
+ if (profile.equals(INTEGRATION_TEST)) {
+ return StringUtils.repeat(indent, 8) + "" + imageName + ":" + imageVersion + "\n";
+ } else {
+ return StringUtils.repeat(indent, 8) + "" + repoUrl + "/" + imageName + ":" + imageVersion + "\n";
}
- return shouldExecute;
}
/**
* Function that performs the migration on the pom file's packaging type.
*/
- private boolean executePackagingMigration(File file){
+ private boolean executePackagingMigration(File file) {
boolean performedSuccessfully = false;
String replacementText = FIRST_REGEX_GROUPING + "docker-build" + SECOND_REGEX_GROUPING;
try {
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 9f3e68941..71c343cb9 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
@@ -17,6 +17,11 @@
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -26,6 +31,8 @@
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");
@@ -49,20 +56,22 @@ public void the_pom_is_updated_to_use_the_fabric8_docker_maven_plugin() {
@And("Fabric8 is configured properly")
public void fabric8_is_configured_properly(){
Model model = PomHelper.getLocationAnnotatedModel(testFile);
- Object executions = model.getBuild().getPlugins().get(1).getExecutions();
- assertNotNull("The executions were not added properly", executions);
+ Object configuration = model.getBuild().getPlugins().get(1).getConfiguration();
+ assertNotNull("The configuration was not added properly", configuration);
}
@Then("the previous configuration was removed")
public void the_previous_configuration_was_removed() {
Model model = PomHelper.getLocationAnnotatedModel(testFile);
- Object configuration = model.getBuild().getPlugins().get(1).getConfiguration();
- assertNull("The previous configuration was not removed successfully", configuration);
+ 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);
}
@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/pom.xml");
+ testFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/migrate-packaging-only/pom.xml");
}
@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() {
@@ -71,18 +80,30 @@ public void the_pom_is_updated_to_use_packaging_type_of_docker_build() {
assertEquals("docker-build", packaging);
}
- @Given("A pom within the tests docker module")
- public void a_pom_within_the_tests_docker_module() {
- testFile = getTestFile("v1_8_0/OrphedomosToFabric8Migration/skip-migration/pom.xml");
- }
@When("The migration is executed")
public void the_migration_is_executed() {
performMigration(new OrphedomosToFabric8Migration());
}
- @Then("The pom is not updated to use the Fabric8 docker-maven-plugin")
- public void the_pom_is_not_updated_to_use_the_fabric8_docker_maven_plugin() {
- assertFalse("The migration should be skipped", 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));
}
+ @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"));
+ }
+
+ @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"));
+ }
}
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 b89678fdf..1861e7b6a 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
@@ -7,12 +7,18 @@ Feature: Migrate from using Orphedomos to Fabric8 docker-maven-plugin
And Fabric8 is configured properly
And the previous configuration was removed
+ 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: 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: Migration does not run for pom file within -tests-docker module
- Given A pom within the tests docker module
- When The migration is executed
- Then The pom is not updated to use the Fabric8 docker-maven-plugin
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/migrate-configuration/pom.xml
index ceab8b797..0f4cbef48 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/migrate-configuration/pom.xml
@@ -99,7 +99,7 @@
${project.version}
-
+
${docker.project.repository.url}
diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-packaging/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-packaging-only/pom.xml
similarity index 100%
rename from foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-packaging/pom.xml
rename to foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-packaging-only/pom.xml
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/migrate-profile/ci/pom.xml
new file mode 100644
index 000000000..ceab8b797
--- /dev/null
+++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-profile/ci/pom.xml
@@ -0,0 +1,110 @@
+
+
+
+
+ 4.0.0
+
+
+ org.test
+ test-project
+ 1.0.0-SNAPSHOT
+
+
+ test-project-docker
+
+ test-project::Docker
+ Contains the Docker Build this test-project
+ pom
+
+
+
+ test-project-spark-worker-docker
+ test-project-policy-decision-point-docker
+ test-project-vault-docker
+
+
+
+
+
+
+ org.technologybrewery.fermenter
+ fermenter-mda
+
+ org.test
+
+
+ test-project-pipeline-models
+
+
+ test-project-pipeline-models
+
+
+ ${version.aissemble}
+
+
+
+
+ ${project.groupId}
+ test-project-pipeline-models
+ ${project.version}
+
+
+
+
+
+
+
+ org.technologybrewery.fermenter
+ fermenter-mda
+ false
+
+ org.test
+ docker-spark-python-pipelines
+
+
+
+ org.technologybrewery.orphedomos
+ orphedomos-maven-plugin
+ ${version.orphedomos.plugin}
+
+ true
+ ${project.version}
+ ${project.artifactId}
+
+
+
+
+
+
+
+ ci
+
+
+
+ org.technologybrewery.orphedomos
+ orphedomos-maven-plugin
+
+ false
+ ${project.version}
+
+
+ ${docker.project.repository.url}
+
+
+
+
+
+
+
diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/skip-migration/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-profile/integration-test/pom.xml
similarity index 100%
rename from foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/skip-migration/pom.xml
rename to foundation/foundation-upgrade/src/test/resources/test-files/v1_8_0/OrphedomosToFabric8Migration/migrate-profile/integration-test/pom.xml