LOG.trace("Searching for {} services", META_INF_SERVICES);
try {
packageNames = findPackageNames();
if (packageNames == null || packageNames.length == 0) {
throw new TypeConverterLoaderException("Cannot find package names to be used for classpath scanning for annotated type converters.");
}
} catch (Exception e) {
throw new TypeConverterLoaderException("Cannot find package names to be used for classpath scanning for annotated type converters.", e);
}
// if we only have camel-core on the classpath then we have already pre-loaded all its type converters
// but we exposed the "org.apache.camel.core" package in camel-core. This ensures there is at least one
// packageName to scan, which triggers the scanning process. That allows us to ensure that we look for
// META-INF/services in all the JARs.
if (packageNames.length == 1 && "org.apache.camel.core".equals(packageNames[0])) {
LOG.debug("No additional package names found in classpath for annotated type converters.");
// no additional package names found to load type converters so break out
return;
}
// now filter out org.apache.camel.core as its not needed anymore (it was just a dummy)
packageNames = filterUnwantedPackage("org.apache.camel.core", packageNames);
// filter out package names which can be loaded as a class directly so we avoid package scanning which
// is much slower and does not work 100% in all runtime containers
Set<Class<?>> classes = new HashSet<Class<?>>();
packageNames = filterPackageNamesOnly(resolver, packageNames, classes);
if (!classes.isEmpty()) {
LOG.debug("Loaded " + classes.size() + " @Converter classes");
}
// if there is any packages to scan and load @Converter classes, then do it
if (packageNames != null && packageNames.length > 0) {
LOG.trace("Found converter packages to scan: {}", packageNames);
Set<Class<?>> scannedClasses = resolver.findAnnotated(Converter.class, packageNames);
if (scannedClasses.isEmpty()) {
throw new TypeConverterLoaderException("Cannot find any type converter classes from the following packages: " + Arrays.asList(packageNames));
}
LOG.debug("Found " + packageNames.length + " packages with " + scannedClasses.size() + " @Converter classes to load");
classes.addAll(scannedClasses);
}