Skip to content

Commit

Permalink
Draft fixes quarkusio#16476
Browse files Browse the repository at this point in the history
  • Loading branch information
cristian-com committed Apr 13, 2021
1 parent f8c503f commit bf6b3dc
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 21 deletions.
8 changes: 6 additions & 2 deletions devtools/cli/src/main/java/io/quarkus/cli/Create.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.cli;

import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -38,6 +37,10 @@ public class Create extends BaseSubCommand implements Callable<Integer> {
"--examples" }, order = 4, description = "Choose which example(s) you want in the generated Quarkus application.")
Set<String> examples;

@CommandLine.Option(names = { "-c",
"--config" }, order = 5, description = "Application configs to be set in the application.properties/yml file. (key1=value1, key2=value2)")
private String config;

@CommandLine.ArgGroup()
TargetBuildTool targetBuildTool = new TargetBuildTool();

Expand Down Expand Up @@ -124,7 +127,7 @@ else if (targetBuildTool.gradleKotlinDsl)
.overrideExamples(examples)
.extensions(extensions)
.noExamples(noExamples)
.configProperties(new HashMap<>()) // TODO: Add support
.configProperties(config)
.execute().isSuccess();

if (status) {
Expand All @@ -144,4 +147,5 @@ else if (targetBuildTool.gradleKotlinDsl)

return CommandLine.ExitCode.OK;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -34,8 +33,6 @@
import org.eclipse.aether.repository.RemoteRepository;
import org.fusesource.jansi.Ansi;

import com.google.common.base.Splitter;

import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.devtools.commands.CreateProject;
import io.quarkus.devtools.messagewriter.MessageWriter;
Expand Down Expand Up @@ -191,8 +188,8 @@ public class CreateProjectMojo extends AbstractMojo {
@Parameter(property = "enableRegistryClient")
private boolean enableRegistryClient;

@Parameter(property = "configProperties")
private String configProperties;
@Parameter(property = "config")
private String config;

@Override
public void execute() throws MojoExecutionException {
Expand Down Expand Up @@ -294,7 +291,7 @@ public void execute() throws MojoExecutionException {
.extensions(extensions)
.overrideExamples(examples)
.noExamples(noExamples)
.configProperties(parsePropertiesString(configProperties));
.configProperties(config);
if (path != null) {
createProject.setValue("path", path);
}
Expand Down Expand Up @@ -326,10 +323,6 @@ public void execute() throws MojoExecutionException {
}
}

static Map<String, String> parsePropertiesString(String s) {
return Splitter.on(",").withKeyValueSeparator(":").split(s);
}

static ExtensionCatalog resolveExtensionsCatalog(String groupId, String artifactId, String version,
ExtensionCatalogResolver catalogResolver, MavenArtifactResolver artifactResolver, MessageWriter log)
throws MojoExecutionException {
Expand Down
4 changes: 4 additions & 0 deletions independent-projects/tools/codestarts/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-app-model</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devtools-common</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devtools-message-writer</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.devtools.codestarts.core.strategy;

import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey.APP_CONFIG;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
Expand All @@ -20,7 +22,6 @@ final class SmartConfigMergeCodestartFileStrategyHandler implements CodestartFil

private static final ObjectMapper YAML_MAPPER = new ObjectMapper(
new YAMLFactory().configure(YAMLGenerator.Feature.WRITE_DOC_START_MARKER, false));
private final static String APP_CONFIG_PROPERTIES = "app_config_properties";

@Override
public String name() {
Expand Down Expand Up @@ -91,8 +92,8 @@ private static String getConfigType(Map<String, Object> data) {

@SuppressWarnings("unchecked")
private Map<String, Object> initConfigMap(final Map<String, Object> data) {
if (data.get(APP_CONFIG_PROPERTIES) instanceof Map) {
return NestedMaps.unflatten((Map<String, Object>) data.get(APP_CONFIG_PROPERTIES));
if (data.get(APP_CONFIG.key()) instanceof Map) {
return NestedMaps.unflatten((Map<String, Object>) data.get(APP_CONFIG.key()));
}

return new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public enum QuarkusDataKey implements DataKey {

NO_EXAMPLES("quarkus-project.no-examples"),
NO_BUILD_TOOL_WRAPPER("quarkus-project.no-build-tool-wrapper"),
NO_DOCKERFILES("quarkus-project.no-dockerfiles");
NO_DOCKERFILES("quarkus-project.no-dockerfiles"),

APP_CONFIG("app-config");

private final String key;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.devtools.commands;

import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey.APP_CONFIG;
import static io.quarkus.devtools.project.codegen.ProjectGenerator.*;
import static java.util.Objects.requireNonNull;

Expand All @@ -13,6 +14,7 @@
import io.quarkus.platform.tools.ToolsConstants;
import io.quarkus.platform.tools.ToolsUtils;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -100,8 +102,12 @@ public CreateProject resourcePath(String resourcePath) {
return this;
}

public CreateProject configProperties(Map<String, String> configProperties) {
setValue(APP_CONFIG_PROPERTIES, configProperties);
public CreateProject configProperties(String configProperties) {
if (ToolsUtils.isBlank(configProperties)) {
setValue(APP_CONFIG.key(), Collections.emptyMap());
} else {
setValue(APP_CONFIG.key(), ToolsUtils.stringToMap(configProperties, ",", "="));
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.quarkus.devtools.commands.handlers;

import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.QuarkusDataKey.APP_CONFIG;
import static io.quarkus.devtools.commands.CreateProject.CODESTARTS;
import static io.quarkus.devtools.commands.CreateProject.NO_BUILDTOOL_WRAPPER;
import static io.quarkus.devtools.commands.CreateProject.NO_DOCKERFILES;
import static io.quarkus.devtools.commands.CreateProject.NO_EXAMPLES;
import static io.quarkus.devtools.commands.CreateProject.OVERRIDE_EXAMPLES;
import static io.quarkus.devtools.commands.handlers.QuarkusCommandHandlers.computeCoordsFromQuery;
import static io.quarkus.devtools.project.codegen.ProjectGenerator.APP_CONFIG_PROPERTIES;
import static io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_ARTIFACT_ID;
import static io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_GROUP_ID;
import static io.quarkus.devtools.project.codegen.ProjectGenerator.BOM_VERSION;
Expand Down Expand Up @@ -101,7 +101,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
.noDockerfiles(invocation.getValue(NO_DOCKERFILES, false))
.addData(platformData)
.addData(LegacySupport.convertFromLegacy(invocation.getValues()))
.putData(APP_CONFIG_PROPERTIES, invocation.getValue(APP_CONFIG_PROPERTIES, Collections.emptyMap()))
.putData(APP_CONFIG.key(), invocation.getValue(APP_CONFIG.key(), Collections.emptyMap()))
.messageWriter(invocation.log())
.build();
invocation.log().info("-----------");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public interface ProjectGenerator {
String IS_SPRING = "is_spring";
String RESOURCE_PATH = "path";
String JAVA_TARGET = "java_target";
String APP_CONFIG_PROPERTIES = "app_config_properties";

String getName();

Expand Down

0 comments on commit bf6b3dc

Please sign in to comment.