Skip to content

Commit

Permalink
Merge pull request #11989 from gsmet/1.8.0-backports-3
Browse files Browse the repository at this point in the history
1.8.0 backports 3
  • Loading branch information
gsmet committed Sep 9, 2020
2 parents 5c585c7 + 6c9de91 commit 6dd5b8a
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import io.quarkus.deployment.builditem.LiveReloadBuildItem;
import io.quarkus.deployment.builditem.QuarkusBuildCloseablesBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
Expand All @@ -63,10 +65,13 @@ public class ApplicationArchiveBuildStep {
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
static final class IndexDependencyConfiguration {
/**
* Artifacts on the class path that should also be indexed, which will allow classes in the index to be
* processed by Quarkus processors
* Artifacts on the classpath that should also be indexed.
* <p>
* Their classes will be in the index and processed by Quarkus processors.
*/
@ConfigItem(name = ConfigItem.PARENT)
@ConfigDocSection
@ConfigDocMapKey("dependency-name")
Map<String, IndexDependencyConfig> indexDependency;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
public class IndexDependencyConfig {

/**
* The maven groupId of the artifact to index
* The maven groupId of the artifact.
*/
@ConfigItem
public String groupId;

/**
* The maven artifactId of the artifact to index
* The maven artifactId of the artifact.
*/
@ConfigItem
public String artifactId;

/**
* The maven classifier of the artifact to index
* The maven classifier of the artifact.
*/
@ConfigItem
public Optional<String> classifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.gradle.tasks;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -78,6 +79,29 @@ public FileCollection getClasspath() {
.plus(mainSourceSet.getResources());
}

@Input
public Map<Object, Object> getQuarkusBuildSystemProperties() {
Map<Object, Object> quarkusSystemProperties = new HashMap<>();
for (Map.Entry<Object, Object> systemProperty : System.getProperties().entrySet()) {
if (systemProperty.getKey().toString().startsWith("quarkus.") &&
systemProperty.getValue() instanceof Serializable) {
quarkusSystemProperties.put(systemProperty.getKey(), systemProperty.getValue());
}
}
return quarkusSystemProperties;
}

@Input
public Map<String, String> getQuarkusBuildEnvProperties() {
Map<String, String> quarkusEnvProperties = new HashMap<>();
for (Map.Entry<String, String> systemProperty : System.getenv().entrySet()) {
if (systemProperty.getKey() != null && systemProperty.getKey().startsWith("QUARKUS_")) {
quarkusEnvProperties.put(systemProperty.getKey(), systemProperty.getValue());
}
}
return quarkusEnvProperties;
}

@OutputFile
public File getRunnerJar() {
return new File(getProject().getBuildDir(), extension().finalName() + "-runner.jar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import io.quarkus.arc.config.ConfigProperties;
import io.quarkus.deployment.index.IndexDependencyConfig;
import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigDocSection;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;

Expand Down Expand Up @@ -42,7 +44,7 @@ public class ArcConfig {
* <li>does not declare any producer which is eligible for injection to any injection point,</li>
* <li>is not directly eligible for injection into any {@link javax.enterprise.inject.Instance} injection point</li>
* </ul>
*
*
* @see UnremovableBeanBuildItem
*/
@ConfigItem(defaultValue = "all")
Expand Down Expand Up @@ -140,10 +142,14 @@ public class ArcConfig {
public Optional<List<String>> unremovableTypes;

/**
* The artifacts that should be excluded from discovery. These artifacts would be otherwise scanned for beans, i.e. they
* Artifacts that should be excluded from discovery.
* <p>
* These artifacts would be otherwise scanned for beans, i.e. they
* contain a Jandex index or a beans.xml descriptor.
*/
@ConfigItem
@ConfigDocSection
@ConfigDocMapKey("dependency-name")
Map<String, IndexDependencyConfig> excludeDependency;

public final boolean isRemoveUnusedBeansFieldValid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public class JibConfig {
/**
* Additional JVM arguments to pass to the JVM when starting the application
*/
@ConfigItem(defaultValue = "-Dquarkus.http.host=0.0.0.0,-Djava.util.logging.manager=org.jboss.logmanager.LogManager")
@ConfigItem(defaultValue = "-Djava.util.logging.manager=org.jboss.logmanager.LogManager")
public List<String> jvmArguments;

/**
* Additional arguments to pass when starting the native application
*/
@ConfigItem(defaultValue = "-Dquarkus.http.host=0.0.0.0")
public List<String> nativeArguments;
@ConfigItem
public Optional<List<String>> nativeArguments;

/**
* If this is set, then it will be used as the entry point of the container image.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,10 @@ private JibContainerBuilder createContainerBuilderFromNative(ContainerImageConfi
if (jibConfig.nativeEntrypoint.isPresent()) {
entrypoint = jibConfig.nativeEntrypoint.get();
} else {
entrypoint = new ArrayList<>(jibConfig.nativeArguments.size() + 1);
List<String> nativeArguments = jibConfig.nativeArguments.orElse(Collections.emptyList());
entrypoint = new ArrayList<>(nativeArguments.size() + 1);
entrypoint.add("./" + BINARY_NAME_IN_CONTAINER);
entrypoint.addAll(jibConfig.nativeArguments);
entrypoint.addAll(nativeArguments);
}
try {
AbsoluteUnixPath workDirInContainer = AbsoluteUnixPath.get("/work");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public class S2iConfig {
/**
* Additional JVM arguments to pass to the JVM when starting the application
*/
@ConfigItem(defaultValue = "-Dquarkus.http.host=0.0.0.0,-Djava.util.logging.manager=org.jboss.logmanager.LogManager")
@ConfigItem(defaultValue = "-Djava.util.logging.manager=org.jboss.logmanager.LogManager")
public List<String> jvmArguments;

/**
* Additional arguments to pass when starting the native application
*/
@ConfigItem(defaultValue = "-Dquarkus.http.host=0.0.0.0")
public List<String> nativeArguments;
@ConfigItem
public Optional<List<String>> nativeArguments;

/**
* The directory where the jar is added during the assemble phase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ public void s2iRequirementsNative(S2iConfig s2iConfig,

builderImageProducer.produce(new BaseImageInfoBuildItem(s2iConfig.baseNativeImage));
Optional<S2iBaseNativeImage> baseImage = S2iBaseNativeImage.findMatching(s2iConfig.baseNativeImage);
List<String> nativeArguments = s2iConfig.nativeArguments.orElse(Collections.emptyList());
baseImage.ifPresent(b -> {
envProducer.produce(
KubernetesEnvBuildItem.createSimpleVar(b.getHomeDirEnvVar(), s2iConfig.nativeBinaryDirectory, OPENSHIFT));
envProducer.produce(
KubernetesEnvBuildItem.createSimpleVar(b.getOptsEnvVar(), String.join(" ", s2iConfig.nativeArguments),
KubernetesEnvBuildItem.createSimpleVar(b.getOptsEnvVar(), String.join(" ", nativeArguments),
OPENSHIFT));
});

if (!baseImage.isPresent()) {
commandProducer.produce(new KubernetesCommandBuildItem(pathToNativeBinary,
s2iConfig.nativeArguments.toArray(new String[s2iConfig.nativeArguments.size()])));
commandProducer.produce(new KubernetesCommandBuildItem(pathToNativeBinary, nativeArguments.toArray(new String[0])));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@

import java.util.Collections;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.ConfigSourceProvider;
import org.jboss.logging.Logger;

import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.runtime.configuration.AbstractRawDefaultConfigSource;

@Recorder
public class KubernetesConfigRecorder {

private static final Logger log = Logger.getLogger(KubernetesConfigRecorder.class);

private static final String CONFIG_ENABLED_PROPERTY_NAME = "quarkus.kubernetes-config.enabled";

public RuntimeValue<ConfigSourceProvider> configSources(KubernetesConfigSourceConfig kubernetesConfigSourceConfig,
KubernetesConfigBuildTimeConfig buildTimeConfig,
KubernetesClientBuildConfig clientConfig) {
if (!kubernetesConfigSourceConfig.enabled && !buildTimeConfig.secretsEnabled) {
if ((!kubernetesConfigSourceConfig.enabled && !buildTimeConfig.secretsEnabled) || isExplicitlyDisabled()) {
log.debug(
"No attempt will be made to obtain configuration from the Kubernetes API server because the functionality has been disabled via configuration");
return emptyRuntimeValue();
Expand All @@ -27,6 +32,26 @@ public RuntimeValue<ConfigSourceProvider> configSources(KubernetesConfigSourceCo
KubernetesClientUtils.createClient(clientConfig)));
}

// We don't want to enable the reading of anything if 'quarkus.kubernetes-config.enabled' is EXPLICITLY set to false
// In order to figure out whether the user has actually set the property, we take advantage of the fact that Smallrye
// Config returns the ConfigSources by descending order - we thus check each ConfigSource to see if the value has been set
private boolean isExplicitlyDisabled() {
Config config = ConfigProvider.getConfig();
Iterable<ConfigSource> configSources = config.getConfigSources();
for (ConfigSource configSource : configSources) {
// this is the ConfigSource that Quarkus Config creates and if we've reached this point, then we know that the
// use has not explicitly configured the value
if (configSource instanceof AbstractRawDefaultConfigSource) {
return false;
}
if (configSource.getPropertyNames().contains(CONFIG_ENABLED_PROPERTY_NAME)) {
// TODO: should probably use converter here
return !Boolean.parseBoolean(configSource.getValue(CONFIG_ENABLED_PROPERTY_NAME));
}
}
return false;
}

public void warnAboutSecrets(KubernetesConfigSourceConfig config, KubernetesConfigBuildTimeConfig buildTimeConfig) {
if (config.secrets.isPresent()
&& !config.secrets.get().isEmpty()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.vertx.http.deployment;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
Expand Down Expand Up @@ -217,7 +218,8 @@ void registerExchangeAttributeBuilders(final BuildProducer<ServiceProviderBuildI
logger.debug("Skipping registration of service providers for " + ExchangeAttributeBuilder.class);
return;
}
try (final FileSystem jarFileSystem = ZipUtils.newFileSystem(codeSource.getLocation().toURI(),
try (final FileSystem jarFileSystem = ZipUtils.newFileSystem(
new URI("jar", codeSource.getLocation().toURI().toString(), null),
Collections.emptyMap())) {
final Path serviceDescriptorFilePath = jarFileSystem.getPath("META-INF", "services",
"io.quarkus.vertx.http.runtime.attribute.ExchangeAttributeBuilder");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,13 @@ public Set<String> apply(JarFile jarFile) {
public ProtectionDomain getProtectionDomain(ClassLoader classLoader) {
URL url = null;
try {
URI uri = new URI("jar:file", null, jarPath.getPath() + "!/", null);
URI uri = new URI("file", null, jarPath.getPath(), null);
url = uri.toURL();
} catch (URISyntaxException | MalformedURLException e) {
throw new RuntimeException("Unable to create protection domain for " + jarPath, e);
}
CodeSource codesource = new CodeSource(url, (Certificate[]) null);
ProtectionDomain protectionDomain = new ProtectionDomain(codesource, null, classLoader, null);
return protectionDomain;
return new ProtectionDomain(codesource, null, classLoader, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ public ProtectionDomain getProtectionDomain(ClassLoader classLoader) {
if (!path.startsWith("/")) {
path = "/" + path;
}
URI uri = new URI("jar:file", null, path + "!/", null);
URI uri = new URI("file", null, path, null);
url = uri.toURL();
} catch (URISyntaxException | MalformedURLException e) {
throw new RuntimeException("Unable to create protection domain for " + jarPath, e);
}
CodeSource codesource = new CodeSource(url, (Certificate[]) null);
ProtectionDomain protectionDomain = new ProtectionDomain(codesource, null, classLoader, null);
return protectionDomain;
return new ProtectionDomain(codesource, null, classLoader, null);
}

private ZipFile file() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ public void canDetectOutputChangeWhenBuilding() throws Exception {
assertThat(runnerJar).exists();
}

@Test
public void canDetectSystemPropertyChangeWhenBuilding() throws Exception {
createProject(SourceType.JAVA);

BuildResult firstBuild = runGradleWrapper(projectRoot, "quarkusBuild", "--stacktrace");

assertThat(firstBuild.getTasks().get(":quarkusBuild")).isEqualTo(BuildResult.SUCCESS_OUTCOME);
assertThat(projectRoot.toPath().resolve("build").resolve("foo-1.0.0-SNAPSHOT-runner.jar")).exists();

BuildResult secondBuild = runGradleWrapper(projectRoot, "quarkusBuild", "-Dquarkus.package.type=fast-jar");

assertThat(secondBuild.getTasks().get(":quarkusBuild")).isEqualTo(BuildResult.SUCCESS_OUTCOME);
assertThat(projectRoot.toPath().resolve("build").resolve("quarkus-app")).exists();
}

@Test
public void canRunTest() throws Exception {
createProject(SourceType.JAVA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public void assertGeneratedResources() throws IOException {
});
assertThat(envVars).anySatisfy(envVar -> {
assertThat(envVar.getName()).isEqualTo("JAVA_OPTIONS");
assertThat(envVar.getValue()).contains("-Dquarkus.http.host=0.0.0.0");
assertThat(envVar.getValue())
.contains("-Djava.util.logging.manager=org.jboss.logmanager.LogManager");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.quarkus.it.main;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;

import org.junit.jupiter.api.Test;

import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.test.junit.QuarkusTest;

/**
* The purpose of this test is to ensure that using the projection domain of a class loaded
* from the QuarkusClassLoader yields the appropriate result
*/
@QuarkusTest
public class QuarkusClassloaderProtectionDomainTest {

@Test
public void testClassFromJar() throws IOException {
Class<?> testClass = org.h2.tools.Server.class;
ClassLoader classLoader = testClass.getClassLoader();
assertTrue(classLoader instanceof QuarkusClassLoader);

URL location = testClass.getProtectionDomain().getCodeSource().getLocation();
assertNotNull(location);

try (InputStream inputStream = location.openStream()) {
try (JarInputStream jarInputStream = new JarInputStream(inputStream)) {
Manifest manifest = jarInputStream.getManifest();
assertNotNull(manifest);
assertNotNull(manifest.getMainAttributes().getValue("Implementation-Version"));
}
}
}

}
Loading

0 comments on commit 6dd5b8a

Please sign in to comment.