Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use atlassian-specific bootdelegation defaults #468

Merged
merged 2 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import co.elastic.apm.agent.context.LifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;

import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;

/**
* Required in OSGi environments like Equinox, which is used in WebSphere.
Expand All @@ -37,18 +36,29 @@
* </p>
*/
public class OsgiBootDelegationEnabler implements LifecycleListener {
private static final List<String> bootdelegationNames = Arrays.asList("org.osgi.framework.bootdelegation", "atlassian.org.osgi.framework.bootdelegation");
private static final String APM_BASE_PACKAGE = "co.elastic.apm.agent.*";
// see https://confluence.atlassian.com/jirakb/using-javaagent-with-jira-790793295.html#UsingjavaagentwithJIRA-Resolution
private static final String ATLASSIAN_BOOTDELEGATION_DEFAULTS = "META-INF.services,com.yourkit,com.singularity.*,com.jprofiler," +
"com.jprofiler.*,org.apache.xerces,org.apache.xerces.*,org.apache.xalan,org.apache.xalan.*,sun.*,com.sun.jndi.*,com.icl.saxon," +
"com.icl.saxon.*,javax.servlet,javax.servlet.*,com.sun.xml.bind.*";

@Override
public void start(ElasticApmTracer tracer) {
for (String bootdelegationName : bootdelegationNames) {
final String systemPackages = System.getProperty(bootdelegationName);
if (systemPackages != null) {
System.setProperty(bootdelegationName, systemPackages + "," + APM_BASE_PACKAGE);
} else {
System.setProperty(bootdelegationName, APM_BASE_PACKAGE);
}
// may be problematic as it could override the defaults in a properties file
appendToSystemProperty("org.osgi.framework.bootdelegation", APM_BASE_PACKAGE);
appendToSystemProperty("atlassian.org.osgi.framework.bootdelegation", ATLASSIAN_BOOTDELEGATION_DEFAULTS, APM_BASE_PACKAGE);
}

private static void appendToSystemProperty(String propertyName, String append) {
appendToSystemProperty(propertyName, null, append);
}

private static void appendToSystemProperty(String propertyName, @Nullable String propertyValueDefault, String append) {
final String systemPackages = System.getProperty(propertyName, propertyValueDefault);
if (systemPackages != null) {
System.setProperty(propertyName, systemPackages + "," + append);
} else {
System.setProperty(propertyName, append);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void testBootdelegation() {
osgiBootDelegationEnabler.start(mock(ElasticApmTracer.class));
assertThat(System.getProperties())
.containsEntry("org.osgi.framework.bootdelegation", "co.elastic.apm.agent.*")
.containsEntry("atlassian.org.osgi.framework.bootdelegation", "co.elastic.apm.agent.*");
.containsKey("atlassian.org.osgi.framework.bootdelegation");
assertThat(System.getProperty("atlassian.org.osgi.framework.bootdelegation")).matches(".+,co.elastic.apm.agent.*");
}

@Test
Expand All @@ -52,6 +53,14 @@ void testBootdelegationWithExistingProperty() {
osgiBootDelegationEnabler.start(mock(ElasticApmTracer.class));
assertThat(System.getProperties())
.containsEntry("org.osgi.framework.bootdelegation", "foo.bar,co.elastic.apm.agent.*")
.containsEntry("atlassian.org.osgi.framework.bootdelegation", "co.elastic.apm.agent.*");
.containsKey("atlassian.org.osgi.framework.bootdelegation");
}

@Test
void testAtlassianBootdelegationWithExistingProperty() {
System.setProperty("atlassian.org.osgi.framework.bootdelegation", "foo.bar");
osgiBootDelegationEnabler.start(mock(ElasticApmTracer.class));
assertThat(System.getProperties())
.containsEntry("atlassian.org.osgi.framework.bootdelegation", "foo.bar,co.elastic.apm.agent.*");
}
}