Skip to content

Commit

Permalink
Merge pull request #425 from Worms308/replacing-some-domain-groovy-cl…
Browse files Browse the repository at this point in the history
…asses-with-java

replaced some domain config classes with java implementation
  • Loading branch information
bgalek authored Oct 15, 2021
2 parents e3a2fda + 783123f commit 54d0933
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 104 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<String> projectDirs = new LinkedList<>();

public List<String> getProjectDirs() {
return projectDirs;
}

public void setProjectDirs(List<String> projectDirs) {
this.projectDirs = projectDirs;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -16,15 +13,15 @@ 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'
}

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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54d0933

Please sign in to comment.