Skip to content

Commit

Permalink
Expose cached DecoratedVersion, and introduce isSnapshot() to Decorat…
Browse files Browse the repository at this point in the history
…edVersion

Introduces a method, getDecoratedVersion() in the VersionConfig class, allowing you to easily retrieve the cached decorated version, instead of having to do versionProvider().get(), which looks less nice (imo)

Also introduces a method, isSnapshot() to DecoratedVersion, which allows you to check if the decorated version is a snapshot.
This is passed the value of VersionContact.isSnapshot().
This is convenient for checking if a version is a snapshot or not when building the project.
  • Loading branch information
solonovamax committed May 3, 2024
1 parent d4fff1e commit 1cd4a56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ abstract class VersionConfig extends BaseExtension {
return uncachedVersionProvider().get()
}

@Nested
VersionService.DecoratedVersion getDecoratedVersion() {
return versionProvider().get()

Check warning on line 229 in src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy

View check run for this annotation

Codecov / codecov/patch

src/main/groovy/pl/allegro/tech/build/axion/release/domain/VersionConfig.groovy#L229

Added line #L229 was not covered by tests
}

@Input
String getVersion() {
return versionProvider().map({ it.decoratedVersion}).get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,23 @@ public DecoratedVersion currentDecoratedVersion(VersionProperties versionPropert
}

return new DecoratedVersion(versionContext.getVersion().toString(), finalVersion, versionContext.getPosition(),
versionContext.getPreviousVersion().toString());
versionContext.getPreviousVersion().toString(), versionContext.isSnapshot());
}

public static class DecoratedVersion {
private final String undecoratedVersion;
private final String decoratedVersion;
private final ScmPosition position;
private final String previousVersion;
private final boolean snapshot;

public DecoratedVersion(String undecoratedVersion, String decoratedVersion, ScmPosition position,
String previousVersion) {
String previousVersion, boolean snapshot) {
this.undecoratedVersion = undecoratedVersion;
this.decoratedVersion = decoratedVersion;
this.position = position;
this.previousVersion = previousVersion;
this.snapshot = snapshot;
}

@Input
Expand All @@ -73,5 +75,10 @@ public final ScmPosition getPosition() {
public final String getPreviousVersion() {
return previousVersion;
}

@Input
public boolean isSnapshot() {
return snapshot;

Check warning on line 81 in src/main/java/pl/allegro/tech/build/axion/release/domain/VersionService.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/pl/allegro/tech/build/axion/release/domain/VersionService.java#L81

Added line #L81 was not covered by tests
}
}
}

0 comments on commit 1cd4a56

Please sign in to comment.