Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions \

This file was deleted.

11 changes: 11 additions & 0 deletions grails-bom/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ publishing {
def plugins = new Properties()
plugins.load(new StringReader(new File("$projectDir/plugins.properties").text))

def profiles = new Properties()
profiles.load(new StringReader(new File("$projectDir/profiles.properties").text))

xml.children().last() + {
def mkp = delegate
mkp.name "Grails BOM"
Expand Down Expand Up @@ -165,6 +168,14 @@ publishing {
mkp.version( plugin.value )
}
}

for(profile in profiles) {
mkp.dependency {
mkp.groupId 'org.grails.profiles'
mkp.artifactId profile.key
mkp.version( profile.value )
}
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions grails-bom/profiles.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
angular=3.1.8
rest-api=3.1.8
base=3.1.8
plugin=3.1.8
web-plugin=3.1.8
web=3.1.8
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.grails.cli.boot

import groovy.grape.Grape
import groovy.grape.GrapeEngine
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import groovy.util.slurpersupport.GPathResult
Expand All @@ -37,21 +38,32 @@ class GrailsDependencyVersions implements DependencyManagement {
protected List<Dependency> dependencies = []

GrailsDependencyVersions() {
this([group: "org.grails", module: "grails-bom", version: GrailsDependencyVersions.package.implementationVersion, type: "pom"])
this(getDefaultEngine())
}

GrailsDependencyVersions(Map<String, String> bomCoords) {
def grape = Grape.getInstance()
grape.addResolver((Map<String,Object>)[name:"grailsCentral", root:"https://repo.grails.org/grails/core"])
this(getDefaultEngine(), bomCoords)
}

GrailsDependencyVersions(GrapeEngine grape) {
this(grape, [group: "org.grails", module: "grails-bom", version: GrailsDependencyVersions.package.implementationVersion, type: "pom"])
}

GrailsDependencyVersions(GrapeEngine grape, Map<String, String> bomCoords) {
def results = grape.resolve(null, bomCoords)

for(URI u in results) {

def pom = new XmlSlurper().parseText(u.toURL().text)
addDependencyManagement(pom)
}
}

GrapeEngine getDefaultEngine() {
def grape = Grape.getInstance()
grape.addResolver((Map<String,Object>)[name:"grailsCentral", root:"https://repo.grails.org/grails/core"])
grape
}

@CompileDynamic
void addDependencyManagement(GPathResult pom) {
pom.dependencyManagement.dependencies.dependency.each { dep ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.grails.cli.profile

import org.eclipse.aether.artifact.Artifact
import org.grails.io.support.Resource

/*
Expand Down Expand Up @@ -57,4 +58,9 @@ interface ProfileRepository {
* @return All the available profiles in the repository
*/
List<Profile> getAllProfiles()

/**
* @return The {@link Artifact} that resolves to the profile
*/
Artifact getProfileArtifact(String profileName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
" maven { url \"${url}\" }".toString()
}.unique().join(ln)

def profileDependencies = profile.dependencies
List<Dependency> profileDependencies = profile.dependencies
def dependencies = profileDependencies.findAll() { Dependency dep ->
dep.scope != 'build'
}
Expand All @@ -249,17 +249,8 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
buildDependencies.addAll f.dependencies.findAll(){ Dependency dep -> dep.scope == 'build'}
}

if(profileCoords.contains(':')) {
def art = new DefaultArtifact(profileCoords)
def version = art.version ?: BuildSettings.grailsVersion
if(version == 'LATEST') version = profile.getVersion()
def finalArt = new DefaultArtifact(art.groupId ?: 'org.grails.profiles', art.artifactId, '', version)
dependencies.add(new Dependency(finalArt, "profile"))
}
else {
def art = new DefaultArtifact('org.grails.profiles', profile.name, '', profile.version)
dependencies.add(new Dependency(art, "profile"))
}
dependencies.add(new Dependency(profileRepository.getProfileArtifact(profileCoords), "profile"))

dependencies = dependencies.unique()

dependencies = dependencies.sort({ Dependency dep -> dep.scope }).collect() { Dependency dep ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package org.grails.cli.profile.git
import grails.build.logging.GrailsConsole
import grails.util.BuildSettings
import groovy.transform.CompileStatic

import org.eclipse.aether.artifact.Artifact
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.ResetCommand.ResetType
import org.grails.cli.profile.*
Expand All @@ -38,6 +38,7 @@ import org.grails.io.support.Resource
@CompileStatic
@Deprecated
class GitProfileRepository implements ProfileRepository {

File profilesDirectory = new File(new File(System.getProperty("user.home")), ".grails/repository")
String originUri = "https://github.com/grails/grails-profile-repository"
String gitBranch = 'master'
Expand Down Expand Up @@ -149,4 +150,7 @@ class GitProfileRepository implements ProfileRepository {
}
}

Artifact getProfileArtifact(String profileName) {
throw new UnsupportedOperationException()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@
package org.grails.cli.profile.repository

import groovy.transform.CompileStatic
import org.eclipse.aether.artifact.Artifact
import org.eclipse.aether.artifact.DefaultArtifact
import org.grails.cli.GrailsCli
import org.grails.cli.profile.AbstractProfile
import org.grails.cli.profile.Command
import org.grails.cli.profile.Profile
import org.grails.cli.profile.ProfileRepository
import org.grails.cli.profile.ProfileRepositoryAware
import org.grails.cli.profile.ProjectContext
import org.grails.cli.profile.ProjectContextAware
import org.grails.cli.profile.commands.DefaultMultiStepCommand
import org.grails.cli.profile.commands.script.GroovyScriptCommand
import org.grails.config.NavigableMap
import org.grails.io.support.ClassPathResource
import org.grails.io.support.Resource
import org.yaml.snakeyaml.Yaml


/**
* A repository that loads profiles from JAR files
Expand Down Expand Up @@ -66,6 +63,25 @@ abstract class AbstractJarProfileRepository implements ProfileRepository {
return sortedProfiles
}

Artifact getProfileArtifact(String profileName) {
if (profileName.contains(':')) {
return new DefaultArtifact(profileName)
}

String groupId = "org.grails.profiles"
String version = null

Map<String, Map> defaultValues = GrailsCli.getSetting("grails.profiles", Map, [:])
defaultValues.remove("repositories")
def data = defaultValues.get(profileName)
if(data instanceof Map) {
groupId = data.get("groupId")
version = data.get("version")
}

return new DefaultArtifact(groupId, profileName, null, version)
}

protected void registerProfile(URL url, ClassLoader parent) {
if(registeredUrls.contains(url)) return

Expand Down Expand Up @@ -115,4 +131,5 @@ abstract class AbstractJarProfileRepository implements ProfileRepository {
return commandsByName.values()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

package org.grails.cli.profile.repository

import grails.build.logging.GrailsConsole
import grails.util.BuildSettings
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.eclipse.aether.artifact.Artifact
import org.eclipse.aether.artifact.DefaultArtifact
import org.eclipse.aether.resolution.VersionResolutionException
import org.grails.cli.GrailsCli
import org.eclipse.aether.graph.Dependency
import org.grails.cli.boot.GrailsDependencyVersions
import org.grails.cli.profile.Profile
import org.springframework.boot.cli.compiler.grape.AetherGrapeEngine
import org.springframework.boot.cli.compiler.grape.AetherGrapeEngineFactory
Expand All @@ -45,18 +44,19 @@ class MavenProfileRepository extends AbstractJarProfileRepository {
List<RepositoryConfiguration> repositoryConfigurations
AetherGrapeEngine grapeEngine
GroovyClassLoader classLoader
DependencyResolutionContext resolutionContext
private boolean resolved = false

MavenProfileRepository(List<RepositoryConfiguration> repositoryConfigurations) {
this.repositoryConfigurations = repositoryConfigurations
classLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader)
this.grapeEngine = AetherGrapeEngineFactory.create(classLoader, repositoryConfigurations, new DependencyResolutionContext())
resolutionContext = new DependencyResolutionContext()
this.grapeEngine = AetherGrapeEngineFactory.create(classLoader, repositoryConfigurations, resolutionContext)
resolutionContext.addDependencyManagement(new GrailsDependencyVersions(grapeEngine))
}

MavenProfileRepository() {
this.repositoryConfigurations = [DEFAULT_REPO]
classLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader)
this.grapeEngine = AetherGrapeEngineFactory.create(classLoader, repositoryConfigurations, new DependencyResolutionContext())
this([DEFAULT_REPO])
}

@Override
Expand All @@ -72,31 +72,11 @@ class MavenProfileRepository extends AbstractJarProfileRepository {
return super.getProfile(profileShortName)
}

protected DefaultArtifact resolveProfileArtifact(String profileName) {
if (profileName.contains(':')) {
return new DefaultArtifact(profileName)
}

def artifactId = profileName
def groupId = "org.grails.profiles"
def version = BuildSettings.isDevelopmentGrailsVersion() ? 'LATEST' : BuildSettings.grailsVersion

Map<String, Map> defaultValues = GrailsCli.getSetting("grails.profiles", Map, [:])
defaultValues.remove("repositories")
def data = defaultValues.get(profileName)
if(data instanceof Map) {
groupId = data.get("groupId")
version = data.get("version")
}

return new DefaultArtifact("$groupId:$artifactId:$version")
}

protected Profile resolveProfile(String profileName) {
DefaultArtifact art = resolveProfileArtifact(profileName)
Artifact art = getProfileArtifact(profileName)

try {
grapeEngine.grab(group: art.groupId, module: art.artifactId, version: art.version)
grapeEngine.grab(group: art.groupId, module: art.artifactId, version: art.version ?: null)
} catch (DependencyResolutionFailedException e ) {

def localData = new File(System.getProperty("user.home"),"/.m2/repository/${art.groupId.replace('.','/')}/$art.artifactId/maven-metadata-local.xml")
Expand Down Expand Up @@ -133,21 +113,18 @@ class MavenProfileRepository extends AbstractJarProfileRepository {

@Override
List<Profile> getAllProfiles() {

if(!resolved) {
def defaultProfileVersion = BuildSettings.isDevelopmentGrailsVersion() ? 'LATEST' : BuildSettings.grailsVersion
List<String> profileNames = ['angular', 'rest-api', 'base','plugin','web-plugin', 'web'].sort()
def grailsConsole = GrailsConsole.instance
for(name in profileNames) {
try {
grapeEngine.grab(group: 'org.grails.profiles', module: name, version: defaultProfileVersion)
} catch (Throwable e) {

grailsConsole.error("Failed to load latest version of profile [$name]. Trying Grails release version", e)
grailsConsole.verbose(e.message)
grapeEngine.grab(group: 'org.grails.profiles', module: name, version: BuildSettings.package.implementationVersion)
List<Map> profiles = []
resolutionContext.managedDependencies.each { Dependency dep ->
if (dep.artifact.groupId == "org.grails.profiles") {
profiles.add([group: dep.artifact.groupId, module: dep.artifact.artifactId])
}
}
profiles.sort { it.module }

for (Map profile in profiles) {
grapeEngine.grab(profile)
}

def localData = new File(System.getProperty("user.home"),"/.m2/repository/org/grails/profiles")
if(localData.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import spock.lang.Specification
*/
class MavenRepositorySpec extends Specification {


@Ignore
void "Test resolve profile"() {
given:"A maven profile repository"
def repo = new MavenProfileRepository()
Expand Down