Skip to content

Commit

Permalink
Merge pull request #204 from groovy/203_fix
Browse files Browse the repository at this point in the history
Check that user property exists before adding to properties
  • Loading branch information
keeganwitt authored Nov 23, 2021
2 parents a7d6a0c + b662879 commit 5fcfa68
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.14.0-SNAPSHOT</version>
<version>1.13.1-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ protected void initializeProperties() {
properties.putAll(session.getUserProperties());
} else if (bindAllProjectProperties && bindSessionUserOverrideProperties && project != null) {
for (Object key : project.getProperties().keySet()) {
properties.put(key, session.getUserProperties().get(key));
if (session.getUserProperties().get(key) != null) {
properties.put(key, session.getUserProperties().get(key));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ public void testAddAllSessionUserProperties() {
assertEquals("bar", testMojo.properties.get("foo"));
}

@Test
public void testBindAllProjectPropertiesAndBindSessionUserOverridePropertiesWhenEmpty() {
MavenSession session = mock(MavenSession.class);
Properties projectProperties = new Properties();
projectProperties.put("foo", "bar");
doReturn(new Properties()).when(session).getUserProperties();
doReturn(projectProperties).when(project).getProperties();
testMojo.session = session;
testMojo.bindAllProjectProperties = true;
testMojo.bindSessionUserOverrideProperties = true;

testMojo.initializeProperties();
}

@Test
public void testSessionPropertiesOverrideProjectPropertiesAndIncludesOthers() {
Properties projectProperties = new Properties();
Expand Down

0 comments on commit 5fcfa68

Please sign in to comment.