Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
package thredds.inventory;

import java.util.Formatter;
import java.util.ServiceLoader;
import javax.annotation.Nullable;
import ucar.nc2.util.NcServiceLoader;

/**
* Static helper methods for CollectionSpecParserAbstract objects.
Expand Down Expand Up @@ -49,7 +49,7 @@ private static CollectionSpecParserProvider getProvider(String spec) {
CollectionSpecParserProvider collectionSpecParserProvider = null;

// look for dynamically loaded CollectionSpecParserProvider
for (CollectionSpecParserProvider provider : ServiceLoader.load(CollectionSpecParserProvider.class)) {
for (CollectionSpecParserProvider provider : NcServiceLoader.load(CollectionSpecParserProvider.class)) {
if (provider.canParse(spec)) {
collectionSpecParserProvider = provider;
break;
Expand Down
4 changes: 2 additions & 2 deletions cdm/core/src/main/java/thredds/inventory/MControllers.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.util.ServiceLoader;
import thredds.filesystem.ControllerOS;
import ucar.nc2.util.NcServiceLoader;

public class MControllers {

Expand All @@ -23,7 +23,7 @@ public static MController create(String location) {

// look for dynamically loaded MControllerProviders
if (location != null) {
for (MControllerProvider provider : ServiceLoader.load(MControllerProvider.class)) {
for (MControllerProvider provider : NcServiceLoader.load(MControllerProvider.class)) {
if (provider.canScan(location)) {
mControllerProvider = provider;
break;
Expand Down
7 changes: 3 additions & 4 deletions cdm/core/src/main/java/thredds/inventory/MFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
package thredds.inventory;

import java.io.IOException;
import java.util.ServiceLoader;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import thredds.filesystem.MFileOS;
import thredds.filesystem.MFileOS7;
import ucar.nc2.internal.ncml.NcmlReader;
import ucar.nc2.util.NcServiceLoader;
import ucar.nc2.util.log.LoggerFactory;
Copy link
Copy Markdown
Member

@lesserwhirls lesserwhirls May 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like switching out org.slf4j.LoggerFactory for ucar.nc2.util.log.LoggerFactory broke compilation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, fixed. Also ran spotless, but all that did was remove some whitespace from my javadoc 🤷

If you think the change needs it, I can add tests, but I gave up quickly when I got errors about missing JDKs.


/**
* Static helper methods for MFile objects.
Expand All @@ -34,7 +33,7 @@ public static MFile create(@Nonnull String location) {
MFileProvider mFileProvider = null;

// look for dynamically loaded MFileProviders
for (MFileProvider provider : ServiceLoader.load(MFileProvider.class)) {
for (MFileProvider provider : NcServiceLoader.load(MFileProvider.class)) {
if (provider.canProvide(location)) {
mFileProvider = provider;
break;
Expand Down
5 changes: 3 additions & 2 deletions cdm/core/src/main/java/ucar/nc2/NetcdfFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import ucar.nc2.util.EscapeStrings;
import ucar.nc2.util.IO;
import ucar.nc2.util.Indent;
import ucar.nc2.util.NcServiceLoader;
import ucar.nc2.util.cache.FileCacheIF;
import ucar.nc2.util.cache.FileCacheable;
import ucar.nc2.util.rc.RC;
Expand Down Expand Up @@ -422,7 +423,7 @@ private static boolean canOpen(RandomAccessFile raf) throws IOException {
if (N3header.isValidFile(raf)) {
return true;
} else {
for (IOServiceProvider iosp : ServiceLoader.load(IOServiceProvider.class)) {
for (IOServiceProvider iosp : NcServiceLoader.load(IOServiceProvider.class)) {
log.info("ServiceLoader IOServiceProvider {}", iosp.getClass().getName());
System.out.printf("ServiceLoader IOServiceProvider found %s%n", iosp.getClass().getName());
if (iosp.isValidFile(raf)) {
Expand Down Expand Up @@ -835,7 +836,7 @@ private static IOServiceProvider getIosp(RandomAccessFile raf) throws IOExceptio
} else {

// look for dynamically loaded IOSPs
for (IOServiceProvider loadedSpi : ServiceLoader.load(IOServiceProvider.class)) {
for (IOServiceProvider loadedSpi : NcServiceLoader.load(IOServiceProvider.class)) {
if (loadedSpi.isValidFile(raf)) {
Class c = loadedSpi.getClass();
try {
Expand Down
5 changes: 3 additions & 2 deletions cdm/core/src/main/java/ucar/nc2/NetcdfFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import ucar.nc2.util.DiskCache;
import ucar.nc2.util.EscapeStrings;
import ucar.nc2.util.IO;
import ucar.nc2.util.NcServiceLoader;
import ucar.nc2.util.rc.RC;
import ucar.unidata.io.UncompressInputStream;
import ucar.unidata.io.bzip2.CBZip2InputStream;
Expand Down Expand Up @@ -423,7 +424,7 @@ public static ucar.unidata.io.RandomAccessFile getRaf(String location, int buffe

if (raf == null) {
// look for dynamically loaded RandomAccessFile Providers
for (RandomAccessFileProvider provider : ServiceLoader.load(RandomAccessFileProvider.class)) {
for (RandomAccessFileProvider provider : NcServiceLoader.load(RandomAccessFileProvider.class)) {
if (provider.isOwnerOf(location)) {
raf = provider.open(location, buffer_size);
// might cause issues if the end of a resource location string
Expand Down Expand Up @@ -809,7 +810,7 @@ private static IOServiceProvider getIosp(ucar.unidata.io.RandomAccessFile raf) t

} else {
// look for dynamically loaded IOSPs, and sort before using
final ServiceLoader<IOServiceProvider> iosps = ServiceLoader.load(IOServiceProvider.class);
final ServiceLoader<IOServiceProvider> iosps = NcServiceLoader.load(IOServiceProvider.class);
final List<IOServiceProvider> sortedIosps = Lists.newArrayList(iosps);
Collections.sort(sortedIosps);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.lang.reflect.Method;
import java.io.IOException;
import java.util.*;
import ucar.nc2.util.NcServiceLoader;

/**
* Abstract class for implementing Convention-specific parsing of netCDF files.
Expand Down Expand Up @@ -401,7 +402,7 @@ public static CoordSysBuilderIF factory(NetcdfDataset ds, CancelTask cancelTask)
// call static isMine() using reflection.
CoordSysBuilderIF builder = null;
if (convClass == null) {
for (CoordSysBuilderIF csb : ServiceLoader.load(CoordSysBuilderIF.class)) {
for (CoordSysBuilderIF csb : NcServiceLoader.load(CoordSysBuilderIF.class)) {

Class c = csb.getClass();
Method m;
Expand Down
5 changes: 3 additions & 2 deletions cdm/core/src/main/java/ucar/nc2/dataset/NetcdfDataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import ucar.nc2.iosp.IOServiceProvider;
import ucar.nc2.ncml.NcMLReader;
import ucar.nc2.util.CancelTask;
import ucar.nc2.util.NcServiceLoader;
import ucar.nc2.util.cache.FileCache;
import ucar.nc2.util.cache.FileFactory;
import java.io.IOException;
Expand Down Expand Up @@ -808,14 +809,14 @@ private static NetcdfFile openProtocolOrFile(DatasetUrl durl, int buffer_size, u
}

// look for dynamically loaded NetcdfFileProvider
for (NetcdfFileProvider provider : ServiceLoader.load(NetcdfFileProvider.class)) {
for (NetcdfFileProvider provider : NcServiceLoader.load(NetcdfFileProvider.class)) {
if (provider.isOwnerOf(durl)) {
return provider.open(durl.getTrueurl(), cancelTask);
}
}

// look for providers who do not have an associated ServiceType.
for (NetcdfFileProvider provider : ServiceLoader.load(NetcdfFileProvider.class)) {
for (NetcdfFileProvider provider : NcServiceLoader.load(NetcdfFileProvider.class)) {
if (provider.isOwnerOf(durl.getTrueurl())) {
return provider.open(durl.getTrueurl(), cancelTask);
}
Expand Down
6 changes: 3 additions & 3 deletions cdm/core/src/main/java/ucar/nc2/dataset/NetcdfDatasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.IOException;
import java.io.Reader;
import java.util.EnumSet;
import java.util.ServiceLoader;
import java.util.Set;
import ucar.nc2.NetcdfFile;
import ucar.nc2.NetcdfFiles;
Expand All @@ -13,6 +12,7 @@
import ucar.nc2.internal.dataset.DatasetEnhancer;
import ucar.nc2.internal.ncml.NcmlReader;
import ucar.nc2.util.CancelTask;
import ucar.nc2.util.NcServiceLoader;
import ucar.nc2.util.cache.FileCache;
import ucar.nc2.util.cache.FileCacheIF;
import ucar.nc2.util.cache.FileFactory;
Expand Down Expand Up @@ -426,14 +426,14 @@ private static NetcdfFile openProtocolOrFile(DatasetUrl durl, int buffer_size, u
Object spiObject) throws IOException {

// look for dynamically loaded NetcdfFileProvider
for (NetcdfFileProvider provider : ServiceLoader.load(NetcdfFileProvider.class)) {
for (NetcdfFileProvider provider : NcServiceLoader.load(NetcdfFileProvider.class)) {
if (provider.isOwnerOf(durl)) {
return provider.open(durl.getTrueurl(), cancelTask);
}
}

// look for providers who do not have an associated ServiceType.
for (NetcdfFileProvider provider : ServiceLoader.load(NetcdfFileProvider.class)) {
for (NetcdfFileProvider provider : NcServiceLoader.load(NetcdfFileProvider.class)) {
if (provider.isOwnerOf(durl.getTrueurl())) {
return provider.open(durl.getTrueurl(), cancelTask);
}
Expand Down
3 changes: 2 additions & 1 deletion cdm/core/src/main/java/ucar/nc2/dataset/VariableDS.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ucar.nc2.internal.dataset.CoordinatesHelper;
import ucar.nc2.util.CancelTask;
import ucar.nc2.util.Misc;
import ucar.nc2.util.NcServiceLoader;

import javax.annotation.Nullable;
import java.io.IOException;
Expand All @@ -38,7 +39,7 @@ public class VariableDS extends Variable implements VariableEnhanced, EnhanceSca

static {
ENHANCEMENT_PROVIDERS = new ArrayList<>();
for (EnhancementProvider enhancementProvider : ServiceLoader.load(EnhancementProvider.class)) {
for (EnhancementProvider enhancementProvider : NcServiceLoader.load(EnhancementProvider.class)) {
ENHANCEMENT_PROVIDERS.add(enhancementProvider);
}
}
Expand Down
4 changes: 2 additions & 2 deletions cdm/core/src/main/java/ucar/nc2/dt/grid/GridDataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import ucar.nc2.Attribute;
import ucar.nc2.AttributeContainer;
Expand All @@ -30,6 +29,7 @@
import ucar.nc2.time.CalendarDate;
import ucar.nc2.time.CalendarDateRange;
import ucar.nc2.units.DateRange;
import ucar.nc2.util.NcServiceLoader;
import ucar.nc2.util.cache.FileCacheIF;
import ucar.unidata.geoloc.LatLonRect;
import ucar.unidata.geoloc.ProjectionRect;
Expand Down Expand Up @@ -116,7 +116,7 @@ public static ucar.nc2.dt.GridDataset openIfce(String location) throws java.io.I
*/
public static ucar.nc2.dt.GridDataset openIfce(String location, Set<NetcdfDataset.Enhance> enhanceMode)
throws java.io.IOException {
for (GridDatasetProvider gdsProvider : ServiceLoader.load(GridDatasetProvider.class)) {
for (GridDatasetProvider gdsProvider : NcServiceLoader.load(GridDatasetProvider.class)) {
if (gdsProvider.isMine(location, enhanceMode)) {
return gdsProvider.open(location, enhanceMode);
}
Expand Down
4 changes: 2 additions & 2 deletions cdm/core/src/main/java/ucar/nc2/filter/Filters.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import com.google.common.collect.ImmutableList;
import java.util.Map;
import java.util.ServiceLoader;
import ucar.nc2.util.NcServiceLoader;

public class Filters {

Expand All @@ -16,7 +16,7 @@ public class Filters {
// load filter service providers
static {
ImmutableList.Builder<FilterProvider> spFiltersBuilder = ImmutableList.builder();
for (FilterProvider fp : ServiceLoader.load(FilterProvider.class)) {
for (FilterProvider fp : NcServiceLoader.load(FilterProvider.class)) {
spFiltersBuilder.add(fp);
}
spFilters = spFiltersBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import ucar.nc2.ft.remote.CdmrFeatureDataset;
import ucar.nc2.ft2.coverage.CoverageDatasetFactory;
import ucar.nc2.ft2.coverage.FeatureDatasetCoverage;
import ucar.nc2.util.NcServiceLoader;
import ucar.nc2.util.Optional;
import java.util.List;
import java.util.ArrayList;
import java.util.Formatter;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ServiceLoader;

/**
* Manager of factories for FeatureDatasets opened as NetcdfDatasets.
Expand All @@ -51,7 +51,7 @@ public class FeatureDatasetFactoryManager {
// search in the order added
static {
// user can override
for (FeatureDatasetFactory csb : ServiceLoader.load(FeatureDatasetFactory.class)) {
for (FeatureDatasetFactory csb : NcServiceLoader.load(FeatureDatasetFactory.class)) {
registerFactory(csb.getClass());
}

Expand Down
4 changes: 2 additions & 2 deletions cdm/core/src/main/java/ucar/nc2/ft/fmrc/GridDatasetInv.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.Formatter;
import java.util.List;
import java.util.Locale;
import java.util.ServiceLoader;
import java.util.StringTokenizer;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
Expand All @@ -38,6 +37,7 @@
import ucar.nc2.time.CalendarDate;
import ucar.nc2.time.CalendarDateFormatter;
import ucar.nc2.units.DateUnit;
import ucar.nc2.util.NcServiceLoader;
import ucar.nc2.constants._Coordinate;
import org.jdom2.output.XMLOutputter;
import org.jdom2.output.Format;
Expand Down Expand Up @@ -85,7 +85,7 @@ private static class GenerateInv implements Callable<GridDatasetInv> {
// Persistence is needed for the TDS
static {
InventoryCacheProvider icp = null;
for (InventoryCacheProvider provider : ServiceLoader.load(InventoryCacheProvider.class)) {
for (InventoryCacheProvider provider : NcServiceLoader.load(InventoryCacheProvider.class)) {
// first one wins
icp = provider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.StringTokenizer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -24,6 +23,7 @@
import ucar.nc2.internal.dataset.spi.CFSubConventionProvider;
import ucar.nc2.internal.ncml.NcmlReader;
import ucar.nc2.util.CancelTask;
import ucar.nc2.util.NcServiceLoader;
import ucar.unidata.util.StringUtil2;

/** Static methods for managing CoordSystemBuilderFactory classes */
Expand Down Expand Up @@ -55,7 +55,7 @@ public interface ConventionNameOk {
// These get precedence
static {
registerConvention(_Coordinate.Convention, new CoordSystemBuilder.Factory());
for (CFSubConventionProvider provider : ServiceLoader.load(CFSubConventionProvider.class)) {
for (CFSubConventionProvider provider : NcServiceLoader.load(CFSubConventionProvider.class)) {
registerConvention(provider.getConventionName(), provider);
}
registerConvention("CF-1.", new CF1Convention.Factory(), String::startsWith);
Expand Down Expand Up @@ -278,7 +278,7 @@ private static CoordSystemBuilderFactory findConventionByIsMine(NetcdfFile orgFi
}

// Use service loader mechanism isMine()
for (CoordSystemBuilderFactory csb : ServiceLoader.load(CoordSystemBuilderFactory.class)) {
for (CoordSystemBuilderFactory csb : NcServiceLoader.load(CoordSystemBuilderFactory.class)) {
if (csb.isMine(orgFile)) {
return csb;
}
Expand All @@ -299,7 +299,7 @@ private static CoordSystemBuilderFactory findCfSubConvention(NetcdfFile orgFile,
}

// Use service loader mechanism isMine()
for (CFSubConventionProvider cfSubCon : ServiceLoader.load(CFSubConventionProvider.class)) {
for (CFSubConventionProvider cfSubCon : NcServiceLoader.load(CFSubConventionProvider.class)) {
if (cfSubCon.isMine(orgFile) || cfSubCon.isMine(convs)) {
return cfSubCon;
}
Expand Down Expand Up @@ -356,7 +356,7 @@ private static CoordSystemBuilderFactory findRegisteredConventionByName(String c
@Nullable
private static CoordSystemBuilderFactory findLoadedConventionByName(String convName) {
// use service loader mechanism
for (CoordSystemBuilderFactory csb : ServiceLoader.load(CoordSystemBuilderFactory.class)) {
for (CoordSystemBuilderFactory csb : NcServiceLoader.load(CoordSystemBuilderFactory.class)) {
if (convName.equals(csb.getConventionName())) {
return csb;
}
Expand Down
Loading
Loading