maven-git-versioning-extension icon indicating copy to clipboard operation
maven-git-versioning-extension copied to clipboard

[Feature Request] Activate and Deactivate Maven Profile based in git ref

Open oalagtash opened this issue 3 years ago • 8 comments

Great plugin! One thing I am missing is activating a profile. I tried using a property to activate a profile, but looks like the profile is not detecting this property.

My Configs look like: maven-git-versioning-extension.xml

<refs>
    <ref type="branch">
        <pattern><![CDATA[(feature\/)(?<project>[A-Za-z]+)-(?<issueNum>[0-9]+).*]]></pattern>
        <version>${version.release}-${ref.project}${ref.issueNum}-SNAPSHOT</version>
        <properties>
            <issueKey>FOO123</issueKey>
        </properties>
    </ref>
</refs>

pom.xml

...
<profile>
    <id>feature-branch</id>
    <activation>
        <property>
            <name>issueKey</name>
        </property>
    </activation>
</profile>
...

When I run clean install the pom version changes, but the profile does not activate.

oalagtash avatar Mar 09 '22 17:03 oalagtash

I'm afraid it is not possible right now. That is because only system properties are supported by maven for the <activation>< property>

qoomon avatar Mar 09 '22 23:03 qoomon

However I could add config section to activate or deactivate profiles

<ref type="branch">
  <profiles>
    <debug>true</debug>
  </profiles>
</ref>

qoomon avatar Mar 09 '22 23:03 qoomon

Yea that would be great!

oalagtash avatar Mar 10 '22 06:03 oalagtash

Apparently it is not that easy to enable profile in a dynamic way or I can't figuring out how. I tried at this branch with GitVersioningProfileSelector class. The strange think is it gets called however it does not have any effect no matter what I return from getActiveProfiles method.

Any help is welcome.

qoomon avatar Apr 21 '22 14:04 qoomon

I have played around a bit with this in https://github.com/advanova/maven-git-versioning-extension/tree/feature/control-profiles

This seems to work now. I think the main problem was this line: https://github.com/qoomon/maven-git-versioning-extension/blob/442d0256919f832ffd61f757bbc5d915fa4edbca/src/main/java/me/qoomon/maven/gitversioning/GitVersioningProfileSelector.java#L40

It should have a == instead of the !=, so that the custom profile activation is activated for all projects, that do have a project directory.

Unfortunately I couldn't rebase this easily, maybe you could help with that, since you know the code better? I could then do the rest to finish this (add tests, add documentation, change schema)

tisoft avatar Jan 02 '23 07:01 tisoft

@tisoft thanks a lot for your deep dive. I'll try to fix it the upcoming days.

qoomon avatar Jan 03 '23 15:01 qoomon

@tisoft I think you are right it is working, however the rebase involves more effort and I don't have the time right now. I maybe able to do the development until the end of January. I'll keep you posted.

qoomon avatar Jan 11 '23 15:01 qoomon

@tisoft Unfortunately there is a challenge to make the configuration available in the ProfileSelector. I don't have the time solve this for now. I reset the branch feature/control-profiles and added a working implementation for GitVersioningProfileSelector. Feel free to open a PR.

qoomon avatar Jan 13 '23 19:01 qoomon