From 66cf7c5e80f15431b03ed71d2bb6ecdea451d9a6 Mon Sep 17 00:00:00 2001 From: Aaron Gershman Date: Wed, 15 Dec 2021 12:47:05 -0600 Subject: [PATCH] Handle profile activation property being null --- .../maven/MavenMojoProjectParser.java | 2 +- .../java/org/openrewrite/maven/BasicIT.java | 17 ++++++++++ .../null_check_profile_activation/pom.xml | 32 +++++++++++++++++++ .../settings.xml | 19 +++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/test/resources-its/org/openrewrite/maven/BasicIT/null_check_profile_activation/pom.xml create mode 100644 src/test/resources-its/org/openrewrite/maven/BasicIT/null_check_profile_activation/settings.xml diff --git a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java index 7c17e80c..6f733daf 100644 --- a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java +++ b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java @@ -191,7 +191,7 @@ private MavenSettings buildSettings() { p.getActivation() == null ? null : new ProfileActivation( p.getActivation().isActiveByDefault(), p.getActivation().getJdk(), - new ProfileActivation.Property( + p.getActivation().getProperty() == null ? null : new ProfileActivation.Property( p.getActivation().getProperty().getName(), p.getActivation().getProperty().getValue() ) diff --git a/src/test/java/org/openrewrite/maven/BasicIT.java b/src/test/java/org/openrewrite/maven/BasicIT.java index c21344b8..7c083eb0 100644 --- a/src/test/java/org/openrewrite/maven/BasicIT.java +++ b/src/test/java/org/openrewrite/maven/BasicIT.java @@ -19,6 +19,23 @@ void groupid_artifactid_should_be_ok(MavenExecutionResult result) { .containsOnly("JAR will be empty - no content was marked for inclusion!"); } + @MavenTest + @MavenOption(value = MavenCLIOptions.SETTINGS, parameter = "settings.xml") + @MavenGoal("${project.groupId}:${project.artifactId}:${project.version}:dryRun") + void null_check_profile_activation(MavenExecutionResult result) { + assertThat(result) + .isSuccessful() + .out() + .info() + .anySatisfy(line -> assertThat(line).contains("Applying recipes would make no changes. No patch file generated.")); + + assertThat(result) + .isSuccessful() + .out() + .warn() + .isEmpty(); + } + @MavenTest @SystemProperty(value = "ossrh_snapshots_url", content = "https://oss.sonatype.org/content/repositories/snapshots") @MavenGoal("${project.groupId}:${project.artifactId}:${project.version}:dryRun") diff --git a/src/test/resources-its/org/openrewrite/maven/BasicIT/null_check_profile_activation/pom.xml b/src/test/resources-its/org/openrewrite/maven/BasicIT/null_check_profile_activation/pom.xml new file mode 100644 index 00000000..8ed3076e --- /dev/null +++ b/src/test/resources-its/org/openrewrite/maven/BasicIT/null_check_profile_activation/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + + org.openrewrite.maven + null_check_profile_activation + 1.0 + jar + BasicIT#null_check_profile_activation + + + 1.8 + 1.8 + UTF-8 + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + org.openrewrite.java.format.AutoFormat + + + + + + diff --git a/src/test/resources-its/org/openrewrite/maven/BasicIT/null_check_profile_activation/settings.xml b/src/test/resources-its/org/openrewrite/maven/BasicIT/null_check_profile_activation/settings.xml new file mode 100644 index 00000000..7189857e --- /dev/null +++ b/src/test/resources-its/org/openrewrite/maven/BasicIT/null_check_profile_activation/settings.xml @@ -0,0 +1,19 @@ + + + + example_profile_id + + true + + + + example_repository_id + https://repo1.maven.org/maven2 + + + + + + \ No newline at end of file