Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced some domain config classes with java implementation #425

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
replaced some domain config classes with java implementation
Worms308 committed Oct 15, 2021

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 783123ff26ebd5a9ef923ee10595c819ac51eb82

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
@@ -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 {

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
@@ -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.*
@@ -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'
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
Original file line number Diff line number Diff line change
@@ -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