Java Code Examples for java.text.Normalizer#isNormalized()

The following examples show how to use java.text.Normalizer#isNormalized() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegularFileObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
    cn.getClass();
    // null check
    if (kind == Kind.OTHER && getKind() != kind) {
        return false;
    }
    String n = cn + kind.extension;
    if (name.equals(n)) {
        return true;
    }
    if (isMacOS && Normalizer.isNormalized(name, Normalizer.Form.NFD)
        && Normalizer.isNormalized(n, Normalizer.Form.NFC)) {
        // On Mac OS X it is quite possible to file name and class
        // name normalized in a different way - in that case we have to normalize file name
        // to the Normal Form Compised (NFC)
        String normName = Normalizer.normalize(name, Normalizer.Form.NFC);
        if (normName.equals(n)) {
            this.name = normName;
            return true;
        }
    }

        if (name.equalsIgnoreCase(n)) {
        try {
            // allow for Windows
            return file.getCanonicalFile().getName().equals(n);
        } catch (IOException e) {
        }
    }
    return false;
}
 
Example 2
Source File: RegularFileObject.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
    cn.getClass();
    // null check
    if (kind == Kind.OTHER && getKind() != kind) {
        return false;
    }
    String n = cn + kind.extension;
    if (name.equals(n)) {
        return true;
    }
    if (isMacOS && Normalizer.isNormalized(name, Normalizer.Form.NFD)
        && Normalizer.isNormalized(n, Normalizer.Form.NFC)) {
        // On Mac OS X it is quite possible to file name and class
        // name normalized in a different way - in that case we have to normalize file name
        // to the Normal Form Compised (NFC)
        String normName = Normalizer.normalize(name, Normalizer.Form.NFC);
        if (normName.equals(n)) {
            this.name = normName;
            return true;
        }
    }

        if (name.equalsIgnoreCase(n)) {
        try {
            // allow for Windows
            return file.getCanonicalFile().getName().equals(n);
        } catch (IOException e) {
        }
    }
    return false;
}
 
Example 3
Source File: PathFileObject.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected boolean isPathNameCompatible(Path p, String simpleName, Kind kind) {
    Objects.requireNonNull(simpleName);
    Objects.requireNonNull(kind);

    if (kind == Kind.OTHER && BaseFileManager.getKind(p) != kind) {
        return false;
    }

    String sn = simpleName + kind.extension;
    String pn = p.getFileName().toString();
    if (pn.equals(sn)) {
        return true;
    }

    if (p.getFileSystem() == defaultFileSystem) {
        if (isMacOS) {
            if (Normalizer.isNormalized(pn, Normalizer.Form.NFD)
                    && Normalizer.isNormalized(sn, Normalizer.Form.NFC)) {
                // On Mac OS X it is quite possible to have the file name and the
                // given simple name normalized in different ways.
                // In that case we have to normalize file name to the
                // Normal Form Composed (NFC).
                String normName = Normalizer.normalize(pn, Normalizer.Form.NFC);
                if (normName.equals(sn)) {
                    return true;
                }
            }
        }

        if (pn.equalsIgnoreCase(sn)) {
            try {
                // allow for Windows
                return p.toRealPath(LinkOption.NOFOLLOW_LINKS).getFileName().toString().equals(sn);
            } catch (IOException e) {
            }
        }
    }

    return false;
}
 
Example 4
Source File: RegularFileObject.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
    cn.getClass();
    // null check
    if (kind == Kind.OTHER && getKind() != kind) {
        return false;
    }
    String n = cn + kind.extension;
    if (name.equals(n)) {
        return true;
    }
    if (isMacOS && Normalizer.isNormalized(name, Normalizer.Form.NFD)
        && Normalizer.isNormalized(n, Normalizer.Form.NFC)) {
        // On Mac OS X it is quite possible to file name and class
        // name normalized in a different way - in that case we have to normalize file name
        // to the Normal Form Compised (NFC)
        String normName = Normalizer.normalize(name, Normalizer.Form.NFC);
        if (normName.equals(n)) {
            this.name = normName;
            return true;
        }
    }

        if (name.equalsIgnoreCase(n)) {
        try {
            // allow for Windows
            return file.getCanonicalFile().getName().equals(n);
        } catch (IOException e) {
        }
    }
    return false;
}
 
