This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new ab8586d5c1d4 CAMEL-26979: camel-quartz - log a WARN when 
quartz.properties at the classpath root or -Dorg.quartz.properties is ignored 
(#30009)
ab8586d5c1d4 is described below

commit ab8586d5c1d41ee365fb45c42c36d26ea864aa80
Author: Federico Mariani <[email protected]>
AuthorDate: Sun Nov 15 16:34:56 2026 +0100

    CAMEL-26979: camel-quartz - log a WARN when quartz.properties at the 
classpath root or -Dorg.quartz.properties is ignored (#30009)
    
    Camel loads only org/quartz/quartz.properties by default, while Quartz 
itself reads these files first.
    The component now says so in a WARN with the propertiesFile value to use, 
and the docs describe the lookup.
    
    CAMEL-26979: camel-quartz - the WARN and the docs name 
propertiesFile=classpath:org/quartz/quartz.properties to keep the default
    
    The docs say precisely when the WARN is logged (the system property is set, 
or else a quartz.properties is at the
    classpath root), and the Javadoc of the check describes what the method 
does. The test checks that the setting keeps
    the default without a WARN, and no longer uses deprecated test support 
methods.
    
    Co-Authored-By: Claude <[email protected]>
---
 .../camel/catalog/docs/quartz-component.adoc       |  13 +-
 .../src/main/docs/quartz-component.adoc            |  13 +-
 .../camel/component/quartz/QuartzComponent.java    |  23 +++
 .../QuartzIgnoredPropertiesFileWarningTest.java    | 187 +++++++++++++++++++++
 4 files changed, 228 insertions(+), 8 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/quartz-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/quartz-component.adoc
index e4db994a2203..674af8c1d5f2 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/quartz-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/quartz-component.adoc
@@ -56,10 +56,15 @@ Each endpoint represents a different timer (in Quartz 
terms, a `Trigger` and ``J
 
 === Configuring quartz.properties file
 
-By default, Quartz will look for a `quartz.properties` file in the
-`org/quartz` directory of the classpath. If you are using WAR
-deployments, this means just drop the quartz.properties in
-`WEB-INF/classes/org/quartz`.
+By default, the Camel Quartz component loads the `quartz.properties` file
+from the `org/quartz` directory of the classpath, which is the default file in 
the Quartz JAR.
+Unlike Quartz itself, it does not read a `quartz.properties` file at the root 
of the classpath,
+or the file set by the `org.quartz.properties` system property. It logs a WARN 
when this system property is set,
+or else when it finds a `quartz.properties` file at the root of the classpath.
+To use such a file, set the `propertiesFile` option, for example to 
`classpath:quartz.properties`
+or `file:/etc/myapp/quartz.properties`.
+To keep the default file without the WARN, for example when the application 
keeps a `quartz.properties` file
+at the root of the classpath for a Quartz scheduler of its own, set 
`propertiesFile` to `classpath:org/quartz/quartz.properties`.
 
 However, the Camel xref:quartz-component.adoc[Quartz] component also allows you
 to configure properties:
diff --git a/components/camel-quartz/src/main/docs/quartz-component.adoc 
b/components/camel-quartz/src/main/docs/quartz-component.adoc
index e4db994a2203..674af8c1d5f2 100644
--- a/components/camel-quartz/src/main/docs/quartz-component.adoc
+++ b/components/camel-quartz/src/main/docs/quartz-component.adoc
@@ -56,10 +56,15 @@ Each endpoint represents a different timer (in Quartz 
terms, a `Trigger` and ``J
 
 === Configuring quartz.properties file
 
-By default, Quartz will look for a `quartz.properties` file in the
-`org/quartz` directory of the classpath. If you are using WAR
-deployments, this means just drop the quartz.properties in
-`WEB-INF/classes/org/quartz`.
+By default, the Camel Quartz component loads the `quartz.properties` file
+from the `org/quartz` directory of the classpath, which is the default file in 
the Quartz JAR.
+Unlike Quartz itself, it does not read a `quartz.properties` file at the root 
of the classpath,
+or the file set by the `org.quartz.properties` system property. It logs a WARN 
when this system property is set,
+or else when it finds a `quartz.properties` file at the root of the classpath.
+To use such a file, set the `propertiesFile` option, for example to 
`classpath:quartz.properties`
+or `file:/etc/myapp/quartz.properties`.
+To keep the default file without the WARN, for example when the application 
keeps a `quartz.properties` file
+at the root of the classpath for a Quartz scheduler of its own, set 
`propertiesFile` to `classpath:org/quartz/quartz.properties`.
 
 However, the Camel xref:quartz-component.adoc[Quartz] component also allows you
 to configure properties:
diff --git 
a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
 
b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
index 3c3a9126422f..fd6c9fe8fa16 100644
--- 
a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
+++ 
b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
@@ -251,6 +251,7 @@ public class QuartzComponent extends DefaultComponent 
implements ExtendedStartup
             // read default props to be able to use a single scheduler per 
camel context
             // if we need more than one scheduler per context use 
setScheduler(Scheduler)
             // or setFactory(SchedulerFactory) methods
+            warnIfQuartzPropertiesFileIsIgnored();
 
             // must use classloader from StdSchedulerFactory to work even in 
OSGi
             InputStream is = 
StdSchedulerFactory.class.getClassLoader().getResourceAsStream("org/quartz/quartz.properties");
@@ -298,6 +299,28 @@ public class QuartzComponent extends DefaultComponent 
implements ExtendedStartup
         return answer;
     }
 
+    /**
+     * Called when none of the options properties, propertiesRef or 
propertiesFile is set, so this component loads only
+     * org/quartz/quartz.properties. Logs a WARN when a file that Quartz 
itself would read instead is ignored: when the
+     * org.quartz.properties system property is set (the file it names is not 
checked), or else when a quartz.properties
+     * is at the root of the classpath.
+     */
+    private void warnIfQuartzPropertiesFileIsIgnored() {
+        String requestedFile = 
System.getProperty(StdSchedulerFactory.PROPERTIES_FILE);
+        if (requestedFile != null) {
+            LOG.warn("The system property {}={} is ignored by the quartz 
component, which loads org/quartz/quartz.properties"
+                     + " unless one of the options properties, propertiesRef 
or propertiesFile is set."
+                     + " Set propertiesFile to use this file (with the file: 
prefix for a file on the file system),"
+                     + " or set 
propertiesFile=classpath:org/quartz/quartz.properties to keep the default.",
+                    StdSchedulerFactory.PROPERTIES_FILE, requestedFile);
+        } else if 
(getCamelContext().getClassResolver().loadResourceAsURL("quartz.properties") != 
null) {
+            LOG.warn("The quartz.properties at the root of the classpath is 
ignored by the quartz component, which loads"
+                     + " org/quartz/quartz.properties unless one of the 
options properties, propertiesRef or propertiesFile"
+                     + " is set. Set 
propertiesFile=classpath:quartz.properties to use it,"
+                     + " or set 
propertiesFile=classpath:org/quartz/quartz.properties to keep the default.");
+        }
+    }
+
     protected String createInstanceName(Properties prop) {
         String instName = 
prop.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
 
diff --git 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzIgnoredPropertiesFileWarningTest.java
 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzIgnoredPropertiesFileWarningTest.java
new file mode 100644
index 000000000000..8b5e995f1925
--- /dev/null
+++ 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzIgnoredPropertiesFileWarningTest.java
@@ -0,0 +1,187 @@
+/*
+ * 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.
+ */
+package org.apache.camel.component.quartz;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.apache.camel.test.junit6.TestExecutionConfiguration;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Property;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.api.parallel.Isolated;
+import org.quartz.SchedulerException;
+import org.quartz.impl.StdSchedulerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Quartz itself reads the file named by the org.quartz.properties system 
property, or a quartz.properties at the root
+ * of the classpath, while the quartz component reads only 
org/quartz/quartz.properties unless an option says otherwise.
+ */
+@Isolated("sets the org.quartz.properties system property")
+class QuartzIgnoredPropertiesFileWarningTest extends CamelTestSupport {
+
+    // the thread count of org/quartz/quartz.properties in the Quartz JAR
+    private static final int DEFAULT_THREAD_COUNT = 10;
+    // the propertiesFile value the WARN names to keep the default file 
without the WARN
+    private static final String KEEP_DEFAULT = 
"classpath:org/quartz/quartz.properties";
+
+    private final List<String> warnings = new CopyOnWriteArrayList<>();
+    private final AbstractAppender appender
+            = new AbstractAppender("QuartzIgnoredPropertiesFile-" + 
UUID.randomUUID(), null, null, true, Property.EMPTY_ARRAY) {
+                @Override
+                public void append(LogEvent event) {
+                    if (event.getLevel() == Level.WARN) {
+                        warnings.add(event.getMessage().getFormattedMessage());
+                    }
+                }
+            };
+
+    @TempDir
+    Path dir;
+
+    private URLClassLoader classLoader;
+
+    @Override
+    public void configureTest(TestExecutionConfiguration 
testExecutionConfiguration) {
+        // each test configures the component before it starts the context
+        testExecutionConfiguration.withUseRouteBuilder(false);
+    }
+
+    @BeforeEach
+    void captureWarnings() {
+        appender.start();
+        componentLogger().addAppender(appender);
+        // addAppender creates a non-additive logger config, which would hide 
this logger from the root appenders
+        componentLogger().setAdditive(true);
+    }
+
+    @AfterEach
+    void stopCapture() {
+        componentLogger().removeAppender(appender);
+        appender.stop();
+        System.clearProperty(StdSchedulerFactory.PROPERTIES_FILE);
+    }
+
+    @Override
+    protected void cleanupResources() throws Exception {
+        if (classLoader != null) {
+            classLoader.close();
+        }
+    }
+
+    @Test
+    void warnsWhenQuartzPropertiesAtClasspathRootIsNotUsed() throws Exception {
+        addQuartzPropertiesToClasspathRoot();
+
+        QuartzComponent quartz = startQuartz(null);
+
+        assertEquals(DEFAULT_THREAD_COUNT, threadPoolSize(quartz));
+        assertEquals(1, 
warningsContaining("propertiesFile=classpath:quartz.properties"), 
warnings::toString);
+        assertEquals(1, warningsContaining("propertiesFile=" + KEEP_DEFAULT), 
warnings::toString);
+    }
+
+    @Test
+    void warnsWhenFileOfSystemPropertyIsNotUsed() throws Exception {
+        Path file = writeQuartzProperties(dir.resolve("my-quartz.properties"));
+        System.setProperty(StdSchedulerFactory.PROPERTIES_FILE, 
file.toString());
+
+        QuartzComponent quartz = startQuartz(null);
+
+        assertEquals(DEFAULT_THREAD_COUNT, threadPoolSize(quartz));
+        assertEquals(1, warningsContaining(file.toString()), 
warnings::toString);
+        assertEquals(1, warningsContaining("propertiesFile=" + KEEP_DEFAULT), 
warnings::toString);
+    }
+
+    @Test
+    void usesQuartzPropertiesAtClasspathRootWithPropertiesFile() throws 
Exception {
+        addQuartzPropertiesToClasspathRoot();
+
+        QuartzComponent quartz = startQuartz("classpath:quartz.properties");
+
+        assertEquals(3, threadPoolSize(quartz));
+        assertEquals(0, warningsContaining("quartz.properties"), 
warnings::toString);
+    }
+
+    @Test
+    void keepsDefaultWithoutWarningWithPropertiesFileOfQuartzJar() throws 
Exception {
+        addQuartzPropertiesToClasspathRoot();
+        Path file = writeQuartzProperties(dir.resolve("my-quartz.properties"));
+        System.setProperty(StdSchedulerFactory.PROPERTIES_FILE, 
file.toString());
+
+        QuartzComponent quartz = startQuartz(KEEP_DEFAULT);
+
+        assertEquals(DEFAULT_THREAD_COUNT, threadPoolSize(quartz));
+        assertEquals(0, warningsContaining("quartz.properties"), 
warnings::toString);
+    }
+
+    @Test
+    void noWarningWithoutQuartzPropertiesFile() throws Exception {
+        QuartzComponent quartz = startQuartz(null);
+
+        assertEquals(DEFAULT_THREAD_COUNT, threadPoolSize(quartz));
+        assertEquals(0, warningsContaining("quartz.properties"), 
warnings::toString);
+    }
+
+    private QuartzComponent startQuartz(String propertiesFile) {
+        QuartzComponent quartz = context.getComponent("quartz", 
QuartzComponent.class);
+        quartz.setPropertiesFile(propertiesFile);
+        context.start();
+        return quartz;
+    }
+
+    private void addQuartzPropertiesToClasspathRoot() throws Exception {
+        writeQuartzProperties(dir.resolve("quartz.properties"));
+        classLoader = new URLClassLoader(new URL[] { dir.toUri().toURL() }, 
getClass().getClassLoader());
+        context.setApplicationContextClassLoader(classLoader);
+    }
+
+    private static Path writeQuartzProperties(Path file) throws Exception {
+        return Files.writeString(file, """
+                org.quartz.scheduler.instanceName=MyScheduler
+                org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
+                org.quartz.threadPool.threadCount=3
+                org.quartz.jobStore.class=org.quartz.simpl.RAMJobStore
+                """);
+    }
+
+    private static int threadPoolSize(QuartzComponent quartz) throws 
SchedulerException {
+        return quartz.getScheduler().getMetaData().getThreadPoolSize();
+    }
+
+    private long warningsContaining(String text) {
+        return warnings.stream().filter(message -> 
message.contains(text)).count();
+    }
+
+    private static Logger componentLogger() {
+        return (Logger) LogManager.getLogger(QuartzComponent.class);
+    }
+}

Reply via email to