Skip to content

Commit

Permalink
add environmentVariables to gradle task quarkusDev
Browse files Browse the repository at this point in the history
  • Loading branch information
Eng-Fouad committed Apr 15, 2023
1 parent e9c5730 commit ddba37e
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.CompileClasspath;
Expand Down Expand Up @@ -82,6 +83,7 @@ public abstract class QuarkusDev extends QuarkusTask {
private final CompilerOptions compilerOptions = new CompilerOptions();

private final Property<File> workingDirectory;
private final MapProperty<String, String> environmentVariables;

private final Property<Boolean> preventNoVerify;
private final Property<Boolean> shouldPropagateJavaCompilerArgs;
Expand Down Expand Up @@ -114,6 +116,8 @@ public QuarkusDev(
workingDirectory = objectFactory.property(File.class);
workingDirectory.convention(getProject().provider(() -> QuarkusPluginExtension.getLastFile(getCompilationOutput())));

environmentVariables = objectFactory.mapProperty(String.class, String.class);

preventNoVerify = objectFactory.property(Boolean.class);
preventNoVerify.convention(false);

Expand Down Expand Up @@ -177,6 +181,16 @@ public void setWorkingDir(String workingDir) {
workingDirectory.set(getProject().file(workingDir));
}

@Input
public MapProperty<String, String> getEnvironmentVariables() {
return environmentVariables;
}

@Internal
public Map<String, String> getEnvVars() {
return environmentVariables.get();
}

@Input
public Property<Boolean> getPreventNoVerify() {
return preventNoVerify;
Expand Down Expand Up @@ -307,6 +321,7 @@ public void startDev() {
if (outputFile == null) {
getProject().exec(action -> {
action.commandLine(runner.args()).workingDir(getWorkingDirectory().get());
action.environment(getEnvVars());
action.setStandardInput(System.in)
.setErrorOutput(System.out)
.setStandardOutput(System.out);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
id 'java'
id 'io.quarkus'
}

group = 'com.quarkus.demo'
version = '1.0'

repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
}
}
mavenCentral()
}

quarkusDev {
environmentVariables = [FOO_VALUE: 'abc', BAR_VALUE: 'def']
}

dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-resteasy'
}

test {
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.value=from-custom-file
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformGroupId=io.quarkus
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pluginManagement {
repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
}
}
mavenCentral()
gradlePluginPortal()
}
//noinspection GroovyAssignabilityCheck
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}

rootProject.name = 'add-envitonment-variables-app'


Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.acme.quarkus.sample;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/hello")
public class HelloResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
String foo = System.getenv("FOO_VALUE"); // abc
String bar = System.getenv("BAR_VALUE"); // def
return foo + bar; // abcdef
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkus.gradle.devmode;

import static org.assertj.core.api.Assertions.assertThat;

public class AddEnvironmentVariablesDevModeTest extends QuarkusDevGradleTestBase {

@Override
protected String projectDirectoryName() {
return "add-envitonment-variables-app";
}

@Override
protected String[] buildArguments() {
return new String[] { "clean", "quarkusDev" };
}

protected void testDevMode() throws Exception {
assertThat(getHttpResponse("/hello")).contains("abcdef");
}
}

0 comments on commit ddba37e

Please sign in to comment.