Skip to content

Commit 582b527

Browse files
committed
Profile - print an error if an application profile is used to create a plugin. Relates to #9849
Currently Grails allows application profiles to be used with the `create-plugin` command. This change disallows that by printing an error and exiting if an application profile is used.
1 parent 7cbcecd commit 582b527

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

grails-shell/src/main/groovy/org/grails/cli/profile/commands/CreateAppCommand.groovy

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
137137
def profileName = evaluateProfileName(mainCommandLine)
138138

139139
Profile profileInstance = profileRepository.getProfile(profileName)
140-
if(profileInstance == null) {
141-
executionContext.console.error("Profile not found for name [$profileName]")
140+
if( !validateProfile(profileInstance, profileName, executionContext)) {
142141
return false
143142
}
144143
List<Feature> features = evaluateFeatures(profileInstance, mainCommandLine).toList()
@@ -202,6 +201,14 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
202201
}
203202
}
204203

204+
protected boolean validateProfile(Profile profileInstance, String profileName, ExecutionContext executionContext) {
205+
if (profileInstance == null) {
206+
executionContext.console.error("Profile not found for name [$profileName]")
207+
return false
208+
}
209+
return true
210+
}
211+
205212
private Map<URL, File> unzippedDirectories = new LinkedHashMap<URL, File>()
206213
@CompileDynamic
207214
protected File unzipProfile(AntBuilder ant, Resource location) {

grails-shell/src/main/groovy/org/grails/cli/profile/commands/CreatePluginCommand.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package org.grails.cli.profile.commands
1818

1919
import groovy.transform.CompileStatic
2020
import org.grails.build.parsing.CommandLine
21+
import org.grails.cli.profile.ExecutionContext
22+
import org.grails.cli.profile.Profile
2123

2224

2325
/**
@@ -48,5 +50,16 @@ class CreatePluginCommand extends CreateAppCommand {
4850
@Override
4951
protected String getDefaultProfile() { "web-plugin" }
5052

53+
@Override
54+
protected boolean validateProfile(Profile profileInstance, String profileName, ExecutionContext executionContext) {
5155

56+
def pluginProfile = profileInstance.extends.find() { Profile parent -> parent.name == 'plugin' }
57+
if(pluginProfile == null) {
58+
executionContext.console.error("No valid plugin profile found for name [$profileName]")
59+
return false
60+
}
61+
else {
62+
return super.validateProfile(profileInstance, profileName, executionContext)
63+
}
64+
}
5265
}

0 commit comments

Comments
 (0)