Repository: mojohaus/versions (java)

Issue:
set-property doesn't work as expected if the property is not present in the module
Considering the pom:

```
<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>
    <groupId>default-group</groupId>
    <artifactId>default-artifact</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <profiles>
        <profile>
            <id>test-profile</id>
            <properties>
                <dummy-api-version>test-value</dummy-api-version>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>localhost</groupId>
                    <artifactId>dummy-api</artifactId>
                    <version>${dummy-api-version}</version>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>

```
running

`mvn versions:set-property -Dproperty=dummy-api-version -DnewVersion=1.2.3 -DgenerateBackupPoms=false -DprofileId=test-profile`

I'm expecting that the `dummy-api-version` property will be `1.2.3` but it doesn't

to make this works it is necessary to add the same property on the module

```
<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>
    <groupId>default-group</groupId>
    <artifactId>default-artifact</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>
    <properties>
        <dummy-api-version>test-value</dummy-api-version>
    </properties>

    <profiles>
        <profile>
            <id>test-profile</id>
            <properties>
                <dummy-api-version>test-value</dummy-api-version>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>localhost</groupId>
                    <artifactId>dummy-api</artifactId>
                    <version>${dummy-api-version}</version>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>
```

even if it changes the value in the profile, it should works even if the property is declared only in the profile

Pull request description:
Fixed #1233- set-property in profile without module  property
Handles the case when the property is not in the project properties but it is present in the profile properties

Patch:
diff --git a/pom.xml b/pom.xml
index a7378820..b213b73a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -358,7 +358,7 @@
       <dependency>
         <groupId>commons-io</groupId>
         <artifactId>commons-io</artifactId>
-        <version>2.18.0</version>
+        <version>2.19.0</version>
       </dependency>
       <dependency>
         <groupId>org.codehaus.plexus</groupId>
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java
index fa11585f..8ce3c29f 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java
@@ -171,8 +171,19 @@ public class SetPropertyMojo extends AbstractVersionsUpdaterMojo {
             Property currentProperty = entry.getKey();
             PropertyVersions version = entry.getValue();
             String newVersionGiven = currentProperty.getVersion();
-            final String profileToApply = isEmpty(profileId) ? version.getProfileId() : profileId;
-            final String currentVersion = getProject().getProperties().getProperty(currentProperty.getName());
+            String profileToApply;
+            String currentVersion;
+            if (isEmpty(profileId)) {
+                profileToApply = version.getProfileId();
+                currentVersion = getProject().getProperties().getProperty(currentProperty.getName());
+            } else {
+                profileToApply = profileId;
+                currentVersion = getProject().getModel().getProfiles().stream()
+                        .filter(profile -> profileId.equals(profile.getId()))
+                        .findFirst()
+                        .map(profile -> profile.getProperties().getProperty(currentProperty.getName()))
+                        .orElse(null);
+            }
             if (currentVersion == null) {
                 continue;
             }


Test patch:
diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetPropertyMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetPropertyMojoTest.java
index b4826170..77841287 100644
--- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetPropertyMojoTest.java
+++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetPropertyMojoTest.java
@@ -128,11 +128,22 @@ public class SetPropertyMojoTest extends AbstractMojoTestCase {
     }
 
     @Test
-    public void testChangeOnlyPropertiesInTheProfile() throws Exception {
+    public void testChangeOnlyPropertiesInTheProfileWithPropertyAlsoInTheModule() throws Exception {
+        testChangeOnlyPropertiesInTheProfile(true);
+    }
+
+    @Test
+    public void testChangeOnlyPropertiesInTheProfileWithPropertyOnlyInProfile() throws Exception {
+        testChangeOnlyPropertiesInTheProfile(false);
+    }
+
+    private void testChangeOnlyPropertiesInTheProfile(boolean withPropertyInTheModule) throws Exception {
         final String newVersion = UUID.randomUUID().toString();
-        final Model model = getModelForProfile("test-profile", true, newVersion);
+        final Model model = getModelForProfile("test-profile", true, newVersion, withPropertyInTheModule);
 
-        assertThat(model.getProperties().getProperty("dummy-api-version"), is("1.0.0"));
+        if (withPropertyInTheModule) {
+            assertThat(model.getProperties().getProperty("dummy-api-version"), is("1.0.0"));
+        }
         assertThat(
                 model.getProfiles().stream()
                         .filter(profile -> "test-profile".equals(profile.getId()))
@@ -181,7 +192,15 @@ public class SetPropertyMojoTest extends AbstractMojoTestCase {
     }
 
     private Model getModelForProfile(String profileName, Boolean setProfile, String newVersion) throws Exception {
-        copyDir(Paths.get("src/test/resources/org/codehaus/mojo/set-property/profiled-new-version"), pomDir);
+        return getModelForProfile(profileName, setProfile, newVersion, true);
+    }
+
+    private Model getModelForProfile(
+            String profileName, Boolean setProfile, String newVersion, Boolean withPropsInModule) throws Exception {
+        final String srcModule = withPropsInModule
+                ? "src/test/resources/org/codehaus/mojo/set-property/profiled-new-version"
+                : "src/test/resources/org/codehaus/mojo/set-property/profiled-new-version-without-props";
+        copyDir(Paths.get(srcModule), pomDir);
         SetPropertyMojo mojo = (SetPropertyMojo) mojoRule.lookupConfiguredMojo(pomDir.toFile(), "set-property");
 
         mojo.repositorySystem = mock(org.eclipse.aether.RepositorySystem.class);
diff --git a/versions-maven-plugin/src/test/resources/org/codehaus/mojo/set-property/profiled-new-version-without-props/pom.xml b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/set-property/profiled-new-version-without-props/pom.xml
new file mode 100644
index 00000000..e8218d45
--- /dev/null
+++ b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/set-property/profiled-new-version-without-props/pom.xml
@@ -0,0 +1,35 @@
+<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>
+    <groupId>default-group</groupId>
+    <artifactId>default-artifact</artifactId>
+    <version>1.0</version>
+    <packaging>pom</packaging>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>versions-maven-plugin</artifactId>
+                <configuration>
+                    <property>dummy-api-version</property>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <profiles>
+        <profile>
+            <id>test-profile</id>
+            <properties>
+                <dummy-api-version>test-value</dummy-api-version>
+            </properties>
+            <dependencies>
+                <dependency>
+                    <groupId>localhost</groupId>
+                    <artifactId>dummy-api</artifactId>
+                    <version>${dummy-api-version}</version>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+</project>