diff --git a/.github/workflows/on_release.yml b/.github/workflows/on_release.yml index d27b371..f9bb55b 100644 --- a/.github/workflows/on_release.yml +++ b/.github/workflows/on_release.yml @@ -64,6 +64,9 @@ jobs: distribution: 'temurin' cache: 'maven' + - name: Update java version + run: mvn versions:set -DnewVersion=${VERSION} -B -U + - name: Package project run: mvn clean package -DskipTests -U -B -P cf-it-tests,examples diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eb6b7e..4f77a91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 1.2.1 - (12/03/2024) - **[BUGFIX]**: plugin: fix ColdFusion detection on Windows [#116](https://github.com/intergral/deep/pull/116) [@LMarkie](https://github.com/LMarkie) +- **[BUGFIX]**: plugin: ensure that failed plugins do not block start up [#118](https://github.com/intergral/deep/pull/118) [@Umaaz](https://github.com/Umaaz) # 1.2.0 - (06/02/2024) - **[CHANGE]**: change log config to allow better control of logging [#103](https://github.com/intergral/deep/pull/103) [@Umaaz](https://github.com/Umaaz) diff --git a/agent/src/main/java/com/intergral/deep/agent/plugins/PluginSpiLoader.java b/agent/src/main/java/com/intergral/deep/agent/plugins/PluginSpiLoader.java index 8ec9492..81ddd26 100644 --- a/agent/src/main/java/com/intergral/deep/agent/plugins/PluginSpiLoader.java +++ b/agent/src/main/java/com/intergral/deep/agent/plugins/PluginSpiLoader.java @@ -27,12 +27,16 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This acts as the main loader for plugins using the SPI loader system. */ public final class PluginSpiLoader { + private static final Logger LOGGER = LoggerFactory.getLogger(PluginSpiLoader.class); + private PluginSpiLoader() { } @@ -59,7 +63,12 @@ public static List loadPlugins(final ISettings settings, final IRef .filter(plugin -> !ResourceDetector.isDisabled(plugin.getClass(), enabledProviders, disabledProviders)) .filter(plugin -> { if (plugin instanceof IConditional) { - return ((IConditional) plugin).isActive(); + try { + return ((IConditional) plugin).isActive(); + } catch (Exception e) { + LOGGER.error("Failed to load plugin {}", plugin.getClass().getName(), e); + return false; + } } return true; }) diff --git a/agent/src/test/java/com/intergral/deep/agent/plugins/MockBadPlugin.java b/agent/src/test/java/com/intergral/deep/agent/plugins/MockBadPlugin.java new file mode 100644 index 0000000..fa89d56 --- /dev/null +++ b/agent/src/test/java/com/intergral/deep/agent/plugins/MockBadPlugin.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 Intergral GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.intergral.deep.agent.plugins; + +import com.intergral.deep.agent.api.spi.IConditional; +import com.intergral.deep.agent.api.spi.IDeepPlugin; + +/** + * This is used to test the SPI loder and just throws an exception on activate. + */ +public class MockBadPlugin implements IDeepPlugin, IConditional { + + + @Override + public boolean isActive() { + throw new RuntimeException("test exception"); + } +} diff --git a/agent/src/test/java/com/intergral/deep/agent/plugins/MockPlugin.java b/agent/src/test/java/com/intergral/deep/agent/plugins/MockPlugin.java new file mode 100644 index 0000000..464232e --- /dev/null +++ b/agent/src/test/java/com/intergral/deep/agent/plugins/MockPlugin.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 Intergral GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.intergral.deep.agent.plugins; + +import com.intergral.deep.agent.api.spi.IDeepPlugin; + +/** + * This is used to test the SPI loder and doesn't need to actually do anything. + */ +public class MockPlugin implements IDeepPlugin { + +} diff --git a/agent/src/test/java/com/intergral/deep/agent/plugins/PluginSpiLoaderTest.java b/agent/src/test/java/com/intergral/deep/agent/plugins/PluginSpiLoaderTest.java new file mode 100644 index 0000000..e995ac1 --- /dev/null +++ b/agent/src/test/java/com/intergral/deep/agent/plugins/PluginSpiLoaderTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2024 Intergral GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.intergral.deep.agent.plugins; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.intergral.deep.agent.api.settings.ISettings; +import com.intergral.deep.agent.api.spi.IDeepPlugin; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +class PluginSpiLoaderTest { + + @Test + void loadPlugins() { + final ISettings settings = Mockito.mock(ISettings.class); + final List iDeepPlugins = PluginSpiLoader.loadPlugins(settings, null, null); + assertNotNull(iDeepPlugins); + + assertTrue(iDeepPlugins.size() > 1); + + final Set classNames = iDeepPlugins.stream().map(Object::getClass).map(Class::getName).collect(Collectors.toSet()); + + assertTrue(classNames.contains(MockPlugin.class.getName())); + assertFalse(classNames.contains(MockBadPlugin.class.getName())); + } +} \ No newline at end of file diff --git a/agent/src/test/resources/META-INF/services/com.intergral.deep.agent.api.spi.IDeepPlugin b/agent/src/test/resources/META-INF/services/com.intergral.deep.agent.api.spi.IDeepPlugin new file mode 100644 index 0000000..0c2223a --- /dev/null +++ b/agent/src/test/resources/META-INF/services/com.intergral.deep.agent.api.spi.IDeepPlugin @@ -0,0 +1,18 @@ +# +# Copyright (C) 2024 Intergral GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +com.intergral.deep.agent.plugins.MockPlugin +com.intergral.deep.agent.plugins.MockBadPlugin