pl.allegro.tech.build.axion.release.infrastructure.di.Context.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of axion-release-plugin Show documentation
Show all versions of axion-release-plugin Show documentation
Gradle release and version management plugin
package pl.allegro.tech.build.axion.release.infrastructure.di
import pl.allegro.tech.build.axion.release.domain.*
import pl.allegro.tech.build.axion.release.domain.hooks.ReleaseHooksRunner
import pl.allegro.tech.build.axion.release.domain.properties.Properties
import pl.allegro.tech.build.axion.release.domain.scm.ScmChangesPrinter
import pl.allegro.tech.build.axion.release.domain.scm.ScmProperties
import pl.allegro.tech.build.axion.release.domain.scm.ScmRepository
import pl.allegro.tech.build.axion.release.domain.scm.ScmService
import pl.allegro.tech.build.axion.release.infrastructure.DryRepository
import pl.allegro.tech.build.axion.release.infrastructure.git.GitChangesPrinter
import pl.allegro.tech.build.axion.release.infrastructure.git.GitRepository
class Context {
private final Map instances = [:]
private final Properties rules
private final ScmRepository scmRepository
private final ScmProperties scmProperties
private final LocalOnlyResolver localOnlyResolver
Context(Properties rules, ScmRepository scmRepository, ScmProperties scmProperties, File projectRoot, LocalOnlyResolver localOnlyResolver) {
this.rules = rules
this.scmRepository = scmRepository
this.scmProperties = scmProperties
this.localOnlyResolver = localOnlyResolver
instances[ScmRepository] = scmRepository
instances[VersionService] = new VersionService(new VersionResolver(scmRepository, scmProperties.directory.toPath().relativize(projectRoot.toPath()).toString()))
}
private T get(Class clazz) {
return (T) instances[clazz]
}
Properties rules() {
return rules
}
ScmRepository repository() {
return rules.dryRun ? new DryRepository(get(ScmRepository)) : get(ScmRepository)
}
ScmService scmService() {
return new ScmService(localOnlyResolver(), scmProperties, repository())
}
LocalOnlyResolver localOnlyResolver() {
return localOnlyResolver
}
VersionService versionService() {
return get(VersionService)
}
Releaser releaser() {
return new Releaser(
versionService(),
scmService(),
new ReleaseHooksRunner(versionService(), scmService())
)
}
ScmChangesPrinter changesPrinter() {
return new GitChangesPrinter(get(ScmRepository) as GitRepository)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy