Skip to content

Commit

Permalink
feat: use ServiceLoader to find implementations instead of searching …
Browse files Browse the repository at this point in the history
…classes in jars

ServiceLoader is Java standard approach for locating implementaitons,
and it allows pluggability without relying on a filesystem layout.

Fixes #5883
  • Loading branch information
vlsi committed May 11, 2023
1 parent 5380e59 commit 38cc8ce
Show file tree
Hide file tree
Showing 186 changed files with 1,558 additions and 297 deletions.
3 changes: 2 additions & 1 deletion build-logic/jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
api(projects.verification)
api("com.github.vlsi.crlf:com.github.vlsi.crlf.gradle.plugin:1.88")
api("com.github.vlsi.gradle-extensions:com.github.vlsi.gradle-extensions.gradle.plugin:1.88")
api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21")
api("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.8.21")
api("org.jetbrains.kotlin.kapt:org.jetbrains.kotlin.kapt.gradle.plugin:1.8.21")
api("org.jetbrains.dokka:org.jetbrains.dokka.gradle.plugin:1.8.10")
}
50 changes: 50 additions & 0 deletions build-logic/jvm/src/main/kotlin/build-logic.autoservice.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.github.vlsi.gradle.dsl.configureEach

plugins {
id("java-library")
}

dependencies {
annotationProcessor("com.google.auto.service:auto-service")
compileOnlyApi("com.google.auto.service:auto-service-annotations")
}

tasks.configureEach<JavaCompile> {
// Verify @AutoService annotations
options.compilerArgs.add("-Averify=true")
}

plugins.withId("org.jetbrains.kotlin.jvm") {
apply(plugin = "org.jetbrains.kotlin.kapt")

dependencies {
"kapt"("com.google.auto.service:auto-service")
// Unfortunately, plugins.withId("..kapt") can't be used as kapt plugin adds configuration via plugins.withId
findProject(":src:bom-thirdparty")?.let {
"kapt"(platform(it))
}
}
}

