Example usage for org.eclipse.jdt.internal.compiler.env AutomaticModuleNaming determineAutomaticModuleName

List of usage examples for org.eclipse.jdt.internal.compiler.env AutomaticModuleNaming determineAutomaticModuleName

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.env AutomaticModuleNaming determineAutomaticModuleName.

Prototype

public static char[] determineAutomaticModuleName(final String jarFileName) 

Source Link

Document

Determine the automatic module name of a given jar as specified in <a href= * "http://download.java.net/java/jdk9/docs/api/java/lang/module/ModuleFinder.html#of-java.nio.file.Path...-"> * ModuleFinder.of</a>

Usage

From source file:org.eclipse.m2e.jdt.internal.InternalModuleSupport.java

License:Open Source License

private static String getModuleNameFromJar(File file) {
    if (!file.isFile()) {
        return null;
    }/*from  w  w  w .j av  a2 s  .co m*/
    char[] moduleName = null;
    try (ZipFile zipFile = new ZipFile(file)) {
        IModule module = null;
        ClassFileReader reader = ClassFileReader.read(zipFile, IModule.MODULE_INFO_CLASS);
        if (reader != null) {
            module = reader.getModuleDeclaration();
            if (module != null) {
                moduleName = module.name();
            }
        }
    } catch (ClassFormatException | IOException ex) {
        log.error(ex.getMessage(), ex);
    }
    if (moduleName == null) {
        moduleName = AutomaticModuleNaming.determineAutomaticModuleName(file.getAbsolutePath());
    }
    return new String(moduleName);
}