Skip to content

Commit

Permalink
Merge pull request #93 from ajoberstar/next
Browse files Browse the repository at this point in the history
Changes for 0.8.0
  • Loading branch information
ajoberstar authored Jul 4, 2018
2 parents 0f980de + c2a4394 commit 96c3360
Show file tree
Hide file tree
Showing 49 changed files with 170 additions and 411 deletions.
36 changes: 3 additions & 33 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,11 @@ plugins {
id 'org.ajoberstar.defaults' version '0.12.0'
}

apply from: 'gradle/locking.gradle'
apply from: 'gradle/bintray.gradle'

allprojects {
group = 'org.ajoberstar.reckon'

dependencyLocking {
lockAllConfigurations()
}

task lock {
doFirst {
assert gradle.startParameter.writeDependencyLocks
}
doLast {
configurations.each {
if (it.canBeResolved) {
it.resolve()
}
}
}
}

plugins.withId('maven-publish') {
publishing {
repositories {
maven {
name = 'bintray'
url = 'https://api.bintray.com/maven/ajoberstar/maven/reckon/;publish=1'
credentials {
username = System.env['BINTRAY_USER']
password = System.env['BINTRAY_KEY']
}
}
}
}
}

}

ext.grgitVersion = '[2.0.0,)'
Expand Down
16 changes: 16 additions & 0 deletions gradle/bintray.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
allprojects {
plugins.withId('maven-publish') {
publishing {
repositories {
maven {
name = 'bintray'
url = 'https://api.bintray.com/maven/ajoberstar/maven/reckon/;publish=1'
credentials {
username = System.env['BINTRAY_USER']
password = System.env['BINTRAY_KEY']
}
}
}
}
}
}
3 changes: 0 additions & 3 deletions gradle/dependency-locks/archives.lockfile

This file was deleted.

3 changes: 0 additions & 3 deletions gradle/dependency-locks/default.lockfile

This file was deleted.

