Skip to content

Commit

Permalink
Merge pull request quarkusio#41902 from aloubyansky/gradle-quarkusCon…
Browse files Browse the repository at this point in the history
…ditionalConfig

Use quarkusConditional prefix for Quarkus conditional dependency configurations
  • Loading branch information
geoand authored Jul 15, 2024
2 parents 19c0e27 + 647a3d5 commit d7b84f6
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ private void queueConditionalDependency(ExtensionDependency<?> extension, Depend
private Configuration createConditionalDependenciesConfiguration(Project project, Dependency conditionalDep) {
// previously we used a detached configuration here but apparently extendsFrom(enforcedPlatforms)
// wouldn't actually enforce platforms on a detached configuration
final String name = conditionalDep.getGroup() + ":" + conditionalDep.getName() + ":" + conditionalDep.getVersion()
+ "Configuration";
var name = getConditionalConfigurationName(conditionalDep);
var config = project.getConfigurations().findByName(name);
if (config == null) {
project.getConfigurations().register(name, configuration -> {
Expand All @@ -184,6 +183,31 @@ private Configuration createConditionalDependenciesConfiguration(Project project
return config;
}

private static String getConditionalConfigurationName(Dependency conditionalDep) {
var name = new StringBuilder().append("quarkusConditional");
appendCapitalized(name, conditionalDep.getGroup());
appendCapitalized(name, conditionalDep.getName());
appendCapitalized(name, conditionalDep.getVersion());
return name.append("Configuration").toString();
}

private static void appendCapitalized(StringBuilder sb, String part) {
if (part != null && !part.isEmpty()) {
boolean toUpperCase = true;
for (int i = 0; i < part.length(); ++i) {
var c = part.charAt(i);
if (toUpperCase) {
sb.append(Character.toUpperCase(c));
toUpperCase = false;
} else if (c == '.' || c == '-') {
toUpperCase = true;
} else {
sb.append(c);
}
}
}
}

private void enableConditionalDependency(ModuleVersionIdentifier dependency) {
final Set<ExtensionDependency<?>> extensions = featureVariants.remove(getFeatureKey(dependency));
if (extensions == null) {
Expand Down

0 comments on commit d7b84f6

Please sign in to comment.