package de.evosec.gradle.gitflow.release;

import org.eclipse.jgit.transport.CredentialsProvider;
import org.gradle.api.Plugin;
import org.gradle.api.Project;

public class ReleasePlugin implements Plugin<Project> {

    private ReleaseExtension extension;

    @Override
    public void apply(Project project) {
        extension = project.getExtensions().create("release", ReleaseExtension.class, project);
        project.afterEvaluate(extension::afterEvaluate);

        CredentialsProvider.setDefault(new GitCredentialsProvider(extension));

        project.getTasks().create("releaseStart", StartReleaseTask.class, task -> task.setPlugin(ReleasePlugin.this));
        project.getTasks().create("releaseFinish", ReleaseFinishTask.class, task -> task.setPlugin(ReleasePlugin.this));
    }

    ReleaseExtension getExtension() {
        return extension;
    }
}

@@ -36,16 +36,61 @@
 lease;%0A%0A
+import com.github.zafarkhaja.semver.Version;%0A
 import o
@@ -136,16 +136,16 @@
 ovider;%0A
-
 import o
@@ -196,16 +196,72 @@
 Project;
+%0Aimport org.gradle.api.plugins.ExtraPropertiesExtension;
 %0A%0Apublic
@@ -637,24 +637,79 @@
 tension));%0A%0A
+        project.allprojects(this::setAndroidVersion);%0A%0A
         proj
@@ -977,24 +977,24 @@
 tension() %7B%0A
-
         retu
@@ -1012,11 +1012,755 @@
 n;%0A    %7D
+%0A%0A    private void setAndroidVersion(Project project) %7B%0A        Object extObj = project.getExtensions().findByName(%22ext%22);%0A        if (!(extObj instanceof ExtraPropertiesExtension)) %7B%0A            return;%0A        %7D%0A%0A        Version version = Version.valueOf(project.getVersion().toString());%0A%0A        int versionCode = extension.getAndroidVersionCodeOffset();%0A        versionCode += version.getPatchVersion();%0A        versionCode += version.getMinorVersion() * 1000;%0A        versionCode += version.getMajorVersion() * 1000000;%0A%0A        ExtraPropertiesExtension ext = (ExtraPropertiesExtension) extObj;%0A        ext.set(%22releaseAndroidVersionCode%22, versionCode);%0A        ext.set(%22releaseAndroidVersionName%22, project.getVersion().toString());%0A    %7D
 %0A%7D%0A

Set releaseAndroidVersionCode and releaseAndroidVersionName to be used for android builds