Example 5
Source File: RegularFileObject.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
    cn.getClass();
    // null check
    if (kind == Kind.OTHER && getKind() != kind) {
        return false;
    }
    String n = cn + kind.extension;
    if (name.equals(n)) {
        return true;
    }
    if (isMacOS && Normalizer.isNormalized(name, Normalizer.Form.NFD)
        && Normalizer.isNormalized(n, Normalizer.Form.NFC)) {
        // On Mac OS X it is quite possible to file name and class
        // name normalized in a different way - in that case we have to normalize file name
        // to the Normal Form Compised (NFC)
        String normName = Normalizer.normalize(name, Normalizer.Form.NFC);
        if (normName.equals(n)) {
            this.name = normName;
            return true;
        }
    }

        if (name.equalsIgnoreCase(n)) {
        try {
            // allow for Windows
            return file.getCanonicalFile().getName().equals(n);
        } catch (IOException e) {
        }
    }
    return false;
}
 
Example 6
Source File: RegularFileObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
    cn.getClass();
    // null check
    if (kind == Kind.OTHER && getKind() != kind) {
        return false;
    }
    String n = cn + kind.extension;
    if (name.equals(n)) {
        return true;
    }
    if (isMacOS && Normalizer.isNormalized(name, Normalizer.Form.NFD)
        && Normalizer.isNormalized(n, Normalizer.Form.NFC)) {
        // On Mac OS X it is quite possible to file name and class
        // name normalized in a different way - in that case we have to normalize file name
        // to the Normal Form Compised (NFC)
        String normName = Normalizer.normalize(name, Normalizer.Form.NFC);
        if (normName.equals(n)) {
            this.name = normName;
            return true;
        }
    }

        if (name.equalsIgnoreCase(n)) {
        try {
            // allow for Windows
            return file.getCanonicalFile().getName().equals(n);
        } catch (IOException e) {
        }
    }
    return false;
}
 
Example 7
Source File: RegularFileObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
    cn.getClass();
    // null check
    if (kind == Kind.OTHER && getKind() != kind) {
        return false;
    }
    String n = cn + kind.extension;
    if (name.equals(n)) {
        return true;
    }
    if (isMacOS && Normalizer.isNormalized(name, Normalizer.Form.NFD)
        && Normalizer.isNormalized(n, Normalizer.Form.NFC)) {
        // On Mac OS X it is quite possible to file name and class
        // name normalized in a different way - in that case we have to normalize file name
        // to the Normal Form Compised (NFC)
        String normName = Normalizer.normalize(name, Normalizer.Form.NFC);
        if (normName.equals(n)) {
            this.name = normName;
            return true;
        }
    }

        if (name.equalsIgnoreCase(n)) {
        try {
            // allow for Windows
            return file.getCanonicalFile().getName().equals(n);
        } catch (IOException e) {
        }
    }
    return false;
}
 
Example 8
Source File: RegularFileObject.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
    cn.getClass();
    // null check
    if (kind == Kind.OTHER && getKind() != kind) {
        return false;
    }
    String n = cn + kind.extension;
    if (name.equals(n)) {
        return true;
    }
    if (isMacOS && Normalizer.isNormalized(name, Normalizer.Form.NFD)
        && Normalizer.isNormalized(n, Normalizer.Form.NFC)) {
        // On Mac OS X it is quite possible to file name and class
        // name normalized in a different way - in that case we have to normalize file name
        // to the Normal Form Compised (NFC)
        String normName = Normalizer.normalize(name, Normalizer.Form.NFC);
        if (normName.equals(n)) {
            this.name = normName;
            return true;
        }
    }

        if (name.equalsIgnoreCase(n)) {
        try {
            // allow for Windows
            return file.getCanonicalFile().getName().equals(n);
        } catch (IOException e) {
        }
    }
    return false;
}
 
Example 9
Source File: LauncherHelper.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method does the following:
 * 1. gets the classname from a Jar's manifest, if necessary
 * 2. loads the class using the System ClassLoader
 * 3. ensures the availability and accessibility of the main method,
 *    using signatureDiagnostic method.
 *    a. does the class exist
 *    b. is there a main
 *    c. is the main public
 *    d. is the main static
 *    e. does the main take a String array for args
 * 4. if no main method and if the class extends FX Application, then call
 *    on FXHelper to determine the main class to launch
 * 5. and off we go......
 *
 * @param printToStderr if set, all output will be routed to stderr
 * @param mode LaunchMode as determined by the arguments passed on the
 * command line
 * @param what either the jar file to launch or the main class when using
 * LM_CLASS mode
 * @return the application's main class
 */
