aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/main/java/com/yahoo/jdisc/core/FelixParams.java
blob: 02ef454279b2ded7331d0797de981fe775b75905 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.core;

import org.apache.felix.framework.cache.BundleCache;
import org.osgi.framework.Constants;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Simon Thoresen Hult
 */
public class FelixParams {

    private final StringBuilder exportPackages;
    private String cachePath = null;
    private boolean loggerEnabled = true;

    public FelixParams() {
        this(ExportPackages.readExportProperty());
    }

    // For testing only
    // Needed because the set of system packages is no longer constant between JVM invocations,
    // since Felix 6 and JDK 9.
    FelixParams(String exportPackages) {
        this.exportPackages = new StringBuilder(exportPackages);
    }

    public FelixParams exportPackage(String pkg) {
        exportPackages.append(",").append(pkg);
        return this;
    }

    public FelixParams setCachePath(String cachePath) {
        this.cachePath = cachePath;
        return this;
    }

    public String getCachePath() {
        return cachePath;
    }

    public FelixParams setLoggerEnabled(boolean loggerEnabled) {
        this.loggerEnabled = loggerEnabled;
        return this;
    }

    public boolean isLoggerEnabled() {
        return loggerEnabled;
    }

    public Map<String, String> toConfig() {
        Map<String, String> ret = new HashMap<>();
        ret.put(BundleCache.CACHE_ROOTDIR_PROP, cachePath);
        ret.put(Constants.FRAMEWORK_SYSTEMPACKAGES, exportPackages.toString());
        ret.put(Constants.FRAMEWORK_BOOTDELEGATION, "com.yourkit.runtime,com.yourkit.probes,com.yourkit.probes.builtin,com.singularity.*");
        ret.put(Constants.FRAMEWORK_BSNVERSION, Constants.FRAMEWORK_BSNVERSION_MANAGED);
        return ret;
    }
}