Skip to content

Commit

Permalink
#58 Fix a bug when attempting to migrate pom files with no build sect…
Browse files Browse the repository at this point in the history
…ion.

Signed-off-by: Peter McClonski <[email protected]>
  • Loading branch information
peter-mcclonski committed May 14, 2024
1 parent a2d6bdd commit 3499bee
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import com.boozallen.aissemble.upgrade.migration.AbstractAissembleMigration;
import com.boozallen.aissemble.upgrade.util.pom.LocationAwareMavenReader;
import com.boozallen.aissemble.upgrade.util.pom.PomModifications;
import org.apache.maven.model.Build;
import org.apache.maven.model.InputLocation;
Expand All @@ -33,23 +34,30 @@ private boolean isHabushuPackaged(Model model) {
}

private boolean doesBuildDirTagExist(Model model) {
return null != model.getBuild().getLocation("directory");
return null != model.getBuild() && null != model.getBuild().getLocation("directory");
}

@Override
protected boolean shouldExecuteOnFile(File file) {
Model model = getLocationAnnotatedModel(file);
return !doesBuildDirTagExist(model) && isHabushuPackaged(model);
return isHabushuPackaged(model) && !doesBuildDirTagExist(model);
}

@Override
protected boolean performMigration(File file) {
Model model = getLocationAnnotatedModel(file);
Build build = model.getBuild();
InputLocation buildLocation = build.getLocation("");
InputLocation inputLocation = new InputLocation(buildLocation.getLineNumber() + 1, buildLocation.getColumnNumber());
String line = "\t\t<directory>dist</directory>\n";
int indent = 2;
InputLocation inputLocation;
String line;
if (build != null) {
InputLocation referenceLocation = build.getLocation("");
inputLocation = new InputLocation(referenceLocation.getLineNumber() + 1, referenceLocation.getColumnNumber());
line = "\t\t<directory>dist</directory>\n";
} else {
inputLocation = model.getLocation(LocationAwareMavenReader.END);
line = "\t<build><directory>dist</directory></build>\n";
}
PomModifications modifications = new PomModifications();
modifications.add(new PomModifications.Insertion(inputLocation, indent, l -> line));
return writeModifications(file, modifications.finalizeMods());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
public class EnableDistOutputFolderForHabushuBuildCacheMigrationSteps extends AbstractMigrationTest {
@Given("a habushu-packaged pom file where the build directory is unspecified")
public void a_habushu_packaged_pom_file_where_the_build_directory_is_unspecified() {
testFile = getTestFile("v1_7_0/EnableHabushuBuildCacheMigration/migration/pom.xml");
testFile = getTestFile("v1_7_0/EnableHabushuBuildCacheMigration/migration/add-dir-when-build-tag-exists/pom.xml");
}

@Given("a habushu-packaged pom file where the build block is unspecified")
public void a_habushu_packaged_pom_file_where_the_build_block_is_unspecified() {
testFile = getTestFile("v1_7_0/EnableHabushuBuildCacheMigration/migration/add-dir-and-build-when-build-tag-does-not-exist/pom.xml");
}

private AbstractAissembleMigration migration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Feature: Adds the <build><directory>dist</directory></build> tag to the pom file
When the habushu build cache migration executes
Then the pom file contains a specification of the build directory

Scenario: A pom file specifying Habushu packaging with no build block is successfully migrated to specify the build directory
Given a habushu-packaged pom file where the build block is unspecified
When the habushu build cache migration executes
Then the pom file contains a specification of the build directory

Scenario: A pom file that does not specify Habushu packaging will not be migrated.
Given a non-habushu-packaged pom file where the packaging is unspecified
When the habushu build cache migration executes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%L
aiSSEMBLE::Foundation::Upgrade
%%
Copyright (C) 2021 Booz Allen
%%
This software package is licensed under the Booz Allen Public License. All Rights Reserved.
#L%
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.boozallen.aissemble</groupId>
<artifactId>test-machine-learning-model</artifactId>
<version>1.7.0-SNAPSHOT</version>
</parent>

<artifactId>aissemble-machine-learning-training</artifactId>
<packaging>habushu</packaging>

<name>aiSSEMBLE::Test::MDA::Machine Learning::Machine Learning Training</name>
<description>${step.description}</description>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>aissemble-foundation-core-python</artifactId>
<version>${project.version}</version>
<type>habushu</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>aissemble-foundation-pdp-client-python</artifactId>
<version>${project.version}</version>
<type>habushu</type>
</dependency>
</dependencies>

</project>

0 comments on commit 3499bee

Please sign in to comment.