diff --git a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java index 966652ab95212..c345727887322 100644 --- a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java +++ b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/AugmentActionImpl.java @@ -21,7 +21,6 @@ import java.util.function.Function; import java.util.stream.Collectors; -import org.eclipse.microprofile.config.spi.ConfigProviderResolver; import org.jboss.logging.Logger; import io.quarkus.bootstrap.BootstrapDebug; @@ -34,23 +33,16 @@ import io.quarkus.bootstrap.app.QuarkusBootstrap; import io.quarkus.bootstrap.classloading.ClassLoaderEventListener; import io.quarkus.bootstrap.classloading.QuarkusClassLoader; -import io.quarkus.builder.BuildChain; import io.quarkus.builder.BuildChainBuilder; -import io.quarkus.builder.BuildExecutionBuilder; import io.quarkus.builder.BuildResult; import io.quarkus.builder.item.BuildItem; -import io.quarkus.deployment.ExtensionLoader; import io.quarkus.deployment.QuarkusAugmentor; import io.quarkus.deployment.builditem.ApplicationClassNameBuildItem; -import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem; import io.quarkus.deployment.builditem.GeneratedClassBuildItem; import io.quarkus.deployment.builditem.GeneratedFileSystemResourceHandledBuildItem; import io.quarkus.deployment.builditem.GeneratedResourceBuildItem; -import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.builditem.LiveReloadBuildItem; import io.quarkus.deployment.builditem.MainClassBuildItem; -import io.quarkus.deployment.builditem.RawCommandLineArgumentsBuildItem; -import io.quarkus.deployment.builditem.ShutdownContextBuildItem; import io.quarkus.deployment.builditem.TransformedClassesBuildItem; import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem; import io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem; @@ -292,70 +284,6 @@ public StartupActionImpl reloadExistingApplication(boolean hasStartedSuccessfull return new StartupActionImpl(curatedApplication, result); } - /** - * Runs a custom augmentation action, such as generating config. - * - * @param chainBuild A consumer that customises the build to select the output targets - * @param executionBuild A consumer that can see the initial build execution - * @return The build result - */ - public BuildResult runCustomAction(Consumer chainBuild, Consumer executionBuild) { - ProfileManager.setLaunchMode(launchMode); - QuarkusClassLoader classLoader = curatedApplication.getAugmentClassLoader(); - - ClassLoader old = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(classLoader); - - final BuildChainBuilder chainBuilder = BuildChain.builder(); - chainBuilder.setClassLoader(classLoader); - - ExtensionLoader.loadStepsFrom(classLoader, new Properties(), - curatedApplication.getApplicationModel(), launchMode, devModeType, null) - .accept(chainBuilder); - chainBuilder.loadProviders(classLoader); - - for (Consumer c : chainCustomizers) { - c.accept(chainBuilder); - } - chainBuilder - .addInitial(ShutdownContextBuildItem.class) - .addInitial(LaunchModeBuildItem.class) - .addInitial(CuratedApplicationShutdownBuildItem.class) - .addInitial(LiveReloadBuildItem.class) - .addInitial(RawCommandLineArgumentsBuildItem.class); - chainBuild.accept(chainBuilder); - - BuildChain chain = chainBuilder - .build(); - boolean auxiliaryApplication = curatedApplication.getQuarkusBootstrap().isAuxiliaryApplication(); - BuildExecutionBuilder execBuilder = chain.createExecutionBuilder("main") - .produce(new LaunchModeBuildItem(launchMode, - devModeType == null ? Optional.empty() : Optional.of(devModeType), - auxiliaryApplication, - Optional.ofNullable(curatedApplication.getQuarkusBootstrap().isHostApplicationIsTestOnly() - ? DevModeType.TEST_ONLY - : (auxiliaryApplication ? DevModeType.LOCAL : null)), - curatedApplication.getQuarkusBootstrap().isTest())) - .produce(new ShutdownContextBuildItem()) - .produce(new CuratedApplicationShutdownBuildItem(curatedApplication.getAugmentClassLoader(), true)) - .produce(new RawCommandLineArgumentsBuildItem()) - .produce(new LiveReloadBuildItem()); - executionBuild.accept(execBuilder); - return execBuilder - .execute(); - } catch (Exception e) { - throw new RuntimeException("Failed to run task", e); - } finally { - try { - ConfigProviderResolver.instance().releaseConfig(ConfigProviderResolver.instance().getConfig(classLoader)); - } catch (Exception ignore) { - - } - Thread.currentThread().setContextClassLoader(old); - } - } - private BuildResult runAugment(boolean firstRun, Set changedResources, ClassChangeInformation classChangeInformation, ClassLoader deploymentClassLoader, Class... finalOutputs) { diff --git a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/GenerateConfigTask.java b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/GenerateConfigTask.java deleted file mode 100644 index 84a4e1e512277..0000000000000 --- a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/GenerateConfigTask.java +++ /dev/null @@ -1,160 +0,0 @@ -package io.quarkus.runner.bootstrap; - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.OpenOption; -import java.nio.file.Path; -import java.nio.file.StandardOpenOption; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.jboss.logging.Logger; - -import io.quarkus.bootstrap.app.CuratedApplication; -import io.quarkus.builder.BuildChainBuilder; -import io.quarkus.builder.BuildExecutionBuilder; -import io.quarkus.builder.BuildResult; -import io.quarkus.deployment.builditem.ArchiveRootBuildItem; -import io.quarkus.deployment.builditem.ConfigDescriptionBuildItem; - -/** - * This phase generates an example configuration file - * - * @author Stuart Douglas - */ -public class GenerateConfigTask implements BiConsumer> { - - private static final Logger log = Logger.getLogger(GenerateConfigTask.class); - - public static final String CONFIG_FILE = "config-file"; - - @Override - public void accept(CuratedApplication application, Map stringObjectMap) { - Path configFile = (Path) stringObjectMap.get(CONFIG_FILE); - //first lets look for some config, as it is not on the current class path - //and we need to load it to run the build process - try { - Path temp = Files.createTempDirectory("empty"); - try { - AugmentActionImpl augmentAction = new AugmentActionImpl(application); - BuildResult buildResult = augmentAction.runCustomAction(new Consumer() { - @Override - public void accept(BuildChainBuilder chainBuilder) { - chainBuilder.addFinal(ConfigDescriptionBuildItem.class); - chainBuilder.addInitial(ArchiveRootBuildItem.class); - } - }, new Consumer() { - @Override - public void accept(BuildExecutionBuilder buildExecutionBuilder) { - buildExecutionBuilder.produce(new ArchiveRootBuildItem(temp)); - } - }); - - List descriptions = buildResult.consumeMulti(ConfigDescriptionBuildItem.class); - Collections.sort(descriptions); - - String existing = ""; - if (Files.exists(configFile)) { - existing = new String(Files.readAllBytes(configFile), StandardCharsets.UTF_8); - } - - StringBuilder sb = new StringBuilder(); - for (ConfigDescriptionBuildItem i : descriptions) { - //we don't want to add these if they already exist - //either in commended or uncommented form - if (existing.contains("\n" + i.getPropertyName() + "=") || - existing.contains("\n#" + i.getPropertyName() + "=")) { - continue; - } - - sb.append("\n#\n"); - sb.append(formatDocs(i.getDocs())); - sb.append("\n#\n#"); - sb.append(i.getPropertyName()).append("="); - if (i.getDefaultValue() != null) { - sb.append(i.getDefaultValue()); - } - sb.append("\n"); - } - - Files.createDirectories(configFile.getParent()); - Files.write(configFile, sb.toString().getBytes(StandardCharsets.UTF_8), - Files.exists(configFile) ? new OpenOption[] { StandardOpenOption.APPEND } : new OpenOption[] {}); - } finally { - Files.deleteIfExists(temp); - } - - } catch (Exception e) { - throw new RuntimeException("Failed to generate config file", e); - } - } - - private String formatDocs(String docs) { - - if (docs == null) { - return ""; - } - StringBuilder builder = new StringBuilder(); - - boolean lastEmpty = false; - boolean first = true; - - for (String line : docs.replace("

", "\n").split("\n")) { - //process line by line - String trimmed = line.trim(); - //if the lines are empty we only include a single empty line at most, and add a # character - if (trimmed.isEmpty()) { - if (!lastEmpty && !first) { - lastEmpty = true; - builder.append("\n#"); - } - continue; - } - //add the newlines - lastEmpty = false; - if (first) { - first = false; - } else { - builder.append("\n"); - } - //replace some special characters, others are taken care of by regex below - builder.append("# " + trimmed.replace("\n", "\n#") - .replace("

    ", "") - .replace("
", "") - .replace("
  • ", " - ") - .replace("
  • ", "")); - } - - String ret = builder.toString(); - //replace @code - ret = Pattern.compile("\\{@code (.*?)\\}").matcher(ret).replaceAll("'$1'"); - //replace @link with a reference to the field name - Matcher matcher = Pattern.compile("\\{@link #(.*?)\\}").matcher(ret); - while (matcher.find()) { - ret = ret.replace(matcher.group(0), "'" + configify(matcher.group(1)) + "'"); - } - - return ret; - } - - private String configify(String group) { - //replace uppercase characters with a - followed by lowercase - StringBuilder ret = new StringBuilder(); - for (int i = 0; i < group.length(); ++i) { - char c = group.charAt(i); - if (Character.isUpperCase(c)) { - ret.append("-"); - ret.append(Character.toLowerCase(c)); - } else { - ret.append(c); - } - } - return ret.toString(); - } - -} diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java index 3429ca47f573a..91b99686942eb 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java @@ -40,7 +40,6 @@ import io.quarkus.gradle.tasks.QuarkusBuild; import io.quarkus.gradle.tasks.QuarkusDev; import io.quarkus.gradle.tasks.QuarkusGenerateCode; -import io.quarkus.gradle.tasks.QuarkusGenerateConfig; import io.quarkus.gradle.tasks.QuarkusListCategories; import io.quarkus.gradle.tasks.QuarkusListExtensions; import io.quarkus.gradle.tasks.QuarkusListPlatforms; @@ -64,7 +63,6 @@ public class QuarkusPlugin implements Plugin { public static final String QUARKUS_GENERATE_CODE_TASK_NAME = "quarkusGenerateCode"; public static final String QUARKUS_GENERATE_CODE_TESTS_TASK_NAME = "quarkusGenerateCodeTests"; public static final String QUARKUS_BUILD_TASK_NAME = "quarkusBuild"; - public static final String GENERATE_CONFIG_TASK_NAME = "generateConfig"; public static final String QUARKUS_DEV_TASK_NAME = "quarkusDev"; public static final String QUARKUS_REMOTE_DEV_TASK_NAME = "quarkusRemoteDev"; public static final String QUARKUS_TEST_TASK_NAME = "quarkusTest"; @@ -107,7 +105,6 @@ private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) { tasks.create(LIST_PLATFORMS_TASK_NAME, QuarkusListPlatforms.class); tasks.create(ADD_EXTENSION_TASK_NAME, QuarkusAddExtension.class); tasks.create(REMOVE_EXTENSION_TASK_NAME, QuarkusRemoveExtension.class); - tasks.create(GENERATE_CONFIG_TASK_NAME, QuarkusGenerateConfig.class); QuarkusGenerateCode quarkusGenerateCode = tasks.create(QUARKUS_GENERATE_CODE_TASK_NAME, QuarkusGenerateCode.class); QuarkusGenerateCode quarkusGenerateCodeTests = tasks.create(QUARKUS_GENERATE_CODE_TESTS_TASK_NAME, diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateConfig.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateConfig.java deleted file mode 100644 index f19b2ecbdb059..0000000000000 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateConfig.java +++ /dev/null @@ -1,80 +0,0 @@ -package io.quarkus.gradle.tasks; - -import java.io.File; -import java.util.Collections; - -import org.gradle.api.GradleException; -import org.gradle.api.file.FileCollection; -import org.gradle.api.tasks.CompileClasspath; -import org.gradle.api.tasks.Input; -import org.gradle.api.tasks.Optional; -import org.gradle.api.tasks.SourceSet; -import org.gradle.api.tasks.TaskAction; -import org.gradle.api.tasks.options.Option; - -import io.quarkus.bootstrap.BootstrapException; -import io.quarkus.bootstrap.app.CuratedApplication; -import io.quarkus.bootstrap.app.QuarkusBootstrap; -import io.quarkus.bootstrap.model.ApplicationModel; -import io.quarkus.runner.bootstrap.GenerateConfigTask; - -public class QuarkusGenerateConfig extends QuarkusTask { - - private String file = "application.properties.example"; - - public QuarkusGenerateConfig() { - super("Generates an example config file"); - } - - @Optional - @Input - public String getFile() { - return file; - } - - /** - * Create a dependency on classpath resolution. This makes sure included build are build this task runs. - * - * @return resolved compile classpath - */ - @CompileClasspath - public FileCollection getClasspath() { - return QuarkusGradleUtils.getSourceSet(getProject(), SourceSet.MAIN_SOURCE_SET_NAME).getCompileClasspath(); - } - - @Option(description = "The name of the file to generate", option = "file") - public void setFile(String file) { - this.file = file; - } - - @TaskAction - public void buildQuarkus() { - getLogger().lifecycle("generating example config"); - - final ApplicationModel appModel = extension().getApplicationModel(); - if (extension().resourcesDir().isEmpty()) { - throw new GradleException("No resources directory, cannot create application.properties"); - } - File target = extension().resourcesDir().iterator().next(); - - String name = file; - if (name == null || name.isEmpty()) { - name = "application.properties.example"; - } - try (CuratedApplication bootstrap = QuarkusBootstrap.builder() - .setBaseClassLoader(getClass().getClassLoader()) - .setExistingModel(appModel) - .setTargetDirectory(getProject().getBuildDir().toPath()) - .setBaseName(extension().finalName()) - .setAppArtifact(appModel.getAppArtifact()) - .setLocalProjectDiscovery(false) - .setIsolateDeployment(true) - .build().bootstrap()) { - bootstrap.runInAugmentClassLoader(GenerateConfigTask.class.getName(), - Collections.singletonMap(GenerateConfigTask.CONFIG_FILE, new File(target, name).toPath())); - getLogger().lifecycle("Generated config file " + name); - } catch (BootstrapException e) { - throw new RuntimeException(e); - } - } -} diff --git a/devtools/maven/src/main/java/io/quarkus/maven/GenerateConfigMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/GenerateConfigMojo.java deleted file mode 100644 index c6608f63a00e5..0000000000000 --- a/devtools/maven/src/main/java/io/quarkus/maven/GenerateConfigMojo.java +++ /dev/null @@ -1,163 +0,0 @@ -package io.quarkus.maven; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; -import java.util.List; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Resource; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.logging.Log; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectHelper; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.impl.RemoteRepositoryManager; -import org.eclipse.aether.repository.RemoteRepository; - -import io.quarkus.bootstrap.app.CuratedApplication; -import io.quarkus.bootstrap.app.QuarkusBootstrap; -import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; -import io.quarkus.maven.dependency.ResolvedArtifactDependency; -import io.quarkus.runner.bootstrap.GenerateConfigTask; - -/** - * Generates an example application.properties, with all properties commented out. - * - * If this is already present then it will be appended too, although only properties that were not already present - * - * @author Stuart Douglas - */ -@Mojo(name = "generate-config", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) -public class GenerateConfigMojo extends AbstractMojo { - - /** - * The entry point to Aether, i.e. the component doing all the work. - * - * @component - */ - @Component - private RepositorySystem repoSystem; - - @Component - private RemoteRepositoryManager remoteRepoManager; - - @Component - private MavenProjectHelper projectHelper; - - /** - * The current repository/network configuration of Maven. - * - * @parameter default-value="${repositorySystemSession}" - * @readonly - */ - @Parameter(defaultValue = "${repositorySystemSession}", readonly = true) - private RepositorySystemSession repoSession; - - /** - * The project's remote repositories to use for the resolution of artifacts and their dependencies. - * - * @parameter default-value="${project.remoteProjectRepositories}" - * @readonly - */ - @Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true) - private List repos; - - /** - * The project's remote repositories to use for the resolution of plugins and their dependencies. - * - * @parameter default-value="${project.remotePluginRepositories}" - * @readonly - */ - @Parameter(defaultValue = "${project.remotePluginRepositories}", readonly = true, required = true) - private List pluginRepos; - - @Parameter(defaultValue = "${project}", readonly = true, required = true) - protected MavenProject project; - - @Parameter(defaultValue = "${project.build.directory}") - private File buildDir; - - @Parameter(defaultValue = "${file}") - private String file; - - @Override - public void execute() throws MojoExecutionException { - - if (project.getPackaging().equals("pom")) { - getLog().info("Type of the artifact is POM, skipping generate-config goal"); - return; - } - if (project.getResources().isEmpty()) { - throw new MojoExecutionException("No resources directory, cannot create application.properties"); - } - - // Here we are creating the output dir if it does not exist just to be able to resolve - // the root app artifact, otherwise the project has to be compiled at least - final Path classesDir = Paths.get(project.getBuild().getOutputDirectory()); - if (!Files.exists(classesDir)) { - if (getLog().isDebugEnabled()) { - getLog().debug("Creating empty " + classesDir + " just to be able to resolve the project's artifact"); - } - try { - Files.createDirectories(classesDir); - } catch (IOException e) { - throw new MojoExecutionException("Failed to create " + classesDir); - } - } - - try { - MavenArtifactResolver resolver = MavenArtifactResolver.builder() - .setRepositorySystem(repoSystem) - .setRepositorySystemSession(repoSession) - .setRemoteRepositories(repos) - .setRemoteRepositoryManager(remoteRepoManager) - .build(); - - final Artifact projectArtifact = project.getArtifact(); - final ResolvedArtifactDependency appArtifact = new ResolvedArtifactDependency(projectArtifact.getGroupId(), - projectArtifact.getArtifactId(), - projectArtifact.getClassifier(), projectArtifact.getArtifactHandler().getExtension(), - projectArtifact.getVersion(), classesDir); - - try (CuratedApplication curatedApplication = QuarkusBootstrap - .builder() - .setAppArtifact(appArtifact) - .setProjectRoot(project.getBasedir().toPath()) - .setMavenArtifactResolver(resolver) - .setBaseClassLoader(getClass().getClassLoader()) - .setBuildSystemProperties(project.getProperties()) - .build().bootstrap()) { - - Resource res = project.getResources().get(0); - File target = new File(res.getDirectory()); - - String name = file; - if (name == null || name.isEmpty()) { - name = "application.properties.example"; - } - Path configFile = new File(target, name).toPath(); - curatedApplication.runInAugmentClassLoader(GenerateConfigTask.class.getName(), - Collections.singletonMap(GenerateConfigTask.CONFIG_FILE, configFile)); - } - } catch (Exception e) { - throw new MojoExecutionException("Failed to generate config file", e); - } - } - - @Override - public void setLog(Log log) { - super.setLog(log); - MojoLogger.delegate = log; - } -} diff --git a/docs/src/main/asciidoc/config-reference.adoc b/docs/src/main/asciidoc/config-reference.adoc index e539aa6fb152b..f2f23f12d1f76 100644 --- a/docs/src/main/asciidoc/config-reference.adoc +++ b/docs/src/main/asciidoc/config-reference.adoc @@ -442,39 +442,6 @@ without any gaps. IMPORTANT: Indexed Properties are not supported in Environment Variables. -== Generate Configuration - -It is also possible to generate an example `application.properties` with all known configuration properties: - -[source,bash] --- -./mvnw quarkus:generate-config --- - -This creates a `src/main/resources/application.properties.example` file that contains all the config options -exposed via the extensions currently present in the application. These options are commented out, and have their value -set to defaults when applicable. For example this HTTP port config entry will appear as: - -.application.properties -[source,properties] --- -# -# The HTTP port -# -#quarkus.http.port=8080 --- - -Rather than generating an example config file, you can also add these to you actual config file by setting the `-Dfile` -parameter: - -[source,bash] --- -./mvnw quarkus:generate-config -Dfile=application.properties --- - -If a config option is already present it will not be added, so it is safe to run this after adding an extension to see -which configurations are available. - [[configuring_quarkus]] == Configuring Quarkus diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java index 692e5013d25f4..bfc8c6d251456 100644 --- a/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java @@ -31,16 +31,6 @@ void setUp(@TempDir File projectRoot) { this.projectRoot = projectRoot; } - @Test - public void canGenerateConfig() throws Exception { - createProject(SourceType.JAVA); - - BuildResult build = runGradleWrapper(projectRoot, "generateConfig"); - - assertThat(build.getTasks().get(":generateConfig")).isEqualTo(BuildResult.SUCCESS_OUTCOME); - assertThat(projectRoot.toPath().resolve("src/main/resources/application.properties.example")).exists(); - } - @ParameterizedTest(name = "Build {0} project") @EnumSource(SourceType.class) public void canBuild(SourceType sourceType) throws Exception { diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/GenerateConfigIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/GenerateConfigIT.java deleted file mode 100644 index 68cbc38412a7a..0000000000000 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/GenerateConfigIT.java +++ /dev/null @@ -1,77 +0,0 @@ -package io.quarkus.maven.it; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; -import java.util.Collections; -import java.util.Properties; -import java.util.stream.Collectors; - -import org.apache.maven.shared.invoker.DefaultInvocationRequest; -import org.apache.maven.shared.invoker.InvocationRequest; -import org.apache.maven.shared.invoker.Invoker; -import org.apache.maven.shared.invoker.InvokerLogger; -import org.apache.maven.shared.invoker.MavenInvocationException; -import org.apache.maven.shared.invoker.PrintStreamLogger; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -@DisableForNative -class GenerateConfigIT extends QuarkusPlatformAwareMojoTestBase { - - private static final String PROJECT_SOURCE_DIR = "projects/classic"; - private File testDir; - private Invoker invoker; - - @Test - void testAddExtensionWithASingleExtension() throws MavenInvocationException, IOException { - testDir = initProject(PROJECT_SOURCE_DIR, "projects/testGenerateConfig"); - invoker = initInvoker(testDir); - generateConfig("test.properties"); - - String file = loadFile("test.properties"); - Assertions.assertTrue(file.contains("#quarkus.log.level")); - Assertions.assertTrue(file.contains("The log level of the root category")); - Assertions.assertTrue(file.contains("#quarkus.thread-pool.growth-resistance=0")); - Assertions.assertTrue(file.contains("The executor growth resistance")); - - generateConfig("application.properties"); - //the existing file should not add properties that already exist - file = loadFile("application.properties"); - Assertions.assertTrue(file.contains("quarkus.log.level=INFO")); - Assertions.assertFalse(file.contains("The log level of the root category")); - Assertions.assertTrue(file.contains("#quarkus.thread-pool.growth-resistance=0")); - Assertions.assertTrue(file.contains("The executor growth resistance")); - } - - private String loadFile(String file) throws IOException { - try (BufferedReader reader = new BufferedReader( - new InputStreamReader(new FileInputStream(new File(testDir, "src/main/resources/" + file)), "UTF-8"))) { - return reader.lines().collect(Collectors.joining("\n")); - } - } - - private void generateConfig(String filename) - throws MavenInvocationException, FileNotFoundException, UnsupportedEncodingException { - InvocationRequest request = new DefaultInvocationRequest(); - request.setBatchMode(true); - request.setGoals(Collections - .singletonList(getMavenPluginGroupId() + ":" + getMavenPluginArtifactId() + ":" - + getMavenPluginVersion() + ":generate-config")); - Properties properties = new Properties(); - properties.setProperty("file", filename); - request.setProperties(properties); - - File log = new File(testDir, "build-generate-config-" + testDir.getName() + ".log"); - PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"), - InvokerLogger.DEBUG); - invoker.setLogger(logger); - invoker.execute(request); - } -}