private void loadInternal()

in java/main/src/main/java/com/epam/deltix/utilities/ResourceLoader.java [959:1036]


    private void loadInternal() {
        if (null == _resourcePathTemplate)
            throw argException("Resource path is not set, use .from(resourcePathTemplate) to set");

        if (null == _deploymentPathTemplate)
            throw argException("Deployment path is not set, use .to(deploymentPathTemplate) to set");

        if (_alwaysOverwrite && _reusePartiallyDeployed)
            throw argException("AlwaysOverwrite=true is not compatible with ReusePartiallyDeployed=true");

        assert (null != _class);

        // TODO: check normalization
        final String pathStr = _deploymentPathDoSubstitution
                ? getVariablesMapper().substitute(_deploymentPathTemplate) : _deploymentPathTemplate;
        final Path path = Paths.get(pathStr);

        final ArrayList<Path> paths = new ArrayList<>();
        // If user did not specify his preferred deployment root path, prepare our own

        final Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));

        if (!path.isAbsolute()) {
            final VariablesMapper vm = getVariablesMapper();
            final String[] rootPaths = {
                    vm.isOsWindows() ? getenv("ProgramData") : null
                    , vm.isOsWindows() ? getenv("AppData") : null
                    , vm.isOsDarwin() ? System.getProperty("user.home") + "/Library/Application Support" : null
                    , vm.isOsLinux() ? System.getProperty("user.home") + "/.local/share" : null
            };

            for (final String rootPath : rootPaths) {
                if (null != rootPath && 0 != rootPath.length()) {
                    final Path root = Paths.get(rootPath);
                    if (root.isAbsolute() && Files.exists(root))
                        paths.add(root.resolve(path));
                }
            }

            // Temp dir and random subfolders in the temp dir are always enabled
            final Path fallbackPath = tempDir.resolve(path);
            final Path fallbackPath2 = fallbackPath.resolve(nextRandomDirString());
            paths.add(fallbackPath);
            paths.add(fallbackPath2);

            FileJanitor.addCleanupPath(fallbackPath, false, RANDOM_DIR_REGEX);
        } else {
            paths.add(path);
            if (_addRandomFallbackSubDirectory) {
                paths.add(path.resolve(nextRandomDirString()));

                FileJanitor.addCleanupPath(path, false, RANDOM_DIR_REGEX);
            }
        }

        // TODO: verify
        FileJanitor.registerForCleanupOnExit();

        if (LogLevel <= DBG) {
            log("Deployment paths:");
            for (final Path p : paths)
                log("%s", p);
        }
        try {
            if (null == _resources)
                listResources();
        } catch (final URISyntaxException | IOException e) {
            throw new RuntimeException(fmt("Failed to list/scan resources at: %s because: %s", _resourcePathTemplate, e), e);
        }

        for (final Path p : paths) {
            if (tryLoadAt(p))
                return;
        }

        // Failure!
        throw new RuntimeException(fmt("Failed to deploy&load native resources using path: %s", _lastUsedPath), _lastDeploymentException);
    }