Skip to content

Commit

Permalink
Enable bootdelegation for atlassian products (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbarny authored Nov 26, 2018
1 parent 93779a8 commit e6de679
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import co.elastic.apm.context.LifecycleListener;
import co.elastic.apm.impl.ElasticApmTracer;

import java.util.Arrays;
import java.util.List;

/**
* Required in OSGi environments like Equinox, which is used in WebSphere.
* By adding the base package of the APM agent,
Expand All @@ -34,16 +37,18 @@
* </p>
*/
public class OsgiBootDelegationEnabler implements LifecycleListener {
private static final String OSGI_BOOTDELEGATION = "org.osgi.framework.bootdelegation";
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.*";

@Override
public void start(ElasticApmTracer tracer) {
final String systemPackages = System.getProperty(OSGI_BOOTDELEGATION);
if (systemPackages != null) {
System.setProperty(OSGI_BOOTDELEGATION, systemPackages + "," + APM_BASE_PACKAGE);
} else {
System.setProperty(OSGI_BOOTDELEGATION, APM_BASE_PACKAGE);
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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package co.elastic.apm.bci;

import co.elastic.apm.impl.ElasticApmTracer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

class OsgiBootDelegationEnablerTest {

private final OsgiBootDelegationEnabler osgiBootDelegationEnabler = new OsgiBootDelegationEnabler();

@BeforeEach
@AfterEach
void clearState() {
System.clearProperty("org.osgi.framework.bootdelegation");
System.clearProperty("atlassian.org.osgi.framework.bootdelegation");
}

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

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

0 comments on commit e6de679

Please sign in to comment.