Search in sources :

Example 1 with LightweightException

use of org.eclipse.n4js.utils.LightweightException in project n4js by eclipse.

the class NpmPackageToProjectAdapter method computeMainModule.

String computeMainModule(File projectFolder) {
    String mainModule = resolveMainModule(projectFolder);
    if (Strings.isNullOrEmpty(mainModule))
        return mainModule;
    File main = new File(mainModule);
    if (!main.isFile()) {
        throw Exceptions.sneakyThrow(new LightweightException("Cannot locate main module with path " + main.toString()));
    }
    Path packagePath = projectFolder.toPath();
    Path packageMainModulePath = main.toPath();
    Path mainmoduleRelative = packagePath.relativize(packageMainModulePath);
    String mainSpecifier = mainmoduleRelative.toString();
    // strip extension
    int dotIndex = mainSpecifier.lastIndexOf('.');
    String ext = (dotIndex == -1) ? "" : mainSpecifier.substring(dotIndex);
    mainSpecifier = mainSpecifier.substring(0, (mainSpecifier.length() - ext.length()));
    // replace windows path separators
    if (OSInfo.isWindows())
        mainSpecifier = mainSpecifier.replace(File.separator, "/");
    // strip relative start part
    if (mainSpecifier.startsWith("./"))
        mainSpecifier = mainSpecifier.substring(2);
    return mainSpecifier;
}
Also used : Path(java.nio.file.Path) LightweightException(org.eclipse.n4js.utils.LightweightException) File(java.io.File)

Aggregations

File (java.io.File)1 Path (java.nio.file.Path)1 LightweightException (org.eclipse.n4js.utils.LightweightException)1