diff --git a/build.gradle b/build.gradle index a64ad6af..172b4264 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +// Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. + // Defines common configuration for each of the 3 subprojects. subprojects { apply plugin: "java-library" @@ -14,7 +16,7 @@ subprojects { mavenCentral() mavenLocal() maven { - url "https://bed-artifactory.bedford.progress.com:443/artifactory/ml-maven-snapshots/" + url = "https://bed-artifactory.bedford.progress.com:443/artifactory/ml-maven-snapshots/" } } @@ -32,7 +34,17 @@ subprojects { testImplementation 'org.slf4j:slf4j-api:2.0.17' } - javadoc.failOnError = false + // Allows for quickly identifying compiler warnings. + tasks.withType(JavaCompile) { + options.compilerArgs += ["-Xlint:unchecked", "-Xlint:deprecation"] + options.deprecation = true + options.warnings = true + } + + javadoc { + failOnError = false + } + // Ignores warnings on params that don't have descriptions, which is a little too noisy javadoc.options.addStringOption('Xdoclint:none', '-quiet') @@ -40,7 +52,7 @@ subprojects { useJUnitPlatform() testLogging { events 'started','passed', 'skipped', 'failed' - exceptionFormat 'full' + exceptionFormat = 'full' } } @@ -89,8 +101,8 @@ subprojects { maven { if (project.hasProperty("mavenUser")) { credentials { - username mavenUser - password mavenPassword + username = mavenUser + password = mavenPassword } url publishUrl allowInsecureProtocol = true @@ -98,8 +110,8 @@ subprojects { name = "central" url = mavenCentralUrl credentials { - username mavenCentralUsername - password mavenCentralPassword + username = mavenCentralUsername + password = mavenCentralPassword } } } diff --git a/examples/local-testing-project/build.gradle b/examples/local-testing-project/build.gradle index dc537579..40ba33d7 100644 --- a/examples/local-testing-project/build.gradle +++ b/examples/local-testing-project/build.gradle @@ -1,8 +1,10 @@ +// Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. + buildscript { repositories { mavenLocal() maven { - url "https://bed-artifactory.bedford.progress.com:443/artifactory/ml-maven-snapshots/" + url = "https://bed-artifactory.bedford.progress.com:443/artifactory/ml-maven-snapshots/" } mavenCentral() } diff --git a/examples/marklogic-cloud-project/build.gradle b/examples/marklogic-cloud-project/build.gradle index 29547f76..e764b6d6 100644 --- a/examples/marklogic-cloud-project/build.gradle +++ b/examples/marklogic-cloud-project/build.gradle @@ -1,8 +1,10 @@ +// Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. + buildscript { repositories { mavenLocal() maven { - url "https://bed-artifactory.bedford.progress.com:443/artifactory/ml-maven-snapshots/" + url = "https://bed-artifactory.bedford.progress.com:443/artifactory/ml-maven-snapshots/" } mavenCentral() } diff --git a/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/AbstractCommand.java b/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/AbstractCommand.java index 7c7bf7ee..456305b4 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/AbstractCommand.java +++ b/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/AbstractCommand.java @@ -206,8 +206,13 @@ protected boolean resourceMergingIsSupported(CommandContext context) { */ protected void storeResourceInCommandContextMap(CommandContext context, File resourceFile, String payload) { final String contextKey = getContextKeyForResourcesToSave(); - List references = (List) context.getContextMap().get(contextKey); - if (references == null) { + Object referencesObj = context.getContextMap().get(contextKey); + List references; + if (referencesObj != null) { + @SuppressWarnings("unchecked") + List existingReferences = (List) referencesObj; + references = existingReferences; + } else { references = new ArrayList<>(); context.getContextMap().put(contextKey, references); } diff --git a/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/AbstractResourceCommand.java b/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/AbstractResourceCommand.java index 0289620b..aeb7aeff 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/AbstractResourceCommand.java +++ b/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/AbstractResourceCommand.java @@ -51,13 +51,17 @@ public void execute(CommandContext context) { } if (mergeResourcesBeforeSaving) { - List references = (List) context.getContextMap().get(getContextKeyForResourcesToSave()); - if (references != null && !references.isEmpty()) { - List mergedReferences = mergeResources(references); - if (useCmaForDeployingResources(context)) { - saveMergedResourcesViaCma(context, mergedReferences); - } else { - saveMergedResources(context, getResourceManager(context), mergedReferences); + Object referencesObj = context.getContextMap().get(getContextKeyForResourcesToSave()); + if (referencesObj != null) { + @SuppressWarnings("unchecked") + List references = (List) referencesObj; + if (!references.isEmpty()) { + List mergedReferences = mergeResources(references); + if (useCmaForDeployingResources(context)) { + saveMergedResourcesViaCma(context, mergedReferences); + } else { + saveMergedResources(context, getResourceManager(context), mergedReferences); + } } } } diff --git a/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/CommandContext.java b/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/CommandContext.java index 0686643c..2ffbff41 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/CommandContext.java +++ b/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/CommandContext.java @@ -65,10 +65,15 @@ public Map> getMapOfPrimaryForests() { if (!appConfig.getCmaConfig().isDeployForests()) { return null; } + final String key = "ml-app-deployer-mapOfPrimaryForests"; - if (contextMap.containsKey(key)) { - return (Map>) contextMap.get(key); + if (contextMap.containsKey(key) && contextMap.get(key) instanceof Map) { + Object mapObj = contextMap.get(key); + @SuppressWarnings("unchecked") + Map> forestMap = (Map>) mapObj; + return forestMap; } + Logger logger = LoggerFactory.getLogger(getClass()); try { logger.info("Retrieving all forest details via CMA"); diff --git a/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/TestConnectionsCommand.java b/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/TestConnectionsCommand.java index 2726835d..aa00e65a 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/TestConnectionsCommand.java +++ b/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/TestConnectionsCommand.java @@ -289,7 +289,7 @@ private TestResult testManageAppServer(ManageClient client) { String version = new ClusterManager(client).getVersion(); return new TestResult(client.getManageConfig(), true, "MarkLogic version: " + version); } catch (Exception ex) { - if (ex instanceof HttpClientErrorException && ((HttpClientErrorException) ex).getRawStatusCode() == 404) { + if (ex instanceof HttpClientErrorException && ((HttpClientErrorException) ex).getStatusCode().value() == 404) { return new TestResult(client.getManageConfig(), false, "Unable to access /manage/v2; received 404; unexpected response: " + ex.getMessage()); } else { diff --git a/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/es/GenerateModelArtifactsCommand.java b/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/es/GenerateModelArtifactsCommand.java index 7957fcb5..f77b102b 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/es/GenerateModelArtifactsCommand.java +++ b/ml-app-deployer/src/main/java/com/marklogic/appdeployer/command/es/GenerateModelArtifactsCommand.java @@ -65,7 +65,7 @@ public void execute(CommandContext context) { protected DatabaseClient buildDatabaseClient(AppConfig appConfig) { String db = appConfig.getModelsDatabase(); - if (StringUtils.isEmpty(db)) { + if (!StringUtils.hasText(db)) { db = appConfig.getContentDatabaseName(); } if (logger.isInfoEnabled()) { diff --git a/ml-app-deployer/src/main/java/com/marklogic/mgmt/ManageClient.java b/ml-app-deployer/src/main/java/com/marklogic/mgmt/ManageClient.java index 4370cfb3..3267b1ee 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/mgmt/ManageClient.java +++ b/ml-app-deployer/src/main/java/com/marklogic/mgmt/ManageClient.java @@ -218,7 +218,7 @@ private void delete(RestTemplate restTemplate, String path, String... headerName */ public HttpEntity buildJsonEntity(String json) { HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON_UTF8); + headers.setContentType(MediaType.APPLICATION_JSON); if (manageConfig != null && manageConfig.isCleanJsonPayloads()) { json = cleanJsonPayload(json); } diff --git a/ml-app-deployer/src/main/java/com/marklogic/mgmt/api/security/RoleObjectNodesSorter.java b/ml-app-deployer/src/main/java/com/marklogic/mgmt/api/security/RoleObjectNodesSorter.java index 172371a1..e102c34c 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/mgmt/api/security/RoleObjectNodesSorter.java +++ b/ml-app-deployer/src/main/java/com/marklogic/mgmt/api/security/RoleObjectNodesSorter.java @@ -32,7 +32,7 @@ public List sortObjectNodes(List objectNodes) { // This is to resolve bug #441, where capability-query's are being dropped because the Role class doesn't // support them. It may be better to refactor this to not deserialize into Role instances so that ObjectNodes // are used the entire time, even though we'd lose some of the convenience methods provided by the Role class. - final Map roleMap = new HashMap(); + final Map roleMap = new HashMap<>(); ObjectReader reader = ObjectMapperFactory.getObjectMapper().readerFor(Role.class); for (ObjectNode objectNode : objectNodes) { diff --git a/ml-app-deployer/src/main/java/com/marklogic/mgmt/mapper/DefaultResourceMapper.java b/ml-app-deployer/src/main/java/com/marklogic/mgmt/mapper/DefaultResourceMapper.java index 52ff659d..2315f5fe 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/mgmt/mapper/DefaultResourceMapper.java +++ b/ml-app-deployer/src/main/java/com/marklogic/mgmt/mapper/DefaultResourceMapper.java @@ -74,7 +74,9 @@ public T readResource(String payload, Class resourceType } jaxbContextMap.put(resourceType, context); } - resource = (T) context.createUnmarshaller().unmarshal(new StringReader(payload)); + @SuppressWarnings("unchecked") + T unmarshalledResource = (T) context.createUnmarshaller().unmarshal(new StringReader(payload)); + resource = unmarshalledResource; } if (api != null && resource != null) { resource.setApi(api); diff --git a/ml-app-deployer/src/main/java/com/marklogic/mgmt/template/GenericTemplateBuilder.java b/ml-app-deployer/src/main/java/com/marklogic/mgmt/template/GenericTemplateBuilder.java index c4e0b110..51f0b2b0 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/mgmt/template/GenericTemplateBuilder.java +++ b/ml-app-deployer/src/main/java/com/marklogic/mgmt/template/GenericTemplateBuilder.java @@ -30,7 +30,7 @@ public void addDefaultPropertyValue(String propertyName, Object value) { public Resource buildTemplate(Map propertyMap) { Resource r; try { - r = (Resource) this.resourceClass.newInstance(); + r = (Resource) this.resourceClass.getDeclaredConstructor().newInstance(); } catch (Exception ex) { throw new RuntimeException(ex); } diff --git a/ml-app-deployer/src/main/java/com/marklogic/rest/util/PreviewInterceptor.java b/ml-app-deployer/src/main/java/com/marklogic/rest/util/PreviewInterceptor.java index c19f4256..97ecae04 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/rest/util/PreviewInterceptor.java +++ b/ml-app-deployer/src/main/java/com/marklogic/rest/util/PreviewInterceptor.java @@ -240,11 +240,6 @@ public HttpStatus getStatusCode() { return HttpStatus.OK; } - @Override - public int getRawStatusCode() { - return 200; - } - @Override public String getStatusText() { return "OK"; diff --git a/ml-app-deployer/src/main/java/com/marklogic/rest/util/SpringWebUtil.java b/ml-app-deployer/src/main/java/com/marklogic/rest/util/SpringWebUtil.java index ad65b1ca..a7877824 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/rest/util/SpringWebUtil.java +++ b/ml-app-deployer/src/main/java/com/marklogic/rest/util/SpringWebUtil.java @@ -16,10 +16,7 @@ public abstract class SpringWebUtil { public static int getHttpStatusCode(ResponseEntity response) { - // This method is deprecated in Spring 6.0 and slated to be removed in Spring 7.0. But it can be safely used - // by both Spring 5.x and 6.x. We'll need to revisit this when we want to support ml-gradle when Spring 7.0 is - // on the classpath as well. - return response.getStatusCodeValue(); + return response.getStatusCode().value(); } public static HttpStatus getHttpStatus(ResponseEntity response) { @@ -27,10 +24,7 @@ public static HttpStatus getHttpStatus(ResponseEntity response) { } public static int getHttpStatusCode(RestClientResponseException ex) { - // This method is deprecated in Spring 6.0 and slated to be removed in Spring 7.0. But it can be safely used - // by both Spring 5.x and 6.x. We'll need to revisit this when we want to support ml-gradle when Spring 7.0 is - // on the classpath as well. - return ex.getRawStatusCode(); + return ex.getStatusCode().value(); } public static HttpStatus getHttpStatus(RestClientResponseException ex) { diff --git a/ml-app-deployer/src/main/java/com/marklogic/rest/util/vendor/OkHttpClientHttpRequest.java b/ml-app-deployer/src/main/java/com/marklogic/rest/util/vendor/OkHttpClientHttpRequest.java index fcc29378..ec52c684 100644 --- a/ml-app-deployer/src/main/java/com/marklogic/rest/util/vendor/OkHttpClientHttpRequest.java +++ b/ml-app-deployer/src/main/java/com/marklogic/rest/util/vendor/OkHttpClientHttpRequest.java @@ -48,7 +48,6 @@ public URI getURI() { } @Override - @SuppressWarnings("removal") protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body body) throws IOException { RequestBody requestBody; @@ -57,7 +56,7 @@ protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body } else if (okhttp3.internal.http.HttpMethod.requiresRequestBody(getMethod().name())) { String header = headers.getFirst(HttpHeaders.CONTENT_TYPE); MediaType contentType = (header != null) ? MediaType.parse(header) : null; - requestBody = RequestBody.create(contentType, new byte[0]); + requestBody = RequestBody.create(new byte[0], contentType); } else { requestBody = null; } diff --git a/ml-app-deployer/src/test/java/com/marklogic/appdeployer/DefaultAppConfigFactoryTest.java b/ml-app-deployer/src/test/java/com/marklogic/appdeployer/DefaultAppConfigFactoryTest.java index d4ed9549..f66f96e9 100644 --- a/ml-app-deployer/src/test/java/com/marklogic/appdeployer/DefaultAppConfigFactoryTest.java +++ b/ml-app-deployer/src/test/java/com/marklogic/appdeployer/DefaultAppConfigFactoryTest.java @@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -public class DefaultAppConfigFactoryTest { +class DefaultAppConfigFactoryTest { private DefaultAppConfigFactory factory; @@ -211,7 +211,7 @@ public void dataConfigProperties() { assertEquals(new File(projectDir, "src/main/more-data").getAbsolutePath(), config.getDataPaths().get(1)); assertEquals("apple", config.getCollections()[0]); assertEquals("banana", config.getCollections()[1]); - assertEquals(new Integer(123), config.getBatchSize()); + assertEquals(123, config.getBatchSize()); assertEquals("Documents", config.getDatabaseName()); assertEquals("manage-user,read,manage-user,update", config.getPermissions()); assertFalse(config.isReplaceTokensInData()); @@ -497,8 +497,8 @@ public void mostProperties() { assertEquals("dev-.*", config.getResourceFilenamesExcludePattern().pattern()); assertEquals("qa-.*", config.getResourceFilenamesIncludePattern().pattern()); - assertEquals(new Integer(1), config.getDatabaseNamesAndReplicaCounts().get("Documents")); - assertEquals(new Integer(2), config.getDatabaseNamesAndReplicaCounts().get("Security")); + assertEquals(1, config.getDatabaseNamesAndReplicaCounts().get("Documents")); + assertEquals(2, config.getDatabaseNamesAndReplicaCounts().get("Security")); Set set = config.getDatabasesWithForestsOnOneHost(); assertEquals(2, set.size()); diff --git a/ml-app-deployer/src/test/java/com/marklogic/appdeployer/scaffold/WriteServerTest.java b/ml-app-deployer/src/test/java/com/marklogic/appdeployer/scaffold/WriteServerTest.java index 29d50dcf..8a0f341b 100644 --- a/ml-app-deployer/src/test/java/com/marklogic/appdeployer/scaffold/WriteServerTest.java +++ b/ml-app-deployer/src/test/java/com/marklogic/appdeployer/scaffold/WriteServerTest.java @@ -11,16 +11,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -public class WriteServerTest extends AbstractResourceWriterTest { +class WriteServerTest extends AbstractResourceWriterTest { @Test - public void defaultValues() { + void defaultValues() { initializeAppDeployer(new DeployOtherServersCommand()); buildResourceAndDeploy(new ServerTemplateBuilder()); Server s = api.server("CHANGEME-name-of-server"); - assertEquals(new Integer(8099), s.getPort()); + assertEquals(8099, s.getPort()); assertEquals("Modules", s.getModulesDatabase()); assertEquals("Documents", s.getContentDatabase()); assertEquals("digest", s.getAuthentication()); diff --git a/ml-app-deployer/src/test/java/com/marklogic/appdeployer/scaffold/WriteTaskTest.java b/ml-app-deployer/src/test/java/com/marklogic/appdeployer/scaffold/WriteTaskTest.java index f151a1d8..dc9f5745 100644 --- a/ml-app-deployer/src/test/java/com/marklogic/appdeployer/scaffold/WriteTaskTest.java +++ b/ml-app-deployer/src/test/java/com/marklogic/appdeployer/scaffold/WriteTaskTest.java @@ -12,10 +12,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class WriteTaskTest extends AbstractResourceWriterTest { +class WriteTaskTest extends AbstractResourceWriterTest { @Test - public void defaultValues() { + void defaultValues() { initializeAppDeployer(new DeployScheduledTasksCommand()); buildResourceAndDeploy(new TaskTemplateBuilder()); @@ -26,7 +26,7 @@ public void defaultValues() { assertEquals("/CHANGEME-path-to-module.sjs", task.getTaskPath()); assertEquals("/", task.getTaskRoot()); assertEquals("daily", task.getTaskType()); - assertEquals(new Integer(1), task.getTaskPeriod()); + assertEquals(1, task.getTaskPeriod()); assertEquals("01:00:00", task.getTaskStartTime()); assertEquals("Documents", task.getTaskDatabase()); assertEquals("Modules", task.getTaskModules()); diff --git a/ml-gradle/build.gradle b/ml-gradle/build.gradle index 826945ab..34be59f7 100644 --- a/ml-gradle/build.gradle +++ b/ml-gradle/build.gradle @@ -37,8 +37,8 @@ gradlePlugin { id = 'com.marklogic.ml-gradle' displayName = 'ml-gradle for MarkLogic' description = 'Gradle plugin for configuring and deploying applications to MarkLogic' - tags.set(['marklogic', 'progress']) - implementationClass = 'com.marklogic.gradle.MarkLogicPlugin' + tags = ['marklogic', 'progress'] + implementationClass = 'com.marklogic.gradle.MarkLogicPlugin' } } } diff --git a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/batch/BatchWriterSupport.java b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/batch/BatchWriterSupport.java index d0956195..648cd126 100644 --- a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/batch/BatchWriterSupport.java +++ b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/batch/BatchWriterSupport.java @@ -5,15 +5,15 @@ import com.marklogic.client.document.DocumentWriteOperation; import com.marklogic.client.ext.helper.LoggingObject; -import org.springframework.core.task.AsyncListenableTaskExecutor; +import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.SyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.scheduling.concurrent.ExecutorConfigurationSupport; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; /** * Support class for BatchWriter implementations that uses Spring's TaskExecutor interface for parallelizing writes to @@ -74,24 +74,22 @@ protected void initializeDefaultTaskExecutor() { } /** - * Will use the WriteListener if the TaskExecutor is an instance of AsyncListenableTaskExecutor. The WriteListener + * Will use the WriteListener if the TaskExecutor is an instance of AsyncTaskExecutor. The WriteListener * will then be used to listen for failures. * * @param runnable * @param items */ protected void executeRunnable(Runnable runnable, final List items) { - if (writeListener != null && taskExecutor instanceof AsyncListenableTaskExecutor) { - AsyncListenableTaskExecutor asyncListenableTaskExecutor = (AsyncListenableTaskExecutor)taskExecutor; - ListenableFuture future = asyncListenableTaskExecutor.submitListenable(runnable); - future.addCallback(new ListenableFutureCallback() { - @Override - public void onFailure(Throwable ex) { + if (writeListener != null && taskExecutor instanceof AsyncTaskExecutor asyncTaskExecutor) { + CompletableFuture future = asyncTaskExecutor.submitCompletable(runnable); + future.whenComplete((result, ex) -> { + if (ex != null) { + if (ex instanceof CompletionException ce && ce.getCause() != null) { + ex = ce.getCause(); + } writeListener.onWriteFailure(ex, items); } - @Override - public void onSuccess(Object result) { - } }); } else { taskExecutor.execute(runnable); diff --git a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/datamovement/job/SimpleExportJob.java b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/datamovement/job/SimpleExportJob.java index 9fde972f..51e7d93f 100644 --- a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/datamovement/job/SimpleExportJob.java +++ b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/datamovement/job/SimpleExportJob.java @@ -15,6 +15,7 @@ public class SimpleExportJob extends AbstractQueryBatcherJob { private ExportListener exportListener; + @SafeVarargs public SimpleExportJob(Consumer... consumers) { exportListener = new ExportListener(); for (Consumer consumer : consumers) { diff --git a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/datamovement/listener/AbstractExportBatchesListener.java b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/datamovement/listener/AbstractExportBatchesListener.java index 507ef16b..eb4fba84 100644 --- a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/datamovement/listener/AbstractExportBatchesListener.java +++ b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/datamovement/listener/AbstractExportBatchesListener.java @@ -27,7 +27,7 @@ public abstract class AbstractExportBatchesListener extends ExportListener { private ServerTransform transform; private Format nonDocumentFormat; private boolean consistentSnapshot; - private Set categories = new HashSet(); + private Set categories = new HashSet<>(); protected abstract void exportBatch(QueryBatch queryBatch); diff --git a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/file/CascadingPropertiesDrivenDocumentFileProcessor.java b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/file/CascadingPropertiesDrivenDocumentFileProcessor.java index c359da5a..19a6bcb0 100644 --- a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/file/CascadingPropertiesDrivenDocumentFileProcessor.java +++ b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/file/CascadingPropertiesDrivenDocumentFileProcessor.java @@ -6,7 +6,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.FileVisitResult; -import java.nio.file.FileVisitor; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.Properties; @@ -21,7 +20,7 @@ * * @since 4.6.0 */ -abstract class CascadingPropertiesDrivenDocumentFileProcessor extends PropertiesDrivenDocumentFileProcessor implements FileVisitor { +abstract class CascadingPropertiesDrivenDocumentFileProcessor extends PropertiesDrivenDocumentFileProcessor implements DocumentFileProcessorWithFileVisitor { final private Stack propertiesStack = new Stack<>(); private boolean cascadingEnabled = false; diff --git a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/file/DefaultDocumentFileReader.java b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/file/DefaultDocumentFileReader.java index 0df05385..e8a30652 100644 --- a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/file/DefaultDocumentFileReader.java +++ b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/file/DefaultDocumentFileReader.java @@ -91,11 +91,11 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th boolean accept = acceptPath(dir, attrs); if (accept) { if (logger.isDebugEnabled()) { - logger.debug("Visiting directory: " + dir); + logger.debug("Visiting directory: {}", dir); } for (DocumentFileProcessor processor : getDocumentFileProcessors()) { - if (processor instanceof FileVisitor) { - ((FileVisitor) processor).preVisitDirectory(dir, attrs); + if (processor instanceof DocumentFileProcessorWithFileVisitor fileVisitorProcessor) { + fileVisitorProcessor.preVisitDirectory(dir, attrs); } } return FileVisitResult.CONTINUE; @@ -121,8 +121,8 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx logger.warn("Error in postVisitDirectory: " + exc.getMessage(), exc); } for (DocumentFileProcessor processor : getDocumentFileProcessors()) { - if (processor instanceof FileVisitor) { - ((FileVisitor) processor).postVisitDirectory(dir, exc); + if (processor instanceof DocumentFileProcessorWithFileVisitor fileVisitorProcessor) { + fileVisitorProcessor.postVisitDirectory(dir, exc); } } return FileVisitResult.CONTINUE; diff --git a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/file/DocumentFileProcessorWithFileVisitor.java b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/file/DocumentFileProcessorWithFileVisitor.java new file mode 100644 index 00000000..4964c3b0 --- /dev/null +++ b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/file/DocumentFileProcessorWithFileVisitor.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. + */ +package com.marklogic.client.ext.file; + +import java.nio.file.FileVisitor; +import java.nio.file.Path; + +/** + * Marker interface for DocumentFileProcessor implementations that also implement FileVisitor. + * This allows for type-safe casting without unchecked warnings. + */ +public interface DocumentFileProcessorWithFileVisitor extends DocumentFileProcessor, FileVisitor { +} diff --git a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/tokenreplacer/DefaultTokenReplacer.java b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/tokenreplacer/DefaultTokenReplacer.java index 9895ca88..15905cb8 100644 --- a/ml-javaclient-util/src/main/java/com/marklogic/client/ext/tokenreplacer/DefaultTokenReplacer.java +++ b/ml-javaclient-util/src/main/java/com/marklogic/client/ext/tokenreplacer/DefaultTokenReplacer.java @@ -33,7 +33,7 @@ public void addPropertiesSource(PropertiesSource source) { protected void initializeHelper() { helper = new PropertyPlaceholderHelper(PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_PREFIX, PlaceholderConfigurerSupport.DEFAULT_PLACEHOLDER_SUFFIX, - PlaceholderConfigurerSupport.DEFAULT_VALUE_SEPARATOR, true); + PlaceholderConfigurerSupport.DEFAULT_VALUE_SEPARATOR, null, true); } /** diff --git a/ml-javaclient-util/src/test/java/com/marklogic/client/ext/datamovement/AbstractDataMovementTest.java b/ml-javaclient-util/src/test/java/com/marklogic/client/ext/datamovement/AbstractDataMovementTest.java index eda82547..b088f574 100644 --- a/ml-javaclient-util/src/test/java/com/marklogic/client/ext/datamovement/AbstractDataMovementTest.java +++ b/ml-javaclient-util/src/test/java/com/marklogic/client/ext/datamovement/AbstractDataMovementTest.java @@ -101,7 +101,7 @@ protected void assertZipFileContainsEntryNames(File file, String... names) { throw new RuntimeException(ie); } - logger.info("Entry names: {}", names); + logger.info("Entry names: {}", Arrays.asList(names)); for (String name : names) { assertTrue(entryNames.contains(name)); } diff --git a/ml-javaclient-util/src/test/java/com/marklogic/client/ext/jaxb/JAXBHandleTest.java b/ml-javaclient-util/src/test/java/com/marklogic/client/ext/jaxb/JAXBHandleTest.java index 15c01a25..f1ac6d87 100644 --- a/ml-javaclient-util/src/test/java/com/marklogic/client/ext/jaxb/JAXBHandleTest.java +++ b/ml-javaclient-util/src/test/java/com/marklogic/client/ext/jaxb/JAXBHandleTest.java @@ -4,17 +4,16 @@ package com.marklogic.client.ext.jaxb; import com.marklogic.client.io.JAXBHandle; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.JRE; - import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.annotation.XmlRootElement; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import static org.junit.jupiter.api.Assertions.assertEquals; -public class JAXBHandleTest { +class JAXBHandleTest { /** * Included solely to verify that when the test is run using Java 11 or Java 17, it will succeed given that the @@ -25,14 +24,14 @@ public class JAXBHandleTest { @Test @EnabledForJreRange(min = JRE.JAVA_11) void simpleTest() throws JAXBException { - JAXBHandle handle = new JAXBHandle(JAXBContext.newInstance(Product.class)); + JAXBHandle handle = new JAXBHandle<>(JAXBContext.newInstance(Product.class)); Product p = new Product(); p.setName("My name"); p.setIndustry("My industry"); handle.set(p); String xml = handle.toString(); - Product p2 = (Product) handle.bytesToContent(xml.getBytes()); + Product p2 = handle.bytesToContent(xml.getBytes()); assertEquals("My name", p2.getName()); assertEquals("My industry", p2.getIndustry()); } diff --git a/ml-javaclient-util/src/test/java/com/marklogic/client/ext/modulesloader/impl/LoadModulesTest.java b/ml-javaclient-util/src/test/java/com/marklogic/client/ext/modulesloader/impl/LoadModulesTest.java index f4f874e4..1f528c90 100644 --- a/ml-javaclient-util/src/test/java/com/marklogic/client/ext/modulesloader/impl/LoadModulesTest.java +++ b/ml-javaclient-util/src/test/java/com/marklogic/client/ext/modulesloader/impl/LoadModulesTest.java @@ -24,11 +24,9 @@ import java.util.Set; import java.util.regex.Pattern; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; -public class LoadModulesTest extends AbstractIntegrationTest { +class LoadModulesTest extends AbstractIntegrationTest { private DatabaseClient modulesClient; private DefaultModulesLoader modulesLoader; @@ -76,7 +74,7 @@ public void jsonRestPropertiesFile() { assertTrue(mgr.getQueryOptionValidation()); assertEquals(ServerConfigurationManager.UpdatePolicy.OVERWRITE_METADATA, mgr.getUpdatePolicy()); assertTrue(mgr.getServerRequestLogging()); - assertTrue(StringUtils.isEmpty(mgr.getDefaultDocumentReadTransform())); + assertFalse(StringUtils.hasText(mgr.getDefaultDocumentReadTransform())); assertTrue(mgr.getDefaultDocumentReadTransformAll()); } finally { setRestPropertiesToMarkLogicDefaults(); @@ -100,7 +98,7 @@ public void xmlRestPropertiesFile() { assertTrue(mgr.getQueryOptionValidation()); assertEquals(ServerConfigurationManager.UpdatePolicy.OVERWRITE_METADATA, mgr.getUpdatePolicy()); assertTrue(mgr.getServerRequestLogging()); - assertTrue(StringUtils.isEmpty(mgr.getDefaultDocumentReadTransform())); + assertFalse(StringUtils.hasText(mgr.getDefaultDocumentReadTransform())); assertTrue(mgr.getDefaultDocumentReadTransformAll()); } finally { setRestPropertiesToMarkLogicDefaults();