public static Class<?> checkAndLoadMain(boolean printToStderr,
                                        int mode,
                                        String what) {
    initOutput(printToStderr);
    // get the class name
    String cn = null;
    switch (mode) {
        case LM_CLASS:
            cn = what;
            break;
        case LM_JAR:
            cn = getMainClassFromJar(what);
            break;
        default:
            // should never happen
            throw new InternalError("" + mode + ": Unknown launch mode");
    }
    cn = cn.replace('/', '.');
    Class<?> mainClass = null;
    try {
        mainClass = scloader.loadClass(cn);
    } catch (NoClassDefFoundError | ClassNotFoundException cnfe) {
        if (System.getProperty("os.name", "").contains("OS X")
            && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) {
            try {
                // On Mac OS X since all names with diacretic symbols are given as decomposed it
                // is possible that main class name comes incorrectly from the command line
                // and we have to re-compose it
                mainClass = scloader.loadClass(Normalizer.normalize(cn, Normalizer.Form.NFC));
            } catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
                abort(cnfe, "java.launcher.cls.error1", cn);
            }
        } else {
            abort(cnfe, "java.launcher.cls.error1", cn);
        }
    }
    // set to mainClass
    appClass = mainClass;

    /*
     * Check if FXHelper can launch it using the FX launcher. In an FX app,
     * the main class may or may not have a main method, so do this before
     * validating the main class.
     */
    if (mainClass.equals(FXHelper.class) ||
            FXHelper.doesExtendFXApplication(mainClass)) {
        // Will abort() if there are problems with the FX runtime
        FXHelper.setFXLaunchParameters(what, mode);
        return FXHelper.class;
    }

    validateMainClass(mainClass);
    return mainClass;
}
 
Example 10
Source File: DefaultTextTokenizer.java    From fdb-record-layer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean hasNext() {
    if (nextToken != null) {
        return true;
    }
    int nextBreak = underlying.following(lastBreak);
    while (nextToken == null && nextBreak != BreakIterator.DONE) {
        String token = text.substring(lastBreak, nextBreak);
        // Normalize the string to a standard normalization.
        // This is done prior to checking for alphabetic characters
        // because some Unicode characters (like the blackboard
        // section) are recognized as characters only once compatibility
        // equivalents are normalized away.
        if (!Normalizer.isNormalized(token, NORMALIZED_FORM)) {
            token = Normalizer.normalize(token, NORMALIZED_FORM);
        }
        boolean isToken = false;
        for (int i = 0; i < token.length(); i++) {
            if (Character.isLetterOrDigit(token.charAt(i))) {
                isToken = true;
                break;
            }
        }
        if (isToken) {
            // Case-fold (using Locale.ROOT to avoid different things happening in Turkey)
            // and remove diacritical marks. The diacritical filter might be too
            // aggressive in that it will also do things like strip away vowels in
            // many abugidas. It does the right thing with Hangul Jamo, though.
            //
            // Example transformations:
            //     hELlo -> hello
            //     Igloo -> igloo (note: if not Locale.ROOT and run in Turkey, the "i" will be missing a tittle)
            //     Après -> apres
            //     Здра́вствуйте -> здравствуите
            //     אֶתְנַחְתָּ֑א -> אתנחתא
            //     అన్నం -> అనన (note: this is essentially stripping the vowels away, which might be "wrong")
            //     안녕하세요 -> 안녕하세요 (Hangul Jamo not transformed)
            token = matcher.reset(token.toLowerCase(Locale.ROOT)).replaceAll("");
            nextToken = token;
        }
        lastBreak = nextBreak;
        nextBreak = underlying.next();
    }
    return nextToken != null;
}
 
Example 11
Source File: LauncherHelper.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method does the following:
 * 1. gets the classname from a Jar's manifest, if necessary
 * 2. loads the class using the System ClassLoader
 * 3. ensures the availability and accessibility of the main method,
 *    using signatureDiagnostic method.
 *    a. does the class exist
 *    b. is there a main
 *    c. is the main public
 *    d. is the main static
 *    e. does the main take a String array for args
 * 4. if no main method and if the class extends FX Application, then call
 *    on FXHelper to determine the main class to launch
 * 5. and off we go......
 *
 * @param printToStderr if set, all output will be routed to stderr
 * @param mode LaunchMode as determined by the arguments passed on the
 * command line
 * @param what either the jar file to launch or the main class when using
 * LM_CLASS mode
 * @return the application's main class
 */
