Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#58 Fix a bug when attempting to migrate pom files with no build sect… #71

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>