Skip to content

Commit

Permalink
TCK Tracking: Jakarta EE 10 Core Profile #6799
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
  • Loading branch information
jbescos committed Jun 14, 2023
1 parent 036d073 commit b2a3cb1
Show file tree
Hide file tree
Showing 51 changed files with 1,736 additions and 58 deletions.
27 changes: 25 additions & 2 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<version.lib.jakarta.jaxrs-api>3.1.0</version.lib.jakarta.jaxrs-api>
<version.lib.jakarta.jms-api>3.0.0</version.lib.jakarta.jms-api>
<version.lib.jakarta.jsonb-api>3.0.0</version.lib.jakarta.jsonb-api>
<version.lib.jakarta.jsonp-api>2.1.1</version.lib.jakarta.jsonp-api>
<version.lib.jakarta.jsonp-api>2.1.0</version.lib.jakarta.jsonp-api>
<version.lib.jakarta.persistence-api>3.1.0</version.lib.jakarta.persistence-api>
<version.lib.jakarta.transaction-api>2.0.0</version.lib.jakarta.transaction-api>
<version.lib.jakarta.validation-api>3.0.0</version.lib.jakarta.validation-api>
Expand Down Expand Up @@ -105,6 +105,9 @@
<version.lib.micronaut.sql>4.4.0</version.lib.micronaut.sql>
<!-- FIXME upgrade to 3.1 when it is released in Maven -->
<version.lib.microprofile-config>3.0.1</version.lib.microprofile-config>
<version.lib.microprofile-core-profile>10.0.1</version.lib.microprofile-core-profile>
<version.lib.microprofile-cdi-tck>4.0.9</version.lib.microprofile-cdi-tck>
<version.lib.microprofile-restfull-tck>3.1.3</version.lib.microprofile-restfull-tck>
<!-- FIXME upgrade to 4.1 when it is released in Maven -->
<version.lib.microprofile-fault-tolerance-api>4.0</version.lib.microprofile-fault-tolerance-api>
<version.lib.microprofile-graphql>2.0</version.lib.microprofile-graphql>
Expand Down Expand Up @@ -140,7 +143,7 @@
<version.lib.opentracing.grpc>0.2.1</version.lib.opentracing.grpc>
<version.lib.opentracing.tracerresolver>0.1.8</version.lib.opentracing.tracerresolver>
<version.lib.perfmark-api>0.25.0</version.lib.perfmark-api>
<version.lib.parsson>1.0.2</version.lib.parsson>
<version.lib.parsson>1.1.2</version.lib.parsson>
<version.lib.postgresql>42.4.3</version.lib.postgresql>
<version.lib.prometheus>0.9.0</version.lib.prometheus>
<version.lib.slf4j>2.0.0</version.lib.slf4j>
Expand Down Expand Up @@ -680,6 +683,26 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jakarta.ee.tck.coreprofile</groupId>
<artifactId>core-profile-tck-impl</artifactId>
<version>${version.lib.microprofile-core-profile}</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-core-impl</artifactId>
<version>${version.lib.microprofile-cdi-tck}</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-api</artifactId>
<version>${version.lib.microprofile-cdi-tck}</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta-restful-ws-tck</artifactId>
<version>${version.lib.microprofile-restfull-tck}</version>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.opentracing</groupId>
<artifactId>microprofile-opentracing-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* is empty)</li>
* <li>replaceConfigSourcesWithMp: (Optional) defaults to false: whether to replace config sources with microprofile if it
* exists</li>
* <li>useWebInfBeans: (Optional) defaults to false: whether WEB-INF/beans.xml should be loaded</li>
* </ul>
*/
public class HelidonContainerConfiguration implements ContainerConfiguration {
Expand All @@ -45,6 +46,7 @@ public class HelidonContainerConfiguration implements ContainerConfiguration {
private boolean deleteTmp = true;
private boolean useRelativePath = false;
private boolean useParentClassloader = true;
private boolean useWebInfBeans = false;
private final List<Consumer<ConfigBuilder>> builderConsumers = new ArrayList<>();

/**
Expand Down Expand Up @@ -104,6 +106,14 @@ public void setUseParentClassloader(boolean useParentClassloader) {
this.useParentClassloader = useParentClassloader;
}

public boolean isUseWebInfBeans() {
return useWebInfBeans;
}

public void setUseWebInfBeans(boolean useWebInfBeans) {
this.useWebInfBeans = useWebInfBeans;
}

@Override
public void validate() throws ConfigurationException {
if ((port <= 0) || (port > Short.MAX_VALUE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import io.helidon.config.mp.MpConfigSources;

import jakarta.enterprise.inject.se.SeContainer;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.enterprise.inject.spi.DefinitionException;
import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.ws.rs.core.Application;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.spi.ConfigBuilder;
Expand All @@ -67,6 +72,9 @@
import org.jboss.shrinkwrap.api.Node;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptor;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
* Implementation of DeployableContainer for launching Helidon microprofile server.
Expand All @@ -77,6 +85,7 @@
* <li>A temporary directory is created</li>
* <li>The WebArchive contents are written to the temporary directory</li>
* <li>beans.xml is created in WEB-INF/classes if not present</li>
* <li>WEB-INF/beans.xml will be moved to WEB-INF/classes/META-INF if present</li>
* <li>The server is started with WEB-INF/classes and all libraries in WEB-INF/libon the classpath.</li>
* </ol>
*
Expand Down Expand Up @@ -180,19 +189,20 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {

Path rootDir = context.deployDir.resolve("");
if (isJavaArchive) {
ensureBeansXml(rootDir);
ensureBeansXml(rootDir, null);
classPath.add(rootDir);
} else {
// Prepare the launcher files
Path webInfDir = context.deployDir.resolve("WEB-INF");
Path classesDir = webInfDir.resolve("classes");
Path libDir = webInfDir.resolve("lib");
ensureBeansXml(classesDir);
ensureBeansXml(classesDir, webInfDir);
addServerClasspath(classPath, classesDir, libDir, rootDir);
loadWebXml(context, webInfDir);
}

startServer(context, classPath.toArray(new Path[0]));
} catch (IOException e) {
} catch (IOException | SAXException | ParserConfigurationException e) {
LOGGER.log(Level.INFO, "Failed to start container", e);
throw new DeploymentException("Failed to copy the archive assets into the deployment directory", e);
} catch (InvocationTargetException e) {
Expand Down Expand Up @@ -221,6 +231,46 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
return new ProtocolMetaData();
}

private void loadWebXml(RunContext context, Path webInfDir) throws IOException, ParserConfigurationException, SAXException, ReflectiveOperationException {
Path webXml = webInfDir.resolve("web.xml");
if (Files.exists(webXml)) {
try(InputStream inputStream = Files.newInputStream(webXml)) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(inputStream);
NodeList nodes = doc.getElementsByTagName("init-param");
for (int i = 0; i < nodes.getLength(); i++) {
NodeList childs = nodes.item(i).getChildNodes();
Application application = application(childs);
if (application != null) {
context.application = Optional.of(application);
break;
}
}
}
}
}

private Application application(NodeList childs) throws ReflectiveOperationException {
boolean isApp = false;
String appName = null;
for (int j = 0; j < childs.getLength(); j++) {
org.w3c.dom.Node element = childs.item(j);
String name = element.getNodeName();
String value = element.getTextContent();
if ("param-name".equals(name) && "jakarta.ws.rs.Application".equals(value)) {
isApp = true;
} else if ("param-value".equals(name)) {
appName = value;
}
}
if (isApp) {
return (Application) Class.forName(appName).getConstructor().newInstance();
} else {
return null;
}
}

static Optional<Exception> lookForSupressedDeploymentException(Throwable t) {
if (t == null) {
return Optional.empty();
Expand Down Expand Up @@ -312,8 +362,8 @@ void startServer(RunContext context, Path[] classPath)
}

context.runnerClass
.getDeclaredMethod("start", Config.class, Integer.TYPE)
.invoke(context.runner, config, containerConfig.getPort());
.getDeclaredMethod("start", Config.class, Integer.TYPE, Optional.class)
.invoke(context.runner, config, containerConfig.getPort(), context.application);
}

private URL[] toUrls(Path[] classPath) {
Expand Down Expand Up @@ -376,17 +426,24 @@ void addServerClasspath(List<Path> classpath, Path classesDir, Path libDir, Path
classpath.add(rootDir);
}

private void ensureBeansXml(Path classesDir) throws IOException {
private void ensureBeansXml(Path classesDir, Path webinfDir) throws IOException {
Path beansPath = classesDir.resolve("META-INF/beans.xml");
Path metaInfPath = beansPath.getParent();
if (null != metaInfPath) {
Files.createDirectories(metaInfPath);
}
if (containerConfig.isUseWebInfBeans() && webinfDir != null) {
// In case exists WEB-INF/beans.xml, then move it to classes/META-INF/beans.xml
Path webInfBeansPath = webinfDir.resolve("beans.xml");
if (Files.exists(webInfBeansPath)) {
Files.move(webInfBeansPath, beansPath);
return;
}
}
if (Files.exists(beansPath)) {
return;
}
try (InputStream beanXmlTemplate = HelidonDeployableContainer.class.getResourceAsStream("/templates/beans.xml")) {
Path metaInfPath = beansPath.getParent();
if (null != metaInfPath) {
Files.createDirectories(metaInfPath);
}

if (null == beanXmlTemplate) {
Files.write(beansPath, new byte[0]);
} else {
Expand Down Expand Up @@ -531,6 +588,8 @@ private static class RunContext {
private Object runner;
// existing class loader
private ClassLoader oldClassLoader;
// TODO Add web.xml application
private Optional<Application> application = Optional.empty();
}

static class HelidonContainerClassloader extends ClassLoader implements Closeable {
Expand Down Expand Up @@ -576,8 +635,10 @@ public Enumeration<URL> getResources(String name) throws IOException {
}
}
}

return Collections.enumeration(result);
// Give priority to WebApp resources (for example ServiceLoader provided by WebApp)
List<URL> toRevert = new ArrayList<URL>(result);
Collections.reverse(toRevert);
return Collections.enumeration(toRevert);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

import java.lang.System.Logger.Level;
import java.lang.reflect.Field;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;

import io.helidon.microprofile.server.Server;
import io.helidon.microprofile.server.ServerCdiExtension;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;

Expand Down Expand Up @@ -56,22 +58,22 @@ private static String getContextRoot(Class<?> application) {
*
* @param config configuration
* @param port port to start the server on
* @param application defines the components of a JAX-RS application and supplies additional meta-data
*/
public void start(Config config, int port) {
public void start(Config config, int port, Optional<Application> application) {
// attempt a stop
stop();

ConfigProviderResolver.instance()
.registerConfig(config, Thread.currentThread().getContextClassLoader());

server = Server.builder()
Server.Builder builder = Server.builder()
.port(port)
.config(config)
.build()
// this is a blocking operation, we will be released once the server is started
// or it fails to start
.start();

.config(config);
application.ifPresent(app -> builder.addApplication(app));
// this is a blocking operation, we will be released once the server is started
// or it fails to start
server = builder.build().start();
LOGGER.log(Level.TRACE, () -> "Started server");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2018, 2022 Oracle and/or its affiliates.
Copyright (c) 2018, 2023 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,8 +19,8 @@
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd"
version="3.0"
https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
version="4.0"
bean-discovery-mode="all">
</beans>

39 changes: 9 additions & 30 deletions microprofile/tests/tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@
<module>tck-reactive-operators</module>
<module>tck-lra</module>
<module>tck-telemetry</module>
<!--
Tests are passing, but maven artifact is not published yet
<module>tck-core-profile</module>
-->
<module>tck-cdi</module>
<module>tck-restfull</module>
<module>tck-jsonb</module>
<module>tck-jsonp</module>
<module>tck-inject</module>
</modules>

<properties>
Expand All @@ -53,36 +62,6 @@
</properties>



<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${version.plugin.surefire}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>tck-ft</id>
Expand Down
Loading

0 comments on commit b2a3cb1

Please sign in to comment.