Skip to content

Commit 5003e39

Browse files
committed
Merge pull request #9745 from Schlogen/3.1.x
Profile feature - specify repos
2 parents 87a7e6b + 5865b2b commit 5003e39

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

grails-shell/src/main/groovy/org/grails/cli/profile/AbstractProfile.groovy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ abstract class AbstractProfile implements Profile {
5555
protected NavigableMap navigableConfig
5656
protected ProfileRepository profileRepository
5757
protected List<Dependency> dependencies = []
58+
protected List<String> repositories = []
5859
protected List<String> parentNames = []
60+
protected List<String> buildRepositories = []
5961
protected List<String> buildPlugins = []
6062
protected List<String> buildExcludes = []
6163
protected final List<Command> internalCommands = []
@@ -193,6 +195,9 @@ abstract class AbstractProfile implements Profile {
193195
}
194196
}
195197

198+
this.repositories = (List<String>)navigableConfig.get("repositories", [])
199+
200+
this.buildRepositories = (List<String>)navigableConfig.get("build.repositories", [])
196201
this.buildPlugins = (List<String>)navigableConfig.get("build.plugins", [])
197202
this.buildExcludes = (List<String>)navigableConfig.get("build.excludes", [])
198203
this.buildMerge = (List<String>)navigableConfig.get("build.merge", null)
@@ -243,6 +248,17 @@ abstract class AbstractProfile implements Profile {
243248
}
244249
}
245250

251+
@Override
252+
List<String> getBuildRepositories() {
253+
List<String> calculatedRepositories = []
254+
def parents = getExtends()
255+
for(profile in parents) {
256+
calculatedRepositories.addAll(profile.buildRepositories)
257+
}
258+
calculatedRepositories.addAll(buildRepositories)
259+
return calculatedRepositories
260+
}
261+
246262
@Override
247263
List<String> getBuildPlugins() {
248264
List<String> calculatedPlugins = []
@@ -258,6 +274,17 @@ abstract class AbstractProfile implements Profile {
258274
return calculatedPlugins
259275
}
260276

277+
@Override
278+
List<String> getRepositories() {
279+
List<String> calculatedRepositories = []
280+
def parents = getExtends()
281+
for(profile in parents) {
282+
calculatedRepositories.addAll(profile.repositories)
283+
}
284+
calculatedRepositories.addAll(repositories)
285+
return calculatedRepositories
286+
}
287+
261288
List<Dependency> getDependencies() {
262289
List<Dependency> calculatedDependencies = []
263290
def parents = getExtends()

grails-shell/src/main/groovy/org/grails/cli/profile/Profile.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public interface Profile {
6262
Iterable<Feature> getDefaultFeatures();
6363

6464
/**
65-
* @return The default features for this profile
65+
* @return The required features for this profile
6666
*/
6767
Iterable<Feature> getRequiredFeatures();
6868

@@ -72,6 +72,11 @@ public interface Profile {
7272
*/
7373
Iterable<Profile> getExtends();
7474

75+
/**
76+
* @return The maven repository definitions for this profile
77+
*/
78+
List<String> getRepositories();
79+
7580
/**
7681
* @return The dependency definitions for this profile
7782
*/
@@ -134,11 +139,16 @@ public interface Profile {
134139
*/
135140
boolean handleCommand(ExecutionContext context);
136141

142+
/**
143+
* @return The buildscript maven repository definitions for this profile
144+
*/
145+
List<String> getBuildRepositories();
137146

138147
/**
139148
* @return The profile names to participate in build merge
140149
*/
141150
List<String> getBuildMergeProfileNames();
151+
142152
/**
143153
* @return The list of build plugins for this profile
144154
*/

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
222222
@CompileDynamic
223223
protected void replaceBuildTokens(String profileCoords, Profile profile, List<Feature> features, File targetDirectory) {
224224
AntBuilder ant = new GrailsConsoleAntBuilder()
225+
def ln = System.getProperty("line.separator")
226+
227+
def repositories = profile.repositories.collect() { String url ->
228+
" maven { url \"${url}\" }".toString()
229+
}.unique().join(ln)
225230

226231
def profileDependencies = profile.dependencies
227232
def dependencies = profileDependencies.findAll() { Dependency dep ->
@@ -248,14 +253,17 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
248253
def art = new DefaultArtifact('org.grails.profiles', profile.name, '', profile.version)
249254
dependencies.add(new Dependency(art, "profile"))
250255
}
251-
def ln = System.getProperty("line.separator")
252256
dependencies = dependencies.unique()
253257

254258
dependencies = dependencies.sort({ Dependency dep -> dep.scope }).collect() { Dependency dep ->
255259
String artifactStr = resolveArtifactString(dep)
256260
" ${dep.scope} \"${artifactStr}\"".toString()
257261
}.unique().join(ln)
258262

263+
def buildRepositories = profile.buildRepositories.collect() { String url ->
264+
" maven { url \"${url}\" }".toString()
265+
}.unique().join(ln)
266+
259267
buildDependencies = buildDependencies.collect() { Dependency dep ->
260268
String artifactStr = resolveArtifactString(dep)
261269
" classpath \"${artifactStr}\"".toString()
@@ -287,8 +295,12 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
287295
replacevalue(buildDependencies)
288296
}
289297
replacefilter {
290-
replacetoken("@buildPlugins@")
291-
replacevalue(buildDependencies)
298+
replacetoken("@buildRepositories@")
299+
replacevalue(buildRepositories)
300+
}
301+
replacefilter {
302+
replacetoken("@repositories@")
303+
replacevalue(repositories)
292304
}
293305
variables.each { k, v ->
294306
replacefilter {

0 commit comments

Comments
 (0)