Skip to content

Commit

Permalink
Use the version from the BOM when version is missing in Profiles. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Oct 11, 2019
1 parent 4697a53 commit d7bde18
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,17 @@ class DependencyVersions implements DependencyManagement {
@CompileDynamic
void addDependencyManagement(GPathResult pom) {
pom.dependencyManagement.dependencies.dependency.each { dep ->
addDependency(dep.groupId.text(), dep.artifactId.text(), dep.version.text())
String version = dep.version.text()
if (version.startsWith('${')) {
String property = version[2..-2]
def child = pom.getProperty("properties").children().find {
it.name() == property
}
if (child) {
version = child.text()
}
}
addDependency(dep.groupId.text(), dep.artifactId.text(), version)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package io.micronaut.cli.io.support

import io.micronaut.cli.profile.Feature
import io.micronaut.cli.profile.Profile
import io.micronaut.cli.profile.ProfileRepository
import org.eclipse.aether.graph.Dependency
import org.eclipse.aether.graph.Exclusion
import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector
Expand All @@ -30,7 +31,7 @@ abstract class BuildTokens {
this.appname = appname
}

abstract Map getTokens(Profile profile, List<Feature> features)
abstract Map getTokens(ProfileRepository profileRepository, Profile profile, List<Feature> features)

protected List<Dependency> materializeDependencies(Profile profile, List<Feature> features) {
List<Dependency> profileDependencies = profile.dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package io.micronaut.cli.io.support
import groovy.transform.InheritConstructors
import io.micronaut.cli.profile.Feature
import io.micronaut.cli.profile.Profile
import io.micronaut.cli.profile.ProfileRepository
import io.micronaut.cli.profile.repository.MavenProfileRepository
import io.micronaut.cli.util.VersionInfo
import org.eclipse.aether.graph.Dependency
Expand All @@ -29,7 +30,7 @@ import org.eclipse.aether.graph.Dependency
@InheritConstructors
class GradleBuildTokens extends BuildTokens {

Map getTokens(Profile profile, List<Feature> features) {
Map getTokens(ProfileRepository profileRepository, Profile profile, List<Feature> features) {
Map tokens = [:]
tokens.put("testFramework", testFramework)
tokens.put("sourceLanguage", sourceLanguage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import groovy.transform.InheritConstructors
import groovy.xml.MarkupBuilder
import io.micronaut.cli.profile.Feature
import io.micronaut.cli.profile.Profile
import io.micronaut.cli.profile.ProfileRepository
import io.micronaut.cli.profile.repository.MavenProfileRepository
import io.micronaut.cli.util.VersionInfo
import org.eclipse.aether.artifact.Artifact
import org.eclipse.aether.graph.Dependency
import org.eclipse.aether.graph.Exclusion

Expand All @@ -47,7 +49,7 @@ class MavenBuildTokens extends BuildTokens {
}

@Override
Map getTokens(Profile profile, List<Feature> features) {
Map getTokens(ProfileRepository profileRepository, Profile profile, List<Feature> features) {
Map tokens = [:]
tokens.put("testFramework", testFramework)
tokens.put("sourceLanguage", sourceLanguage)
Expand Down Expand Up @@ -143,14 +145,21 @@ class MavenBuildTokens extends BuildTokens {
annotationProcessorPathsXml."$methodToCall" {
groupId(artifact.groupId)
artifactId(artifact.artifactId)
def artifactVersion = artifact.version
if (!artifactVersion || artifactVersion == 'BOM') {
def resolvedVersion = profileRepository.findVersion(artifact.artifactId)
if (resolvedVersion ) {
artifactVersion = resolvedVersion
}
}
if (artifact.groupId.startsWith("io.micronaut")) {
if (!artifact.version || artifact.version == 'BOM') {
if (!artifactVersion || artifactVersion == 'BOM') {
version("\${micronaut.version}")
} else {
version(artifact.version)
version(artifactVersion)
}
} else {
version(artifact.version)
version(artifactVersion)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package io.micronaut.cli.profile

import io.micronaut.cli.io.support.Resource
import org.eclipse.aether.artifact.Artifact
import org.eclipse.aether.graph.Dependency

import javax.annotation.Nullable

/**
*
Expand Down Expand Up @@ -70,4 +73,11 @@ interface ProfileRepository {
* @return The {@link Artifact} that resolves to the profile
*/
Artifact getProfileArtifact(String profileName)

/**
* Finds the version for the given artifact ID.
* @return the version
*/
@Nullable String findVersion(String artifactId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ abstract class AbstractCreateCommand extends ArgumentCompletingCommand implement
return
}

Map tokens = buildTokens.getTokens(profile, features)
Map tokens = buildTokens.getTokens(profileRepository, profile, features)

if (tokens == null) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import io.micronaut.cli.profile.ProjectContext
import io.micronaut.cli.profile.ProjectContextAware
import org.eclipse.aether.artifact.Artifact
import org.eclipse.aether.artifact.DefaultArtifact
import org.eclipse.aether.graph.Dependency

/**
* A repository that loads profiles from JAR files
Expand All @@ -48,6 +49,11 @@ abstract class AbstractJarProfileRepository implements ProfileRepository {
return profilesByName[profileName]
}

@Override
String findVersion(String artifactId) {
return null
}

@Override
Profile getProfile(String profileName, Boolean parentProfile) {
return getProfile(profileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ class MavenProfileRepository extends AbstractJarProfileRepository {
this([DEFAULT_REPO])
}

@Override
@CompileDynamic
String findVersion(String artifactId) {
return profileDependencyVersions.find(artifactId)?.version
}

@Override
Profile getProfile(String profileName, Boolean parentProfile) {
String profileShortName = profileName
Expand Down

0 comments on commit d7bde18

Please sign in to comment.