public static Class<?> checkAndLoadMain(boolean printToStderr,
                                        int mode,
                                        String what) {
    initOutput(printToStderr);
    // get the class name
    String cn = null;
    switch (mode) {
        case LM_CLASS:
            cn = what;
            break;
        case LM_JAR:
            cn = getMainClassFromJar(what);
            break;
        default:
            // should never happen
            throw new InternalError("" + mode + ": Unknown launch mode");
    }
    cn = cn.replace('/', '.');
    Class<?> mainClass = null;
    try {
        mainClass = scloader.loadClass(cn);
    } catch (NoClassDefFoundError | ClassNotFoundException cnfe) {
        if (System.getProperty("os.name", "").contains("OS X")
            && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) {
            try {
                // On Mac OS X since all names with diacretic symbols are given as decomposed it
                // is possible that main class name comes incorrectly from the command line
                // and we have to re-compose it
                mainClass = scloader.loadClass(Normalizer.normalize(cn, Normalizer.Form.NFC));
            } catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
                abort(cnfe, "java.launcher.cls.error1", cn);
            }
        } else {
            abort(cnfe, "java.launcher.cls.error1", cn);
        }
    }
    // set to mainClass
    appClass = mainClass;

    /*
     * Check if FXHelper can launch it using the FX launcher. In an FX app,
     * the main class may or may not have a main method, so do this before
     * validating the main class.
     */
    if (mainClass.equals(FXHelper.class) ||
            FXHelper.doesExtendFXApplication(mainClass)) {
        // Will abort() if there are problems with the FX runtime
        FXHelper.setFXLaunchParameters(what, mode);
        return FXHelper.class;
    }

    validateMainClass(mainClass);
    return mainClass;
}
 
Example 12
Source File: LauncherHelper.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method does the following:
 * 1. gets the classname from a Jar's manifest, if necessary
 * 2. loads the class using the System ClassLoader
 * 3. ensures the availability and accessibility of the main method,
 *    using signatureDiagnostic method.
 *    a. does the class exist
 *    b. is there a main
 *    c. is the main public
 *    d. is the main static
 *    e. does the main take a String array for args
 * 4. if no main method and if the class extends FX Application, then call
 *    on FXHelper to determine the main class to launch
 * 5. and off we go......
 *
 * @param printToStderr if set, all output will be routed to stderr
 * @param mode LaunchMode as determined by the arguments passed on the
 * command line
 * @param what either the jar file to launch or the main class when using
 * LM_CLASS mode
 * @return the application's main class
 */
public static Class<?> checkAndLoadMain(boolean printToStderr,
                                        int mode,
                                        String what) {
    initOutput(printToStderr);
    // get the class name
    String cn = null;
    switch (mode) {
        case LM_CLASS:
            cn = what;
            break;
        case LM_JAR:
            cn = getMainClassFromJar(what);
            break;
        default:
            // should never happen
            throw new InternalError("" + mode + ": Unknown launch mode");
    }
    cn = cn.replace('/', '.');
    Class<?> mainClass = null;
    try {
        mainClass = scloader.loadClass(cn);
    } catch (NoClassDefFoundError | ClassNotFoundException cnfe) {
        if (System.getProperty("os.name", "").contains("OS X")
            && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) {
            try {
                // On Mac OS X since all names with diacretic symbols are given as decomposed it
                // is possible that main class name comes incorrectly from the command line
                // and we have to re-compose it
                mainClass = scloader.loadClass(Normalizer.normalize(cn, Normalizer.Form.NFC));
            } catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
                abort(cnfe, "java.launcher.cls.error1", cn);
            }
        } else {
            abort(cnfe, "java.launcher.cls.error1", cn);
        }
    }
    // set to mainClass
    appClass = mainClass;

    /*
     * Check if FXHelper can launch it using the FX launcher. In an FX app,
     * the main class may or may not have a main method, so do this before
     * validating the main class.
     */
    if (mainClass.equals(FXHelper.class) ||
            FXHelper.doesExtendFXApplication(mainClass)) {
        // Will abort() if there are problems with the FX runtime
        FXHelper.setFXLaunchParameters(what, mode);
        return FXHelper.class;
    }

    validateMainClass(mainClass);
    return mainClass;
}
 
Example 13
Source File: LauncherHelper.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Loads the main class from the class path (LM_CLASS or LM_JAR).
 */