20 changes: 20 additions & 0 deletions gradle/locking.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
allprojects {
plugins.withId('java-base') {
sourceSets.all { sourceSet ->
configurations[sourceSet.compileClasspathConfigurationName].resolutionStrategy.activateDependencyLocking()
configurations[sourceSet.runtimeClasspathConfigurationName].resolutionStrategy.activateDependencyLocking()
}

task lock {
doFirst {
assert gradle.startParameter.writeDependencyLocks
}
doLast {
sourceSets.all { sourceSet ->
configurations[sourceSet.compileClasspathConfigurationName].resolve()
configurations[sourceSet.runtimeClasspathConfigurationName].resolve()
}
}
}
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-rc-3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-rc-1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

This file was deleted.

3 changes: 0 additions & 3 deletions reckon-core/gradle/dependency-locks/archives.lockfile

This file was deleted.

14 changes: 0 additions & 14 deletions reckon-core/gradle/dependency-locks/compile.lockfile

This file was deleted.

3 changes: 0 additions & 3 deletions reckon-core/gradle/dependency-locks/compileOnly.lockfile

This file was deleted.

14 changes: 0 additions & 14 deletions reckon-core/gradle/dependency-locks/default.lockfile

This file was deleted.

14 changes: 0 additions & 14 deletions reckon-core/gradle/dependency-locks/runtime.lockfile

This file was deleted.

This file was deleted.

28 changes: 0 additions & 28 deletions reckon-core/gradle/dependency-locks/testCompile.lockfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ commons-logging:commons-logging:1.2
junit:junit:4.12
net.java.dev.jna:jna-platform:4.1.0
net.java.dev.jna:jna:4.1.0
org.ajoberstar:grgit:2.2.1
org.ajoberstar:grgit:2.3.0
org.apache.commons:commons-lang3:3.7
org.apache.httpcomponents:httpclient:4.5.2
org.apache.httpcomponents:httpcore:4.4.4
Expand Down
3 changes: 0 additions & 3 deletions reckon-core/gradle/dependency-locks/testCompileOnly.lockfile

This file was deleted.

29 changes: 0 additions & 29 deletions reckon-core/gradle/dependency-locks/testRuntime.lockfile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ commons-logging:commons-logging:1.2
junit:junit:4.12
net.java.dev.jna:jna-platform:4.1.0
net.java.dev.jna:jna:4.1.0
org.ajoberstar:grgit:2.2.1
org.ajoberstar:grgit:2.3.0
org.apache.commons:commons-lang3:3.7
org.apache.httpcomponents:httpclient:4.5.2
org.apache.httpcomponents:httpcore:4.4.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
Expand Down Expand Up @@ -55,7 +56,7 @@ public GitInventorySupplier(Repository repo, Function<String, Optional<String>>
@Override
public VcsInventory getInventory() {
// share this walk throughout to benefit from its caching
try (RevWalk walk = new RevWalk(repo)) {
try (ObjectReader reader = repo.newObjectReader(); RevWalk walk = new RevWalk(reader)) {
// saves on some performance as we don't really need the commit bodys
walk.setRetainBody(false);

Expand Down Expand Up @@ -94,7 +95,7 @@ public VcsInventory getInventory() {
Set<Version> claimedVersions = taggedVersions.stream().map(TaggedVersion::getVersion).collect(Collectors.toSet());

return new VcsInventory(
headObjectId.getName(),
reader.abbreviate(headObjectId).name(),
isClean(),
currentVersion,
baseVersion.getVersion(),
Expand Down
40 changes: 31 additions & 9 deletions reckon-core/src/main/java/org/ajoberstar/reckon/core/Reckoner.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.ajoberstar.reckon.core;

import java.time.Clock;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;
Expand All @@ -19,13 +22,17 @@ public final class Reckoner {
public static final String FINAL_STAGE = "final";
public static final String SNAPSHOT_STAGE = "snapshot";

private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX");

private final Clock clock;
private final VcsInventorySupplier inventorySupplier;
private final Function<VcsInventory, Optional<String>> scopeCalc;
private final BiFunction<VcsInventory, Version, Optional<String>> stageCalc;
private final Set<String> stages;
private final String defaultStage;

private Reckoner(VcsInventorySupplier inventorySupplier, Function<VcsInventory, Optional<String>> scopeCalc, BiFunction<VcsInventory, Version, Optional<String>> stageCalc, Set<String> stages, String defaultStage) {
private Reckoner(Clock clock, VcsInventorySupplier inventorySupplier, Function<VcsInventory, Optional<String>> scopeCalc, BiFunction<VcsInventory, Version, Optional<String>> stageCalc, Set<String> stages, String defaultStage) {
this.clock = clock;
this.inventorySupplier = inventorySupplier;
this.scopeCalc = scopeCalc;
this.stageCalc = stageCalc;
Expand All @@ -43,6 +50,10 @@ public Version reckon() {
Version targetNormal = reckonNormal(inventory);
Version reckoned = reckonTargetVersion(inventory, targetNormal);

if (reckoned.isSignificant() && !inventory.isClean()) {
throw new IllegalStateException("Cannot release a final or significant stage without a clean repo.");
}

if (inventory.getClaimedVersions().contains(reckoned) && !inventory.getCurrentVersion().map(reckoned::equals).orElse(false)) {
throw new IllegalStateException("Reckoned version " + reckoned + " has already been released.");
}
Expand Down Expand Up @@ -89,17 +100,14 @@ private Version reckonTargetVersion(VcsInventory inventory, Version targetNormal
String stage = stageCalc.apply(inventory, targetNormal)
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(String::toLowerCase)
.orElse(null);

if (stage != null && !stages.contains(stage)) {
String message = String.format("Stage \"%s\" is not one of: %s", stage, stages);
throw new IllegalArgumentException(message);
}

if (stage != null && !inventory.isClean()) {
throw new IllegalStateException("Cannot release a final or significant stage without a clean repo.");
}

if (FINAL_STAGE.equals(stage)) {
return targetNormal;
}
Expand All @@ -118,8 +126,8 @@ private Version reckonTargetVersion(VcsInventory inventory, Version targetNormal
return Version.valueOf(String.format("%s-%s", targetBase.getNormal(), "SNAPSHOT"));
} else if (stage == null) {
String buildMetadata = inventory.getCommitId()
.map(sha -> inventory.isClean() ? sha : sha + ".uncommitted")
.orElse("uncommitted");
.filter(sha -> inventory.isClean())
.orElseGet(() -> DATE_FORMAT.format(ZonedDateTime.now(clock)));

return Version.valueOf(String.format("%s-%s.%d.%d+%s", targetBase.getNormal(), baseStageName, baseStageNum, inventory.getCommitsSinceBase(), buildMetadata));
} else if (stage.equals(baseStageName)) {
Expand All @@ -134,12 +142,18 @@ public static Builder builder() {
}

public static final class Builder {
private Clock clock;
private VcsInventorySupplier inventorySupplier;
private Function<VcsInventory, Optional<String>> scopeCalc;
private BiFunction<VcsInventory, Version, Optional<String>> stageCalc;
private Set<String> stages;
private String defaultStage;

Builder clock(Clock clock) {
this.clock = clock;
return this;
}

Builder vcs(VcsInventorySupplier inventorySupplier) {
this.inventorySupplier = inventorySupplier;
return this;
Expand Down Expand Up @@ -178,12 +192,19 @@ public Builder scopeCalc(Function<VcsInventory, Optional<String>> scopeCalc) {
* @return this builder
*/
public Builder stages(String... stages) {
this.stages = Arrays.stream(stages).collect(Collectors.toSet());
this.stages = Arrays.stream(stages)
.map(String::toLowerCase)
.collect(Collectors.toSet());
this.defaultStage = this.stages.stream()
.filter(name -> !FINAL_STAGE.equals(name))
.sorted()
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("No non-final stages provided."));

if (this.stages.contains(SNAPSHOT_STAGE)) {
throw new IllegalArgumentException("Snapshots are not supported in stage mode.");
}

return this;
}

Expand Down Expand Up @@ -216,11 +237,12 @@ public Builder stageCalc(BiFunction<VcsInventory, Version, Optional<String>> sta
* @return the reckoner
*/
public Reckoner build() {
Clock clock = Optional.ofNullable(this.clock).orElseGet(Clock::systemUTC);
Objects.requireNonNull(inventorySupplier, "Must provide a vcs.");
Objects.requireNonNull(scopeCalc, "Must provide a scope supplier.");
Objects.requireNonNull(stages, "Must provide set of stages.");
Objects.requireNonNull(stageCalc, "Must provide a stage supplier.");
return new Reckoner(inventorySupplier, scopeCalc, stageCalc, stages, defaultStage);
return new Reckoner(clock, inventorySupplier, scopeCalc, stageCalc, stages, defaultStage);
}
}
}
Loading

0 comments on commit 96c3360

Please sign in to comment.