Skip to content

Commit d3a034d

Browse files
committed
META-INF service removal
1 parent ad9a859 commit d3a034d

File tree

8 files changed

+1242
-1286
lines changed

8 files changed

+1242
-1286
lines changed

sources/net.sf.j2s.java.core/src/java/util/ServiceLoader.java

Lines changed: 109 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public final class ServiceLoader<S>
186186
implements Iterable<S>
187187
{
188188

189-
private static final String PREFIX = "META-INF/services/";
189+
//private static final String PREFIX = "META-INF/services/";
190190

191191
// The class or interface representing the service being loaded
192192
private final Class<S> service;
@@ -239,44 +239,45 @@ private static void fail(Class<?> service, String msg)
239239
throw new ServiceConfigurationError(service.getName() + ": " + msg);
240240
}
241241

242-
private static void fail(Class<?> service, URL u, int line, String msg)
243-
throws ServiceConfigurationError
244-
{
245-
fail(service, u + ":" + line + ": " + msg);
246-
}
247-
248-
// Parse a single line from the given configuration file, adding the name
249-
// on the line to the names list.
250-
//
251-
private int parseLine(Class<?> service, URL u, BufferedReader r, int lc,
252-
List<String> names)
253-
throws IOException, ServiceConfigurationError
254-
{
255-
String ln = r.readLine();
256-
if (ln == null) {
257-
return -1;
258-
}
259-
int ci = ln.indexOf('#');
260-
if (ci >= 0) ln = ln.substring(0, ci);
261-
ln = ln.trim();
262-
int n = ln.length();
263-
if (n != 0) {
264-
if ((ln.indexOf(' ') >= 0) || (ln.indexOf('\t') >= 0))
265-
fail(service, u, lc, "Illegal configuration-file syntax");
266-
int cp = ln.codePointAt(0);
267-
if (!Character.isJavaIdentifierStart(cp))
268-
fail(service, u, lc, "Illegal provider-class name: " + ln);
269-
for (int i = Character.charCount(cp); i < n; i += Character.charCount(cp)) {
270-
cp = ln.codePointAt(i);
271-
if (!Character.isJavaIdentifierPart(cp) && (cp != '.'))
272-
fail(service, u, lc, "Illegal provider-class name: " + ln);
273-
}
274-
if (!providers.containsKey(ln) && !names.contains(ln))
275-
names.add(ln);
276-
}
277-
return lc + 1;
278-
}
279-
242+
// private static void fail(Class<?> service, URL u, int line, String msg)
243+
// throws ServiceConfigurationError
244+
// {
245+
// fail(service, u + ":" + line + ": " + msg);
246+
// }
247+
248+
// // Parse a single line from the given configuration file, adding the name
249+
// // on the line to the names list.
250+
// //
251+
// private int parseLine(Class<?> service, URL u, BufferedReader r, int lc,
252+
// List<String> names)
253+
// throws IOException, ServiceConfigurationError
254+
// {
255+
// String ln = r.readLine();
256+
// if (ln == null) {
257+
// return -1;
258+
// }
259+
// int ci = ln.indexOf('#');
260+
// if (ci >= 0) ln = ln.substring(0, ci);
261+
// ln = ln.trim();
262+
// int n = ln.length();
263+
// if (n != 0) {
264+
// if ((ln.indexOf(' ') >= 0) || (ln.indexOf('\t') >= 0))
265+
// fail(service, u, lc, "Illegal configuration-file syntax");
266+
// int cp = ln.codePointAt(0);
267+
// if (!Character.isJavaIdentifierStart(cp))
268+
// fail(service, u, lc, "Illegal provider-class name: " + ln);
269+
// for (int i = Character.charCount(cp); i < n; i += Character.charCount(cp)) {
270+
// cp = ln.codePointAt(i);
271+
// if (!Character.isJavaIdentifierPart(cp) && (cp != '.'))
272+
// fail(service, u, lc, "Illegal provider-class name: " + ln);
273+
// }
274+
// if (!providers.containsKey(ln) && !names.contains(ln))
275+
// names.add(ln);
276+
// }
277+
// return lc + 1;
278+
// }
279+
//
280+
//
280281
// Parse the content of the given URL as a provider-configuration file.
281282
//
282283
// @param service
@@ -294,29 +295,29 @@ private int parseLine(Class<?> service, URL u, BufferedReader r, int lc,
294295
// If an I/O error occurs while reading from the given URL, or
295296
// if a configuration-file format error is detected
296297
//
297-
private Iterator<String> parse(Class<?> service, URL u)
298-
throws ServiceConfigurationError
299-
{
300-
InputStream in = null;
301-
BufferedReader r = null;
302-
ArrayList<String> names = new ArrayList<>();
303-
try {
304-
in = u.openStream();
305-
r = new BufferedReader(new InputStreamReader(in, "utf-8"));
306-
int lc = 1;
307-
while ((lc = parseLine(service, u, r, lc, names)) >= 0);
308-
} catch (IOException x) {
309-
fail(service, "Error reading configuration file", x);
310-
} finally {
311-
try {
312-
if (r != null) r.close();
313-
if (in != null) in.close();
314-
} catch (IOException y) {
315-
fail(service, "Error closing configuration file", y);
316-
}
317-
}
318-
return names.iterator();
319-
}
298+
// private Iterator<String> parse(Class<?> service, URL u)
299+
// throws ServiceConfigurationError
300+
// {
301+
// InputStream in = null;
302+
// BufferedReader r = null;
303+
// ArrayList<String> names = new ArrayList<>();
304+
// try {
305+
// in = u.openStream();
306+
// r = new BufferedReader(new InputStreamReader(in, "utf-8"));
307+
// int lc = 1;
308+
// while ((lc = parseLine(service, u, r, lc, names)) >= 0);
309+
// } catch (IOException x) {
310+
// fail(service, "Error reading configuration file", x);
311+
// } finally {
312+
// try {
313+
// if (r != null) r.close();
314+
// if (in != null) in.close();
315+
// } catch (IOException y) {
316+
// fail(service, "Error closing configuration file", y);
317+
// }
318+
// }
319+
// return names.iterator();
320+
// }
320321

321322
// Private inner class implementing fully-lazy provider lookup
322323
//
@@ -326,8 +327,8 @@ private class LazyIterator
326327

327328
Class<S> service;
328329
ClassLoader loader;
329-
Enumeration<URL> configs = null;
330-
Iterator<String> pending = null;
330+
// Enumeration<URL> configs = null;
331+
// Iterator<String> pending = null;
331332
String nextName = null;
332333

333334
private LazyIterator(Class<S> service, ClassLoader loader) {
@@ -336,28 +337,30 @@ private LazyIterator(Class<S> service, ClassLoader loader) {
336337
}
337338

338339
private boolean hasNextService() {
339-
if (nextName != null) {
340-
return true;
341-
}
342-
if (configs == null) {
343-
try {
344-
String fullName = PREFIX + service.getName();
345-
if (loader == null)
346-
configs = ClassLoader.getSystemResources(fullName);
347-
else
348-
configs = loader.getResources(fullName);
349-
} catch (IOException x) {
350-
fail(service, "Error locating configuration files", x);
351-
}
352-
}
353-
while ((pending == null) || !pending.hasNext()) {
354-
if (!configs.hasMoreElements()) {
355-
return false;
356-
}
357-
pending = parse(service, configs.nextElement());
358-
}
359-
nextName = pending.next();
360-
return true;
340+
return false;
341+
// SwingJS no JAR files
342+
// if (nextName != null) {
343+
// return true;
344+
// }
345+
// if (configs == null) {
346+
// try {
347+
// String fullName = PREFIX + service.getName();
348+
// if (loader == null)
349+
// configs = ClassLoader.getSystemResources(fullName);
350+
// else
351+
// configs = loader.getResources(fullName);
352+
// } catch (IOException x) {
353+
// fail(service, "Error locating configuration files", x);
354+
// }
355+
// }
356+
// while ((pending == null) || !pending.hasNext()) {
357+
// if (!configs.hasMoreElements()) {
358+
// return false;
359+
// }
360+
// pending = parse(service, configs.nextElement());
361+
// }
362+
// nextName = pending.next();
363+
// return true;
361364
}
362365

363366
private S nextService() {
@@ -388,29 +391,34 @@ private S nextService() {
388391
throw new Error(); // This cannot happen
389392
}
390393

391-
public boolean hasNext() {
394+
@Override
395+
public boolean hasNext() {
392396
if (acc == null) {
393397
return hasNextService();
394398
} else {
395399
PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>() {
396-
public Boolean run() { return hasNextService(); }
400+
@Override
401+
public Boolean run() { return hasNextService(); }
397402
};
398403
return AccessController.doPrivileged(action, acc);
399404
}
400405
}
401406

402-
public S next() {
407+
@Override
408+
public S next() {
403409
if (acc == null) {
404410
return nextService();
405411
} else {
406412
PrivilegedAction<S> action = new PrivilegedAction<S>() {
407-
public S run() { return nextService(); }
413+
@Override
414+
public S run() { return nextService(); }
408415
};
409416
return AccessController.doPrivileged(action, acc);
410417
}
411418
}
412419

413-
public void remove() {
420+
@Override
421+
public void remove() {
414422
throw new UnsupportedOperationException();
415423
}
416424

@@ -462,25 +470,29 @@ public void remove() {
462470
* @return An iterator that lazily loads providers for this loader's
463471
* service
464472
*/
465-
public Iterator<S> iterator() {
473+
@Override
474+
public Iterator<S> iterator() {
466475
return new Iterator<S>() {
467476

468477
Iterator<Map.Entry<String,S>> knownProviders
469478
= providers.entrySet().iterator();
470479

471-
public boolean hasNext() {
480+
@Override
481+
public boolean hasNext() {
472482
if (knownProviders.hasNext())
473483
return true;
474484
return lookupIterator.hasNext();
475485
}
476486

477-
public S next() {
487+
@Override
488+
public S next() {
478489
if (knownProviders.hasNext())
479490
return knownProviders.next().getValue();
480491
return lookupIterator.next();
481492
}
482493

483-
public void remove() {
494+
@Override
495+
public void remove() {
484496
throw new UnsupportedOperationException();
485497
}
486498

@@ -579,7 +591,8 @@ public static <S> ServiceLoader<S> loadInstalled(Class<S> service) {
579591
*
580592
* @return A descriptive string
581593
*/
582-
public String toString() {
594+
@Override
595+
public String toString() {
583596
return "java.util.ServiceLoader[" + service.getName() + "]";
584597
}
585598

0 commit comments

Comments
 (0)