From 783123ff26ebd5a9ef923ee10595c819ac51eb82 Mon Sep 17 00:00:00 2001 From: mania Date: Fri, 15 Oct 2021 15:25:19 +0200 Subject: [PATCH] replaced some domain config classes with java implementation --- .../axion/release/domain/ChecksConfig.groovy | 16 ----- .../release/domain/MonorepoConfig.groovy | 5 -- .../release/domain/NextVersionConfig.groovy | 35 ----------- .../domain/NextVersionSerializer.groovy | 40 ------------- .../infrastructure/config/RulesFactory.groovy | 1 - .../axion/release/domain/ChecksConfig.java | 38 ++++++++++++ .../axion/release/domain/MonorepoConfig.java | 19 ++++++ .../release/domain/NextVersionConfig.java | 59 +++++++++++++++++++ .../release/domain/NextVersionSerializer.java | 41 +++++++++++++ .../config/MonorepoPropertiesFactory.java | 2 +- .../domain/NextVersionSerializerTest.groovy | 7 +-- .../release/domain/VersionSorterTest.groovy | 1 - .../NextVersionPropertiesBuilder.groovy | 1 + 13 files changed, 161 insertions(+), 104 deletions(-) delete mode 100644 src/main/groovy/pl/allegro/tech/build/axion/release/domain/ChecksConfig.groovy delete mode 100644 src/main/groovy/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.groovy delete mode 100644 src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.groovy delete mode 100644 src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionSerializer.groovy create mode 100644 src/main/java/pl/allegro/tech/build/axion/release/domain/ChecksConfig.java create mode 100644 src/main/java/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.java create mode 100644 src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.java create mode 100644 src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionSerializer.java diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/ChecksConfig.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/ChecksConfig.groovy deleted file mode 100644 index 78d3478a..00000000 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/ChecksConfig.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain - -import org.gradle.api.tasks.Input - -class ChecksConfig { - - @Input - boolean aheadOfRemote = true - - @Input - boolean uncommittedChanges = true - - @Input - boolean snapshotDependencies = true - -} diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.groovy deleted file mode 100644 index fa90d018..00000000 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.groovy +++ /dev/null @@ -1,5 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain - -class MonorepoConfig { - public List projectDirs = [] -} diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.groovy deleted file mode 100644 index 72d77bfd..00000000 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.groovy +++ /dev/null @@ -1,35 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain - -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Nested - -class NextVersionConfig { - - @Input - String suffix = 'alpha' - - @Input - String separator = '-' - - @Nested - Closure serializer = NextVersionSerializer.DEFAULT.serializer - - @Nested - Closure deserializer = NextVersionSerializer.DEFAULT.deserializer - - void serializer(String type) { - this.serializer = NextVersionSerializer.find(type).serializer - } - - void serializer(Closure c) { - this.serializer = c - } - - void deserializer(String type) { - this.deserializer = NextVersionSerializer.valueOf(type).deserializer - } - - void deserializer(Closure c) { - this.deserializer = c - } -} diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionSerializer.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionSerializer.groovy deleted file mode 100644 index 2a6a2cf8..00000000 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionSerializer.groovy +++ /dev/null @@ -1,40 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain - -import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties -import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition - -enum NextVersionSerializer { - - DEFAULT('default', - { NextVersionProperties rules, String version -> - return rules.suffix ? version + rules.separator + rules.suffix : version - }, - { NextVersionProperties rules, ScmPosition position, String tag -> - if (rules.suffix.isEmpty()) { - return tag - } - return tag.replaceFirst(rules.separator + rules.suffix, '') - } - ) - - private final String type - - final Closure serializer - - final Closure deserializer - - private NextVersionSerializer(String type, Closure serializer, Closure deserializer) { - this.type = type - this.serializer = serializer - this.deserializer = deserializer - } - - static NextVersionSerializer find(String type) { - NextVersionSerializer serializer = values().find { it.type == type } - if (serializer == null) { - throw new IllegalArgumentException("There is no predefined next version serializers with $type type. " + - "You can choose from: ${values().collect { it.type }}"); - } - return serializer - } -} diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/RulesFactory.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/RulesFactory.groovy index 5e2073c7..7a1b6999 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/RulesFactory.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/config/RulesFactory.groovy @@ -8,7 +8,6 @@ import pl.allegro.tech.build.axion.release.domain.VersionConfig import pl.allegro.tech.build.axion.release.domain.properties.Properties import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition import pl.allegro.tech.build.axion.release.domain.scm.ScmRepository -import pl.allegro.tech.build.axion.release.infrastructure.di.ScmRepositoryFactory class RulesFactory { diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/ChecksConfig.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/ChecksConfig.java new file mode 100644 index 00000000..efb469af --- /dev/null +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/ChecksConfig.java @@ -0,0 +1,38 @@ +package pl.allegro.tech.build.axion.release.domain; + +import org.gradle.api.tasks.Input; + +public class ChecksConfig { + @Input + private boolean aheadOfRemote = true; + + @Input + private boolean uncommittedChanges = true; + + @Input + private boolean snapshotDependencies = true; + + public void setAheadOfRemote(boolean aheadOfRemote) { + this.aheadOfRemote = aheadOfRemote; + } + + public void setUncommittedChanges(boolean uncommittedChanges) { + this.uncommittedChanges = uncommittedChanges; + } + + public void setSnapshotDependencies(boolean snapshotDependencies) { + this.snapshotDependencies = snapshotDependencies; + } + + public boolean isAheadOfRemote() { + return aheadOfRemote; + } + + public boolean isUncommittedChanges() { + return uncommittedChanges; + } + + public boolean isSnapshotDependencies() { + return snapshotDependencies; + } +} diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.java new file mode 100644 index 00000000..cf34edd3 --- /dev/null +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/MonorepoConfig.java @@ -0,0 +1,19 @@ +package pl.allegro.tech.build.axion.release.domain; + +import org.gradle.api.tasks.Internal; + +import java.util.LinkedList; +import java.util.List; + +public class MonorepoConfig { + @Internal + private List projectDirs = new LinkedList<>(); + + public List getProjectDirs() { + return projectDirs; + } + + public void setProjectDirs(List projectDirs) { + this.projectDirs = projectDirs; + } +} diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.java new file mode 100644 index 00000000..9ed76511 --- /dev/null +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionConfig.java @@ -0,0 +1,59 @@ +package pl.allegro.tech.build.axion.release.domain; + +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.Nested; +import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties.*; + +public class NextVersionConfig { + @Input + private String suffix = "alpha"; + + @Input + private String separator = "-"; + + @Nested + private Serializer serializer = NextVersionSerializer.DEFAULT.serializer; + + @Nested + private Deserializer deserializer = NextVersionSerializer.DEFAULT.deserializer; + + public void setSerializer(String type) { + this.serializer = NextVersionSerializer.find(type).serializer; + } + + public void setSerializer(Serializer c) { + this.serializer = c; + } + + public void setDeserializer(String type) { + this.deserializer = NextVersionSerializer.valueOf(type).deserializer; + } + + public void setDeserializer(Deserializer c) { + this.deserializer = c; + } + + public String getSuffix() { + return suffix; + } + + public void setSuffix(String suffix) { + this.suffix = suffix; + } + + public String getSeparator() { + return separator; + } + + public void setSeparator(String separator) { + this.separator = separator; + } + + public Serializer getSerializer() { + return serializer; + } + + public Deserializer getDeserializer() { + return deserializer; + } +} diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionSerializer.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionSerializer.java new file mode 100644 index 00000000..d6457fa1 --- /dev/null +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/NextVersionSerializer.java @@ -0,0 +1,41 @@ +package pl.allegro.tech.build.axion.release.domain; + +import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties; +import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition; + +import java.util.Arrays; +import java.util.stream.Collectors; + +import static pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties.Deserializer; +import static pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties.Serializer; + +public enum NextVersionSerializer { + + DEFAULT("default", + (NextVersionProperties rules, String version) -> + rules.getSuffix() != null ? version + rules.getSeparator() + rules.getSuffix() : version, + (NextVersionProperties rules, ScmPosition position, String tag) -> + rules.getSuffix().isEmpty() ? tag : tag.replaceFirst(rules.getSeparator() + rules.getSuffix(), "") + ); + + private final String type; + + public final Serializer serializer; + + public final Deserializer deserializer; + + NextVersionSerializer(String type, Serializer serializer, Deserializer deserializer) { + this.type = type; + this.serializer = serializer; + this.deserializer = deserializer; + } + + static NextVersionSerializer find(String type) { + return Arrays.stream(values()) + .filter(it -> it.type.equals(type)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException( + "There is no predefined next version serializers with " + type + " type. " + + "You can choose from: " + Arrays.stream(values()).map(it -> it.type).collect(Collectors.joining()))); + } +} diff --git a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/config/MonorepoPropertiesFactory.java b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/config/MonorepoPropertiesFactory.java index 5bad0d8b..15aca034 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/config/MonorepoPropertiesFactory.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/config/MonorepoPropertiesFactory.java @@ -6,6 +6,6 @@ public class MonorepoPropertiesFactory { public static MonorepoProperties create(Project project, MonorepoConfig config, String currentBranch) { - return new MonorepoProperties(config.projectDirs); + return new MonorepoProperties(config.getProjectDirs()); } } diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionSerializerTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionSerializerTest.groovy index 0dd1064a..a2673efd 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionSerializerTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/NextVersionSerializerTest.groovy @@ -1,9 +1,6 @@ package pl.allegro.tech.build.axion.release.domain -import pl.allegro.tech.build.axion.release.TagPrefixConf import pl.allegro.tech.build.axion.release.domain.properties.NextVersionProperties -import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition -import pl.allegro.tech.build.axion.release.domain.scm.ScmPositionBuilder import spock.lang.Specification import static pl.allegro.tech.build.axion.release.TagPrefixConf.* @@ -16,7 +13,7 @@ class NextVersionSerializerTest extends Specification { def "default serializer should append separator and suffix"() { when: - String version = NextVersionSerializer.DEFAULT.serializer(rules, fullPrefix() + '1.0.0') + String version = NextVersionSerializer.DEFAULT.serializer.apply(rules, fullPrefix() + '1.0.0') then: version == fullPrefix() +'1.0.0-beta' @@ -24,7 +21,7 @@ class NextVersionSerializerTest extends Specification { def "default deserializer should trim separator and suffix"() { when: - String version = NextVersionSerializer.DEFAULT.deserializer(rules, scmPosition('master'), fullPrefix() + '1.0.0-beta') + String version = NextVersionSerializer.DEFAULT.deserializer.apply(rules, scmPosition('master'), fullPrefix() + '1.0.0-beta') then: version == fullPrefix() + '1.0.0' diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy index 76b20303..d863f980 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/VersionSorterTest.groovy @@ -1,6 +1,5 @@ package pl.allegro.tech.build.axion.release.domain -import pl.allegro.tech.build.axion.release.TagPrefixConf import pl.allegro.tech.build.axion.release.domain.properties.NextVersionPropertiesBuilder import pl.allegro.tech.build.axion.release.domain.properties.TagPropertiesBuilder import pl.allegro.tech.build.axion.release.domain.properties.VersionPropertiesBuilder diff --git a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/NextVersionPropertiesBuilder.groovy b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/NextVersionPropertiesBuilder.groovy index c892d3de..4a9c545d 100644 --- a/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/NextVersionPropertiesBuilder.groovy +++ b/src/test/groovy/pl/allegro/tech/build/axion/release/domain/properties/NextVersionPropertiesBuilder.groovy @@ -2,6 +2,7 @@ package pl.allegro.tech.build.axion.release.domain.properties import pl.allegro.tech.build.axion.release.domain.NextVersionSerializer + class NextVersionPropertiesBuilder { private String nextVersion