Skip to content

Commit c043013

Browse files
jameskleehgraemerocher
authored andcommitted
Parent profiles should resolve from the bom (#10123)
* Remove version for transitive profile dependencies that are managed by the bom * Fix tests
1 parent 6e171c4 commit c043013

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ abstract class AbstractProfile implements Profile {
326326
@Override
327327
public Iterable<Profile> getExtends() {
328328
return parentNames.collect() { String name ->
329-
def parent = profileRepository.getProfile(name)
329+
def parent = profileRepository.getProfile(name, true)
330330
if(parent == null) {
331331
throw new IllegalStateException("Profile [$name] declares an invalid dependency on parent profile [$name]")
332332
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ interface ProfileRepository {
3737
*/
3838
Profile getProfile(String profileName)
3939

40+
/**
41+
* Obtains a named {@link Profile}
42+
* @param profileName The name of the profile
43+
* @param parentProfile Whether or not the profile is a parent of another profile
44+
* @return The {@link Profile} or null
45+
*/
46+
Profile getProfile(String profileName, Boolean parentProfile)
47+
4048
/**
4149
* The directory where the profile is located
4250
*

grails-shell/src/main/groovy/org/grails/cli/profile/git/GitProfileRepository.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ class GitProfileRepository implements ProfileRepository {
7272
}
7373
}
7474

75+
Profile getProfile(String profileName, Boolean parentProfile) {
76+
getProfile(profileName)
77+
}
78+
7579
@Override
7680
List<Profile> getAllProfiles() {
7781
def allDirectories = new File(profilesDirectory, "profiles").listFiles()?.findAll() { File f -> f.isDirectory() && !f.isHidden() && !f.name.startsWith('.') }

grails-shell/src/main/groovy/org/grails/cli/profile/repository/AbstractJarProfileRepository.groovy

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,20 @@ abstract class AbstractJarProfileRepository implements ProfileRepository {
3939

4040
protected final List<Profile> allProfiles = []
4141
protected final Map<String, Profile> profilesByName = [:]
42+
protected static final String DEFAULT_PROFILE_GROUPID = "org.grails.profiles"
4243

4344
private Set<URL> registeredUrls = []
45+
4446
@Override
4547
Profile getProfile(String profileName) {
4648
return profilesByName[profileName]
4749
}
4850

51+
@Override
52+
Profile getProfile(String profileName, Boolean parentProfile) {
53+
return getProfile(profileName)
54+
}
55+
4956
List<Profile> getAllProfiles() {
5057
return allProfiles
5158
}
@@ -68,7 +75,7 @@ abstract class AbstractJarProfileRepository implements ProfileRepository {
6875
return new DefaultArtifact(profileName)
6976
}
7077

71-
String groupId = "org.grails.profiles"
78+
String groupId = DEFAULT_PROFILE_GROUPID
7279
String version = null
7380

7481
Map<String, Map> defaultValues = GrailsCli.getSetting("grails.profiles", Map, [:])

grails-shell/src/main/groovy/org/grails/cli/profile/repository/MavenProfileRepository.groovy

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,44 @@ class MavenProfileRepository extends AbstractJarProfileRepository {
4545
AetherGrapeEngine grapeEngine
4646
GroovyClassLoader classLoader
4747
DependencyResolutionContext resolutionContext
48+
GrailsDependencyVersions profileDependencyVersions
4849
private boolean resolved = false
4950

5051
MavenProfileRepository(List<RepositoryConfiguration> repositoryConfigurations) {
5152
this.repositoryConfigurations = repositoryConfigurations
5253
classLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader)
5354
resolutionContext = new DependencyResolutionContext()
5455
this.grapeEngine = AetherGrapeEngineFactory.create(classLoader, repositoryConfigurations, resolutionContext)
55-
resolutionContext.addDependencyManagement(new GrailsDependencyVersions(grapeEngine))
56+
profileDependencyVersions = new GrailsDependencyVersions(grapeEngine)
57+
resolutionContext.addDependencyManagement(profileDependencyVersions)
5658
}
5759

5860
MavenProfileRepository() {
5961
this([DEFAULT_REPO])
6062
}
6163

6264
@Override
63-
Profile getProfile(String profileName) {
65+
Profile getProfile(String profileName, Boolean parentProfile) {
6466
String profileShortName = profileName
6567
if(profileName.contains(':')) {
6668
def art = new DefaultArtifact(profileName)
6769
profileShortName = art.artifactId
6870
}
69-
if(!resolved || !profilesByName.containsKey(profileShortName)) {
70-
return resolveProfile(profileName)
71+
if (!profilesByName.containsKey(profileShortName)) {
72+
if(parentProfile && profileDependencyVersions.find(DEFAULT_PROFILE_GROUPID, profileShortName)) {
73+
return resolveProfile(profileShortName)
74+
} else {
75+
return resolveProfile(profileName)
76+
}
7177
}
7278
return super.getProfile(profileShortName)
7379
}
7480

81+
@Override
82+
Profile getProfile(String profileName) {
83+
getProfile(profileName, false)
84+
}
85+
7586
protected Profile resolveProfile(String profileName) {
7687
Artifact art = getProfileArtifact(profileName)
7788

grails-shell/src/test/groovy/org/grails/cli/profile/ResourceProfileSpec.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ class ResourceProfileSpec extends Specification {
5858
def profileRepository = Mock(ProfileRepository)
5959

6060
def profile = new ResourceProfile(profileRepository, "web", mockResource)
61-
profileRepository.getProfile("web" ) >> profile
61+
profileRepository.getProfile("web", true) >> profile
6262

6363
def baseProfile = Mock(Profile)
6464
baseProfile.getDependencies() >> [ new Dependency(new DefaultArtifact("foo:bar:2.0"), "test")]
6565
baseProfile.getBuildPlugins() >> [ "foo-plug"]
66-
profileRepository.getProfile("base" ) >> baseProfile
66+
profileRepository.getProfile("base", true) >> baseProfile
6767

6868

6969
when:"The dependencies are accessed"
@@ -96,12 +96,12 @@ class ResourceProfileSpec extends Specification {
9696
def profileRepository = Mock(ProfileRepository)
9797

9898
def profile = new ResourceProfile(profileRepository, "web", mockResource)
99-
profileRepository.getProfile("web" ) >> profile
99+
profileRepository.getProfile("web", true) >> profile
100100

101101
def baseProfile = Mock(Profile)
102102
baseProfile.getDependencies() >> [ new Dependency(new DefaultArtifact("foo:bar:2.0"), "test")]
103103
baseProfile.getBuildPlugins() >> [ "foo-plug"]
104-
profileRepository.getProfile("base" ) >> baseProfile
104+
profileRepository.getProfile("base", true) >> baseProfile
105105

106106

107107
when:"The dependencies are accessed"

0 commit comments

Comments
 (0)