private static Class<?> loadMainClass(int mode, String what) {
    // get the class name
    String cn;
    switch (mode) {
        case LM_CLASS:
            cn = what;
            break;
        case LM_JAR:
            cn = getMainClassFromJar(what);
            break;
        default:
            // should never happen
            throw new InternalError("" + mode + ": Unknown launch mode");
    }

    // load the main class
    cn = cn.replace('/', '.');
    Class<?> mainClass = null;
    ClassLoader scl = ClassLoader.getSystemClassLoader();
    try {
        try {
            mainClass = Class.forName(cn, false, scl);
        } catch (NoClassDefFoundError | ClassNotFoundException cnfe) {
            if (System.getProperty("os.name", "").contains("OS X")
                    && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) {
                try {
                    // On Mac OS X since all names with diacritical marks are
                    // given as decomposed it is possible that main class name
                    // comes incorrectly from the command line and we have
                    // to re-compose it
                    String ncn = Normalizer.normalize(cn, Normalizer.Form.NFC);
                    mainClass = Class.forName(ncn, false, scl);
                } catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
                    abort(cnfe1, "java.launcher.cls.error1", cn,
                            cnfe1.getClass().getCanonicalName(), cnfe1.getMessage());
                }
            } else {
                abort(cnfe, "java.launcher.cls.error1", cn,
                        cnfe.getClass().getCanonicalName(), cnfe.getMessage());
            }
        }
    } catch (LinkageError le) {
        abort(le, "java.launcher.cls.error6", cn,
                le.getClass().getName() + ": " + le.getLocalizedMessage());
    }
    return mainClass;
}
 
Example 14
Source File: LauncherHelper.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method does the following:
 * 1. gets the classname from a Jar's manifest, if necessary
 * 2. loads the class using the System ClassLoader
 * 3. ensures the availability and accessibility of the main method,
 *    using signatureDiagnostic method.
 *    a. does the class exist
 *    b. is there a main
 *    c. is the main public
 *    d. is the main static
 *    e. does the main take a String array for args
 * 4. if no main method and if the class extends FX Application, then call
 *    on FXHelper to determine the main class to launch
 * 5. and off we go......
 *
 * @param printToStderr if set, all output will be routed to stderr
 * @param mode LaunchMode as determined by the arguments passed on the
 * command line
 * @param what either the jar file to launch or the main class when using
 * LM_CLASS mode
 * @return the application's main class
 */
public static Class<?> checkAndLoadMain(boolean printToStderr,
                                        int mode,
                                        String what) {
    initOutput(printToStderr);
    // get the class name
    String cn = null;
    switch (mode) {
        case LM_CLASS:
            cn = what;
            break;
        case LM_JAR:
            cn = getMainClassFromJar(what);
            break;
        default:
            // should never happen
            throw new InternalError("" + mode + ": Unknown launch mode");
    }
    cn = cn.replace('/', '.');
    Class<?> mainClass = null;
    try {
        mainClass = scloader.loadClass(cn);
    } catch (NoClassDefFoundError | ClassNotFoundException cnfe) {
        if (System.getProperty("os.name", "").contains("OS X")
            && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) {
            try {
                // On Mac OS X since all names with diacretic symbols are given as decomposed it
                // is possible that main class name comes incorrectly from the command line
                // and we have to re-compose it
                mainClass = scloader.loadClass(Normalizer.normalize(cn, Normalizer.Form.NFC));
            } catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
                abort(cnfe, "java.launcher.cls.error1", cn);
            }
        } else {
            abort(cnfe, "java.launcher.cls.error1", cn);
        }
    }
    // set to mainClass
    appClass = mainClass;

    /*
     * Check if FXHelper can launch it using the FX launcher. In an FX app,
     * the main class may or may not have a main method, so do this before
     * validating the main class.
     */
    if (mainClass.equals(FXHelper.class) ||
            FXHelper.doesExtendFXApplication(mainClass)) {
        // Will abort() if there are problems with the FX runtime
        FXHelper.setFXLaunchParameters(what, mode);
        return FXHelper.class;
    }

    validateMainClass(mainClass);
    return mainClass;
}
 
Example 15
Source File: LauncherHelper.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the main class for a module. The query is either a module name
 * or module-name/main-class. For the former then the module's main class
 * is obtained from the module descriptor (MainClass attribute).
 */
