private void processHybrisConfigAutoloadPaths()

in src/com/intellij/idea/plugin/hybris/project/descriptors/DefaultHybrisProjectDescriptor.java [307:366]


    private void processHybrisConfigAutoloadPaths(final Hybrisconfig hybrisconfig, final TreeSet<String> explicitlyDefinedModules) {
        if (getHybrisDistributionDirectory() == null) return;

        final var autoloadPaths = new HashMap<String, Integer>();

        hybrisconfig.getExtensions().getPath().stream()
            .filter(ScanType::isAutoload)
            .filter(it -> it.getDir() != null)
            .forEach(it -> {
                final var depth = it.getDepth();
                final var dir = it.getDir();

                if (depth == null) {
                    autoloadPaths.put(dir, HybrisConstants.DEFAULT_EXTENSIONS_PATH_DEPTH);
                } else if (depth > 0) {
                    if (!autoloadPaths.containsKey(dir)) {
                        autoloadPaths.put(dir, depth);
                    } else {
                        autoloadPaths.computeIfPresent(dir, (s, oldValue) -> Math.max(oldValue, depth));
                    }
                }
            });

        if (autoloadPaths.isEmpty()) return;

        final var platform = Paths.get(getHybrisDistributionDirectory().getPath(), HybrisConstants.PLATFORM_MODULE_PREFIX).toString();
        final var path = Paths.get(platform, "env.properties");

        try (final var fis = Files.newBufferedReader(path, StandardCharsets.ISO_8859_1)) {
            final var properties = PropertiesUtil.loadProperties(fis);
            properties.entrySet().forEach(entry -> {
                final var value = entry.getValue().replace("${platformhome}", platform);
                entry.setValue(Paths.get(value).normalize().toString());
            });
            properties.put("platformhome", platform);

            final var normalizedPaths = autoloadPaths.entrySet().stream().collect(Collectors.toMap(entry -> {
                for (final var property : properties.entrySet()) {
                    if (entry.getKey().contains("${" + property.getKey() + '}')) {
                        return Paths.get(entry.getKey().replace("${" + property.getKey() + '}', property.getValue())).normalize().toString();
                    }
                }
                return Paths.get(entry.getKey()).normalize().toString();
            }, Map.Entry::getValue));

            foundModules.forEach(it -> {
                for (final var entry : normalizedPaths.entrySet()) {
                    final var moduleDir = it.getModuleRootDirectory().getPath();
                    if (moduleDir.startsWith(entry.getKey())
                        && Paths.get(moduleDir.substring(entry.getKey().length())).getNameCount() <= entry.getValue()
                    ) {
                        explicitlyDefinedModules.add(it.getName());
                        break;
                    }
                }
            });
        } catch (IOException e) {
            // NOP
        }
    }