<commit_before>package com.yahoo.container.core.config;

import com.yahoo.config.FileReference;
import com.yahoo.osgi.Osgi;
import org.osgi.framework.Bundle;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;

/**
 * Installs all platform bundles, using the {@link DiskBundleInstaller}.
 * All platform bundles reside on disk, and they are never uninstalled.
 *
 * @author gjoranv
 */
public class PlatformBundleLoader {
    private static final Logger log = Logger.getLogger(PlatformBundleLoader.class.getName());

    private final Osgi osgi;
    private final DiskBundleInstaller installer;

    public PlatformBundleLoader(Osgi osgi) {
        this(osgi, new DiskBundleInstaller());
    }

    PlatformBundleLoader(Osgi osgi, DiskBundleInstaller installer) {
        this.osgi = osgi;
        this.installer = installer;
    }

    public void useBundles(List<FileReference> fileReferences) {
        Set<Bundle> installedBundles = install(fileReferences);
        BundleStarter.startBundles(installedBundles);
    }

    private Set<Bundle> install(List<FileReference> bundlesToInstall) {
        var installedBundles = new LinkedHashSet<Bundle>();
        for (FileReference reference : bundlesToInstall) {
            try {
                installedBundles.addAll(installBundleFromDisk(reference));
            }
            catch(Exception e) {
                throw new RuntimeException("Could not install bundle '" + reference + "'", e);
            }
        }
        return installedBundles;
    }

    private List<Bundle> installBundleFromDisk(FileReference reference) {
        log.info("Installing bundle from disk with reference '" + reference.value() + "'");
        List<Bundle> bundles = installer.installBundles(reference, osgi);
        log.fine("Installed " + bundles.size() + " bundles for file reference " + reference);
        return bundles;
    }

}<commit_msg>Ignore later calls to add or alter the set of platform bundles.<commit_after>package com.yahoo.container.core.config;

import com.yahoo.config.FileReference;
import com.yahoo.osgi.Osgi;
import org.osgi.framework.Bundle;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;

/**
 * Used to install the bundles that are added as platform bundles by the config-model.
 *
 * All platform bundles reside on disk, and they are never uninstalled.
 * Platform bundles are allowed to pre-install other bundles on disk via the
 * X-JDisc-Preinstall-Bundle manifest header.
 *
 * After the first time, attempts to install additional bundles should be a NOP.
 *
 * @author gjoranv
 */
public class PlatformBundleLoader {
    private static final Logger log = Logger.getLogger(PlatformBundleLoader.class.getName());

    private final Osgi osgi;
    private final DiskBundleInstaller installer;

    private Set<Bundle> installedBundles;
    private boolean hasLoadedBundles = false;

    public PlatformBundleLoader(Osgi osgi) {
        this(osgi, new DiskBundleInstaller());
    }

    PlatformBundleLoader(Osgi osgi, DiskBundleInstaller installer) {
        this.osgi = osgi;
        this.installer = installer;
    }

    public void useBundles(List<FileReference> fileReferences) {
        if (hasLoadedBundles) {
            log.fine(() -> "Platform bundles have already been installed." +
                    "\nInstalled bundles: " + installedBundles +
                    "\nGiven files: " + fileReferences);
            return;
        }
        installedBundles = install(fileReferences);
        BundleStarter.startBundles(installedBundles);
        hasLoadedBundles = true;
    }

    private Set<Bundle> install(List<FileReference> bundlesToInstall) {
        var allInstalled = new LinkedHashSet<Bundle>();
        for (FileReference reference : bundlesToInstall) {
            try {
                allInstalled.addAll(installBundleFromDisk(reference));
            }
            catch(Exception e) {
                throw new RuntimeException("Could not install bundle '" + reference + "'", e);
            }
        }
        return allInstalled;
    }

    private List<Bundle> installBundleFromDisk(FileReference reference) {
        log.info("Installing bundle from disk with reference '" + reference.value() + "'");
        List<Bundle> bundles = installer.installBundles(reference, osgi);
        log.fine("Installed " + bundles.size() + " bundles for file reference " + reference);
        return bundles;
    }

}
{'fraction_non_alphanumeric': 0.09243326715199647, 'fraction_numerical': 0.0, 'mean_word_length': 3.05183199285076, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4559526', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1186, 'n_words': 321}