private static Class<?> loadModuleMainClass(String what) {
    int i = what.indexOf('/');
    String mainModule;
    String mainClass;
    if (i == -1) {
        mainModule = what;
        mainClass = null;
    } else {
        mainModule = what.substring(0, i);
        mainClass = what.substring(i+1);
    }

    // main module is in the boot layer
    ModuleLayer layer = ModuleLayer.boot();
    Optional<Module> om = layer.findModule(mainModule);
    if (!om.isPresent()) {
        // should not happen
        throw new InternalError("Module " + mainModule + " not in boot Layer");
    }
    Module m = om.get();

    // get main class
    if (mainClass == null) {
        Optional<String> omc = m.getDescriptor().mainClass();
        if (!omc.isPresent()) {
            abort(null, "java.launcher.module.error1", mainModule);
        }
        mainClass = omc.get();
    }

    // load the class from the module
    Class<?> c = null;
    try {
        c = Class.forName(m, mainClass);
        if (c == null && System.getProperty("os.name", "").contains("OS X")
                && Normalizer.isNormalized(mainClass, Normalizer.Form.NFD)) {

            String cn = Normalizer.normalize(mainClass, Normalizer.Form.NFC);
            c = Class.forName(m, cn);
        }
    } catch (LinkageError le) {
        abort(null, "java.launcher.module.error3", mainClass, m.getName(),
                le.getClass().getName() + ": " + le.getLocalizedMessage());
    }
    if (c == null) {
        abort(null, "java.launcher.module.error2", mainClass, mainModule);
    }

    System.setProperty("jdk.module.main.class", c.getName());
    return c;
}
 
Example 16
Source File: LauncherHelper.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Loads the main class from the class path (LM_CLASS or LM_JAR).
 */
private static Class<?> loadMainClass(int mode, String what) {
    // get the class name
    String cn;
    switch (mode) {
        case LM_CLASS:
            cn = what;
            break;
        case LM_JAR:
            cn = getMainClassFromJar(what);
            break;
        default:
            // should never happen
            throw new InternalError("" + mode + ": Unknown launch mode");
    }

    // load the main class
    cn = cn.replace('/', '.');
    Class<?> mainClass = null;
    ClassLoader scl = ClassLoader.getSystemClassLoader();
    try {
        try {
            mainClass = Class.forName(cn, false, scl);
        } catch (NoClassDefFoundError | ClassNotFoundException cnfe) {
            if (System.getProperty("os.name", "").contains("OS X")
                    && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) {
                try {
                    // On Mac OS X since all names with diacritical marks are
                    // given as decomposed it is possible that main class name
                    // comes incorrectly from the command line and we have
                    // to re-compose it
                    String ncn = Normalizer.normalize(cn, Normalizer.Form.NFC);
                    mainClass = Class.forName(ncn, false, scl);
                } catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
                    abort(cnfe1, "java.launcher.cls.error1", cn,
                            cnfe1.getClass().getCanonicalName(), cnfe1.getMessage());
                }
            } else {
                abort(cnfe, "java.launcher.cls.error1", cn,
                        cnfe.getClass().getCanonicalName(), cnfe.getMessage());
            }
        }
    } catch (LinkageError le) {
        abort(le, "java.launcher.cls.error6", cn,
                le.getClass().getName() + ": " + le.getLocalizedMessage());
    }
    return mainClass;
}
 
Example 17
Source File: LauncherHelper.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method does the following:
 * 1. gets the classname from a Jar's manifest, if necessary
 * 2. loads the class using the System ClassLoader
 * 3. ensures the availability and accessibility of the main method,
 *    using signatureDiagnostic method.
 *    a. does the class exist
 *    b. is there a main
 *    c. is the main public
 *    d. is the main static
 *    e. does the main take a String array for args
 * 4. if no main method and if the class extends FX Application, then call
 *    on FXHelper to determine the main class to launch
 * 5. and off we go......
 *
 * @param printToStderr if set, all output will be routed to stderr
 * @param mode LaunchMode as determined by the arguments passed on the
 * command line
 * @param what either the jar file to launch or the main class when using
 * LM_CLASS mode
 * @return the application's main class
 */
