Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 57 additions & 23 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,63 @@
version: 2
version: 2.1

orbs:
# Using the gradle orb for better caching and setup
gradle: circleci/gradle@2.2.0

jobs:
build:
working_directory: ~/alfanse/embers
parallelism: 1
docker:
- image: circleci/openjdk:11-jdk
- image: cimg/openjdk:17.0.10
steps:
- checkout
- run:
working_directory: ~/alfanse/embers
# for diagnostics, show me the version, includes JVM, and Gradle.
command: ./gradlew --version
# Build
- run: make build
- store_test_results:
path: embers-services/build/test-results
- store_test_results:
path: embers-acceptance-tests/build/test-results
- store_test_results:
path: embers-spring/build/test-results
- store_artifacts:
name: store embers-acceptance-tests reports
path: embers-acceptance-tests/build/yatspec
destination: yatspec
- store_artifacts:
name: store jacoco reports
path: build/reports/jacoco
destination: jacoco
- checkout

# Restore Gradle dependencies cache
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.gradle" }}
- v1-dependencies-

# Show versions for diagnostics
- run:
name: Show versions
command: |
java -version
./gradlew --version

# Build with Gradle
- run:
name: Build and test
command: ./gradlew build --no-daemon --stacktrace
environment:
# Configure Gradle to use more memory
GRADLE_OPTS: '-Dorg.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8'

# Save Gradle dependencies cache
- save_cache:
paths:
- ~/.gradle
key: v1-dependencies-{{ checksum "build.gradle" }}

# Store test results for CircleCI test insights
- store_test_results:
path: embers-services/build/test-results
- store_test_results:
path: embers-acceptance-tests/build/test-results
- store_test_results:
path: embers-spring/build/test-results

# Store artifacts for later inspection
- store_artifacts:
name: Store acceptance test reports
path: embers-acceptance-tests/build/yatspec
destination: yatspec
- store_artifacts:
name: Store JaCoCo reports
path: build/reports/jacoco
destination: jacoco
- store_artifacts:
name: Store test results
path: build/reports/tests
destination: test-reports
100 changes: 28 additions & 72 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}
}
dependencies {
classpath "com.adarshr:gradle-test-logger-plugin:1.7.0"
classpath "com.adarshr:gradle-test-logger-plugin:4.0.0"
}
}

