in geronimo-mail_2.1_spec/src/main/java/jakarta/mail/Session.java [552:676]
private ProviderInfo loadProviders(final ClassLoader cl) {
// we create a merged map from reading all of the potential address map entries. The locations
// searched are:
// 0. java.home/conf/javamail.address.map
// 1. java.home/lib/javamail.address.map
// 2. META-INF/javamail.address.map
// 3. META-INF/javamail.default.address.map
//
// JDK 1.9 adds a new <java.home>/conf directory to hold configuration
// files that were previously stored in <java.home>/lib. When using
// JavaMail on JDK 1.9, it should look for its (optional) configuration
// files in the <java.home>/conf directory.
final ProviderInfo info = new ProviderInfo();
// NOTE: Unlike the addressMap, we process these in the defined order. The loading routine
// will not overwrite entries if they already exist in the map.
try {
File file = new File(System.getProperty("java.home"), "conf/javamail.providers");
if (!file.exists()){
file = new File(System.getProperty("java.home"), "lib/javamail.providers");
}
final InputStream is = new FileInputStream(file);
try {
loadProviders(info, is);
if (debug) {
writeDebug("Loaded lib/javamail.providers from " + file.toString());
}
} finally{
is.close();
}
} catch (final SecurityException e) {
// ignore
} catch (final IOException e) {
// ignore
}
try {
final Enumeration e = cl.getResources("META-INF/javamail.providers");
while (e.hasMoreElements()) {
final URL url = (URL) e.nextElement();
if (debug) {
writeDebug("Loading META-INF/javamail.providers from " + url.toString());
}
final InputStream is = url.openStream();
try {
loadProviders(info, is);
} finally{
is.close();
}
}
} catch (final SecurityException e) {
// ignore
} catch (final IOException e) {
// ignore
}
// we could be running in an OSGi environment, so there might be some globally defined
// providers
try {
final Collection<URL> l = MailProviderRegistry.getProviders();
for (final URL url : l) {
if (debug) {
writeDebug("Loading META-INF/javamail.providers from " + url.toString());
}
final InputStream is = url.openStream();
try {
loadProviders(info, is);
} finally{
is.close();
}
}
} catch (final SecurityException e) {
// ignore
} catch (final IOException e) {
// ignore
}
try {
final Enumeration e = cl.getResources("META-INF/javamail.default.providers");
while (e.hasMoreElements()) {
final URL url = (URL) e.nextElement();
if (debug) {
writeDebug("Loading javamail.default.providers from " + url.toString());
}
final InputStream is = url.openStream();
try {
loadProviders(info, is);
} finally{
is.close();
}
}
} catch (final SecurityException e) {
// ignore
} catch (final IOException e) {
// ignore
}
// we could be running in an OSGi environment, so there might be some globally defined
// providers
try {
final Collection<URL> l = MailProviderRegistry.getDefaultProviders();
for (final URL url : l) {
if (debug) {
writeDebug("Loading META-INF/javamail.providers from " + url.toString());
}
final InputStream is = url.openStream();
try {
loadProviders(info, is);
} finally{
is.close();
}
}
} catch (final SecurityException e) {
// ignore
} catch (final IOException e) {
// ignore
}
// make sure this is added to the global map.
providersByClassLoader.put(cl, info);
return info;
}