public static Class<?> checkAndLoadMain(boolean printToStderr,
                                        int mode,
                                        String what) {
    initOutput(printToStderr);
    // get the class name
    String cn = null;
    switch (mode) {
        case LM_CLASS:
            cn = what;
            break;
        case LM_JAR:
            cn = getMainClassFromJar(what);
            break;
        default:
            // should never happen
            throw new InternalError("" + mode + ": Unknown launch mode");
    }
    cn = cn.replace('/', '.');
    Class<?> mainClass = null;
    try {
        mainClass = scloader.loadClass(cn);
    } catch (NoClassDefFoundError | ClassNotFoundException cnfe) {
        if (System.getProperty("os.name", "").contains("OS X")
            && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) {
            try {
                // On Mac OS X since all names with diacretic symbols are given as decomposed it
                // is possible that main class name comes incorrectly from the command line
                // and we have to re-compose it
                mainClass = scloader.loadClass(Normalizer.normalize(cn, Normalizer.Form.NFC));
            } catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
                abort(cnfe, "java.launcher.cls.error1", cn);
            }
        } else {
            abort(cnfe, "java.launcher.cls.error1", cn);
        }
    }
    // set to mainClass
    appClass = mainClass;

    /*
     * Check if FXHelper can launch it using the FX launcher. In an FX app,
     * the main class may or may not have a main method, so do this before
     * validating the main class.
     */
    if (mainClass.equals(FXHelper.class) ||
            FXHelper.doesExtendFXApplication(mainClass)) {
        // Will abort() if there are problems with the FX runtime
        FXHelper.setFXLaunchParameters(what, mode);
        return FXHelper.class;
    }

    validateMainClass(mainClass);
    return mainClass;
}
 
Example 18
Source File: Payments.java    From SwissQRBill with MIT License 4 votes vote down vote up
private static void cleanValue(String value, CleaningResult result, boolean isNormalized) {
    /* This code has cognitive complexity 30. Deal with it. */
    if (value == null)
        return;

    int len = value.length(); // length of value
    boolean justProcessedSpace = false; // flag indicating whether we've just processed a space character
    StringBuilder sb = null; // String builder for result
    int lastCopiedPos = 0; // last position (excluding) copied to the result

    // String processing pattern: Iterate all characters and focus on runs of valid
    // characters that can simply be copied. If all characters are valid, no memory
    // is allocated.
    int pos = 0;
    while (pos < len) {
        char ch = value.charAt(pos); // current character

        if (Payments.isValidQRBillCharacter(ch)) {
            justProcessedSpace = ch == ' ';
            pos++;
            continue;
        }

        // Check for normalization
        if (ch > 0xff && !isNormalized) {
            isNormalized = Normalizer.isNormalized(value, Normalizer.Form.NFC);
            if (!isNormalized) {
                // Normalize string and start over
                value = Normalizer.normalize(value, Normalizer.Form.NFC);
                cleanValue(value, result, true);
                return;
            }
        }

        if (sb == null)
            sb = new StringBuilder(value.length());

        // copy processed characters to result before taking care of the invalid
        // character
        if (pos > lastCopiedPos)
            sb.append(value, lastCopiedPos, pos);

        if (Character.isHighSurrogate(ch)) {
            // Proper Unicode handling to prevent surrogates and combining characters
            // from being replaced with multiples periods.
            int codePoint = value.codePointAt(pos);
            if (Character.getType(codePoint) != Character.COMBINING_SPACING_MARK)
                sb.append('.');
            justProcessedSpace = false;
            pos++;
        } else {
            if (ch <= ' ') {
                if (!justProcessedSpace)
                    sb.append(' ');
                justProcessedSpace = true;
            } else {
                sb.append('.');
                justProcessedSpace = false;
            }
        }
        pos++;
        lastCopiedPos = pos;
    }

    if (sb == null) {
        result.cleanedString = value.trim();
        return;
    }

    if (lastCopiedPos < len)
        sb.append(value, lastCopiedPos, len);

    result.cleanedString = sb.toString().trim();
    result.replacedUnsupportedChars = true;
}
 
Example 19
Source File: LauncherHelper.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method does the following:
 * 1. gets the classname from a Jar's manifest, if necessary
 * 2. loads the class using the System ClassLoader
 * 3. ensures the availability and accessibility of the main method,
 *    using signatureDiagnostic method.
 *    a. does the class exist
 *    b. is there a main
 *    c. is the main public
 *    d. is the main static
 *    e. does the main take a String array for args
 * 4. if no main method and if the class extends FX Application, then call
 *    on FXHelper to determine the main class to launch
 * 5. and off we go......
 *
 * @param printToStderr if set, all output will be routed to stderr
 * @param mode LaunchMode as determined by the arguments passed on the
 * command line
 * @param what either the jar file to launch or the main class when using
 * LM_CLASS mode
 * @return the application's main class
 */
public static Class<?> checkAndLoadMain(boolean printToStderr,
                                        int mode,
                                        String what) {
    initOutput(printToStderr);
    // get the class name
    String cn = null;
    switch (mode) {
        case LM_CLASS:
            cn = what;
            break;
        case LM_JAR:
            cn = getMainClassFromJar(what);
            break;
        default:
            // should never happen
            throw new InternalError("" + mode + ": Unknown launch mode");
    }
    cn = cn.replace('/', '.');
    Class<?> mainClass = null;
    try {
        mainClass = scloader.loadClass(cn);
    } catch (NoClassDefFoundError | ClassNotFoundException cnfe) {
        if (System.getProperty("os.name", "").contains("OS X")
            && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) {
            try {
                // On Mac OS X since all names with diacretic symbols are given as decomposed it
                // is possible that main class name comes incorrectly from the command line
                // and we have to re-compose it
                mainClass = scloader.loadClass(Normalizer.normalize(cn, Normalizer.Form.NFC));
            } catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
                abort(cnfe, "java.launcher.cls.error1", cn);
            }
        } else {
            abort(cnfe, "java.launcher.cls.error1", cn);
        }
    }
    // set to mainClass
    appClass = mainClass;

    /*
     * Check if FXHelper can launch it using the FX launcher. In an FX app,
     * the main class may or may not have a main method, so do this before
     * validating the main class.
     */
    if (mainClass.equals(FXHelper.class) ||
            FXHelper.doesExtendFXApplication(mainClass)) {
        // Will abort() if there are problems with the FX runtime
        FXHelper.setFXLaunchParameters(what, mode);
        return FXHelper.class;
    }

    validateMainClass(mainClass);
    return mainClass;
}
 
Example 20
Source File: LauncherHelper.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method does the following:
 * 1. gets the classname from a Jar's manifest, if necessary
 * 2. loads the class using the System ClassLoader
 * 3. ensures the availability and accessibility of the main method,
 *    using signatureDiagnostic method.
 *    a. does the class exist
 *    b. is there a main
 *    c. is the main public
 *    d. is the main static
 *    e. does the main take a String array for args
 * 4. if no main method and if the class extends FX Application, then call
 *    on FXHelper to determine the main class to launch
 * 5. and off we go......
 *
 * @param printToStderr if set, all output will be routed to stderr
 * @param mode LaunchMode as determined by the arguments passed on the
 * command line
 * @param what either the jar file to launch or the main class when using
 * LM_CLASS mode
 * @return the application's main class
 */
public static Class<?> checkAndLoadMain(boolean printToStderr,
                                        int mode,
                                        String what) {
    initOutput(printToStderr);
    // get the class name
    String cn = null;
    switch (mode) {
        case LM_CLASS:
            cn = what;
            break;
        case LM_JAR:
            cn = getMainClassFromJar(what);
            break;
        default:
            // should never happen
            throw new InternalError("" + mode + ": Unknown launch mode");
    }
    cn = cn.replace('/', '.');
    Class<?> mainClass = null;
    try {
        mainClass = scloader.loadClass(cn);
    } catch (NoClassDefFoundError | ClassNotFoundException cnfe) {
        if (System.getProperty("os.name", "").contains("OS X")
            && Normalizer.isNormalized(cn, Normalizer.Form.NFD)) {
            try {
                // On Mac OS X since all names with diacretic symbols are given as decomposed it
                // is possible that main class name comes incorrectly from the command line
                // and we have to re-compose it
                mainClass = scloader.loadClass(Normalizer.normalize(cn, Normalizer.Form.NFC));
            } catch (NoClassDefFoundError | ClassNotFoundException cnfe1) {
                abort(cnfe, "java.launcher.cls.error1", cn);
            }
        } else {
            abort(cnfe, "java.launcher.cls.error1", cn);
        }
    }
    // set to mainClass
    appClass = mainClass;

    /*
     * Check if FXHelper can launch it using the FX launcher. In an FX app,
     * the main class may or may not have a main method, so do this before
     * validating the main class.
     */
    if (mainClass.equals(FXHelper.class) ||
            FXHelper.doesExtendFXApplication(mainClass)) {
        // Will abort() if there are problems with the FX runtime
        FXHelper.setFXLaunchParameters(what, mode);
        return FXHelper.class;
    }

    validateMainClass(mainClass);
    return mainClass;
}