tasks.configureEach<Jar> {
manifest {
attributes["JMeter-Skip-Class-Scanning"] = "true"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
plugins {
id("build-logic.java")
id("java-library")
id("build-logic.autoservice")
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dependencies {
}
findProject(":src:bom-thirdparty")?.let{
api(platform(it))
annotationProcessor(platform(it))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/

plugins {
id("build-logic.java")
id("java-library")
id("build-logic.java-library")
}

if (file("src/main/groovy").isDirectory || file("src/test/groovy").isDirectory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ plugins {
id("build-logic.test-base")
id("com.github.autostyle")
kotlin("jvm")
kotlin("kapt") apply false
}

dependencies {
Expand Down
1 change: 1 addition & 0 deletions build-logic/root-build/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ dependencies {
api("com.github.vlsi.gradle-extensions:com.github.vlsi.gradle-extensions.gradle.plugin:1.88")
api("org.nosphere.apache.rat:org.nosphere.apache.rat.gradle.plugin:0.8.0")
api("org.jetbrains.gradle.plugin.idea-ext:org.jetbrains.gradle.plugin.idea-ext.gradle.plugin:1.1.7")
api("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.8.21")
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ plugins {
id("com.github.vlsi.ide")
id("org.nosphere.apache.rat")
id("org.jetbrains.gradle.plugin.idea-ext")
kotlin("jvm") apply false
}

ide {
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ val notPublishedProjects by extra {
projects.src.release,
projects.src.testkit,
projects.src.testkitWiremock,
projects.src.testServices,
).mapTo(mutableSetOf()) { it.dependencyProject }
}

Expand All @@ -86,7 +87,7 @@ publishedProjects.forEach {project ->
throw IllegalStateException(
"Project ${project.path} is listed in publishedProjects, however it misses maven-publish plugin. " +
"Please add maven-publish plugin (e.g. replace build-logic.jvm-library with build-logic.jvm-published-library) or " +
"move the project to the list of published ones"
"move the project to the list of notPublishedProjects"
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ org.gradle.parallel=true
org.gradle.caching=true
#org.gradle.caching.debug=true

kapt.include.compile.classpath=false

# See https://github.com/gradle/gradle/pull/11358 , https://issues.apache.org/jira/browse/INFRA-14923
# repository.apache.org does not yet support .sha256 and .sha512 checksums
systemProp.org.gradle.internal.publish.checksums.insecure=true
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ include(
"src:release",
"src:testkit",
"src:testkit-wiremock",
"src:test-services",
"src:dist",
"src:dist-check"
)
Expand Down
2 changes: 2 additions & 0 deletions src/bom-thirdparty/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ dependencies {

api("bsf:bsf:2.4.0")
api("cglib:cglib-nodep:3.3.0")
api("com.google.auto.service:auto-service:1.0.1")
api("com.google.auto.service:auto-service-annotations:1.0.1")
api("com.fasterxml.jackson.core:jackson-annotations:2.13.4")
api("com.fasterxml.jackson.core:jackson-core:2.13.4")
api("com.fasterxml.jackson.core:jackson-databind:2.13.4.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@

import org.apache.jmeter.extractor.json.jmespath.JMESPathCache;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.visualizers.ResultRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.auto.service.AutoService;

/**
* Implement ResultsRender for JMES Path tester
* @since 5.2
*/
@AutoService(ResultRenderer.class)
public class RenderAsJmesPathRenderer extends AbstractRenderAsJsonRenderer {
private static final Logger log = LoggerFactory.getLogger(RenderAsJmesPathRenderer.class);
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@

import org.apache.jmeter.extractor.json.jsonpath.JSONManager;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.visualizers.ResultRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.auto.service.AutoService;

/**
* Implement ResultsRender for JSON Path tester
* @since 3.0
*/
@AutoService(ResultRenderer.class)
public class RenderAsJsonRenderer extends AbstractRenderAsJsonRenderer {
private static final Logger log = LoggerFactory.getLogger(RenderAsJsonRenderer.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.auto.service.AutoService;

/**
* Export transactions names for web report
* @since 3.3
*/
@AutoService({
Command.class,
MenuCreator.class
})
public class ExportTransactionAndSamplerNames extends AbstractAction implements MenuCreator {
private static final Logger log = LoggerFactory.getLogger(ExportTransactionAndSamplerNames.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@
import org.apache.jorphan.gui.GuiUtils;
import org.apache.jorphan.gui.JLabeledTextField;

import com.google.auto.service.AutoService;

/**
* Implement ResultsRender for Boundary Extractor tester
*/
@AutoService(ResultRenderer.class)
public class RenderAsBoundaryExtractor implements ResultRenderer, ActionListener {

private static final String BOUNDARY_EXTRACTOR_TESTER_COMMAND = "boundary_extractor_tester"; // $NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@
import org.apache.jorphan.gui.JLabeledTextField;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;

import com.google.auto.service.AutoService;

/**
* Implement ResultsRender for CSS/JQuery tester
* @since 2.10
*/
@AutoService(ResultRenderer.class)
public class RenderAsCssJQuery implements ResultRenderer, ActionListener {

private static final String CSSJQUEY_TESTER_COMMAND = "cssjquery_tester"; // $NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.auto.service.AutoService;

@AutoService(ResultRenderer.class)
public class RenderAsDocument extends SamplerResultTab implements ResultRenderer {

private static final Logger log = LoggerFactory.getLogger(RenderAsDocument.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.auto.service.AutoService;

@AutoService(ResultRenderer.class)
public class RenderAsHTML extends SamplerResultTab implements ResultRenderer {
private static final Logger log = LoggerFactory.getLogger(RenderAsHTML.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.apache.jmeter.util.JMeterUtils;
import org.jsoup.Jsoup;

import com.google.auto.service.AutoService;

@AutoService(ResultRenderer.class)
public class RenderAsHTMLFormatted extends SamplerResultTab implements ResultRenderer {

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;

import com.google.auto.service.AutoService;

@AutoService(ResultRenderer.class)
public class RenderAsHTMLWithEmbedded extends RenderAsHTML
implements ResultRenderer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;

import com.google.auto.service.AutoService;

@AutoService(ResultRenderer.class)
public class RenderAsJSON extends SamplerResultTab implements ResultRenderer {
private static final String TAB_SEPARATOR = " "; //$NON-NLS-1$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;

import com.google.auto.service.AutoService;

/**
* Implement ResultsRender for Regexp tester
*/
@AutoService(ResultRenderer.class)
public class RenderAsRegexp implements ResultRenderer, ActionListener {

private static final String REGEXP_TESTER_COMMAND = "regexp_tester"; // $NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;

import com.google.auto.service.AutoService;

@AutoService(ResultRenderer.class)
public class RenderAsText extends SamplerResultTab implements ResultRenderer {

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
import org.w3c.tidy.Tidy;
import org.xml.sax.SAXException;

import com.google.auto.service.AutoService;

@AutoService(ResultRenderer.class)
public class RenderAsXML extends SamplerResultTab
implements ResultRenderer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import com.google.auto.service.AutoService;


/**
* Implement ResultsRender for XPath tester
*/
@AutoService(ResultRenderer.class)
public class RenderAsXPath implements ResultRenderer, ActionListener {

private static final Logger log = LoggerFactory.getLogger(RenderAsXPath.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.auto.service.AutoService;

/**
* Implement ResultsRender for XPath tester
*/
@AutoService(ResultRenderer.class)
public class RenderAsXPath2 implements ResultRenderer, ActionListener {

private static final Logger log = LoggerFactory.getLogger(RenderAsXPath2.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;

import com.google.auto.service.AutoService;

import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;

Expand All @@ -43,6 +45,7 @@
* {@link ResultRenderer} implementation that uses JAVAFX WebEngine to render as browser do
* @since 3.2
*/
@AutoService(ResultRenderer.class)
public class RenderInBrowser extends SamplerResultTab implements ResultRenderer {

private JFXPanel jfxPanel;
Expand Down
Loading

0 comments on commit 38cc8ce

Please sign in to comment.