-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
169 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
gradle-plugin/src/main/java/org/dmfs/gradle/gver/tasks/ApplicableReleaseTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.dmfs.gradle.gver.tasks; | ||
|
||
import org.dmfs.gver.dsl.GitVersionConfig; | ||
import org.dmfs.gver.dsl.ReleaseType; | ||
import org.dmfs.jems2.iterable.DelegatingIterable; | ||
import org.dmfs.jems2.iterable.Mapped; | ||
import org.dmfs.jems2.iterable.Sieved; | ||
import org.eclipse.jgit.lib.Repository; | ||
import org.eclipse.jgit.revwalk.RevCommit; | ||
|
||
import java.util.Map; | ||
|
||
public final class ApplicableReleaseTypes extends DelegatingIterable<ReleaseType> | ||
{ | ||
public ApplicableReleaseTypes(GitVersionConfig config, Repository repository, RevCommit revCommit, String name) | ||
{ | ||
super(new Mapped<>(Map.Entry::getValue, | ||
new Sieved<>(entry -> entry.getKey().matches(repository, revCommit, name), | ||
config.mTagConfig.mTagMappings.entrySet()))); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
gradle-plugin/src/main/java/org/dmfs/gradle/gver/tasks/TagPreReleaseTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.dmfs.gradle.gver.tasks; | ||
|
||
import org.dmfs.gradle.gver.utils.ProjectRepositoryFunction; | ||
import org.dmfs.gver.dsl.GitVersionConfig; | ||
import org.dmfs.jems2.iterable.Mapped; | ||
import org.dmfs.jems2.optional.First; | ||
import org.dmfs.semver.StrictParser; | ||
import org.dmfs.semver.VersionSequence; | ||
import org.eclipse.jgit.api.Git; | ||
import org.eclipse.jgit.api.errors.GitAPIException; | ||
import org.eclipse.jgit.lib.ObjectId; | ||
import org.eclipse.jgit.lib.Repository; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.Task; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.dmfs.gver.dsl.ReleaseType.PRERELEASE; | ||
import static org.eclipse.jgit.lib.Constants.R_TAGS; | ||
|
||
|
||
/** | ||
* A Gradle {@link Task} that tags the current HEAD with a new pre-release version. | ||
* Note, that this task will throw an {@link IllegalStateException} when the current HEAD is not on a pre-release branch. | ||
*/ | ||
public class TagPreReleaseTask extends DefaultTask | ||
{ | ||
public TagPreReleaseTask() | ||
{ | ||
setGroup("gver"); | ||
setDescription("Tags the HEAD commit with a new pre-release version."); | ||
} | ||
|
||
@TaskAction | ||
public void perform() throws IOException, GitAPIException | ||
{ | ||
try (Repository r = ProjectRepositoryFunction.INSTANCE.value(getProject())) | ||
{ | ||
Git git = new Git(r); | ||
GitVersionConfig config = (GitVersionConfig) getProject().getExtensions().getByName("gver"); | ||
ObjectId head = r.resolve("HEAD"); | ||
|
||
if (!new First<>(PRERELEASE::equals, new ApplicableReleaseTypes(config, r, r.parseCommit(head), r.getBranch())) | ||
.isPresent()) | ||
{ | ||
throw new IllegalStateException("Not adding a release tag on non-pre-release branch"); | ||
} | ||
|
||
getLogger().lifecycle(getProject().getVersion().toString()); | ||
getLogger().lifecycle(""+new StrictParser().parse(getProject().getVersion().toString()).build().isPresent()); | ||
String version = new VersionSequence(new StrictParser().parse(getProject().getVersion().toString())).toString(); | ||
|
||
if (!new First<>(version::equals, | ||
new Mapped<>(tag -> tag.getName().startsWith(R_TAGS) ? tag.getName().substring(R_TAGS.length()) : tag.getName(), | ||
git.tagList().call())).isPresent()) | ||
{ | ||
git.tag() | ||
.setObjectId(r.parseCommit(head)) | ||
.setName(version) | ||
.call(); | ||
} | ||
else | ||
{ | ||
getLogger().lifecycle("Tag {} already exists. Not adding tag.", version); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.dmfs.gver.dsl; | ||
|
||
public enum ReleaseType | ||
{ | ||
RELEASE, | ||
PRERELEASE, | ||
NOTHING | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.dmfs.gver.dsl; | ||
|
||
import groovy.lang.Closure; | ||
import org.dmfs.gver.git.changetypefacories.Condition; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public final class TagConfig | ||
{ | ||
public final Map<Condition, ReleaseType> mTagMappings = new LinkedHashMap<>(); | ||
|
||
public final ReleaseType release = ReleaseType.RELEASE; | ||
public final ReleaseType preRelease = ReleaseType.PRERELEASE; | ||
public final ReleaseType nothing = ReleaseType.NOTHING; | ||
|
||
public ConditionConsumer with(ReleaseType type) | ||
{ | ||
return new ConditionConsumer() | ||
{ | ||
@Override | ||
public void when(Closure<?> condition) | ||
{ | ||
Conditions conditions = new Conditions(); | ||
condition.setResolveStrategy(Closure.DELEGATE_FIRST); | ||
condition.setDelegate(conditions); | ||
condition.call(); | ||
|
||
mTagMappings.put(conditions, type); | ||
} | ||
|
||
@Override | ||
public Void getOtherwise() | ||
{ | ||
mTagMappings.put((repository, commit, branch) -> true, type); | ||
return null; | ||
} | ||
|
||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters