Skip to content

Commit

Permalink
fix: custom project name exposed as Provider instead of string Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
augi committed May 3, 2022
1 parent 2f135f0 commit a3a9e1d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.TaskProvider
import org.gradle.internal.os.OperatingSystem
import org.gradle.process.JavaForkOptions
Expand Down Expand Up @@ -70,21 +71,13 @@ abstract class ComposeSettings {
protected String customProjectName
protected Boolean customProjectNameSet
protected String safeProjectNamePrefix
void setProjectName(String customProjectName)
{
void setProjectName(String customProjectName) {
this.customProjectName = customProjectName
this.customProjectNameSet = true
}
String getProjectName() {
if (customProjectNameSet) {
return customProjectName
}
else if (projectNamePrefix) {
return "${projectNamePrefix}_${nestedName}"
}
else {
return "${safeProjectNamePrefix}_${nestedName}"
}
private Provider<String> projectNameProvider
Provider<String> getProjectName() {
this.projectNameProvider
}
String projectNamePrefix
String nestedName
Expand All @@ -100,6 +93,17 @@ abstract class ComposeSettings {
ComposeSettings(Project project, String name = '', String parentName = '') {
this.nestedName = parentName + name
this.safeProjectNamePrefix = generateSafeProjectNamePrefix(project)
this.projectNameProvider = project.<String>provider({
if (customProjectNameSet) {
return customProjectName
}
else if (projectNamePrefix) {
return "${projectNamePrefix}_${nestedName}"
}
else {
return "${safeProjectNamePrefix}_${nestedName}"
}
})

useComposeFiles.empty()
startedServices.empty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ class DockerComposePluginTest extends Specification {
project.extensions.findByName('dockerCompose') instanceof ComposeExtension
}

def "propagate custom project name to ComposeExecutor"() {
def project = ProjectBuilder.builder().build()
when:
project.plugins.apply 'docker-compose'
project.dockerCompose {
projectName = 'custom-project-name'
}
then:
ComposeExecutor.getInstance(project, project.dockerCompose).get().parameters.projectName.get() == 'custom-project-name'
}

def "allows to define extra properties"() {
def project = ProjectBuilder.builder().build()
when:
Expand Down

3 comments on commit a3a9e1d

@mskonovalov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, would you mind updating the readme on how to set the value now?
Thanks

@augi
Copy link
Member Author

@augi augi commented on a3a9e1d May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no change in this - check the test that is setting the property.

@mskonovalov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your reply.
Not exactly true.
I should have mentioned I'm using kotlin DSL. So for Groovy it doesn't change but for Kotlin it is a val now so attempt to call projectName = "name" will cause attempt to reassign the val.
Instead now you have to call setProjectName("name")

Please sign in to comment.