Expand All @@ -19,7 +19,8 @@ allprojects {
apply plugin: 'jacoco'
apply plugin: 'com.adarshr.test-logger'

sourceCompatibility = 1.8
sourceCompatibility = 17
targetCompatibility = 17

repositories {
mavenCentral()
Expand All @@ -35,81 +36,36 @@ allprojects {
}

task codeCoverageReport(type: JacocoReport) {
//swiped from http://csiebler.github.io/blog/2014/02/09/multi-project-code-coverage-using-gradle-and-jacoco/
//swiped from http://csiebler.github.io/blog/2014/02/09/multi-project-code-coverage-using-gradle-and-jacoco/

// Gather execution data from all subprojects
// (change this if you e.g. want to calculate unit test/integration test coverage separately)
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
// Enable the report to be generated
dependsOn subprojects*.test

// Add all relevant sourcesets from the subprojects
subprojects.each {
sourceSets it.sourceSets.main
}
// Gather execution data from all subprojects
executionData fileTree(project.rootDir).include("**/build/jacoco/*.exec")


// Configure source and class directories from all subprojects
sourceDirectories.setFrom(files(subprojects.sourceSets.main.allSource.srcDirs))
classDirectories.setFrom(files(subprojects.sourceSets.main.output))

// Enable XML report for CI tools if needed
reports {
html.enabled true
html.destination file("${buildDir}/reports/jacoco")
println "code coverage reports: " + html.destination
}
}
html.required = true
xml.required = false
csv.required = false

html.outputLocation = layout.buildDirectory.dir('reports/jacoco')
println "Code coverage reports will be generated at: ${html.outputLocation.get()}"
// xml.outputLocation = layout.buildDirectory.file('reports/jacoco/jacocoTestReport.xml')

// always run the tests before generating the report
codeCoverageReport.dependsOn {
subprojects*.test
}
}

check.dependsOn jacocoTestReport

subprojects {

def jaxb = '2.3.0'
def junitJupiter = '5.7.1'

extensions.add("libs", [
core: [
//the only libraries the production jar depends on
'javax.ws.rs:javax.ws.rs-api:2.1',
'javax.inject:javax.inject:1',
'javax.activation:activation:1.1.1',
"javax.xml.bind:jaxb-api:$jaxb",
"com.sun.xml.bind:jaxb-core:$jaxb",
"com.sun.xml.bind:jaxb-impl:$jaxb",
'org.jdbi:jdbi:2.78'
],
unit_tests: [
"org.junit.jupiter:junit-jupiter:$junitJupiter",
'org.easytesting:fest-assert-core:2.0M10',
'org.mockito:mockito-core:3.8.0',
'org.mockito:mockito-junit-jupiter:3.8.0'
],
acceptance_tests: [
// the bdd framework, makes pretty html reports from Junit tests
'com.github.nickmcdowall:yatspec:2021.1.1'
],
jersey: [
// implements javax.ws.rs
'org.glassfish.jersey.core:jersey-server:2.2',
'org.glassfish.jersey.containers:jersey-container-servlet:2.2'
],
jaxson: [
// handles json serialisation
'com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.5.2'
],
gson: [
//serialise java to json
'com.google.code.gson:gson:2.8.2'
],
json_assert: [
'org.skyscreamer:jsonassert:1.2.3'
],
jetty: [
// beloved server
'org.eclipse.jetty:jetty-server:9.3.0.M1',
'org.eclipse.jetty:jetty-servlet:9.3.0.M1'
],
database: [
// beloved in-memory DB for testing.
'org.hsqldb:hsqldb:2.3.2'
]
])
// Configure the test task to generate execution data
tasks.withType(Test).configureEach {
finalizedBy codeCoverageReport
doLast {
logger.lifecycle("Test execution completed. Generating JaCoCo report...")
}
}
22 changes: 14 additions & 8 deletions embers-acceptance-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ test {
test.mustRunAfter ":embers-services:build"

dependencies {
compile project(":embers-services")
compile libs.acceptance_tests
compile libs.database
implementation project(":embers-services")
implementation libs.bundles.core
implementation libs.gson
implementation libs.bundles.acceptance.tests
implementation libs.bundles.database

testCompile libs.unit_tests
testCompile libs.acceptance_tests
testCompile libs.jersey
testCompile libs.jaxson
testCompile libs.jetty
testImplementation libs.bundles.unit.tests
testImplementation libs.bundles.acceptance.tests
testImplementation libs.bundles.jakarta.web.server
testImplementation libs.bundles.jersey
testImplementation libs.bundles.jetty
testImplementation libs.jaxson

// Platform BOMs for dependency management
testImplementation platform('org.eclipse.jetty:jetty-bom:12.0.7')
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public EmbersDatabase(String jdbcUrl) {
this.jdbcUrl = jdbcUrl;
}


public void startInMemoryDatabase() throws Exception {
System.out.println("Starting the Embers database");
DriverManager.registerDriver(jdbcDriver.driverInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
import adf.embers.configuration.EmbersHandlerConfiguration;
import adf.embers.configuration.EmbersProcessorConfiguration;
import adf.embers.configuration.EmbersRepositoryConfiguration;

import jakarta.servlet.Servlet;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.component.LifeCycle;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;

import javax.servlet.Servlet;
import javax.sql.DataSource;
import java.util.logging.Level;
import java.util.logging.Logger;

public class EmbersJettyServer {

Expand All @@ -22,24 +29,71 @@ public EmbersJettyServer(int port) {
}

public void startHttpServer(DataSource dataSource) throws Exception {
System.out.println("Starting the Embers Server");

EmbersRepositoryConfiguration embersRepositoryConfiguration = new EmbersRepositoryConfiguration(dataSource);
EmbersProcessorConfiguration embersProcessorConfiguration = new EmbersProcessorConfiguration(embersRepositoryConfiguration);
EmbersHandlerConfiguration embersConfiguration = new EmbersHandlerConfiguration(embersProcessorConfiguration);

Servlet jerseyServlet = createJerseyServletWithEmbersHandlers(embersConfiguration);

server.setHandler(createEmbersHandler(jerseyServlet));
server.start();
System.out.println("Starting the Embers Server on port: " + server.getURI());

// Disable Weld logging to avoid unnecessary warnings
Logger.getLogger("org.jboss.weld").setLevel(Level.SEVERE);

// Set HK2 as the injection manager
System.setProperty("jersey.config.server.disableAutoDiscovery", "true");
System.setProperty("jersey.config.server.disableMetainfServicesLookup", "true");
System.setProperty("jersey.config.server.disableMoxyJson", "true");

try {
// Create HK2 service locator
ServiceLocator locator = ServiceLocatorUtilities.createAndPopulateServiceLocator("EmbersServiceLocator");

// Manually register services
EmbersRepositoryConfiguration embersRepositoryConfiguration = new EmbersRepositoryConfiguration(dataSource);
ServiceLocatorUtilities.addOneConstant(locator, embersRepositoryConfiguration);

EmbersProcessorConfiguration embersProcessorConfiguration = new EmbersProcessorConfiguration(embersRepositoryConfiguration);
ServiceLocatorUtilities.addOneConstant(locator, embersProcessorConfiguration);

EmbersHandlerConfiguration embersConfiguration = new EmbersHandlerConfiguration(embersProcessorConfiguration);
ServiceLocatorUtilities.addOneConstant(locator, embersConfiguration);

// Create Jersey resource config with HK2
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.property("jersey.config.server.provider.classnames",
"org.glassfish.jersey.media.multipart.MultiPartFeature");

// Register resources
resourceConfig.register(embersConfiguration.getQueryHandler());
resourceConfig.register(embersConfiguration.getAdminQueryHandler());
resourceConfig.register(embersConfiguration.getQueryResultCacheHandler());

// Create servlet container with HK2
ServletContainer servletContainer = new ServletContainer(resourceConfig);

// Set up the handler
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
handler.setContextPath("/" + EmbersServer.CONTEXT_PATH_ROOT);
ServletHolder servletHolder = new ServletHolder("jersey-servlet", servletContainer);
handler.addServlet(servletHolder, "/*");

System.out.println("Created handler: " + handler);
server.setHandler(handler);

System.out.println("Starting Jetty server...");
server.start();
System.out.println("Started the Embers Server at: http://localhost:" + server.getURI().getPort() + "/" + EmbersServer.CONTEXT_PATH_ROOT);
} catch (Exception e) {
System.err.println("Error starting Embers server: " + e.getMessage());
e.printStackTrace();
throw e;
}
}

public void stopHttpServer() {
System.out.println("Stopping the Embers server");
try {
server.stop();
System.out.println("Stopped the Embers server");
} catch (Exception e) {
System.err.println("Exception stopping jetty server: "+e.getMessage());
System.err.println("Exception stopping jetty server: " + e.getMessage() + "/n");
} finally {
LifeCycle.stop(server);
}
}

Expand All @@ -53,10 +107,12 @@ private Servlet createJerseyServletWithEmbersHandlers(EmbersHandlerConfiguration

private Handler createEmbersHandler(Servlet embersServlet) {
ServletContextHandler handler = new ServletContextHandler();
handler.addServlet(new ServletHolder(embersServlet), "/");
//setting context path separately works
handler.setContextPath("/" + EmbersServer.CONTEXT_PATH_ROOT);


// Add the servlet
ServletHolder servletHolder = new ServletHolder("embers", embersServlet);
handler.addServlet(servletHolder, "/*");

return handler;
}
}
Loading
Loading