ObjectChecker: use java.text.Normalizer directly
Base Java version for JGit is now Java 7. The java.text.Normalizer class was available in Java 6. Reflection is no longer required to normalize strings for Mac OS X. Change-Id: I98e14b72629a7a729a2d40a3aa275932841274e8
This commit is contained in:
parent
7177b506b4
commit
e3acf01748
|
@ -48,9 +48,8 @@
|
|||
import static org.eclipse.jgit.util.RawParseUtils.nextLF;
|
||||
import static org.eclipse.jgit.util.RawParseUtils.parseBase10;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.Normalizer;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
@ -790,58 +789,6 @@ public void checkBlob(final byte[] raw) throws CorruptObjectException {
|
|||
|
||||
private String normalize(byte[] raw, int ptr, int end) {
|
||||
String n = RawParseUtils.decode(raw, ptr, end).toLowerCase(Locale.US);
|
||||
return macosx ? Normalizer.normalize(n) : n;
|
||||
}
|
||||
|
||||
private static class Normalizer {
|
||||
// TODO Simplify invocation to Normalizer after dropping Java 5.
|
||||
private static final Method normalize;
|
||||
private static final Object nfc;
|
||||
static {
|
||||
Method method;
|
||||
Object formNfc;
|
||||
try {
|
||||
Class<?> formClazz = Class.forName("java.text.Normalizer$Form"); //$NON-NLS-1$
|
||||
formNfc = formClazz.getField("NFC").get(null); //$NON-NLS-1$
|
||||
method = Class.forName("java.text.Normalizer") //$NON-NLS-1$
|
||||
.getMethod("normalize", CharSequence.class, formClazz); //$NON-NLS-1$
|
||||
} catch (ClassNotFoundException e) {
|
||||
method = null;
|
||||
formNfc = null;
|
||||
} catch (NoSuchFieldException e) {
|
||||
method = null;
|
||||
formNfc = null;
|
||||
} catch (NoSuchMethodException e) {
|
||||
method = null;
|
||||
formNfc = null;
|
||||
} catch (SecurityException e) {
|
||||
method = null;
|
||||
formNfc = null;
|
||||
} catch (IllegalArgumentException e) {
|
||||
method = null;
|
||||
formNfc = null;
|
||||
} catch (IllegalAccessException e) {
|
||||
method = null;
|
||||
formNfc = null;
|
||||
}
|
||||
normalize = method;
|
||||
nfc = formNfc;
|
||||
}
|
||||
|
||||
static String normalize(String in) {
|
||||
if (normalize == null)
|
||||
return in;
|
||||
try {
|
||||
return (String) normalize.invoke(null, in, nfc);
|
||||
} catch (IllegalAccessException e) {
|
||||
return in;
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof RuntimeException)
|
||||
throw (RuntimeException) e.getCause();
|
||||
if (e.getCause() instanceof Error)
|
||||
throw (Error) e.getCause();
|
||||
return in;
|
||||
}
|
||||
}
|
||||
return macosx ? Normalizer.normalize(n, Normalizer.Form.NFC) : n;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue