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 7, 2023
1 parent 349516a commit 6d3bb73
Show file tree
Hide file tree
Showing 95 changed files with 896 additions and 67 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")
}
44 changes: 44 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,44 @@
/*
* 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))
}
}
}
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
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 @@ -74,6 +74,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 @@ -17,8 +17,11 @@

package org.apache.jmeter.extractor.json.render;

import com.google.auto.service.AutoService;

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;

Expand All @@ -31,6 +34,7 @@
* 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 @@ -19,15 +19,19 @@

import java.util.List;

import com.google.auto.service.AutoService;

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;

/**
* 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 @@ -34,6 +34,8 @@
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import com.google.auto.service.AutoService;

import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.extractor.BoundaryExtractor;
import org.apache.jmeter.samplers.SampleResult;
Expand All @@ -44,6 +46,7 @@
/**
* 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 @@ -37,6 +37,8 @@
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import com.google.auto.service.AutoService;

import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.extractor.Extractor;
import org.apache.jmeter.extractor.HtmlExtractor;
Expand All @@ -53,6 +55,7 @@
* 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 @@ -17,12 +17,15 @@

package org.apache.jmeter.visualizers;

import com.google.auto.service.AutoService;

import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.Document;
import org.apache.jmeter.util.JMeterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@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 @@ -28,11 +28,14 @@
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;

import com.google.auto.service.AutoService;

import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@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 @@ -17,10 +17,13 @@

package org.apache.jmeter.visualizers;

import com.google.auto.service.AutoService;

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

@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 @@ -17,9 +17,12 @@

package org.apache.jmeter.visualizers;

import com.google.auto.service.AutoService;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.io.IOException;

import com.google.auto.service.AutoService;

import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;
Expand All @@ -29,6 +31,7 @@
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;

@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 @@ -37,6 +37,8 @@
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import com.google.auto.service.AutoService;

import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;
Expand All @@ -53,6 +55,7 @@
/**
* 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 @@ -17,9 +17,12 @@

package org.apache.jmeter.visualizers;

import com.google.auto.service.AutoService;

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

@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 @@ -42,6 +42,8 @@
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import com.google.auto.service.AutoService;

import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.util.XPathUtil;
Expand All @@ -53,6 +55,7 @@
import org.w3c.tidy.Tidy;
import org.xml.sax.SAXException;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import javax.swing.border.EmptyBorder;
import javax.xml.parsers.ParserConfigurationException;

import com.google.auto.service.AutoService;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.jmeter.assertions.gui.XMLConfPanel;
Expand All @@ -63,6 +65,7 @@
/**
* 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 @@ -36,6 +36,8 @@
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

import com.google.auto.service.AutoService;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.jmeter.extractor.XPath2Extractor;
Expand All @@ -51,6 +53,7 @@
/**
* 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 6d3bb73

Please sign in to comment.